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.
25 #include "util/container.h"
26 #include "mapgen.h" // for MapgenParams
29 #define BLOCK_EMERGE_ALLOW_GEN (1 << 0)
30 #define BLOCK_EMERGE_FORCE_QUEUE (1 << 1)
32 #define EMERGE_DBG_OUT(x) do { \
33 if (enable_mapgen_debug_info) \
34 infostream << "EmergeThread: " x << std::endl; \
38 class INodeDefManager;
43 class DecorationManager;
44 class SchematicManager;
47 // Structure containing inputs/outputs for chunk generation
48 struct BlockMakeData {
53 v3s16 blockpos_requested;
54 UniqueQueue<v3s16> transforming_liquid;
55 INodeDefManager *nodedef;
63 ~BlockMakeData() { delete vmanip; }
66 // Result from processing an item on the emerge queue
76 typedef void (*EmergeCompletionCallback)(
77 v3s16 blockpos, EmergeAction action, void *param);
81 EmergeCompletionCallback,
86 struct BlockEmergeData {
89 EmergeCallbackList callbacks;
94 INodeDefManager *ndef;
95 bool enable_mapgen_debug_info;
99 std::set<u32> gen_notify_on_deco_ids;
101 // Parameters passed to mapgens owned by ServerMap
102 // TODO(hmmmm): Remove this after mapgen helper methods using them
103 // are moved to ServerMap
104 MapgenParams *mgparams;
106 // Hackish workaround:
107 // For now, EmergeManager must hold onto a ptr to the Map's setting manager
108 // since the Map can only be accessed through the Environment, and the
109 // Environment is not created until after script initialization.
110 MapSettingsManager *map_settings_mgr;
112 // Managers of various map generation-related components
113 BiomeManager *biomemgr;
115 DecorationManager *decomgr;
116 SchematicManager *schemmgr;
119 EmergeManager(Server *server);
122 bool initMapgens(MapgenParams *mgparams);
128 bool enqueueBlockEmerge(
132 bool ignore_queue_limits=false);
134 bool enqueueBlockEmergeEx(
138 EmergeCompletionCallback callback,
139 void *callback_param);
141 v3s16 getContainingChunk(v3s16 blockpos);
143 Mapgen *getCurrentMapgen();
145 // Mapgen helpers methods
146 Biome *getBiomeAtPoint(v3s16 p);
147 int getSpawnLevelAtPoint(v2s16 p);
148 int getGroundLevelAtPoint(v2s16 p);
149 bool isBlockUnderground(v3s16 blockpos);
151 static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
154 std::vector<Mapgen *> m_mapgens;
155 std::vector<EmergeThread *> m_threads;
156 bool m_threads_active;
159 std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
160 UNORDERED_MAP<u16, u16> m_peer_queue_count;
163 u16 m_qlimit_diskonly;
164 u16 m_qlimit_generate;
166 // Requires m_queue_mutex held
167 EmergeThread *getOptimalThread();
169 bool pushBlockEmergeData(
173 EmergeCompletionCallback callback,
174 void *callback_param,
175 bool *entry_already_exists);
177 bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
179 friend class EmergeThread;
181 DISABLE_CLASS_COPY(EmergeManager);