Skip to content

Commit

Permalink
Replace setting unlimited_player_transfer_distance with player_transf…
Browse files Browse the repository at this point in the history
…er_distance
  • Loading branch information
SmallJoker authored and kahrl committed Nov 8, 2014
1 parent 96fcca4 commit c40e993
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
3 changes: 3 additions & 0 deletions minetest.conf.example
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/content_sao.cpp
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/content_sao.h
Expand Up @@ -171,7 +171,6 @@ class PlayerSAO : public ServerActiveObject
void addedToEnvironment(u32 dtime_s);
void removingFromEnvironment();
bool isStaticAllowed() const;
bool unlimitedTransferDistance() const;
std::string getClientInitializationData(u16 protocol_version);
std::string getStaticData();
bool isAttached();
Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down
41 changes: 26 additions & 15 deletions src/environment.cpp
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/environment.h
Expand Up @@ -259,6 +259,7 @@ class ServerEnvironment : public Environment
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);

Expand All @@ -267,6 +268,7 @@ class ServerEnvironment : public Environment
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);

Expand Down
11 changes: 9 additions & 2 deletions src/server.cpp
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/serverlist.cpp
Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/serverobject.h
Expand Up @@ -69,9 +69,6 @@ class ServerActiveObject : public ActiveObject
// environment
virtual bool environmentDeletes() const
{ return true; }

virtual bool unlimitedTransferDistance() const
{ return false; }

// Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type,
Expand Down

0 comments on commit c40e993

Please sign in to comment.