Fix bone-attached entities (#10015)
[oweals/minetest.git] / src / emerge.h
index 135121b39c74822e9a72083ab2513ebfee7aeb36..6f204666df70776a69aea6aef2e4a41630ebe8ed 100644 (file)
@@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "network/networkprotocol.h"
 #include "irr_v3d.h"
 #include "util/container.h"
-#include "mapgen.h" // for MapgenParams
+#include "mapgen/mapgen.h" // for MapgenParams
 #include "map.h"
 
 #define BLOCK_EMERGE_ALLOW_GEN   (1 << 0)
@@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 }
 
 class EmergeThread;
-class INodeDefManager;
+class NodeDefManager;
 class Settings;
 
 class BiomeManager;
@@ -44,6 +44,7 @@ class OreManager;
 class DecorationManager;
 class SchematicManager;
 class Server;
+class ModApiMapgen;
 
 // Structure containing inputs/outputs for chunk generation
 struct BlockMakeData {
@@ -53,7 +54,7 @@ struct BlockMakeData {
        v3s16 blockpos_max;
        v3s16 blockpos_requested;
        UniqueQueue<v3s16> transforming_liquid;
-       INodeDefManager *nodedef = nullptr;
+       const NodeDefManager *nodedef = nullptr;
 
        BlockMakeData() = default;
 
@@ -86,9 +87,38 @@ struct BlockEmergeData {
        EmergeCallbackList callbacks;
 };
 
+class EmergeParams {
+       friend class EmergeManager;
+public:
+       EmergeParams() = delete;
+       ~EmergeParams();
+       DISABLE_CLASS_COPY(EmergeParams);
+
+       const NodeDefManager *ndef; // shared
+       bool enable_mapgen_debug_info;
+
+       u32 gen_notify_on;
+       const std::set<u32> *gen_notify_on_deco_ids; // shared
+
+       BiomeManager *biomemgr;
+       OreManager *oremgr;
+       DecorationManager *decomgr;
+       SchematicManager *schemmgr;
+
+private:
+       EmergeParams(EmergeManager *parent, const BiomeManager *biomemgr,
+               const OreManager *oremgr, const DecorationManager *decomgr,
+               const SchematicManager *schemmgr);
+};
+
 class EmergeManager {
+       /* The mod API needs unchecked access to allow:
+        * - using decomgr or oremgr to place decos/ores
+        * - using schemmgr to load and place schematics
+        */
+       friend class ModApiMapgen;
 public:
-       INodeDefManager *ndef;
+       const NodeDefManager *ndef;
        bool enable_mapgen_debug_info;
 
        // Generation Notify
@@ -106,18 +136,23 @@ public:
        // Environment is not created until after script initialization.
        MapSettingsManager *map_settings_mgr;
 
-       // Managers of various map generation-related components
-       BiomeManager *biomemgr;
-       OreManager *oremgr;
-       DecorationManager *decomgr;
-       SchematicManager *schemmgr;
-
        // Methods
        EmergeManager(Server *server);
        ~EmergeManager();
        DISABLE_CLASS_COPY(EmergeManager);
 
-       bool initMapgens(MapgenParams *mgparams);
+       // no usage restrictions
+       const BiomeManager *getBiomeManager() const { return biomemgr; }
+       const OreManager *getOreManager() const { return oremgr; }
+       const DecorationManager *getDecorationManager() const { return decomgr; }
+       const SchematicManager *getSchematicManager() const { return schemmgr; }
+       // only usable before mapgen init
+       BiomeManager *getWritableBiomeManager();
+       OreManager *getWritableOreManager();
+       DecorationManager *getWritableDecorationManager();
+       SchematicManager *getWritableSchematicManager();
+
+       void initMapgens(MapgenParams *mgparams);
 
        void startThreads();
        void stopThreads();
@@ -160,6 +195,13 @@ private:
        u16 m_qlimit_diskonly;
        u16 m_qlimit_generate;
 
+       // Managers of various map generation-related components
+       // Note that each Mapgen gets a copy(!) of these to work with
+       BiomeManager *biomemgr;
+       OreManager *oremgr;
+       DecorationManager *decomgr;
+       SchematicManager *schemmgr;
+
        // Requires m_queue_mutex held
        EmergeThread *getOptimalThread();