Modernize client code (#6250)
[oweals/minetest.git] / src / emerge.cpp
index 1c9719c4898104d4e33638d277385aa1817a452b..0fc31e9e168e5927a359f2aab4bec340eecbda47 100644 (file)
@@ -40,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mg_schematic.h"
 #include "nodedef.h"
 #include "profiler.h"
-#include "scripting_game.h"
+#include "scripting_server.h"
 #include "server.h"
 #include "serverobject.h"
 #include "settings.h"
@@ -85,6 +85,31 @@ private:
        friend class EmergeManager;
 };
 
+class MapEditEventAreaIgnorer
+{
+public:
+       MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a):
+               m_ignorevariable(ignorevariable)
+       {
+               if(m_ignorevariable->getVolume() == 0)
+                       *m_ignorevariable = a;
+               else
+                       m_ignorevariable = NULL;
+       }
+
+       ~MapEditEventAreaIgnorer()
+       {
+               if(m_ignorevariable)
+               {
+                       assert(m_ignorevariable->getVolume() != 0);
+                       *m_ignorevariable = VoxelArea();
+               }
+       }
+
+private:
+       VoxelArea *m_ignorevariable;
+};
+
 ////
 //// EmergeManager
 ////
@@ -96,12 +121,10 @@ EmergeManager::EmergeManager(Server *server)
        this->oremgr    = new OreManager(server);
        this->decomgr   = new DecorationManager(server);
        this->schemmgr  = new SchematicManager(server);
-       this->gen_notify_on = 0;
 
        // Note that accesses to this variable are not synchronized.
        // This is because the *only* thread ever starting or stopping
        // EmergeThreads should be the ServerThread.
-       this->m_threads_active = false;
 
        enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
 
@@ -174,6 +197,9 @@ bool EmergeManager::initMapgens(MapgenParams *params)
 
 Mapgen *EmergeManager::getCurrentMapgen()
 {
+       if (!m_threads_active)
+               return NULL;
+
        for (u32 i = 0; i != m_threads.size(); i++) {
                if (m_threads[i]->isCurrentThread())
                        return m_threads[i]->m_mapgen;
@@ -372,7 +398,7 @@ bool EmergeManager::pushBlockEmergeData(
 bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata)
 {
        std::map<v3s16, BlockEmergeData>::iterator it;
-       UNORDERED_MAP<u16, u16>::iterator it2;
+       std::unordered_map<u16, u16>::iterator it2;
 
        it = m_blocks_enqueued.find(pos);
        if (it == m_blocks_enqueued.end())
@@ -603,7 +629,7 @@ void *EmergeThread::run()
                        continue;
                }
 
-               if (blockpos_over_limit(pos))
+               if (blockpos_over_max_limit(pos))
                        continue;
 
                bool allow_gen = bedata.flags & BLOCK_EMERGE_ALLOW_GEN;