diff options
| author | Mel <mel@rnrd.eu> | 2026-09-04 00:46:51 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2026-09-04 00:46:51 +0200 |
| commit | 00d2b26a6e1566faae85fb7bc6870f0f2db7ac7f (patch) | |
| tree | d2678ba7b36e0863e68094208059b94bbdda24d3 /src/World/Generation/Decoration.cpp | |
| parent | 1952628825ee526e4ae32170266f8eaa323a0e16 (diff) | |
| download | meowcraft-00d2b26a6e1566faae85fb7bc6870f0f2db7ac7f.tar.zst meowcraft-00d2b26a6e1566faae85fb7bc6870f0f2db7ac7f.zip | |
Make tree generation portable for ARM (and other architectures with saturating unsigned rounding of floats)
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'src/World/Generation/Decoration.cpp')
| -rw-r--r-- | src/World/Generation/Decoration.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/World/Generation/Decoration.cpp b/src/World/Generation/Decoration.cpp index ecfa49b..8ab7c2a 100644 --- a/src/World/Generation/Decoration.cpp +++ b/src/World/Generation/Decoration.cpp @@ -14,6 +14,20 @@ void Decorator::put_block(Chunk& chunk, Pos pos, BlockType block) { } } +void Decorator::put_block(Chunk& chunk, Pos pos, Position::BlockLocalOffset offset, BlockType block) { + Int x = TO(Int, pos.x()) + offset.x(); + Int y = TO(Int, pos.y()) + offset.y(); + Int z = TO(Int, pos.z()) + offset.z(); + + if (x < 0 || x >= TO(Int, Chunk::Width) + || y < 0 || y >= TO(Int, Chunk::Height) + || z < 0 || z >= TO(Int, Chunk::Width)) { + return; + } + + put_block(chunk, Pos{x, y, z}, block); +} + void Decorator::draw_column(Chunk& chunk, Pos pos, UInt height, BlockType block) { Pos current_pos = pos; for (UInt i = 0; i < height; i++) { @@ -28,15 +42,14 @@ void Decorator::draw_circle(Chunk& chunk, Pos pos, Vector<3> axis, Real radius, auto ortho1 = normalized_axis.any_orthogonal(); auto ortho2 = normalized_axis.cross(ortho1); - auto r = [](const Real x) { return static_cast<UInt>(std::round(x)); }; + auto r = [](const Real x) { return TO(I16, std::lround(x)); }; 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); + put_block(chunk, pos, Position::BlockLocalOffset{r(p.x()), r(p.y()), r(p.z())}, block); } } } |
