ServerEnvironment: Remove direct dependency on EmergeManager
[oweals/minetest.git] / src / emerge.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef EMERGE_HEADER
21 #define EMERGE_HEADER
22
23 #include <map>
24 #include "irr_v3d.h"
25 #include "util/container.h"
26 #include "map.h" // for ManualMapVoxelManipulator
27 #include "mapgen.h" // for MapgenParams
28
29 #define MGPARAMS_SET_MGNAME      1
30 #define MGPARAMS_SET_SEED        2
31 #define MGPARAMS_SET_WATER_LEVEL 4
32 #define MGPARAMS_SET_FLAGS       8
33
34 #define BLOCK_EMERGE_ALLOWGEN (1<<0)
35
36 #define EMERGE_DBG_OUT(x) \
37         { if (enable_mapgen_debug_info) \
38         infostream << "EmergeThread: " x << std::endl; }
39
40 class EmergeThread;
41 //class Mapgen;
42 //struct MapgenFactory;
43 class Biome;
44 class BiomeDefManager;
45 class Decoration;
46 class Ore;
47 class INodeDefManager;
48 class Settings;
49
50 struct BlockMakeData {
51         ManualMapVoxelManipulator *vmanip;
52         u64 seed;
53         v3s16 blockpos_min;
54         v3s16 blockpos_max;
55         v3s16 blockpos_requested;
56         UniqueQueue<v3s16> transforming_liquid;
57         INodeDefManager *nodedef;
58
59         BlockMakeData():
60                 vmanip(NULL),
61                 seed(0),
62                 nodedef(NULL)
63         {}
64
65         ~BlockMakeData() { delete vmanip; }
66 };
67
68 struct BlockEmergeData {
69         u16 peer_requested;
70         u8 flags;
71 };
72
73 class EmergeManager {
74 public:
75         INodeDefManager *ndef;
76
77         std::map<std::string, MapgenFactory *> mglist;
78
79         std::vector<Mapgen *> mapgen;
80         std::vector<EmergeThread *> emergethread;
81
82         bool threads_active;
83
84         //settings
85         MapgenParams params;
86         bool mapgen_debug_info;
87         u16 qlimit_total;
88         u16 qlimit_diskonly;
89         u16 qlimit_generate;
90
91         u32 gennotify;
92
93         //block emerge queue data structures
94         JMutex queuemutex;
95         std::map<v3s16, BlockEmergeData *> blocks_enqueued;
96         std::map<u16, u16> peer_queue_count;
97
98         //Mapgen-related structures
99         BiomeDefManager *biomedef;
100         std::vector<Ore *> ores;
101         std::vector<Decoration *> decorations;
102
103         EmergeManager(IGameDef *gamedef);
104         ~EmergeManager();
105
106         void initMapgens();
107         Mapgen *getCurrentMapgen();
108         Mapgen *createMapgen(std::string mgname, int mgid,
109                                                 MapgenParams *mgparams);
110         MapgenSpecificParams *createMapgenParams(std::string mgname);
111         void startThreads();
112         void stopThreads();
113         bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
114
115         void registerMapgen(std::string name, MapgenFactory *mgfactory);
116         void loadParamsFromSettings(Settings *settings);
117         void saveParamsToSettings(Settings *settings);
118
119         //mapgen helper methods
120         Biome *getBiomeAtPoint(v3s16 p);
121         int getGroundLevelAtPoint(v2s16 p);
122         bool isBlockUnderground(v3s16 blockpos);
123         u32 getBlockSeed(v3s16 p);
124 };
125
126 #endif