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;
46 // Structure containing inputs/outputs for chunk generation
47 struct BlockMakeData {
52 v3s16 blockpos_requested;
53 UniqueQueue<v3s16> transforming_liquid;
54 INodeDefManager *nodedef;
62 ~BlockMakeData() { delete vmanip; }
65 // Result from processing an item on the emerge queue
75 typedef void (*EmergeCompletionCallback)(
76 v3s16 blockpos, EmergeAction action, void *param);
80 EmergeCompletionCallback,
85 struct BlockEmergeData {
88 EmergeCallbackList callbacks;
93 INodeDefManager *ndef;
94 bool enable_mapgen_debug_info;
98 std::set<u32> gen_notify_on_deco_ids;
100 // Map generation parameters
103 // Managers of various map generation-related components
104 BiomeManager *biomemgr;
106 DecorationManager *decomgr;
107 SchematicManager *schemmgr;
110 EmergeManager(IGameDef *gamedef);
113 void loadMapgenParams();
120 bool enqueueBlockEmerge(
124 bool ignore_queue_limits=false);
126 bool enqueueBlockEmergeEx(
130 EmergeCompletionCallback callback,
131 void *callback_param);
133 v3s16 getContainingChunk(v3s16 blockpos);
135 Mapgen *getCurrentMapgen();
137 // Mapgen helpers methods
138 Biome *getBiomeAtPoint(v3s16 p);
139 int getGroundLevelAtPoint(v2s16 p);
140 bool isBlockUnderground(v3s16 blockpos);
142 static MapgenFactory *getMapgenFactory(const std::string &mgname);
143 static void getMapgenNames(
144 std::vector<const char *> *mgnames, bool include_hidden);
145 static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
148 std::vector<Mapgen *> m_mapgens;
149 std::vector<EmergeThread *> m_threads;
150 bool m_threads_active;
153 std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
154 std::map<u16, u16> m_peer_queue_count;
157 u16 m_qlimit_diskonly;
158 u16 m_qlimit_generate;
160 // Requires m_queue_mutex held
161 EmergeThread *getOptimalThread();
162 bool pushBlockEmergeData(v3s16 pos, u16 peer_requested, u16 flags,
163 EmergeCompletionCallback callback, void *callback_param);
164 bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
166 friend class EmergeThread;
168 DISABLE_CLASS_COPY(EmergeManager);