diff options
| author | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
| commit | fe2baedc760c2f29e2c720f6b1132a2de33c5430 (patch) | |
| tree | dfbe1c72a17805a3cab6e0d47433e9021890c9ca /src/World/Generation/Decoration.cpp | |
| parent | 41fbca10f6c6cdd9c1623f1347e7ecb40f5e7f59 (diff) | |
| download | meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.tar.zst meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.zip | |
Use own size types
Diffstat (limited to 'src/World/Generation/Decoration.cpp')
| -rw-r--r-- | src/World/Generation/Decoration.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/World/Generation/Decoration.cpp b/src/World/Generation/Decoration.cpp index 26eb397..f3f7c46 100644 --- a/src/World/Generation/Decoration.cpp +++ b/src/World/Generation/Decoration.cpp @@ -12,26 +12,26 @@ void Decorator::put_block(Chunk& chunk, Pos pos, BlockType block) { } } -void Decorator::draw_column(Chunk& chunk, Pos pos, uint height, BlockType block) { +void Decorator::draw_column(Chunk& chunk, Pos pos, UInt height, BlockType block) { Pos current_pos = pos; - for (uint i = 0; i < height; i++) { + for (UInt i = 0; i < height; i++) { put_block(chunk, current_pos, block); current_pos += Pos::up(); } } -void Decorator::draw_circle(Chunk& chunk, Pos pos, Vector<3> axis, float radius, BlockType block) { +void Decorator::draw_circle(Chunk& chunk, Pos pos, Vector<3> axis, Real radius, BlockType block) { auto normalized_axis = axis.normalize(); auto ortho1 = normalized_axis.any_orthogonal(); auto ortho2 = normalized_axis.cross(ortho1); - auto r = [](const float x) { return static_cast<uint>(std::round(x)); }; + auto r = [](const Real x) { return static_cast<UInt>(std::round(x)); }; - int radius_round = std::round(radius); - for (int32_t d1 = -radius_round; d1 <= radius_round; d1++) { - float height = std::sqrt(radius * radius - d1 * d1); - for (int32_t d2 = -height; d2 <= (int)height; d2++) { + Int radius_round = std::round(radius); + for (I32 d1 = -radius_round; d1 <= radius_round; d1++) { + Real height = std::sqrt(radius * radius - d1 * d1); + for (I32 d2 = -height; d2 <= (Int)height; d2++) { auto p = ortho1 * d1 + ortho2 * d2; Pos block_pos = pos + Pos{r(p.x()), r(p.y()), r(p.z())}; put_block(chunk, block_pos, block); @@ -41,9 +41,9 @@ void Decorator::draw_circle(Chunk& chunk, Pos pos, Vector<3> axis, float radius, 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 x = 0; x < Chunk::Width; x++) { + for (UInt z = 0; z < Chunk::Width; z++) { + for (UInt y = Chunk::Height; y > 1; y--) { Pos pos{x, y, z}; if (!is_valid_position(pos)) continue; @@ -56,7 +56,7 @@ void TreeDecorator::decorate_chunk(Chunk& chunk) { if (type != BlockType::Snow && type != BlockType::Grass && type != BlockType::Dirt) break; - auto noise = m_tree_noise.at({(float)x, (float)z}); + auto noise = m_tree_noise.at({(Real)x, (Real)z}); if (noise < 0.8f) continue; @@ -73,24 +73,24 @@ void TreeDecorator::decorate_chunk(Chunk& chunk) { } void TreeDecorator::draw_tree(Chunk& chunk, Pos pos) const { - auto noise = m_tree_noise.at({(float)pos.x(), (float)pos.z()}); - uint height = std::round(10 * noise - 4.75f); + auto noise = m_tree_noise.at({(Real)pos.x(), (Real)pos.z()}); + UInt height = std::round(10 * noise - 4.75f); draw_column(chunk, pos, height, BlockType::Wood); - uint max_leaf_height = 4; - for (int x = 0; x < max_leaf_height; x++) { + UInt max_leaf_height = 4; + for (Int x = 0; x < max_leaf_height; x++) { Pos p{pos.x(), pos.y() + height + x - 2, pos.z()}; - float radius = s_tree_radius - 0.5f + x * ((0.3f * x - 1.45f) * x + 1.25f); + Real radius = s_tree_radius - 0.5f + x * ((0.3f * x - 1.45f) * x + 1.25f); draw_circle(chunk, p, Vector<3>::up(), radius, BlockType::Leaves); } } -bool TreeDecorator::is_valid_position(Vector<3, uint> pos) { - int tree_radius = s_tree_radius; - return (int)pos.x() - tree_radius >= 0 +Bool TreeDecorator::is_valid_position(Vector<3, UInt> pos) { + Int tree_radius = s_tree_radius; + return (Int)pos.x() - tree_radius >= 0 && pos.x() + tree_radius <= Chunk::Width - && (int)pos.z() - tree_radius >= 0 + && (Int)pos.z() - tree_radius >= 0 && pos.z() + tree_radius <= Chunk::Width; } |
