Add core.get_mapgen_names() to Main Menu API (and use it)
[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::vector<Mapgen *> mapgen;
74         std::vector<EmergeThread *> emergethread;
75
76         bool threads_active;
77
78         //settings
79         MapgenParams params;
80         bool mapgen_debug_info;
81         u16 qlimit_total;
82         u16 qlimit_diskonly;
83         u16 qlimit_generate;
84
85         u32 gen_notify_on;
86         std::set<u32> gen_notify_on_deco_ids;
87
88         //// Block emerge queue data structures
89         JMutex queuemutex;
90         std::map<v3s16, BlockEmergeData *> blocks_enqueued;
91         std::map<u16, u16> peer_queue_count;
92
93         //// Managers of map generation-related components
94         BiomeManager *biomemgr;
95         OreManager *oremgr;
96         DecorationManager *decomgr;
97         SchematicManager *schemmgr;
98
99         //// Methods
100         EmergeManager(IGameDef *gamedef);
101         ~EmergeManager();
102
103         void loadMapgenParams();
104         void initMapgens();
105         Mapgen *getCurrentMapgen();
106         Mapgen *createMapgen(const std::string &mgname, int mgid,
107                 MapgenParams *mgparams);
108         MapgenSpecificParams *createMapgenParams(const std::string &mgname);
109         static void getMapgenNames(std::list<const char *> &mgnames);
110         void startThreads();
111         void stopThreads();
112         bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
113
114         void loadParamsFromSettings(Settings *settings);
115         void saveParamsToSettings(Settings *settings);
116
117         //mapgen helper methods
118         Biome *getBiomeAtPoint(v3s16 p);
119         int getGroundLevelAtPoint(v2s16 p);
120         bool isBlockUnderground(v3s16 blockpos);
121         u32 getBlockSeed(v3s16 p);
122 };
123
124 #endif