Replace setting unlimited_player_transfer_distance with player_transfer_distance

This commit is contained in:
SmallJoker 2014-11-08 14:35:55 +01:00 committed by Kahrl
parent 96fcca4ea0
commit c40e993ce4
9 changed files with 42 additions and 28 deletions

View File

@ -295,7 +295,10 @@
# See /privs in game for a full list on your server and mod configuration.
#default_privs = interact, shout
# Whether players are shown to clients without any range limit
# deprecated, use the setting player_transfer_distance instead
#unlimited_player_transfer_distance = true
# Defines the maximal player transfer distance in blocks (0 = unlimited)
#player_transfer_distance = 0
# Whether to enable players killing each other
#enable_pvp = true
# If this is set, players will always (re)spawn at the given position

View File

@ -1038,11 +1038,6 @@ bool PlayerSAO::isStaticAllowed() const
return false;
}
bool PlayerSAO::unlimitedTransferDistance() const
{
return g_settings->getBool("unlimited_player_transfer_distance");
}
std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
{
std::ostringstream os(std::ios::binary);

View File

@ -171,7 +171,6 @@ public:
void addedToEnvironment(u32 dtime_s);
void removingFromEnvironment();
bool isStaticAllowed() const;
bool unlimitedTransferDistance() const;
std::string getClientInitializationData(u16 protocol_version);
std::string getStaticData();
bool isAttached();

View File

@ -202,7 +202,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("give_initial_stuff", "false");
settings->setDefault("default_password", "");
settings->setDefault("default_privs", "interact, shout");
settings->setDefault("unlimited_player_transfer_distance", "true");
settings->setDefault("player_transfer_distance", "0");
settings->setDefault("enable_pvp", "true");
settings->setDefault("disallow_empty_password", "false");
settings->setDefault("disable_anticheat", "false");

View File

@ -1345,11 +1345,17 @@ bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj)
inside a radius around a position
*/
void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
s16 player_radius,
std::set<u16> &current_objects,
std::set<u16> &added_objects)
{
v3f pos_f = intToFloat(pos, BS);
f32 radius_f = radius * BS;
f32 player_radius_f = player_radius * BS;
if (player_radius_f < 0)
player_radius_f = 0;
/*
Go through the object list,
- discard m_removed objects,
@ -1369,12 +1375,15 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
// Discard if removed or deactivating
if(object->m_removed || object->m_pending_deactivation)
continue;
if(object->unlimitedTransferDistance() == false){
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
if (object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
// Discard if too far
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
if(distance_f > radius_f)
if (distance_f > player_radius_f && player_radius_f != 0)
continue;
}
} else if (distance_f > radius_f)
continue;
// Discard if already on current_objects
std::set<u16>::iterator n;
n = current_objects.find(id);
@ -1390,11 +1399,17 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
inside a radius around a position
*/
void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
s16 player_radius,
std::set<u16> &current_objects,
std::set<u16> &removed_objects)
{
v3f pos_f = intToFloat(pos, BS);
f32 radius_f = radius * BS;
f32 player_radius_f = player_radius * BS;
if (player_radius_f < 0)
player_radius_f = 0;
/*
Go through current_objects; object is removed if:
- object is not found in m_active_objects (this is actually an
@ -1423,19 +1438,15 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
continue;
}
// If transfer distance is unlimited, don't remove
if(object->unlimitedTransferDistance())
continue;
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
if(distance_f >= radius_f)
{
removed_objects.insert(id);
if (object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
if (distance_f <= player_radius_f || player_radius_f == 0)
continue;
} else if (distance_f <= radius_f)
continue;
}
// Not removed
// Object is no longer visible
removed_objects.insert(id);
}
}

View File

@ -259,6 +259,7 @@ public:
inside a radius around a position
*/
void getAddedActiveObjects(v3s16 pos, s16 radius,
s16 player_radius,
std::set<u16> &current_objects,
std::set<u16> &added_objects);
@ -267,6 +268,7 @@ public:
inside a radius around a position
*/
void getRemovedActiveObjects(v3s16 pos, s16 radius,
s16 player_radius,
std::set<u16> &current_objects,
std::set<u16> &removed_objects);

View File

@ -707,7 +707,14 @@ void Server::AsyncRunStep(bool initial_step)
// Radius inside which objects are active
s16 radius = g_settings->getS16("active_object_send_range_blocks");
s16 player_radius = g_settings->getS16("player_transfer_distance");
if (player_radius == 0 && g_settings->exists("unlimited_player_transfer_distance") &&
!g_settings->getBool("unlimited_player_transfer_distance"))
player_radius = radius;
radius *= MAP_BLOCKSIZE;
player_radius *= MAP_BLOCKSIZE;
for(std::map<u16, RemoteClient*>::iterator
i = clients.begin();
@ -733,9 +740,9 @@ void Server::AsyncRunStep(bool initial_step)
std::set<u16> removed_objects;
std::set<u16> added_objects;
m_env->getRemovedActiveObjects(pos, radius,
m_env->getRemovedActiveObjects(pos, radius, player_radius,
client->m_known_objects, removed_objects);
m_env->getAddedActiveObjects(pos, radius,
m_env->getAddedActiveObjects(pos, radius, player_radius,
client->m_known_objects, added_objects);
// Ignore if nothing happened

View File

@ -229,7 +229,7 @@ void sendAnnounce(const std::string &action,
server["rollback"] = g_settings->getBool("enable_rollback_recording");
server["mapgen"] = g_settings->get("mg_name");
server["privs"] = g_settings->get("default_privs");
server["can_see_far_names"] = g_settings->getBool("unlimited_player_transfer_distance");
server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
server["mods"] = Json::Value(Json::arrayValue);
for (std::vector<ModSpec>::const_iterator it = mods.begin();
it != mods.end();

View File

@ -69,9 +69,6 @@ public:
// environment
virtual bool environmentDeletes() const
{ return true; }
virtual bool unlimitedTransferDistance() const
{ return false; }
// Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type,