]> git.lizzy.rs Git - minetest.git/blob - src/mapgen.h
Added debug log level setting
[minetest.git] / src / mapgen.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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 MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "mapnode.h"
27 #include "noise.h"
28 #include "settings.h"
29 #include <map>
30
31 /////////////////// Mapgen flags
32 #define MG_TREES         0x01
33 #define MG_CAVES         0x02
34 #define MG_DUNGEONS      0x04
35 #define MGV6_FORESTS     0x08
36 #define MGV6_BIOME_BLEND 0x10
37 #define MG_FLAT          0x20
38
39 class BiomeDefManager;
40 class Biome;
41 class EmergeManager;
42 class MapBlock;
43 class ManualMapVoxelManipulator;
44 class VoxelManipulator;
45 class INodeDefManager;
46
47 struct BlockMakeData {
48         bool no_op;
49         ManualMapVoxelManipulator *vmanip;
50         u64 seed;
51         v3s16 blockpos_min;
52         v3s16 blockpos_max;
53         v3s16 blockpos_requested;
54         UniqueQueue<v3s16> transforming_liquid;
55         INodeDefManager *nodedef;
56
57         BlockMakeData();
58         ~BlockMakeData();
59 };
60
61 struct MapgenParams {
62         std::string mg_name;
63         int chunksize;
64         u64 seed;
65         int water_level;
66         u32 flags;
67
68         MapgenParams() {
69                 mg_name     = "v6";
70                 seed        = 0;
71                 water_level = 1;
72                 chunksize   = 5;
73                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
74         }
75         
76         virtual bool readParams(Settings *settings) = 0;
77         virtual void writeParams(Settings *settings) {};
78 };
79
80 class Mapgen {
81 public:
82         int seed;
83         int water_level;
84         bool generating;
85         int id;
86
87         virtual void makeChunk(BlockMakeData *data) {};
88         virtual int getGroundLevelAtPoint(v2s16 p) = 0;
89
90         //Legacy functions for Farmesh (pending removal)
91         static bool get_have_beach(u64 seed, v2s16 p2d);
92         static double tree_amount_2d(u64 seed, v2s16 p);
93         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
94 };
95
96 struct MapgenFactory {
97         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
98                                                                  EmergeManager *emerge) = 0;
99         virtual MapgenParams *createMapgenParams() = 0;
100 };
101
102 class EmergeManager {
103 public:
104         std::map<std::string, MapgenFactory *> mglist;
105
106         //settings
107         MapgenParams *params;
108
109         //mapgen objects here
110         Mapgen *mapgen;
111
112         //biome manager
113         BiomeDefManager *biomedef;
114
115         EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef);
116         ~EmergeManager();
117
118         void initMapgens(MapgenParams *mgparams);
119         Mapgen *createMapgen(std::string mgname, int mgid,
120                                                 MapgenParams *mgparams, EmergeManager *emerge);
121         MapgenParams *createMapgenParams(std::string mgname);
122         Mapgen *getMapgen();
123         void addBlockToQueue();
124         
125         void registerMapgen(std::string name, MapgenFactory *mgfactory);
126         MapgenParams *getParamsFromSettings(Settings *settings);
127         void setParamsToSettings(Settings *settings);
128         
129         //mapgen helper methods
130         Biome *getBiomeAtPoint(v3s16 p);
131         int getGroundLevelAtPoint(v2s16 p);
132         bool isBlockUnderground(v3s16 blockpos);
133         u32 getBlockSeed(v3s16 p);
134 };
135
136 #endif
137