ServerEnvironment: Remove direct dependency on EmergeManager
authorkwolekr <kwolekr@minetest.net>
Sun, 9 Feb 2014 21:36:30 +0000 (16:36 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 9 Feb 2014 21:36:30 +0000 (16:36 -0500)
src/emerge.h
src/environment.cpp
src/environment.h
src/map.cpp
src/map.h
src/server.cpp

index 14a2728baa457c264a8ffecae8336c98f4c2d003..f3bafc8c8dc0a088d33b28b238cc1b1fce119977 100644 (file)
@@ -70,15 +70,7 @@ struct BlockEmergeData {
        u8 flags;
 };
 
-class IBackgroundBlockEmerger
-{
-public:
-       virtual bool enqueueBlockEmerge(u16 peer_id, v3s16 p,
-                       bool allow_generate) = 0;
-       virtual ~IBackgroundBlockEmerger() {}
-};
-
-class EmergeManager : public IBackgroundBlockEmerger {
+class EmergeManager {
 public:
        INodeDefManager *ndef;
 
index aea3afeaa9b25540617e89952bb337eace73c020..08564046e9706b72d30461e47024f85317255f4d 100644 (file)
@@ -312,12 +312,10 @@ void ActiveBlockList::update(std::list<v3s16> &active_positions,
 */
 
 ServerEnvironment::ServerEnvironment(ServerMap *map,
-               GameScripting *scriptIface,
-               IGameDef *gamedef, IBackgroundBlockEmerger *emerger):
+               GameScripting *scriptIface, IGameDef *gamedef):
        m_map(map),
        m_script(scriptIface),
        m_gamedef(gamedef),
-       m_emerger(emerger),
        m_random_spawn_timer(3),
        m_send_recommended_timer(0),
        m_active_block_interval_overload_skip(0),
@@ -1148,11 +1146,8 @@ void ServerEnvironment::step(float dtime)
                {
                        v3s16 p = *i;
 
-                       MapBlock *block = m_map->getBlockNoCreateNoEx(p);
+                       MapBlock *block = m_map->getBlockOrEmerge(p);
                        if(block==NULL){
-                               // Block needs to be fetched first
-                               m_emerger->enqueueBlockEmerge(
-                                               PEER_ID_INEXISTENT, p, false);
                                m_active_blocks.m_list.erase(p);
                                continue;
                        }
index ffd4a15541e61fa91e647558780ace04a9e55261..9e282476fd82a34399c10f06ac6d0e2cf7b4d462 100644 (file)
@@ -44,7 +44,6 @@ class ActiveBlockModifier;
 class ServerActiveObject;
 class ITextureSource;
 class IGameDef;
-class IBackgroundBlockEmerger;
 class Map;
 class ServerMap;
 class ClientMap;
@@ -194,8 +193,7 @@ class ServerEnvironment : public Environment
 {
 public:
        ServerEnvironment(ServerMap *map, GameScripting *scriptIface,
-                       IGameDef *gamedef,
-                       IBackgroundBlockEmerger *emerger);
+                       IGameDef *gamedef);
        ~ServerEnvironment();
 
        Map & getMap();
@@ -367,8 +365,6 @@ private:
        GameScripting* m_script;
        // Game definition
        IGameDef *m_gamedef;
-       // Background block emerger (the EmergeManager, in practice)
-       IBackgroundBlockEmerger *m_emerger;
        // Active object list
        std::map<u16, ServerActiveObject*> m_active_objects;
        // Outgoing network message buffer for active objects
index 075649f94966cf2821579be45d14857c784bc70d..22ea41e04d0431fcc48e54256282db59b8ed63cc 100644 (file)
@@ -3126,7 +3126,9 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
 
                return block;
        }
-       /*if(allow_generate)
+
+#if 0
+       if(allow_generate)
        {
                std::map<v3s16, MapBlock*> modified_blocks;
                MapBlock *block = generateBlock(p, modified_blocks);
@@ -3149,11 +3151,21 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
 
                        return block;
                }
-       }*/
+       }
+#endif
 
        return NULL;
 }
 
+MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d)
+{
+       MapBlock *block = getBlockNoCreateNoEx(p3d);
+       if (block == NULL)
+               m_emerge->enqueueBlockEmerge(PEER_ID_INEXISTENT, p3d, false);
+
+       return block;
+}
+
 void ServerMap::prepareBlock(MapBlock *block) {
        ServerEnvironment *senv = &((Server *)m_gamedef)->getEnv();
 
index 54d8fe9eaf30b1c83524861494084d942de47b74..191cf5f94b4f437a1bc750ce7d014098548c2292 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -424,6 +424,14 @@ public:
        */
        MapBlock * emergeBlock(v3s16 p, bool create_blank=true);
        
+       /*
+               Try to get a block.
+               If it does not exist in memory, add it to the emerge queue.
+               - Memory
+               - Emerge Queue (deferred disk or generate)
+       */
+       MapBlock *getBlockOrEmerge(v3s16 p3d);
+
        // Carries out any initialization necessary before block is sent
        void prepareBlock(MapBlock *block);
 
index 151bcada13b0fd70a2cb1dd44018734cec66dcdc..66f3cc1a74d058600e4a5af05f4960b427ef2c9d 100644 (file)
@@ -343,7 +343,7 @@ Server::Server(
 
        // Initialize Environment
        ServerMap *servermap = new ServerMap(path_world, this, m_emerge);
-       m_env = new ServerEnvironment(servermap, m_script, this, m_emerge);
+       m_env = new ServerEnvironment(servermap, m_script, this);
 
        m_clients.setEnv(m_env);