-#include "mapgen_math.h"
-
-
-/////////////////////////////// Emerge Manager ////////////////////////////////
-
-EmergeManager::EmergeManager(IGameDef *gamedef) {
- //register built-in mapgens
- registerMapgen("v6", new MapgenFactoryV6());
- registerMapgen("v7", new MapgenFactoryV7());
- registerMapgen("indev", new MapgenFactoryIndev());
- registerMapgen("singlenode", new MapgenFactorySinglenode());
- registerMapgen("math", new MapgenFactoryMath());
-
- this->ndef = gamedef->getNodeDefManager();
- this->biomedef = new BiomeDefManager();
- this->params = NULL;
-
- this->luaoverride_params = NULL;
- this->luaoverride_params_modified = 0;
- this->luaoverride_flagmask = 0;
-
- mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
-
- queuemutex.Init();
-
- int nthreads;
- if (g_settings->get("num_emerge_threads").empty()) {
- int nprocs = porting::getNumberOfProcessors();
- // leave a proc for the main thread and one for some other misc threads
- nthreads = (nprocs > 2) ? nprocs - 2 : 1;
- } else {
- nthreads = g_settings->getU16("num_emerge_threads");
- }
+#include "mg_biome.h"
+#include "mg_ore.h"
+#include "mg_decoration.h"
+#include "mg_schematic.h"
+#include "nodedef.h"
+#include "profiler.h"
+#include "scripting_game.h"
+#include "server.h"
+#include "serverobject.h"
+#include "settings.h"
+#include "voxel.h"
+
+
+struct MapgenDesc {
+ const char *name;
+ MapgenFactory *factory;
+ bool is_user_visible;
+};
+
+class EmergeThread : public Thread {
+public:
+ bool enable_mapgen_debug_info;
+ int id;
+
+ EmergeThread(Server *server, int ethreadid);
+ ~EmergeThread();
+
+ void *run();
+ void signal();
+
+ // Requires queue mutex held
+ bool pushBlock(v3s16 pos);
+
+ void cancelPendingItems();
+
+ static void runCompletionCallbacks(
+ v3s16 pos, EmergeAction action,
+ const EmergeCallbackList &callbacks);
+
+private:
+ Server *m_server;
+ ServerMap *m_map;
+ EmergeManager *m_emerge;
+ Mapgen *m_mapgen;
+
+ Event m_queue_event;
+ std::queue<v3s16> m_block_queue;
+
+ bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata);
+
+ EmergeAction getBlockOrStartGen(
+ v3s16 pos, bool allow_gen, MapBlock **block, BlockMakeData *data);
+ MapBlock *finishGen(v3s16 pos, BlockMakeData *bmdata,
+ std::map<v3s16, MapBlock *> *modified_blocks);
+
+ friend class EmergeManager;
+};
+
+////
+//// Built-in mapgens
+////
+
+MapgenDesc g_reg_mapgens[] = {
+ {"v5", new MapgenFactoryV5, true},
+ {"v6", new MapgenFactoryV6, true},
+ {"v7", new MapgenFactoryV7, true},
+ {"fractal", new MapgenFactoryFractal, false},
+ {"singlenode", new MapgenFactorySinglenode, false},
+};
+
+////
+//// EmergeManager
+////
+
+EmergeManager::EmergeManager(IGameDef *gamedef)
+{
+ this->ndef = gamedef->getNodeDefManager();
+ this->biomemgr = new BiomeManager(gamedef);
+ this->oremgr = new OreManager(gamedef);
+ this->decomgr = new DecorationManager(gamedef);
+ this->schemmgr = new SchematicManager(gamedef);
+ 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");
+
+ // If unspecified, leave a proc for the main thread and one for
+ // some other misc thread
+ s16 nthreads = 0;
+ if (!g_settings->getS16NoEx("num_emerge_threads", nthreads))
+ nthreads = Thread::getNumberOfProcessors() - 2;