summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-29 17:31:10 +0200
committerMel <einebeere@gmail.com>2023-07-29 17:31:10 +0200
commit15352db7bc03a176ea7a184f40a7f4e72b54b5fe (patch)
treee826870299577e2c6b0ecc79171f8a6accaa6a51
parent6b69d4b5b648253f894707723af0e2eae9f71445 (diff)
downloadmeowcraft-15352db7bc03a176ea7a184f40a7f4e72b54b5fe.tar.zst
meowcraft-15352db7bc03a176ea7a184f40a7f4e72b54b5fe.zip
Add default light to just-generated chunks
-rw-r--r--src/World/Chunk.hpp4
-rw-r--r--src/World/Generation/Decoration.cpp14
-rw-r--r--src/World/Generation/Decoration.hpp5
-rw-r--r--src/World/Generation/Generator.cpp1
-rw-r--r--src/World/Generation/Generator.hpp1
5 files changed, 22 insertions, 3 deletions
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index 1aa2dd1..0b00c97 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -21,8 +21,8 @@ public:
m_position{(Real)x * Width, 0.0f, (Real)y * Width} {}
struct BlockData {
- BlockData() : type(BlockType::Air), light{200} {}
- BlockData(BlockType t) : type(t), light{200} {}
+ BlockData() : type(BlockType::Air), light{0} {}
+ BlockData(BlockType t) : type(t), light{0} {}
BlockType type;
U8 light;
diff --git a/src/World/Generation/Decoration.cpp b/src/World/Generation/Decoration.cpp
index bcabffa..556b5e7 100644
--- a/src/World/Generation/Decoration.cpp
+++ b/src/World/Generation/Decoration.cpp
@@ -45,7 +45,7 @@ void TreeDecorator::decorate_chunk(Chunk& chunk) {
Pos last_tree = Pos::max();
for (UInt x = 0; x < Chunk::Width; x++) {
for (UInt z = 0; z < Chunk::Width; z++) {
- for (UInt y = Chunk::Height; y > 1; y--) {
+ for (UInt y = Chunk::Height - 1; y != 0; y--) {
Pos pos{x, y, z};
if (!is_valid_position(pos))
continue;
@@ -96,4 +96,16 @@ Bool TreeDecorator::is_valid_position(Vector<3, UInt> pos) {
&& pos.z() + tree_radius <= Chunk::Width;
}
+void DefaultLightDecorator::decorate_chunk(Chunk& chunk) {
+ for (UInt x = 0; x < Chunk::Width; x++) {
+ for (UInt z = 0; z < Chunk::Width; z++) {
+ for (UInt y = Chunk::Height - 1; y != 0; y--) {
+ auto& block = chunk.at(x, y, z);
+ if (!block.type.is_translucent()) break;
+ chunk.at(x, y, z).light = 200;
+ }
+ }
+ }
+}
+
}
diff --git a/src/World/Generation/Decoration.hpp b/src/World/Generation/Decoration.hpp
index b7a839b..2f119ff 100644
--- a/src/World/Generation/Decoration.hpp
+++ b/src/World/Generation/Decoration.hpp
@@ -31,4 +31,9 @@ private:
Math::Random::Noise<2> m_tree_noise;
};
+class DefaultLightDecorator final : public Decorator {
+public:
+ void decorate_chunk(Chunk& chunk) override;
+};
+
}
diff --git a/src/World/Generation/Generator.cpp b/src/World/Generation/Generator.cpp
index 9d63fc1..79c10b6 100644
--- a/src/World/Generation/Generator.cpp
+++ b/src/World/Generation/Generator.cpp
@@ -126,6 +126,7 @@ Generator::Map3D<Bool> Generator::generate_terrain(Map2D<Real>& height_map, I64
}
void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<Bool>& terrain_map) {
+ // TODO: Put all of this into decorators.
constexpr UInt dirt_depth = 4;
constexpr UInt water_height = 40;
diff --git a/src/World/Generation/Generator.hpp b/src/World/Generation/Generator.hpp
index ee78dc5..85f2c38 100644
--- a/src/World/Generation/Generator.hpp
+++ b/src/World/Generation/Generator.hpp
@@ -45,6 +45,7 @@ private:
static inline std::vector<Decorator*> s_decorators = {
new TreeDecorator(),
+ new DefaultLightDecorator(),
};
Math::Perlin::Noise<2> m_landmass_noise{.scale=800.0f, .octaves=4, .persistence=0.3f, .lacunarity=3.5f};