]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
The new mapgen, noise functions, et al.
[dragonfireclient.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
29 class BiomeDefManager;
30 class Biome;
31
32 //struct BlockMakeData;
33 class MapBlock;
34 class ManualMapVoxelManipulator;
35 class INodeDefManager;
36
37 struct BlockMakeData {
38         bool no_op;
39         ManualMapVoxelManipulator *vmanip;
40         u64 seed;
41         v3s16 blockpos_min;
42         v3s16 blockpos_max;
43         v3s16 blockpos_requested;
44         UniqueQueue<v3s16> transforming_liquid;
45         INodeDefManager *nodedef;
46
47         BlockMakeData();
48         ~BlockMakeData();
49 };
50
51 class Mapgen {
52 public:
53         BlockMakeData *data;
54         ManualMapVoxelManipulator *vmanip;
55         INodeDefManager *ndef;
56         BiomeDefManager *biomedef;
57
58         int ystride;
59         int zstride;
60
61         v3s16 csize;
62         int seed;
63         int water_level;
64
65         Noise *noise_terrain;
66         Noise *noise_bgroup;
67         Noise *noise_heat;
68         Noise *noise_humidity;
69
70         v3s16 node_min;
71         v3s16 node_max;
72
73         float *map_terrain;
74         float *map_bgroup;
75         float *map_heat;
76         float *map_humidity;
77
78         bool generating;
79         int id;
80
81         NoiseParams *np_terrain;
82         NoiseParams *np_bgroup;
83         NoiseParams *np_heat;
84         NoiseParams *np_humidity;
85
86         //should these be broken off into a "commonly used nodes" class?
87         MapNode n_air;
88         MapNode n_water;
89         MapNode n_lava;
90
91         Mapgen(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0);
92         Mapgen(BiomeDefManager *biomedef, int mapgenid, u64 seed,
93                    NoiseParams *np_terrain, NoiseParams *np_bgroup,
94                    NoiseParams *np_heat,    NoiseParams *np_humidity);
95         void initMapgen(BiomeDefManager *biomedef, int mapgenid, u64 seed,
96                            NoiseParams *np_terrain, NoiseParams *np_bgroup,
97                            NoiseParams *np_heat,    NoiseParams *np_humidity);
98         ~Mapgen();
99
100         void makeChunk(BlockMakeData *data);
101         void updateLiquid(v3s16 node_min, v3s16 node_max);
102         void updateLighting(v3s16 node_min, v3s16 node_max);
103
104         //Legacy functions for Farmesh (pending removal)
105         static bool get_have_beach(u64 seed, v2s16 p2d);
106         static double tree_amount_2d(u64 seed, v2s16 p);
107         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
108 };
109
110 class EmergeManager {
111 public:
112         //settings
113         u64 seed;
114         int water_level;
115         NoiseParams *np_terrain;
116         NoiseParams *np_bgroup;
117         NoiseParams *np_heat;
118         NoiseParams *np_humidity;
119
120         //biome manager
121         BiomeDefManager *biomedef;
122
123         //mapgen objects here
124
125         EmergeManager(IGameDef *gamedef);
126         ~EmergeManager();
127         void addBlockToQueue();
128
129
130
131         //mapgen helper methods
132         Biome *getBiomeAtPoint(v3s16 p);
133         int getGroundLevelAtPoint(v2s16 p);
134         bool isBlockUnderground(v3s16 blockpos);
135         u32 getBlockSeed(v3s16 p);
136 };
137
138
139 /*
140 namespace mapgen
141 {
142         // Finds precise ground level at any position
143         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
144
145         // Find out if block is completely underground
146         bool block_is_underground(u64 seed, v3s16 blockpos);
147
148         // Get a pseudorandom seed for a position on the map
149         u32 get_blockseed(u64 seed, v3s16 p);
150
151         // Main map generation routine
152         void make_block(BlockMakeData *data);
153
154
155         //These are used by FarMesh
156         bool get_have_beach(u64 seed, v2s16 p2d);
157         double tree_amount_2d(u64 seed, v2s16 p);
158
159         struct BlockMakeData
160         {
161                 bool no_op;
162                 ManualMapVoxelManipulator *vmanip; // Destructor deletes
163                 u64 seed;
164                 v3s16 blockpos_min;
165                 v3s16 blockpos_max;
166                 v3s16 blockpos_requested;
167                 UniqueQueue<v3s16> transforming_liquid;
168                 INodeDefManager *nodedef;
169
170                 BlockMakeData();
171                 ~BlockMakeData();
172         };
173
174 }; // namespace mapgen
175 */
176 #endif
177