Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
emerge.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5#pragma once
6
7#include <map>
8#include <mutex>
10#include "irr_v3d.h"
11#include "util/container.h"
12#include "util/metricsbackend.h"
13#include "mapgen/mapgen.h" // for MapgenParams
14#include "map.h"
15
16#define BLOCK_EMERGE_ALLOW_GEN (1 << 0)
17#define BLOCK_EMERGE_FORCE_QUEUE (1 << 1)
18
19#define EMERGE_DBG_OUT(x) { \
20 if (enable_mapgen_debug_info) \
21 infostream << "EmergeThread: " x << std::endl; \
22}
23
24class EmergeThread;
25class NodeDefManager;
26class Settings;
28class BiomeManager;
29class OreManager;
32class Server;
33class ModApiMapgen;
35
36// Structure containing inputs/outputs for chunk generation
38 MMVManip *vmanip = nullptr;
39 // Global map seed
40 u64 seed = 0;
44 const NodeDefManager *nodedef = nullptr;
45
46 BlockMakeData() = default;
47
48 ~BlockMakeData() { delete vmanip; }
49};
50
51// Result from processing an item on the emerge queue
59
60constexpr const char *emergeActionStrs[] = {
61 "cancelled",
62 "errored",
63 "from_memory",
64 "from_disk",
65 "generated",
66};
67
68// Callback
70 v3s16 blockpos, EmergeAction action, void *param);
71
72typedef std::vector<
73 std::pair<
75 void *
76 >
78
84
116
118 /* The mod API needs unchecked access to allow:
119 * - using decomgr or oremgr to place decos/ores
120 * - using schemmgr to load and place schematics
121 */
122 friend class ModApiMapgen;
123public:
126
127 // Generation Notify
130 std::set<std::string> gen_notify_on_custom;
131
132 // Parameters passed to mapgens owned by ServerMap
133 // TODO(hmmmm): Remove this after mapgen helper methods using them
134 // are moved to ServerMap
136
137 // Hackish workaround:
138 // For now, EmergeManager must hold onto a ptr to the Map's setting manager
139 // since the Map can only be accessed through the Environment, and the
140 // Environment is not created until after script initialization.
142
143 // Methods
147
148 const BiomeGen *getBiomeGen() const { return biomegen; }
149
150 // no usage restrictions
151 const BiomeManager *getBiomeManager() const { return biomemgr; }
152 const OreManager *getOreManager() const { return oremgr; }
155 // only usable before mapgen init
160
163 void initMap(MapDatabaseAccessor *holder);
165 void resetMap();
166
167 void startThreads();
168 void stopThreads();
169 bool isRunning();
170
172 session_t peer_id,
173 v3s16 blockpos,
174 bool allow_generate,
175 bool ignore_queue_limits=false);
176
178 v3s16 blockpos,
179 session_t peer_id,
180 u16 flags,
182 void *callback_param);
183
184 size_t getQueueSize();
185 bool isBlockInQueue(v3s16 pos);
186
188
189 // Mapgen helpers methods
191 bool isBlockUnderground(v3s16 blockpos);
192
193 static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
194
195private:
196 std::vector<Mapgen *> m_mapgens;
197 std::vector<EmergeThread *> m_threads;
198 bool m_threads_active = false;
199
200 // The map database
202
203 std::mutex m_queue_mutex;
204 std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
205 std::unordered_map<u16, u32> m_peer_queue_count;
206
210
211 // Emerge metrics
213
214 // Managers of various map generation-related components
215 // Note that each Mapgen gets a copy(!) of these to work with
221
222 // Requires m_queue_mutex held
224
226 v3s16 pos,
227 u16 peer_requested,
228 u16 flags,
230 void *callback_param,
231 bool *entry_already_exists);
232
233 bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
234
236
237 friend class EmergeThread;
238};
Definition mg_biome.h:80
Definition mg_biome.h:203
Definition mg_decoration.h:112
Definition emerge.h:117
bool enable_mapgen_debug_info
Definition emerge.h:125
OreManager * oremgr
Definition emerge.h:218
BiomeGen * biomegen
Definition emerge.h:216
MapSettingsManager * map_settings_mgr
Definition emerge.h:141
std::vector< Mapgen * > m_mapgens
Definition emerge.h:196
u32 gen_notify_on
Definition emerge.h:128
~EmergeManager()
Definition emerge.cpp:120
void stopThreads()
Definition emerge.cpp:233
const BiomeManager * getBiomeManager() const
Definition emerge.h:151
const OreManager * getOreManager() const
Definition emerge.h:152
void reportCompletedEmerge(EmergeAction action)
Definition emerge.cpp:443
OreManager * getWritableOreManager()
Definition emerge.cpp:153
bool isBlockUnderground(v3s16 blockpos)
Definition emerge.cpp:346
u32 m_qlimit_generate
Definition emerge.h:209
void startThreads()
Definition emerge.cpp:221
bool isBlockInQueue(v3s16 pos)
Definition emerge.cpp:310
EmergeManager(Server *server, MetricsBackend *mb)
Definition emerge.cpp:63
bool enqueueBlockEmergeEx(v3s16 blockpos, session_t peer_id, u16 flags, EmergeCompletionCallback callback, void *callback_param)
Definition emerge.cpp:274
MapDatabaseAccessor * m_db
Definition emerge.h:201
const NodeDefManager * ndef
Definition emerge.h:124
bool isRunning()
Definition emerge.cpp:252
BiomeManager * getWritableBiomeManager()
Definition emerge.cpp:146
u32 m_qlimit_diskonly
Definition emerge.h:208
std::set< u32 > gen_notify_on_deco_ids
Definition emerge.h:129
Mapgen * getCurrentMapgen()
Definition emerge.cpp:206
std::set< std::string > gen_notify_on_custom
Definition emerge.h:130
void initMapgens(MapgenParams *mgparams)
Definition emerge.cpp:187
SchematicManager * schemmgr
Definition emerge.h:220
BiomeManager * biomemgr
Definition emerge.h:217
EmergeThread * getOptimalThread()
Definition emerge.cpp:423
static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize)
Definition emerge.cpp:323
bool pushBlockEmergeData(v3s16 pos, u16 peer_requested, u16 flags, EmergeCompletionCallback callback, void *callback_param, bool *entry_already_exists)
Definition emerge.cpp:352
std::mutex m_queue_mutex
Definition emerge.h:203
u32 m_qlimit_total
Definition emerge.h:207
bool m_threads_active
Definition emerge.h:198
void initMap(MapDatabaseAccessor *holder)
Definition emerge.cpp:174
DISABLE_CLASS_COPY(EmergeManager)
SchematicManager * getWritableSchematicManager()
Definition emerge.cpp:167
std::vector< EmergeThread * > m_threads
Definition emerge.h:197
const DecorationManager * getDecorationManager() const
Definition emerge.h:153
MapgenParams * mgparams
Definition emerge.h:135
const SchematicManager * getSchematicManager() const
Definition emerge.h:154
bool enqueueBlockEmerge(session_t peer_id, v3s16 blockpos, bool allow_generate, bool ignore_queue_limits=false)
Definition emerge.cpp:258
void resetMap()
resets the reference
Definition emerge.cpp:181
std::map< v3s16, BlockEmergeData > m_blocks_enqueued
Definition emerge.h:204
std::unordered_map< u16, u32 > m_peer_queue_count
Definition emerge.h:205
bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata)
Definition emerge.cpp:400
const BiomeGen * getBiomeGen() const
Definition emerge.h:148
MetricCounterPtr m_completed_emerge_counter[5]
Definition emerge.h:212
DecorationManager * decomgr
Definition emerge.h:219
size_t getQueueSize()
Definition emerge.cpp:304
int getSpawnLevelAtPoint(v2s16 p)
Definition emerge.cpp:333
DecorationManager * getWritableDecorationManager()
Definition emerge.cpp:160
Definition emerge.h:85
bool enable_mapgen_debug_info
Definition emerge.h:93
GenerateNotifier createNotifier() const
Definition emerge.h:105
const std::set< u32 > * gen_notify_on_deco_ids
Definition emerge.h:96
BiomeGen * biomegen
Definition emerge.h:99
EmergeParams()=delete
~EmergeParams()
Definition emerge.cpp:33
DISABLE_CLASS_COPY(EmergeParams)
u32 gen_notify_on
Definition emerge.h:95
OreManager * oremgr
Definition emerge.h:101
BiomeManager * biomemgr
Definition emerge.h:100
const NodeDefManager * ndef
Definition emerge.h:92
DecorationManager * decomgr
Definition emerge.h:102
const std::set< std::string > * gen_notify_on_custom
Definition emerge.h:97
SchematicManager * schemmgr
Definition emerge.h:103
Definition emerge_internal.h:25
Definition mapgen.h:68
Definition map.h:305
Definition map_settings_manager.h:30
Definition mapgen.h:153
Definition metricsbackend.h:39
Definition l_mapgen.h:18
This class is for getting the actual properties of nodes from their content ID.
Definition nodedef.h:540
Definition mg_ore.h:148
Definition mg_schematic.h:117
Definition server.h:166
Definition settings.h:109
Definition container.h:26
std::vector< std::pair< EmergeCompletionCallback, void * > > EmergeCallbackList
Definition emerge.h:77
EmergeAction
Definition emerge.h:52
@ EMERGE_FROM_DISK
Definition emerge.h:56
@ EMERGE_FROM_MEMORY
Definition emerge.h:55
@ EMERGE_GENERATED
Definition emerge.h:57
@ EMERGE_CANCELLED
Definition emerge.h:53
@ EMERGE_ERRORED
Definition emerge.h:54
constexpr const char * emergeActionStrs[]
Definition emerge.h:60
void(* EmergeCompletionCallback)(v3s16 blockpos, EmergeAction action, void *param)
Definition emerge.h:69
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
std::shared_ptr< MetricCounter > MetricCounterPtr
Definition metricsbackend.h:22
Definition activeobjectmgr.cpp:11
u16 session_t
Definition networkprotocol.h:22
Definition emerge.h:79
u16 flags
Definition emerge.h:81
u16 peer_requested
Definition emerge.h:80
EmergeCallbackList callbacks
Definition emerge.h:82
Definition emerge.h:37
BlockMakeData()=default
~BlockMakeData()
Definition emerge.h:48
v3s16 blockpos_max
Definition emerge.h:42
u64 seed
Definition emerge.h:40
const NodeDefManager * nodedef
Definition emerge.h:44
MMVManip * vmanip
Definition emerge.h:38
UniqueQueue< v3s16 > transforming_liquid
Definition emerge.h:43
v3s16 blockpos_min
Definition emerge.h:41
Definition servermap.h:24
Definition mapgen.h:114
static std::string p(std::string path)
Definition test_filesys.cpp:53