From 7616537bc071bc93f8d36c84b94603528be1efb0 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Wed, 12 Nov 2014 23:01:13 -0500 Subject: Add Generator Element Management framework Add BiomeManager, OreManager, DecorationManager, and SchematicManager --- src/mg_biome.cpp | 87 ++++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 66 deletions(-) (limited to 'src/mg_biome.cpp') diff --git a/src/mg_biome.cpp b/src/mg_biome.cpp index b1172a09d..4b9bc0dc1 100644 --- a/src/mg_biome.cpp +++ b/src/mg_biome.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "mg_biome.h" +#include "gamedef.h" #include "nodedef.h" #include "map.h" //for ManualMapVoxelManipulator #include "log.h" @@ -26,19 +27,25 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/mathconstants.h" #include "porting.h" +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); -BiomeDefManager::BiomeDefManager(NodeResolver *resolver) +/////////////////////////////////////////////////////////////////////////////// + + +BiomeManager::BiomeManager(IGameDef *gamedef) { - biome_registration_finished = false; + 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; - + b->id = 0; b->name = "Default"; b->flags = 0; @@ -55,41 +62,21 @@ BiomeDefManager::BiomeDefManager(NodeResolver *resolver) resolver->addNode("air", "", CONTENT_AIR, &b->c_dust); resolver->addNode("mapgen_water_source", "", CONTENT_AIR, &b->c_dust_water); - biomes.push_back(b); + add(b); } -BiomeDefManager::~BiomeDefManager() + +BiomeManager::~BiomeManager() { //if (biomecache) // delete[] biomecache; - - for (size_t i = 0; i != biomes.size(); i++) - delete biomes[i]; } -Biome *BiomeDefManager::createBiome(BiomeTerrainType btt) -{ - /*switch (btt) { - case BIOME_TERRAIN_NORMAL: - return new Biome; - case BIOME_TERRAIN_LIQUID: - return new BiomeLiquid; - case BIOME_TERRAIN_NETHER: - return new BiomeHell; - case BIOME_TERRAIN_AETHER: - return new BiomeSky; - case BIOME_TERRAIN_FLAT: - return new BiomeSuperflat; - } - return NULL;*/ - return new Biome; -} - // just a PoC, obviously needs optimization later on (precalculate this) -void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) +void BiomeManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) { int i = 0; for (int y = 0; y != input->mapsize.Y; y++) { @@ -102,38 +89,17 @@ void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) } -bool BiomeDefManager::addBiome(Biome *b) -{ - if (biome_registration_finished) { - errorstream << "BiomeDefManager: biome registration already " - "finished, dropping " << b->name << std::endl; - return false; - } - - size_t nbiomes = biomes.size(); - if (nbiomes >= 0xFF) { - errorstream << "BiomeDefManager: too many biomes, dropping " - << b->name << std::endl; - return false; - } - - b->id = (u8)nbiomes; - biomes.push_back(b); - verbosestream << "BiomeDefManager: added biome " << b->name << std::endl; - - return true; -} - - -Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y) +Biome *BiomeManager::getBiome(float heat, float humidity, s16 y) { Biome *b, *biome_closest = NULL; float dist_min = FLT_MAX; - for (size_t i = 1; i < biomes.size(); i++) { - b = biomes[i]; - if (y > b->height_max || y < b->height_min) + 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); continue; + } float d_heat = heat - b->heat_point; float d_humidity = humidity - b->humidity_point; @@ -145,16 +111,5 @@ Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y) } } - return biome_closest ? biome_closest : biomes[0]; -} - - -u8 BiomeDefManager::getBiomeIdByName(const char *name) -{ - for (size_t i = 0; i != biomes.size(); i++) { - if (!strcasecmp(name, biomes[i]->name.c_str())) - return i; - } - - return 0; + return biome_closest ? biome_closest : (Biome *)m_elements[0]; } -- cgit v1.2.3