From d4457ef42061435a1ccf6f5e056f37bac9b30c02 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 4 Jun 2016 20:24:07 -0400 Subject: [PATCH] Mapgen: Optimize biomemap creation by combining with generateBiomes --- src/mapgen.cpp | 20 +++++++++++++++++--- src/mapgen_flat.cpp | 1 - src/mapgen_fractal.cpp | 1 - src/mapgen_v5.cpp | 1 - src/mapgen_v7.cpp | 1 - src/mapgen_valleys.cpp | 5 +---- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 66892a574..576fb219a 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -524,6 +524,10 @@ MapgenBasic::~MapgenBasic() MgStoneType MapgenBasic::generateBiomes() { + // can't generate biomes without a biome generator! + assert(biomegen); + assert(biomemap); + v3s16 em = vm->m_area.getExtent(); u32 index = 0; MgStoneType stone_type = MGSTONE_STONE; @@ -546,6 +550,8 @@ MgStoneType MapgenBasic::generateBiomes() bool river_water_above = c_above == c_river_water_source; bool water_above = c_above == c_water_source || river_water_above; + biomemap[index] = BIOME_NONE; + // If there is air or water above enable top/filler placement, otherwise force // nplaced to stone level by setting a number exceeding any possible filler depth. u16 nplaced = (air_above || water_above) ? 0 : U16_MAX; @@ -560,11 +566,19 @@ MgStoneType MapgenBasic::generateBiomes() // 1. At the surface of stone below air or water. // 2. At the surface of water below air. // 3. When stone or water is detected but biome has not yet been calculated. - if ((c == c_stone && (air_above || water_above || !biome)) - || ((c == c_water_source || c == c_river_water_source) - && (air_above || !biome))) { + bool is_stone_surface = (c == c_stone) && + (air_above || water_above || !biome); + + bool is_water_surface = + (c == c_water_source || c == c_river_water_source) && + (air_above || !biome); + + if (is_stone_surface || is_water_surface) { biome = biomegen->getBiomeAtIndex(index, y); + if (biomemap[index] == BIOME_NONE && is_stone_surface) + biomemap[index] = biome->index; + depth_top = biome->depth_top; base_filler = MYMAX(depth_top + biome->depth_filler + diff --git a/src/mapgen_flat.cpp b/src/mapgen_flat.cpp index 724f06825..7cc6aad5c 100644 --- a/src/mapgen_flat.cpp +++ b/src/mapgen_flat.cpp @@ -192,7 +192,6 @@ void MapgenFlat::makeChunk(BlockMakeData *data) // Init biome generator, place biome-specific nodes, and build biomemap biomegen->calcBiomeNoise(node_min); - biomegen->getBiomes(heightmap); MgStoneType stone_type = generateBiomes(); if (flags & MG_CAVES) diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp index b613bf358..c47a7bfdc 100644 --- a/src/mapgen_fractal.cpp +++ b/src/mapgen_fractal.cpp @@ -208,7 +208,6 @@ void MapgenFractal::makeChunk(BlockMakeData *data) // Init biome generator, place biome-specific nodes, and build biomemap biomegen->calcBiomeNoise(node_min); - biomegen->getBiomes(heightmap); MgStoneType stone_type = generateBiomes(); if (flags & MG_CAVES) diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 3e10ec2a5..74d5e1ee3 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -190,7 +190,6 @@ void MapgenV5::makeChunk(BlockMakeData *data) // Init biome generator, place biome-specific nodes, and build biomemap biomegen->calcBiomeNoise(node_min); - biomegen->getBiomes(heightmap); MgStoneType stone_type = generateBiomes(); // Generate caves diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 7327facae..35dcdcd94 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -219,7 +219,6 @@ void MapgenV7::makeChunk(BlockMakeData *data) // Init biome generator, place biome-specific nodes, and build biomemap biomegen->calcBiomeNoise(node_min); - biomegen->getBiomes(heightmap); MgStoneType stone_type = generateBiomes(); if (flags & MG_CAVES) diff --git a/src/mapgen_valleys.cpp b/src/mapgen_valleys.cpp index 6581b792f..bbf20719d 100644 --- a/src/mapgen_valleys.cpp +++ b/src/mapgen_valleys.cpp @@ -250,10 +250,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) // Generate base terrain with initial heightmaps s16 stone_surface_max_y = generateTerrain(); - // Build biomemap - m_bgen->getBiomes(heightmap); - - // Place biome-specific nodes + // Place biome-specific nodes and build biomemap MgStoneType stone_type = generateBiomes(); // Cave creation. -- 2.25.1