Fixed objects being sometimes not able to be stored statically in a block when block...
authorPerttu Ahola <celeron55@gmail.com>
Fri, 1 Jul 2011 18:04:40 +0000 (21:04 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 1 Jul 2011 18:04:40 +0000 (21:04 +0300)
src/environment.cpp
src/main.cpp
src/map.cpp
src/map.h
src/server.cpp

index ac69c8ae28798690d3fb9f6b4cefe05f09fba086..ac78107a3d641196922312540950210e0d5ab400 100644 (file)
@@ -1177,7 +1177,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
                        block->setChangedFlag();
        }
        else{
-               dstream<<"WARNING: Server: Could not find a block for "
+               dstream<<"WARNING: ServerEnv: Could not find a block for "
                                <<"storing newly added static active object"<<std::endl;
        }
 
@@ -1349,7 +1349,20 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
                StaticObject s_obj(obj->getType(), objectpos, staticdata);
                // Add to the block where the object is located in
                v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
-               MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
+               // Get or generate the block
+               MapBlock *block = m_map->emergeBlock(blockpos);
+
+               /*MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
+               if(block == NULL)
+               {
+                       // Block not found. Is the old block still ok?
+                       if(oldblock)
+                               block = oldblock;
+                       // Load from disk or generate
+                       else
+                               block = m_map->emergeBlock(blockpos);
+               }*/
+
                if(block)
                {
                        block->m_static_objects.insert(0, s_obj);
@@ -1357,17 +1370,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
                        obj->m_static_exists = true;
                        obj->m_static_block = block->getPos();
                }
-               // If not possible, add back to previous block
-               else if(oldblock)
-               {
-                       oldblock->m_static_objects.insert(0, s_obj);
-                       oldblock->setChangedFlag();
-                       obj->m_static_exists = true;
-                       obj->m_static_block = oldblock->getPos();
-               }
                else{
-                       dstream<<"WARNING: Server: Could not find a block for "
-                                       <<"storing static object"<<std::endl;
+                       dstream<<"WARNING: ServerEnv: Could not find or generate "
+                                       <<"a block for storing static object"<<std::endl;
                        obj->m_static_exists = false;
                        continue;
                }
index cd5df666d4c31534994c882a6dcdfd0b2f0ca955..698c5fc712d416b8c1317d80ba84561e98118243 100644 (file)
@@ -126,6 +126,16 @@ SUGG: Erosion simulation at map generation time
        - Simulate rock falling from cliffs when water has removed\r
          enough solid rock from the bottom\r
 \r
+SUGG: For non-mapgen FarMesh: Add a per-sector database to store surface\r
+      stuff as simple flags/values\r
+      - Light?\r
+         - A building?\r
+         And at some point make the server send this data to the client too,\r
+         instead of referring to the noise functions\r
+         - Ground height\r
+         - Surface ground type\r
+         - Trees?\r
+\r
 Gaming ideas:\r
 -------------\r
 \r
@@ -199,12 +209,13 @@ SUGG: Make fetching sector's blocks more efficient when rendering
       sectors that have very large amounts of blocks (on client)\r
          - Is this necessary at all?\r
 \r
-TODO: Flowing water animation\r
-\r
 SUGG: Draw cubes in inventory directly with 3D drawing commands, so that\r
       animating them is easier.\r
 \r
 SUGG: Option for enabling proper alpha channel for textures\r
+\r
+TODO: Flowing water animation\r
+\r
 TODO: A setting for enabling bilinear filtering for textures\r
 \r
 TODO: Better control of draw_control.wanted_max_blocks\r
@@ -321,15 +332,6 @@ TODO: Think about using same bits for material for fences and doors, for
 TODO: Move mineral to param2, increment map serialization version, add\r
       conversion\r
 \r
-TODO: Add a per-sector database to store surface stuff as simple flags/values\r
-      - Light?\r
-         - A building?\r
-         And at some point make the server send this data to the client too,\r
-         instead of referring to the noise functions\r
-         - Ground height\r
-         - Surface ground type\r
-         - Trees?\r
-\r
 TODO: Restart irrlicht completely when coming back to main menu from game.\r
        - This gets rid of everything that is stored in irrlicht's caches.\r
 \r
