diff options
Diffstat (limited to 'src/World')
| -rw-r--r-- | src/World/Generation/Decoration.cpp | 19 | ||||
| -rw-r--r-- | src/World/Generation/Decoration.hpp | 2 |
2 files changed, 18 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); } } } diff --git a/src/World/Generation/Decoration.hpp b/src/World/Generation/Decoration.hpp index c157688..4f74800 100644 --- a/src/World/Generation/Decoration.hpp +++ b/src/World/Generation/Decoration.hpp @@ -14,6 +14,8 @@ public: virtual void decorate_chunk(Chunk& chunk) = 0; static void put_block(Chunk& chunk, Pos pos, BlockType block); + static void put_block(Chunk& chunk, Pos pos, Position::BlockLocalOffset offset, BlockType block); + static void draw_column(Chunk& chunk, Pos pos, UInt height, BlockType block); static void draw_circle(Chunk& chunk, Pos pos, Vector<3> axis, Real radius, BlockType block); }; |
