3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
22 #include "map.h" //for ManualMapVoxelManipulator
27 NoiseParams nparams_biome_def_heat =
28 {50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.70};
29 NoiseParams nparams_biome_def_humidity =
30 {50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55};
33 BiomeDefManager::BiomeDefManager() {
34 biome_registration_finished = false;
35 np_heat = &nparams_biome_def_heat;
36 np_humidity = &nparams_biome_def_humidity;
38 // Create default biome to be used in case none exist
45 b->c_top = CONTENT_AIR;
47 b->c_filler = b->c_top;
48 b->filler_height = MAP_GENERATION_LIMIT;
50 b->height_min = -MAP_GENERATION_LIMIT;
51 b->height_max = MAP_GENERATION_LIMIT;
53 b->humidity_point = 0.0;
59 BiomeDefManager::~BiomeDefManager() {
61 // delete[] biomecache;
63 for (size_t i = 0; i != biomes.size(); i++)
68 Biome *BiomeDefManager::createBiome(BiomeTerrainType btt) {
70 case BIOME_TERRAIN_NORMAL:
72 case BIOME_TERRAIN_LIQUID:
73 return new BiomeLiquid;
74 case BIOME_TERRAIN_NETHER:
76 case BIOME_TERRAIN_AETHER:
78 case BIOME_TERRAIN_FLAT:
79 return new BiomeSuperflat;
86 // just a PoC, obviously needs optimization later on (precalculate this)
87 void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) {
89 for (int y = 0; y != input->mapsize.Y; y++) {
90 for (int x = 0; x != input->mapsize.X; x++, i++) {
91 float heat = (input->heat_map[i] + 1) * 50;
92 float humidity = (input->humidity_map[i] + 1) * 50;
93 biomeid_map[i] = getBiome(heat, humidity, input->height_map[i])->id;
99 void BiomeDefManager::resolveNodeNames(INodeDefManager *ndef) {
102 biome_registration_finished = true;
104 for (size_t i = 0; i != biomes.size(); i++) {
107 if (b->c_top == CONTENT_IGNORE) {
108 b->c_top = ndef->getId(b->top_nodename);
109 if (b->c_top == CONTENT_IGNORE) {
110 errorstream << "BiomeDefManager::resolveNodeNames: node '"
111 << b->top_nodename << "' not defined" << std::endl;
112 b->c_top = CONTENT_AIR;
117 if (b->c_filler == CONTENT_IGNORE) {
118 b->c_filler = ndef->getId(b->filler_nodename);
119 if (b->c_filler == CONTENT_IGNORE) {
120 errorstream << "BiomeDefManager::resolveNodeNames: node '"
121 << b->filler_nodename << "' not defined" << std::endl;
122 b->c_filler = CONTENT_AIR;
123 b->filler_height = MAP_GENERATION_LIMIT;
130 void BiomeDefManager::addBiome(Biome *b) {
131 if (biome_registration_finished) {
132 errorstream << "BIomeDefManager: biome registration already finished, dropping " << b->name <<std::endl;
137 size_t nbiomes = biomes.size();
138 if (nbiomes >= 0xFF) {
139 errorstream << "BiomeDefManager: too many biomes, dropping " << b->name << std::endl;
146 verbosestream << "BiomeDefManager: added biome " << b->name << std::endl;
150 Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y) {
151 Biome *b, *biome_closest = NULL;
152 float dist_min = FLT_MAX;
154 for (size_t i = 1; i < biomes.size(); i++) {
156 if (y > b->height_max || y < b->height_min)
159 float d_heat = heat - b->heat_point;
160 float d_humidity = humidity - b->humidity_point;
161 float dist = (d_heat * d_heat) +
162 (d_humidity * d_humidity);
163 if (dist < dist_min) {
169 return biome_closest ? biome_closest : biomes[0];
173 u8 BiomeDefManager::getBiomeIdByName(const char *name) {
174 for (size_t i = 0; i != biomes.size(); i++) {
175 if (!strcasecmp(name, biomes[i]->name.c_str()))