mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor: terrain generation (#9)
* feat: add BlockType * refactor: use fBM for heightmap generation * feat: improve mountain realism * refactor: adjust mountain spawn probability * feat: add biome boundary blending * refactor: remove resolve_biome_adjacency_conflict function * feat: add snowy plain * perf: speed up world generation * refactor: lower overall terrain height
This commit is contained in:
@@ -10,7 +10,7 @@ void BiomeBuilder::build_bottom() {
|
||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ void BiomeBuilder::fill_water() {
|
||||
}
|
||||
int height = heightmap[x][z];
|
||||
for (int y = height; y < SEA_LEVEL; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 7;
|
||||
m_blocks[Chunk::index(x, y, z)] = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ void DesertBuilder::build_blocks() {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
|
||||
for (int y = height - 5; y <= height; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 4;
|
||||
m_blocks[Chunk::index(x, y, z)] = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ void ForestBuilder::build_blocks() {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = height - 5; y < height; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 2;
|
||||
m_blocks[Chunk::index(x, y, z)] = 2;
|
||||
}
|
||||
m_blocks[Chunk::get_index(x, height, z)] = 1;
|
||||
m_blocks[Chunk::index(x, height, z)] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,8 @@ void MountainBuilder::build_blocks() {
|
||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = height - 5; y <= height - 1; y++) {
|
||||
if (y > 110) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
} else {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 2;
|
||||
}
|
||||
}
|
||||
if (height > 110) {
|
||||
m_blocks[Chunk::get_index(x, height, z)] = 3;
|
||||
} else {
|
||||
m_blocks[Chunk::get_index(x, height, z)] = 1;
|
||||
for (int y = 5; y <= height; y++) {
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ void PlainBuilder::build_blocks() {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = height - 5; y < height; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 2;
|
||||
m_blocks[Chunk::index(x, y, z)] = 2;
|
||||
}
|
||||
m_blocks[Chunk::get_index(x, height, z)] = 1;
|
||||
m_blocks[Chunk::index(x, height, z)] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ void RiverBuilder::build_blocks() {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 3;
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = height - 5; y <= height - 1; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 2;
|
||||
m_blocks[Chunk::index(x, y, z)] = 2;
|
||||
}
|
||||
for (int y = height; y <= height; y++) {
|
||||
if (y >= SEA_LEVEL - 1) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 1;
|
||||
m_blocks[Chunk::index(x, y, z)] = 1;
|
||||
} else {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 2;
|
||||
m_blocks[Chunk::index(x, y, z)] = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ void RiverBuilder::build_vegetation() {
|
||||
continue;
|
||||
}
|
||||
for (int y = height + 1; y < SEA_LEVEL; y++) {
|
||||
m_blocks[Chunk::get_index(x, y, z)] = 7;
|
||||
m_blocks[Chunk::index(x, y, z)] = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
src/gameplay/builders/snowy_plain_builder.cpp
Normal file
38
src/gameplay/builders/snowy_plain_builder.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "Cubed/gameplay/builders/snowy_plain_builder.hpp"
|
||||
|
||||
#include "Cubed/gameplay/chunk.hpp"
|
||||
#include "Cubed/gameplay/chunk_generator.hpp"
|
||||
namespace Cubed {
|
||||
SnowyPlainBuilder::SnowyPlainBuilder(ChunkGenerator& chunk_generator)
|
||||
: m_chunk_generator(chunk_generator) {}
|
||||
|
||||
void SnowyPlainBuilder::build_biome() {
|
||||
BiomeBuilder::build_bottom();
|
||||
build_blocks();
|
||||
};
|
||||
|
||||
void SnowyPlainBuilder::build_blocks() {
|
||||
auto& m_chunk = m_chunk_generator.chunk();
|
||||
auto& m_blocks = m_chunk.blocks();
|
||||
auto& m_heightmap = m_chunk.heightmap();
|
||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
int height = static_cast<int>(m_heightmap[x][z]);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[Chunk::index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = height - 5; y < height; y++) {
|
||||
m_blocks[Chunk::index(x, y, z)] = 2;
|
||||
}
|
||||
m_blocks[Chunk::index(x, height, z)] = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SnowyPlainBuilder::build_vegetation() { fill_water(); }
|
||||
|
||||
ChunkGenerator& SnowyPlainBuilder::get_chunk_generator() {
|
||||
return m_chunk_generator;
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user