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/thread.h"
27 #define MGPARAMS_SET_MGNAME 1
28 #define MGPARAMS_SET_SEED 2
29 #define MGPARAMS_SET_WATER_LEVEL 4
30 #define MGPARAMS_SET_FLAGS 8
32 #define BLOCK_EMERGE_ALLOWGEN (1<<0)
34 #define EMERGE_DBG_OUT(x) \
35 { if (enable_mapgen_debug_info) \
36 infostream << "EmergeThread: " x << std::endl; }
42 class BiomeDefManager;
44 class ManualMapVoxelManipulator;
48 struct BlockMakeData {
49 ManualMapVoxelManipulator *vmanip;
53 v3s16 blockpos_requested;
54 UniqueQueue<v3s16> transforming_liquid;
55 INodeDefManager *nodedef;
63 ~BlockMakeData() { delete vmanip; }
66 struct BlockEmergeData {
73 INodeDefManager *ndef;
75 std::map<std::string, MapgenFactory *> mglist;
77 std::vector<Mapgen *> mapgen;
78 std::vector<EmergeThread *> emergethread;
82 bool mapgen_debug_info;
87 MapgenParams *luaoverride_params;
88 u32 luaoverride_params_modified;
89 u32 luaoverride_flagmask;
91 //block emerge queue data structures
93 std::map<v3s16, BlockEmergeData *> blocks_enqueued;
94 std::map<u16, u16> peer_queue_count;
96 //Mapgen-related structures
97 BiomeDefManager *biomedef;
98 std::vector<Ore *> ores;
99 std::vector<Decoration *> decorations;
101 EmergeManager(IGameDef *gamedef);
104 void initMapgens(MapgenParams *mgparams);
105 Mapgen *getCurrentMapgen();
106 Mapgen *createMapgen(std::string mgname, int mgid,
107 MapgenParams *mgparams);
108 MapgenParams *createMapgenParams(std::string mgname);
109 bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
111 void registerMapgen(std::string name, MapgenFactory *mgfactory);
112 MapgenParams *getParamsFromSettings(Settings *settings);
113 void setParamsToSettings(Settings *settings);
115 //mapgen helper methods
116 Biome *getBiomeAtPoint(v3s16 p);
117 int getGroundLevelAtPoint(v2s16 p);
118 bool isBlockUnderground(v3s16 blockpos);
119 u32 getBlockSeed(v3s16 p);
122 class EmergeThread : public SimpleThread
127 EmergeManager *emerge;
129 bool enable_mapgen_debug_info;
133 std::queue<v3s16> blockqueue;
135 EmergeThread(Server *server, int ethreadid):
150 if(IsRunning() == false)
156 bool popBlockEmerge(v3s16 *pos, u8 *flags);
157 bool getBlockOrStartGen(v3s16 p, MapBlock **b,
158 BlockMakeData *data, bool allow_generate);