Expose mapgen parameters on scripting init
[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 BLOCK_EMERGE_ALLOWGEN (1<<0)
30
31 #define EMERGE_DBG_OUT(x) \
32         do {                                                   \
33                 if (enable_mapgen_debug_info)                      \
34                         infostream << "EmergeThread: " x << std::endl; \
35         } while (0)
36
37 class EmergeThread;
38 class INodeDefManager;
39 class Settings;
40
41 class BiomeManager;
42 class OreManager;
43 class DecorationManager;
44 class SchematicManager;
45
46 struct BlockMakeData {
47         ManualMapVoxelManipulator *vmanip;
48         u64 seed;
49         v3s16 blockpos_min;
50         v3s16 blockpos_max;
51         v3s16 blockpos_requested;
52         UniqueQueue<v3s16> transforming_liquid;
53         INodeDefManager *nodedef;
54
55         BlockMakeData():
56                 vmanip(NULL),
57                 seed(0),
58                 nodedef(NULL)
59         {}
60
61         ~BlockMakeData() { delete vmanip; }
62 };
63
64 struct BlockEmergeData {
65         u16 peer_requested;
66         u8 flags;
67 };
68
69 class EmergeManager {
70 public:
71         INodeDefManager *ndef;
72
73         std::map<std::string, MapgenFactory *> mglist;
74
75         std::vector<Mapgen *> mapgen;
76         std::vector<EmergeThread *> emergethread;
77
78         bool threads_active;
79
80         //settings
81         MapgenParams params;
82         bool mapgen_debug_info;
83         u16 qlimit_total;
84         u16 qlimit_diskonly;
85         u16 qlimit_generate;
86
87         u32 gen_notify_on;
88         std::set<u32> gen_notify_on_deco_ids;
89
90         //// Block emerge queue data structures
91         JMutex queuemutex;
92         std::map<v3s16, BlockEmergeData *> blocks_enqueued;
93         std::map<u16, u16> peer_queue_count;
94
95         //// Managers of map generation-related components
96         BiomeManager *biomemgr;
97         OreManager *oremgr;
98         DecorationManager *decomgr;
99         SchematicManager *schemmgr;
100
101         //// Methods
102         EmergeManager(IGameDef *gamedef);
103         ~EmergeManager();
104
105         void loadMapgenParams();
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