LuaVoxelManip: Add option to allocate blank data
[oweals/minetest.git] / src / mg_biome.cpp
index 4b9bc0dc190728e366d73f0770b2bc094cbb2ce4..763bef1bc5df94cbb6e424896eb1c748011ec94f 100644 (file)
@@ -29,20 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 const char *BiomeManager::ELEMENT_TITLE = "biome";
 
-NoiseParams nparams_biome_def_heat(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.70);
-NoiseParams nparams_biome_def_humidity(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55);
-
 
 ///////////////////////////////////////////////////////////////////////////////
 
-
-BiomeManager::BiomeManager(IGameDef *gamedef)
+BiomeManager::BiomeManager(IGameDef *gamedef) :
+       GenElementManager(gamedef)
 {
-       NodeResolver *resolver = gamedef->getNodeDefManager()->getResolver();
-
-       np_heat     = &nparams_biome_def_heat;
-       np_humidity = &nparams_biome_def_humidity;
-
        // Create default biome to be used in case none exist
        Biome *b = new Biome;
 
@@ -56,11 +48,14 @@ BiomeManager::BiomeManager(IGameDef *gamedef)
        b->heat_point     = 0.0;
        b->humidity_point = 0.0;
 
-       resolver->addNode("air",                 "", CONTENT_AIR, &b->c_top);
-       resolver->addNode("air",                 "", CONTENT_AIR, &b->c_filler);
-       resolver->addNode("mapgen_water_source", "", CONTENT_AIR, &b->c_water);
-       resolver->addNode("air",                 "", CONTENT_AIR, &b->c_dust);
-       resolver->addNode("mapgen_water_source", "", CONTENT_AIR, &b->c_dust_water);
+       NodeResolveInfo *nri = new NodeResolveInfo(b);
+       nri->nodenames.push_back("air");
+       nri->nodenames.push_back("air");
+       nri->nodenames.push_back("mapgen_stone");
+       nri->nodenames.push_back("mapgen_water_source");
+       nri->nodenames.push_back("air");
+       nri->nodenames.push_back("mapgen_water_source");
+       m_ndef->pendNodeResolve(nri);
 
        add(b);
 }
@@ -76,16 +71,11 @@ BiomeManager::~BiomeManager()
 
 
 // just a PoC, obviously needs optimization later on (precalculate this)
-void BiomeManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map)
+void BiomeManager::calcBiomes(s16 sx, s16 sy, float *heat_map,
+       float *humidity_map, s16 *height_map, u8 *biomeid_map)
 {
-       int i = 0;
-       for (int y = 0; y != input->mapsize.Y; y++) {
-               for (int x = 0; x != input->mapsize.X; x++, i++) {
-                       float heat     = (input->heat_map[i] + 1) * 50;
-                       float humidity = (input->humidity_map[i] + 1) * 50;
-                       biomeid_map[i] = getBiome(heat, humidity, input->height_map[i])->id;
-               }
-       }
+       for (s32 i = 0; i != sx * sy; i++)
+               biomeid_map[i] = getBiome(heat_map[i], humidity_map[i], height_map[i])->id;
 }
 
 
@@ -96,10 +86,8 @@ Biome *BiomeManager::getBiome(float heat, float humidity, s16 y)
 
        for (size_t i = 1; i < m_elements.size(); i++) {
                b = (Biome *)m_elements[i];
-               if (!b || y > b->height_max || y < b->height_min) {
-                       printf("not good - %p %d %d %d\n", b, y, b->height_max, b->height_min);
+               if (!b || y > b->height_max || y < b->height_min)
                        continue;
-               }
 
                float d_heat     = heat     - b->heat_point;
                float d_humidity = humidity - b->humidity_point;
@@ -110,6 +98,32 @@ Biome *BiomeManager::getBiome(float heat, float humidity, s16 y)
                        biome_closest = b;
                }
        }
-       
+
        return biome_closest ? biome_closest : (Biome *)m_elements[0];
 }
+
+void BiomeManager::clear()
+{
+
+       for (size_t i = 1; i < m_elements.size(); i++) {
+               Biome *b = (Biome *)m_elements[i];
+               delete b;
+       }
+
+       m_elements.resize(1);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+void Biome::resolveNodeNames(NodeResolveInfo *nri)
+{
+       m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt_with_grass", CONTENT_AIR,    c_top);
+       m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt",            CONTENT_AIR,    c_filler);
+       m_ndef->getIdFromResolveInfo(nri, "mapgen_stone",           CONTENT_AIR,    c_stone);
+       m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source",    CONTENT_AIR,    c_water);
+       m_ndef->getIdFromResolveInfo(nri, "air",                    CONTENT_IGNORE, c_dust);
+       m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source",    CONTENT_IGNORE, c_dust_water);
+}
+