Rewrite generate notification mechanism
[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 "mapgen.h" // for MapgenParams
27 #include "map.h"
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         do {                                                   \
38                 if (enable_mapgen_debug_info)                      \
39                         infostream << "EmergeThread: " x << std::endl; \
40         } while (0)
41
42 class EmergeThread;
43 class INodeDefManager;
44 class Settings;
45
46 class BiomeManager;
47 class OreManager;
48 class DecorationManager;
49 class SchematicManager;
50
51 struct BlockMakeData {
52         ManualMapVoxelManipulator *vmanip;
53         u64 seed;
54         v3s16 blockpos_min;
55         v3s16 blockpos_max;
56         v3s16 blockpos_requested;
57         UniqueQueue<v3s16> transforming_liquid;
58         INodeDefManager *nodedef;
59
60         BlockMakeData():
61                 vmanip(NULL),
62                 seed(0),
63                 nodedef(NULL)
64         {}
65
66         ~BlockMakeData() { delete vmanip; }
67 };
68
69 struct BlockEmergeData {
70         u16 peer_requested;
71         u8 flags;
72 };
73
74 class EmergeManager {
75 public:
76         INodeDefManager *ndef;
77
78         std::map<std::string, MapgenFactory *> mglist;
79
80         std::vector<Mapgen *> mapgen;
81         std::vector<EmergeThread *> emergethread;
82
83         bool threads_active;
84
85         //settings
86         MapgenParams params;
87         bool mapgen_debug_info;
88         u16 qlimit_total;
89         u16 qlimit_diskonly;
90         u16 qlimit_generate;
91
92         u32 gen_notify_on;
93         std::set<u32> gen_notify_on_deco_ids;
94
95         //// Block emerge queue data structures
96         JMutex queuemutex;
97         std::map<v3s16, BlockEmergeData *> blocks_enqueued;
98         std::map<u16, u16> peer_queue_count;
99
100         //// Managers of map generation-related components
101         BiomeManager *biomemgr;
102         OreManager *oremgr;
103         DecorationManager *decomgr;
104         SchematicManager *schemmgr;
105
106         //// Methods
107         EmergeManager(IGameDef *gamedef);
108         ~EmergeManager();
109
110         void loadMapgenParams();
111         void initMapgens();
112         Mapgen *getCurrentMapgen();
113         Mapgen *createMapgen(std::string mgname, int mgid,
114                 MapgenParams *mgparams);
115         MapgenSpecificParams *createMapgenParams(std::string mgname);
116         void startThreads();
117         void stopThreads();
118         bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
119
120         void registerMapgen(std::string name, MapgenFactory *mgfactory);
121         void loadParamsFromSettings(Settings *settings);
122         void saveParamsToSettings(Settings *settings);
123
124         //mapgen helper methods
125         Biome *getBiomeAtPoint(v3s16 p);
126         int getGroundLevelAtPoint(v2s16 p);
127         bool isBlockUnderground(v3s16 blockpos);
128         u32 getBlockSeed(v3s16 p);
129 };
130
131 #endif