]> git.lizzy.rs Git - dragonfireclient.git/blob - src/emerge.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.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
28 #define MGPARAMS_SET_MGNAME      1
29 #define MGPARAMS_SET_SEED        2
30 #define MGPARAMS_SET_WATER_LEVEL 4
31 #define MGPARAMS_SET_FLAGS       8
32
33 #define BLOCK_EMERGE_ALLOWGEN (1<<0)
34
35 #define EMERGE_DBG_OUT(x) \
36         { if (enable_mapgen_debug_info) \
37         infostream << "EmergeThread: " x << std::endl; }
38
39 class EmergeThread;
40 class Mapgen;
41 struct MapgenParams;
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 IBackgroundBlockEmerger
74 {
75 public:
76         virtual bool enqueueBlockEmerge(u16 peer_id, v3s16 p,
77                         bool allow_generate) = 0;
78 };
79
80 class EmergeManager : public IBackgroundBlockEmerger {
81 public:
82         INodeDefManager *ndef;
83
84         std::map<std::string, MapgenFactory *> mglist;
85         
86         std::vector<Mapgen *> mapgen;
87         std::vector<EmergeThread *> emergethread;
88         
89         //settings
90         MapgenParams *params;
91         bool mapgen_debug_info;
92         u16 qlimit_total;
93         u16 qlimit_diskonly;
94         u16 qlimit_generate;
95         
96         MapgenParams *luaoverride_params;
97         u32 luaoverride_params_modified;
98         u32 luaoverride_flagmask;
99         
100         //block emerge queue data structures
101         JMutex queuemutex;
102         std::map<v3s16, BlockEmergeData *> blocks_enqueued;
103         std::map<u16, u16> peer_queue_count;
104
105         //Mapgen-related structures
106         BiomeDefManager *biomedef;
107         std::vector<Ore *> ores;
108         std::vector<Decoration *> decorations;
109
110         EmergeManager(IGameDef *gamedef);
111         ~EmergeManager();
112
113         void initMapgens(MapgenParams *mgparams);
114         Mapgen *getCurrentMapgen();
115         Mapgen *createMapgen(std::string mgname, int mgid,
116                                                 MapgenParams *mgparams);
117         MapgenParams *createMapgenParams(std::string mgname);
118         void triggerAllThreads();
119         bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
120         
121         void registerMapgen(std::string name, MapgenFactory *mgfactory);
122         MapgenParams *getParamsFromSettings(Settings *settings);
123         void setParamsToSettings(Settings *settings);
124         
125         //mapgen helper methods
126         Biome *getBiomeAtPoint(v3s16 p);
127         int getGroundLevelAtPoint(v2s16 p);
128         bool isBlockUnderground(v3s16 blockpos);
129         u32 getBlockSeed(v3s16 p);
130 };
131
132 #endif