Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mapgen flags: Add 'biomes' global mapgen flag (#7355)
Previously the only way to disable biomes was to 'clear' the registered
biomes in a mod, but this method causes large amounts of unnecessary
processing:
1. Calculation of 4 2D noises.
2. Looping through all nodes of a mapchunk replacing nodes with identical
nodes.
The new flag disables those operations.
  • Loading branch information
paramat committed Jun 8, 2018
1 parent 9ca37d8 commit 0b23253
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion builtin/settingtypes.txt
Expand Up @@ -1282,7 +1282,7 @@ mapgen_limit (Map generation limit) int 31000 0 31000
# and junglegrass, in all other mapgens this flag controls all decorations.
# Flags that are not enabled are not modified from the default.
# Flags starting with 'no' are used to explicitly disable them.
mg_flags (Mapgen flags) flags caves,dungeons,light,decorations caves,dungeons,light,decorations,nocaves,nodungeons,nolight,nodecorations
mg_flags (Mapgen flags) flags caves,dungeons,light,decorations,biomes caves,dungeons,light,decorations,biomes,nocaves,nodungeons,nolight,nodecorations,nobiomes

# Whether dungeons occasionally project from the terrain.
projecting_dungeons (Projecting dungeons) bool true
Expand Down
3 changes: 2 additions & 1 deletion src/mapgen/mapgen.cpp
Expand Up @@ -56,7 +56,8 @@ FlagDesc flagdesc_mapgen[] = {
{"dungeons", MG_DUNGEONS},
{"light", MG_LIGHT},
{"decorations", MG_DECORATIONS},
{NULL, 0}
{"biomes", MG_BIOMES},
{NULL, 0}
};

FlagDesc flagdesc_gennotify[] = {
Expand Down
3 changes: 2 additions & 1 deletion src/mapgen/mapgen.h
Expand Up @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MG_FLAT 0x08 // Deprecated. Moved into mgv6 flags
#define MG_LIGHT 0x10
#define MG_DECORATIONS 0x20
#define MG_BIOMES 0x40

typedef u8 biome_t; // copy from mg_biome.h to avoid an unnecessary include

Expand Down Expand Up @@ -122,7 +123,7 @@ struct MapgenParams {
u64 seed = 0;
s16 water_level = 1;
s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT;
u32 flags = MG_CAVES | MG_LIGHT | MG_DECORATIONS;
u32 flags = MG_CAVES | MG_LIGHT | MG_DECORATIONS | MG_BIOMES;

BiomeParams *bparams = nullptr;

Expand Down
9 changes: 6 additions & 3 deletions src/mapgen/mapgen_carpathian.cpp
Expand Up @@ -247,8 +247,10 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
generateBiomes();
if (flags & MG_BIOMES) {
biomegen->calcBiomeNoise(node_min);
generateBiomes();
}

// Generate tunnels, caverns and large randomwalk caves
if (flags & MG_CAVES) {
Expand Down Expand Up @@ -284,7 +286,8 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

// Update liquids
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
Expand Down
9 changes: 6 additions & 3 deletions src/mapgen/mapgen_flat.cpp
Expand Up @@ -195,8 +195,10 @@ void MapgenFlat::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
generateBiomes();
if (flags & MG_BIOMES) {
biomegen->calcBiomeNoise(node_min);
generateBiomes();
}

if (flags & MG_CAVES) {
// Generate tunnels
Expand All @@ -217,7 +219,8 @@ void MapgenFlat::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

//printf("makeChunk: %dms\n", t.stop());

Expand Down
9 changes: 6 additions & 3 deletions src/mapgen/mapgen_fractal.cpp
Expand Up @@ -206,8 +206,10 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
generateBiomes();
if (flags & MG_BIOMES) {
biomegen->calcBiomeNoise(node_min);
generateBiomes();
}

if (flags & MG_CAVES) {
// Generate tunnels
Expand All @@ -228,7 +230,8 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

//printf("makeChunk: %dms\n", t.stop());

Expand Down
9 changes: 6 additions & 3 deletions src/mapgen/mapgen_v5.cpp
Expand Up @@ -206,8 +206,10 @@ void MapgenV5::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
generateBiomes();
if (flags & MG_BIOMES) {
biomegen->calcBiomeNoise(node_min);
generateBiomes();
}

// Generate tunnels, caverns and large randomwalk caves
if (flags & MG_CAVES) {
Expand Down Expand Up @@ -243,7 +245,8 @@ void MapgenV5::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

//printf("makeChunk: %dms\n", t.stop());

Expand Down
9 changes: 6 additions & 3 deletions src/mapgen/mapgen_v7.cpp
Expand Up @@ -326,8 +326,10 @@ void MapgenV7::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
generateBiomes();
if (flags & MG_BIOMES) {
biomegen->calcBiomeNoise(node_min);
generateBiomes();
}

// Generate tunnels, caverns and large randomwalk caves
if (flags & MG_CAVES) {
Expand Down Expand Up @@ -363,7 +365,8 @@ void MapgenV7::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

// Update liquids
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
Expand Down
6 changes: 4 additions & 2 deletions src/mapgen/mapgen_valleys.cpp
Expand Up @@ -231,7 +231,8 @@ void MapgenValleys::makeChunk(BlockMakeData *data)
updateHeightmap(node_min, node_max);

// Place biome-specific nodes and build biomemap
generateBiomes();
if (flags & MG_BIOMES)
generateBiomes();

// Generate tunnels, caverns and large randomwalk caves
if (flags & MG_CAVES) {
Expand Down Expand Up @@ -265,7 +266,8 @@ void MapgenValleys::makeChunk(BlockMakeData *data)
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

// Sprinkle some dust on top after everything else was generated
dustTopNodes();
if (flags & MG_BIOMES)
dustTopNodes();

updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

Expand Down
5 changes: 5 additions & 0 deletions src/mapgen/mg_biome.cpp
Expand Up @@ -192,7 +192,12 @@ BiomeGenOriginal::BiomeGenOriginal(BiomeManager *biomemgr,

heatmap = noise_heat->result;
humidmap = noise_humidity->result;

biomemap = new biome_t[m_csize.X * m_csize.Z];
// Initialise with the ID of the default biome so that cavegen can get
// biomes when biome generation (which calculates the biomemap IDs) is
// disabled.
memset(biomemap, 0, sizeof(biome_t) * m_csize.X * m_csize.Z);
}

BiomeGenOriginal::~BiomeGenOriginal()
Expand Down

0 comments on commit 0b23253

Please sign in to comment.