Biome API: Add per-biome riverbed material and depth

Mgvalleys: Remove riverbed sand placement from base terrain generation
Riverbed material placement moved to MapgenBasic::generateBiomes()
Document fields and add note that the biome API is still unstable
master
paramat 2016-06-03 12:58:50 +01:00
parent 7841f1c509
commit d24f384174
6 changed files with 33 additions and 17 deletions

View File

@ -3723,6 +3723,9 @@ Definition tables
### Biome definition (`register_biome`) ### Biome definition (`register_biome`)
**Note**
The biome API is still in an experimental phase and subject to change.
{ {
name = "tundra", name = "tundra",
node_dust = "default:snow", node_dust = "default:snow",
@ -3742,6 +3745,9 @@ Definition tables
-- ^ Node that replaces all seawater nodes not in the defined surface layer. -- ^ Node that replaces all seawater nodes not in the defined surface layer.
node_river_water = "default:ice", node_river_water = "default:ice",
-- ^ Node that replaces river water in mapgens that use default:river_water. -- ^ Node that replaces river water in mapgens that use default:river_water.
node_riverbed = "default:gravel",
depth_riverbed = 2,
-- ^ Node placed under river water and thickness of this layer.
y_min = 1, y_min = 1,
y_max = 31000, y_max = 31000,
-- ^ Lower and upper limits for biome. -- ^ Lower and upper limits for biome.

View File

@ -536,13 +536,15 @@ MgStoneType MapgenBasic::generateBiomes()
u16 depth_top = 0; u16 depth_top = 0;
u16 base_filler = 0; u16 base_filler = 0;
u16 depth_water_top = 0; u16 depth_water_top = 0;
u16 depth_riverbed = 0;
u32 vi = vm->m_area.index(x, node_max.Y, z); u32 vi = vm->m_area.index(x, node_max.Y, z);
// Check node at base of mapchunk above, either a node of a previously // Check node at base of mapchunk above, either a node of a previously
// generated mapchunk or if not, a node of overgenerated base terrain. // generated mapchunk or if not, a node of overgenerated base terrain.
content_t c_above = vm->m_data[vi + em.X].getContent(); content_t c_above = vm->m_data[vi + em.X].getContent();
bool air_above = c_above == CONTENT_AIR; bool air_above = c_above == CONTENT_AIR;
bool water_above = (c_above == c_water_source || c_above == c_river_water_source); bool river_water_above = c_above == c_river_water_source;
bool water_above = c_above == c_water_source || river_water_above;
// If there is air or water above enable top/filler placement, otherwise force // 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. // nplaced to stone level by setting a number exceeding any possible filler depth.
@ -564,10 +566,11 @@ MgStoneType MapgenBasic::generateBiomes()
biome = biomegen->getBiomeAtIndex(index, y); biome = biomegen->getBiomeAtIndex(index, y);
depth_top = biome->depth_top; depth_top = biome->depth_top;
base_filler = MYMAX(depth_top base_filler = MYMAX(depth_top +
+ biome->depth_filler biome->depth_filler +
+ noise_filler_depth->result[index], 0.f); noise_filler_depth->result[index], 0.f);
depth_water_top = biome->depth_water_top; depth_water_top = biome->depth_water_top;
depth_riverbed = biome->depth_riverbed;
// Detect stone type for dungeons during every biome calculation. // Detect stone type for dungeons during every biome calculation.
// This is more efficient than detecting per-node and will not // This is more efficient than detecting per-node and will not
@ -590,7 +593,15 @@ MgStoneType MapgenBasic::generateBiomes()
|| c_below == c_river_water_source) || c_below == c_river_water_source)
nplaced = U16_MAX; nplaced = U16_MAX;
if (nplaced < depth_top) { if (river_water_above) {
if (nplaced < depth_riverbed) {
vm->m_data[vi] = MapNode(biome->c_riverbed);
nplaced++;
} else {
nplaced = U16_MAX; // Disable top/filler placement
river_water_above = false;
}
} else if (nplaced < depth_top) {
vm->m_data[vi] = MapNode(biome->c_top); vm->m_data[vi] = MapNode(biome->c_top);
nplaced++; nplaced++;
} else if (nplaced < base_filler) { } else if (nplaced < base_filler) {
@ -610,9 +621,10 @@ MgStoneType MapgenBasic::generateBiomes()
water_above = true; water_above = true;
} else if (c == c_river_water_source) { } else if (c == c_river_water_source) {
vm->m_data[vi] = MapNode(biome->c_river_water); vm->m_data[vi] = MapNode(biome->c_river_water);
nplaced = depth_top; // Enable filler placement for next surface nplaced = 0; // Enable riverbed placement for next surface
air_above = false; air_above = false;
water_above = true; water_above = true;
river_water_above = true;
} else if (c == CONTENT_AIR) { } else if (c == CONTENT_AIR) {
nplaced = 0; // Enable top/filler placement for next surface nplaced = 0; // Enable top/filler placement for next surface
air_above = true; air_above = true;

View File

@ -114,11 +114,6 @@ MapgenValleys::MapgenValleys(int mapgenid, MapgenParams *params, EmergeManager *
// Resolve content to be used // Resolve content to be used
c_lava_source = ndef->getId("mapgen_lava_source"); c_lava_source = ndef->getId("mapgen_lava_source");
c_sand = ndef->getId("mapgen_sand");
// Fall back to more basic content if not defined
if (c_sand == CONTENT_IGNORE)
c_sand = c_stone;
} }
@ -493,7 +488,6 @@ int MapgenValleys::generateTerrain()
MapNode n_air(CONTENT_AIR); MapNode n_air(CONTENT_AIR);
MapNode n_river_water(c_river_water_source); MapNode n_river_water(c_river_water_source);
MapNode n_sand(c_sand);
MapNode n_stone(c_stone); MapNode n_stone(c_stone);
MapNode n_water(c_water_source); MapNode n_water(c_water_source);
@ -537,10 +531,7 @@ int MapgenValleys::generateTerrain()
float surface_delta = (float)y - surface_y; float surface_delta = (float)y - surface_y;
bool river = y + 1 < river_y; bool river = y + 1 < river_y;
if (fabs(surface_delta) <= 0.5f && y > water_level && river) { if (slope * fill > surface_delta) {
// river bottom
vm->m_data[index_data] = n_sand;
} else if (slope * fill > surface_delta) {
// ground // ground
vm->m_data[index_data] = n_stone; vm->m_data[index_data] = n_stone;
if (y > heightmap[index_2d]) if (y > heightmap[index_2d])
@ -553,7 +544,7 @@ int MapgenValleys::generateTerrain()
} else if (river) { } else if (river) {
// river // river
vm->m_data[index_data] = n_river_water; vm->m_data[index_data] = n_river_water;
} else { } else { // air
vm->m_data[index_data] = n_air; vm->m_data[index_data] = n_air;
} }
} }

