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.
23 #include "map.h" //for ManualMapVoxelManipulator
25 #include "util/numeric.h"
27 #include "util/mathconstants.h"
30 const char *BiomeManager::ELEMENT_TITLE = "biome";
32 NoiseParams nparams_biome_def_heat(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.70);
33 NoiseParams nparams_biome_def_humidity(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55);
36 ///////////////////////////////////////////////////////////////////////////////
39 BiomeManager::BiomeManager(IGameDef *gamedef)
41 NodeResolver *resolver = gamedef->getNodeDefManager()->getResolver();
43 np_heat = &nparams_biome_def_heat;
44 np_humidity = &nparams_biome_def_humidity;
46 // Create default biome to be used in case none exist
54 b->height_min = -MAP_GENERATION_LIMIT;
55 b->height_max = MAP_GENERATION_LIMIT;
57 b->humidity_point = 0.0;
59 resolver->addNode("air", "", CONTENT_AIR, &b->c_top);
60 resolver->addNode("air", "", CONTENT_AIR, &b->c_filler);
61 resolver->addNode("mapgen_water_source", "", CONTENT_AIR, &b->c_water);
62 resolver->addNode("air", "", CONTENT_AIR, &b->c_dust);
63 resolver->addNode("mapgen_water_source", "", CONTENT_AIR, &b->c_dust_water);
70 BiomeManager::~BiomeManager()
73 // delete[] biomecache;
78 // just a PoC, obviously needs optimization later on (precalculate this)
79 void BiomeManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map)
82 for (int y = 0; y != input->mapsize.Y; y++) {
83 for (int x = 0; x != input->mapsize.X; x++, i++) {
84 float heat = (input->heat_map[i] + 1) * 50;
85 float humidity = (input->humidity_map[i] + 1) * 50;
86 biomeid_map[i] = getBiome(heat, humidity, input->height_map[i])->id;
92 Biome *BiomeManager::getBiome(float heat, float humidity, s16 y)
94 Biome *b, *biome_closest = NULL;
95 float dist_min = FLT_MAX;
97 for (size_t i = 1; i < m_elements.size(); i++) {
98 b = (Biome *)m_elements[i];
99 if (!b || y > b->height_max || y < b->height_min) {
100 printf("not good - %p %d %d %d\n", b, y, b->height_max, b->height_min);
104 float d_heat = heat - b->heat_point;
105 float d_humidity = humidity - b->humidity_point;
106 float dist = (d_heat * d_heat) +
107 (d_humidity * d_humidity);
108 if (dist < dist_min) {
114 return biome_closest ? biome_closest : (Biome *)m_elements[0];