Make players be again visible from a long distance
authorPerttu Ahola <celeron55@gmail.com>
Thu, 1 Dec 2011 23:08:14 +0000 (01:08 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 1 Dec 2011 23:08:14 +0000 (01:08 +0200)
src/environment.cpp
src/player.cpp
src/player.h
src/serverobject.h

index 17c9ecfffc69755ca4b5094f4143aeaf105741d6..e8dfebcb363988b43a730457a45ced35f3feb266 100644 (file)
@@ -1217,10 +1217,12 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
                // Discard if removed
                if(object->m_removed)
                        continue;
-               // Discard if too far
-               f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
-               if(distance_f > radius_f)
-                       continue;
+               if(object->unlimitedTransferDistance() == false){
+                       // Discard if too far
+                       f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
+                       if(distance_f > radius_f)
+                               continue;
+               }
                // Discard if already on current_objects
                core::map<u16, bool>::Node *n;
                n = current_objects.find(id);
@@ -1255,24 +1257,33 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
        {
                u16 id = i.getNode()->getKey();
                ServerActiveObject *object = getActiveObject(id);
-               if(object == NULL)
-               {
+
+               if(object == NULL){
                        infostream<<"ServerEnvironment::getRemovedActiveObjects():"
                                        <<" object in current_objects is NULL"<<std::endl;
+                       removed_objects.insert(id, false);
+                       continue;
                }
-               else if(object->m_removed == false)
+
+               if(object->m_removed)
                {
-                       f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
-                       /*infostream<<"removed == false"
-                                       <<"distance_f = "<<distance_f
-                                       <<", radius_f = "<<radius_f<<std::endl;*/
-                       if(distance_f < radius_f)
-                       {
-                               // Not removed
-                               continue;
-                       }
+                       removed_objects.insert(id, false);
+                       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, false);
+                       continue;
                }
-               removed_objects.insert(id, false);
+               
+               // Not removed
        }
 }
 
index 8825668968c0fe510911d35c6687f22f688905ee..f22eddfc1b7da845770691f6ef3ed8895535ee8e 100644 (file)
@@ -242,6 +242,11 @@ void ServerRemotePlayer::removingFromEnvironment()
        m_is_in_environment = false;
 }
 
+bool ServerRemotePlayer::unlimitedTransferDistance() const
+{
+       return true;
+}
+
 void ServerRemotePlayer::step(float dtime, bool send_recommended)
 {
        if(send_recommended == false)
index c9dbe76bb93858f6b7f14b54aa4a547387076f31..cfd59d6cabf812909e63e739b43f26ea1f00b9e6 100644 (file)
@@ -216,6 +216,9 @@ public:
        
        bool environmentDeletes() const
        { return false; }
+
+       virtual bool unlimitedTransferDistance() const;
+       
        bool isStaticAllowed() const
        { return false; }
 
index 1386136cebdb6a7551476727a17cfe73c55df533..fd8a51a9e06d716f7145aa2a9439ded617a669eb 100644 (file)
@@ -63,6 +63,9 @@ 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,