]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapblockobject.cpp
added dedicated server build without irrlicht
[minetest.git] / src / mapblockobject.cpp
index 985a01dc160ad4d813b60b21bfffedfc96b86771..8b52b9447f36599a916655e88d18b45d116662ba 100644 (file)
@@ -1,5 +1,20 @@
 /*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include "mapblockobject.h"
@@ -33,8 +48,16 @@ void MapBlockObject::setBlockChanged()
 */
 void MovingObject::move(float dtime, v3f acceleration)
 {
-       //m_pos += dtime * 3.0;
-
+       DSTACK("%s: typeid=%i, pos=(%f,%f,%f), speed=(%f,%f,%f)"
+                       ", dtime=%f, acc=(%f,%f,%f)",
+                       __FUNCTION_NAME,
+                       getTypeId(),
+                       m_pos.X, m_pos.Y, m_pos.Z,
+                       m_speed.X, m_speed.Y, m_speed.Z,
+                       dtime,
+                       acceleration.X, acceleration.Y, acceleration.Z
+                       );
+       
        v3s16 oldpos_i = floatToInt(m_pos);
        
        if(m_block->isValidPosition(oldpos_i) == false)
@@ -50,6 +73,16 @@ void MovingObject::move(float dtime, v3f acceleration)
                m_pos += m_speed * dtime;
                return;
        }
+       
+       // Set insane speed to zero
+       // Otherwise there will be divides by zero and other silly stuff
+       if(m_speed.getLength() > 1000.0*BS)
+               m_speed = v3f(0,0,0);
+               
+       // Limit speed to a reasonable value
+       float speed_limit = 20.0*BS;
+       if(m_speed.getLength() > speed_limit)
+               m_speed = m_speed * (speed_limit / m_speed.getLength());
 
        v3f position = m_pos;
        v3f oldpos = position;
@@ -112,9 +145,9 @@ void MovingObject::move(float dtime, v3f acceleration)
                for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
                {
                        try{
-                               if(m_block->getNodeParent(v3s16(x,y,z)).d == MATERIAL_AIR){
+                               if(content_walkable(m_block->getNodeParent(v3s16(x,y,z)).d)
+                                               == false)
                                        continue;
-                               }
                        }
                        catch(InvalidPositionException &e)
                        {
@@ -306,17 +339,7 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                                        " id="<<id
                                        <<std::endl;*/
 
-                       if(type_id == MAPBLOCKOBJECT_TYPE_TEST)
-                       {
-                               // The constructors of objects shouldn't need
-                               // any more parameters than this.
-                               obj = new TestObject(m_block, id, pos);
-                       }
-                       else if(type_id == MAPBLOCKOBJECT_TYPE_TEST2)
-                       {
-                               obj = new Test2Object(m_block, id, pos);
-                       }
-                       else if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
+                       if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
                        {
                                obj = new SignObject(m_block, id, pos);
                        }
@@ -471,40 +494,53 @@ MapBlockObject * MapBlockObjectList::get(s16 id)
 
 void MapBlockObjectList::step(float dtime, bool server)
 {
+       DSTACK(__FUNCTION_NAME);
+       
        JMutexAutoLock lock(m_mutex);
-
+       
        core::map<s16, bool> ids_to_delete;
 
-       for(core::map<s16, MapBlockObject*>::Iterator
-                       i = m_objects.getIterator();
-                       i.atEnd() == false; i++)
        {
-               MapBlockObject *obj = i.getNode()->getValue();
-               
-               if(server)
-               {
-                       bool to_delete = obj->serverStep(dtime);
+               DSTACK("%s: stepping objects", __FUNCTION_NAME);
 
-                       if(to_delete)
-                               ids_to_delete.insert(obj->m_id, true);
-               }
-               else
+               for(core::map<s16, MapBlockObject*>::Iterator
+                               i = m_objects.getIterator();
+                               i.atEnd() == false; i++)
                {
-                       obj->clientStep(dtime);
+                       MapBlockObject *obj = i.getNode()->getValue();
+                       
+                       DSTACK("%s: stepping object type %i", __FUNCTION_NAME,
+                                       obj->getTypeId());
+
+                       if(server)
+                       {
+                               bool to_delete = obj->serverStep(dtime);
+
+                               if(to_delete)
+                                       ids_to_delete.insert(obj->m_id, true);
+                       }
+                       else
+                       {
+                               obj->clientStep(dtime);
+                       }
                }
        }
 
-       // Delete objects in delete queue
-       for(core::map<s16, bool>::Iterator
-                       i = ids_to_delete.getIterator();
-                       i.atEnd() == false; i++)
        {
-               s16 id = i.getNode()->getKey();
+               DSTACK("%s: deleting objects", __FUNCTION_NAME);
 
-               MapBlockObject *obj = m_objects[id];
-               obj->removeFromScene();
-               delete obj;
-               m_objects.remove(id);
+               // Delete objects in delete queue
+               for(core::map<s16, bool>::Iterator
+                               i = ids_to_delete.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       s16 id = i.getNode()->getKey();
+
+                       MapBlockObject *obj = m_objects[id];
+                       obj->removeFromScene();
+                       delete obj;
+                       m_objects.remove(id);
+               }
        }
        
        /*
@@ -513,36 +549,42 @@ void MapBlockObjectList::step(float dtime, bool server)
 
        if(server == false)
                return;
-
-       for(core::map<s16, MapBlockObject*>::Iterator
-                       i = m_objects.getIterator();
-                       i.atEnd() == false; i++)
+       
        {
-               MapBlockObject *obj = i.getNode()->getValue();
+               DSTACK("%s: object wrap loop", __FUNCTION_NAME);
 
-               v3s16 pos_i = floatToInt(obj->m_pos);
-
-               if(m_block->isValidPosition(pos_i))
+               for(core::map<s16, MapBlockObject*>::Iterator
+                               i = m_objects.getIterator();
+                               i.atEnd() == false; i++)
                {
-                       // No wrap
-                       continue;
-               }
+                       MapBlockObject *obj = i.getNode()->getValue();
 
-               bool impossible = wrapObject(obj);
+                       v3s16 pos_i = floatToInt(obj->m_pos);
 
-               if(impossible)
-               {
-                       // No wrap
-                       continue;
-               }
+                       if(m_block->isValidPosition(pos_i))
+                       {
+                               // No wrap
+                               continue;
+                       }
 
-               // Restart find
-               i = m_objects.getIterator();
+                       bool impossible = wrapObject(obj);
+
+                       if(impossible)
+                       {
+                               // No wrap
+                               continue;
+                       }
+
+                       // Restart find
+                       i = m_objects.getIterator();
+               }
        }
 }
 
 bool MapBlockObjectList::wrapObject(MapBlockObject *object)
 {
+       DSTACK(__FUNCTION_NAME);
+       
        // No lock here; this is called so that the lock is already locked.
        //JMutexAutoLock lock(m_mutex);