index 79f2a40aff5e98f1c5e5d2b4b2b58d5a675f5ac4..dc66b4d554d3ad81e691b320dfb34becceee6fea 100644 (file)
@@ -2442,23 +2442,51 @@ MapBlock * ServerMap::createBlock(v3s16 p)
        return block;
 }
 
-#if 0
-MapBlock * ServerMap::emergeBlock(
-               v3s16 p,
-               bool only_from_disk,
-               core::map<v3s16, MapBlock*> &changed_blocks,
-               core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
-)
+MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
 {
-       DSTACKF("%s: p=(%d,%d,%d), only_from_disk=%d",
+       DSTACKF("%s: p=(%d,%d,%d), allow_generate=%d",
                        __FUNCTION_NAME,
-                       p.X, p.Y, p.Z, only_from_disk);
+                       p.X, p.Y, p.Z, allow_generate);
        
-       // This has to be redone or removed
-       assert(0);
+       {
+               MapBlock *block = getBlockNoCreateNoEx(p);
+               if(block)
+                       return block;
+       }
+
+       {
+               MapBlock *block = loadBlock(p);
+               if(block)
+                       return block;
+       }
+
+       if(allow_generate)
+       {
+               core::map<v3s16, MapBlock*> modified_blocks;
+               MapBlock *block = generateBlock(p, modified_blocks);
+               if(block)
+               {
+                       MapEditEvent event;
+                       event.type = MEET_OTHER;
+                       event.p = p;
+
+                       // Copy modified_blocks to event
+                       for(core::map<v3s16, MapBlock*>::Iterator
+                                       i = modified_blocks.getIterator();
+                                       i.atEnd()==false; i++)
+                       {
+                               event.modified_blocks.insert(i.getNode()->getKey(), false);
+                       }
+
+                       // Queue event
+                       dispatchEvent(&event);
+                                                               
+                       return block;
+               }
+       }
+
        return NULL;
 }
-#endif
 
 #if 0
        /*
index 71101b8e41dac60cf10cba1c35141a539da7eb04..a8aa8e6790a32940a16e8f5638165aef1804b910 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -57,7 +57,7 @@ enum MapEditEventType{
        // Node metadata of block changed (not knowing which node exactly)
        // p stores block coordinate
        MEET_BLOCK_NODE_METADATA_CHANGED,
-       // Anything else
+       // Anything else (modified_blocks are set unsent)
        MEET_OTHER
 };
 
@@ -338,24 +338,13 @@ public:
        */
        MapBlock * createBlock(v3s16 p);
 
-#if 0
        /*
-               NOTE: This comment might be outdated
-               
                Forcefully get a block from somewhere.
-
-               InvalidPositionException possible if only_from_disk==true
-               
-               Parameters:
-               changed_blocks: Blocks that have been modified
+               - Memory
+               - Load from disk
+               - Generate
        */
-       MapBlock * emergeBlock(
-                       v3s16 p,
-                       bool only_from_disk,
-                       core::map<v3s16, MapBlock*> &changed_blocks,
-                       core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
-       );
-#endif
+       MapBlock * emergeBlock(v3s16 p, bool allow_generate=true);
        
        // Helper for placing objects on ground level
        s16 findGroundLevel(v2s16 p2d);
index 798f36ac109f3c2d29b91efc19248668a9c40193..c2433e1af033d9fdf6525f3abf60620c2f9170bd 100644 (file)
@@ -1739,6 +1739,7 @@ void Server::AsyncRunStep()
                        */
                        if(far_players.size() > 0)
                        {
+                               // Convert list format to that wanted by SetBlocksNotSent
                                core::map<v3s16, MapBlock*> modified_blocks2;
                                for(core::map<v3s16, bool>::Iterator
                                                i = event->modified_blocks.getIterator();
@@ -1748,6 +1749,7 @@ void Server::AsyncRunStep()
                                        modified_blocks2.insert(p,
                                                        m_env.getMap().getBlockNoCreateNoEx(p));
                                }
+                               // Set blocks not sent
                                for(core::list<u16>::Iterator
                                                i = far_players.begin();
                                                i != far_players.end(); i++)