3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "util/container.h"
27 #include "mapgen.h" // for MapgenParams
30 #define BLOCK_EMERGE_ALLOW_GEN (1 << 0)
31 #define BLOCK_EMERGE_FORCE_QUEUE (1 << 1)
33 #define EMERGE_DBG_OUT(x) do { \
34 if (enable_mapgen_debug_info) \
35 infostream << "EmergeThread: " x << std::endl; \
39 class INodeDefManager;
44 class DecorationManager;
45 class SchematicManager;
48 // Structure containing inputs/outputs for chunk generation
49 struct BlockMakeData {
54 v3s16 blockpos_requested;
55 UniqueQueue<v3s16> transforming_liquid;
56 INodeDefManager *nodedef;
64 ~BlockMakeData() { delete vmanip; }
67 // Result from processing an item on the emerge queue
77 typedef void (*EmergeCompletionCallback)(
78 v3s16 blockpos, EmergeAction action, void *param);
82 EmergeCompletionCallback,
87 struct BlockEmergeData {
90 EmergeCallbackList callbacks;
95 INodeDefManager *ndef;
96 bool enable_mapgen_debug_info;
100 std::set<u32> gen_notify_on_deco_ids;
102 // Parameters passed to mapgens owned by ServerMap
103 // TODO(hmmmm): Remove this after mapgen helper methods using them
104 // are moved to ServerMap
105 MapgenParams *mgparams;
107 // Hackish workaround:
108 // For now, EmergeManager must hold onto a ptr to the Map's setting manager
109 // since the Map can only be accessed through the Environment, and the
110 // Environment is not created until after script initialization.
111 MapSettingsManager *map_settings_mgr;
113 // Managers of various map generation-related components
114 BiomeManager *biomemgr;
116 DecorationManager *decomgr;
117 SchematicManager *schemmgr;
120 EmergeManager(Server *server);
123 bool initMapgens(MapgenParams *mgparams);
129 bool enqueueBlockEmerge(
133 bool ignore_queue_limits=false);
135 bool enqueueBlockEmergeEx(
139 EmergeCompletionCallback callback,
140 void *callback_param);
142 v3s16 getContainingChunk(v3s16 blockpos);
144 Mapgen *getCurrentMapgen();
146 // Mapgen helpers methods
147 Biome *getBiomeAtPoint(v3s16 p);
148 int getSpawnLevelAtPoint(v2s16 p);
149 int getGroundLevelAtPoint(v2s16 p);
150 bool isBlockUnderground(v3s16 blockpos);
152 static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
155 std::vector<Mapgen *> m_mapgens;
156 std::vector<EmergeThread *> m_threads;
157 bool m_threads_active;
159 std::mutex m_queue_mutex;
160 std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
161 std::unordered_map<u16, u16> m_peer_queue_count;
164 u16 m_qlimit_diskonly;
165 u16 m_qlimit_generate;
167 // Requires m_queue_mutex held
168 EmergeThread *getOptimalThread();
170 bool pushBlockEmergeData(
174 EmergeCompletionCallback callback,
175 void *callback_param,
176 bool *entry_already_exists);
178 bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
180 friend class EmergeThread;
182 DISABLE_CLASS_COPY(EmergeManager);