X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Femerge.h;h=76653e6cdf84d5da2e2db71a5b6c6bf8d1943b95;hb=9762650f978cc7bae78861b70a051b26cc5e2dc6;hp=1653199ecbb15d5f59fb83b4c79b7cfab3a79d59;hpb=f6e4c5d9cf459e8278a76a2beaee59732e841458;p=minetest.git diff --git a/src/emerge.h b/src/emerge.h index 1653199ec..76653e6cd 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -26,13 +26,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen.h" // for MapgenParams #include "map.h" -#define BLOCK_EMERGE_ALLOWGEN (1<<0) +#define BLOCK_EMERGE_ALLOW_GEN (1 << 0) +#define BLOCK_EMERGE_FORCE_QUEUE (1 << 1) -#define EMERGE_DBG_OUT(x) \ - do { \ - if (enable_mapgen_debug_info) \ - infostream << "EmergeThread: " x << std::endl; \ - } while (0) +#define EMERGE_DBG_OUT(x) do { \ + if (enable_mapgen_debug_info) \ + infostream << "EmergeThread: " x << std::endl; \ +} while (0) class EmergeThread; class INodeDefManager; @@ -42,7 +42,9 @@ class BiomeManager; class OreManager; class DecorationManager; class SchematicManager; +class Server; +// Structure containing inputs/outputs for chunk generation struct BlockMakeData { MMVManip *vmanip; u64 seed; @@ -61,60 +63,122 @@ struct BlockMakeData { ~BlockMakeData() { delete vmanip; } }; +// Result from processing an item on the emerge queue +enum EmergeAction { + EMERGE_CANCELLED, + EMERGE_ERRORED, + EMERGE_FROM_MEMORY, + EMERGE_FROM_DISK, + EMERGE_GENERATED, +}; + +// Callback +typedef void (*EmergeCompletionCallback)( + v3s16 blockpos, EmergeAction action, void *param); + +typedef std::vector< + std::pair< + EmergeCompletionCallback, + void * + > +> EmergeCallbackList; + struct BlockEmergeData { u16 peer_requested; - u8 flags; + u16 flags; + EmergeCallbackList callbacks; }; class EmergeManager { public: INodeDefManager *ndef; + bool enable_mapgen_debug_info; - std::vector mapgen; - std::vector emergethread; - - bool threads_active; - - //settings - MapgenParams params; - bool mapgen_debug_info; - u16 qlimit_total; - u16 qlimit_diskonly; - u16 qlimit_generate; - + // Generation Notify u32 gen_notify_on; std::set gen_notify_on_deco_ids; - //// Block emerge queue data structures - JMutex queuemutex; - std::map blocks_enqueued; - std::map peer_queue_count; + // Parameters passed to mapgens owned by ServerMap + // TODO(hmmmm): Remove this after mapgen helper methods using them + // are moved to ServerMap + MapgenParams *mgparams; + + // Hackish workaround: + // For now, EmergeManager must hold onto a ptr to the Map's setting manager + // since the Map can only be accessed through the Environment, and the + // Environment is not created until after script initialization. + MapSettingsManager *map_settings_mgr; - //// Managers of map generation-related components + // Managers of various map generation-related components BiomeManager *biomemgr; OreManager *oremgr; DecorationManager *decomgr; SchematicManager *schemmgr; - //// Methods - EmergeManager(IGameDef *gamedef); + // Methods + EmergeManager(Server *server); ~EmergeManager(); - void loadMapgenParams(); - static MapgenSpecificParams *createMapgenParams(const std::string &mgname); - void initMapgens(); - Mapgen *getCurrentMapgen(); - Mapgen *createMapgen(const std::string &mgname, int mgid, - MapgenParams *mgparams); - static void getMapgenNames(std::list &mgnames); + bool initMapgens(MapgenParams *mgparams); + void startThreads(); void stopThreads(); - bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate); + bool isRunning(); + + bool enqueueBlockEmerge( + u16 peer_id, + v3s16 blockpos, + bool allow_generate, + bool ignore_queue_limits=false); + + bool enqueueBlockEmergeEx( + v3s16 blockpos, + u16 peer_id, + u16 flags, + EmergeCompletionCallback callback, + void *callback_param); - //mapgen helper methods + v3s16 getContainingChunk(v3s16 blockpos); + + Mapgen *getCurrentMapgen(); + + // Mapgen helpers methods Biome *getBiomeAtPoint(v3s16 p); + int getSpawnLevelAtPoint(v2s16 p); int getGroundLevelAtPoint(v2s16 p); bool isBlockUnderground(v3s16 blockpos); + + static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize); + +private: + std::vector m_mapgens; + std::vector m_threads; + bool m_threads_active; + + Mutex m_queue_mutex; + std::map m_blocks_enqueued; + UNORDERED_MAP m_peer_queue_count; + + u16 m_qlimit_total; + u16 m_qlimit_diskonly; + u16 m_qlimit_generate; + + // Requires m_queue_mutex held + EmergeThread *getOptimalThread(); + + bool pushBlockEmergeData( + v3s16 pos, + u16 peer_requested, + u16 flags, + EmergeCompletionCallback callback, + void *callback_param, + bool *entry_already_exists); + + bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata); + + friend class EmergeThread; + + DISABLE_CLASS_COPY(EmergeManager); }; #endif