View File

@ -46,6 +46,7 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
b->depth_top = 0; b->depth_top = 0;
b->depth_filler = -MAX_MAP_GENERATION_LIMIT; b->depth_filler = -MAX_MAP_GENERATION_LIMIT;
b->depth_water_top = 0; b->depth_water_top = 0;
b->depth_riverbed = 0;
b->y_min = -MAX_MAP_GENERATION_LIMIT; b->y_min = -MAX_MAP_GENERATION_LIMIT;
b->y_max = MAX_MAP_GENERATION_LIMIT; b->y_max = MAX_MAP_GENERATION_LIMIT;
b->heat_point = 0.0; b->heat_point = 0.0;
@ -57,6 +58,7 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
b->m_nodenames.push_back("mapgen_water_source"); b->m_nodenames.push_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_water_source"); b->m_nodenames.push_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_river_water_source"); b->m_nodenames.push_back("mapgen_river_water_source");
b->m_nodenames.push_back("mapgen_stone");
b->m_nodenames.push_back("ignore"); b->m_nodenames.push_back("ignore");
m_ndef->pendNodeResolve(b); m_ndef->pendNodeResolve(b);
@ -237,5 +239,6 @@ void Biome::resolveNodeNames()
getIdFromNrBacklog(&c_water_top, "mapgen_water_source", CONTENT_AIR); getIdFromNrBacklog(&c_water_top, "mapgen_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_water, "mapgen_water_source", CONTENT_AIR); getIdFromNrBacklog(&c_water, "mapgen_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_river_water, "mapgen_river_water_source", CONTENT_AIR); getIdFromNrBacklog(&c_river_water, "mapgen_river_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_riverbed, "mapgen_stone", CONTENT_AIR);
getIdFromNrBacklog(&c_dust, "ignore", CONTENT_IGNORE); getIdFromNrBacklog(&c_dust, "ignore", CONTENT_IGNORE);
} }

View File

@ -54,11 +54,13 @@ public:
content_t c_water_top; content_t c_water_top;
content_t c_water; content_t c_water;
content_t c_river_water; content_t c_river_water;
content_t c_riverbed;
content_t c_dust; content_t c_dust;
s16 depth_top; s16 depth_top;
s16 depth_filler; s16 depth_filler;
s16 depth_water_top; s16 depth_water_top;
s16 depth_riverbed;
s16 y_min; s16 y_min;
s16 y_max; s16 y_max;

View File

@ -378,6 +378,7 @@ Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
b->depth_top = getintfield_default(L, index, "depth_top", 0); b->depth_top = getintfield_default(L, index, "depth_top", 0);
b->depth_filler = getintfield_default(L, index, "depth_filler", -31000); b->depth_filler = getintfield_default(L, index, "depth_filler", -31000);
b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0); b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0);
b->depth_riverbed = getintfield_default(L, index, "depth_riverbed", 0);
b->y_min = getintfield_default(L, index, "y_min", -31000); b->y_min = getintfield_default(L, index, "y_min", -31000);
b->y_max = getintfield_default(L, index, "y_max", 31000); b->y_max = getintfield_default(L, index, "y_max", 31000);
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.f); b->heat_point = getfloatfield_default(L, index, "heat_point", 0.f);
@ -391,6 +392,7 @@ Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
nn.push_back(getstringfield_default(L, index, "node_water_top", "")); nn.push_back(getstringfield_default(L, index, "node_water_top", ""));
nn.push_back(getstringfield_default(L, index, "node_water", "")); nn.push_back(getstringfield_default(L, index, "node_water", ""));
nn.push_back(getstringfield_default(L, index, "node_river_water", "")); nn.push_back(getstringfield_default(L, index, "node_river_water", ""));
nn.push_back(getstringfield_default(L, index, "node_riverbed", ""));
nn.push_back(getstringfield_default(L, index, "node_dust", "")); nn.push_back(getstringfield_default(L, index, "node_dust", ""));
ndef->pendNodeResolve(b); ndef->pendNodeResolve(b);