From 9041dfd60ae8a8056df1a5e7e85609a231406d3d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 9 Dec 2023 05:01:06 +0100 Subject: w --- src/chunk-walls.cpp | 59 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'src/chunk-walls.cpp') diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index 8cfdaf64..59c20434 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -7,35 +7,30 @@ #include #include -// +x +y +z -// +x +y -z -// -x -y +z -// -x +y -z - namespace floormat { -using namespace floormat::Quads; -using Wall::Group_; +void chunk::ensure_alloc_walls() +{ + if (!_walls) [[unlikely]] + _walls = Pointer{InPlaceInit}; +} namespace { constexpr Vector2 half_tile = TILE_SIZE2*.5f; constexpr float X = half_tile.x(), Y = half_tile.y(), Z = TILE_SIZE.z(); -} // namespace +using namespace floormat::Quads; +using Wall::Group_; -void chunk::ensure_alloc_walls() -{ - if (!_walls) [[unlikely]] - _walls = Pointer{InPlaceInit}; -} +template constexpr std::array make_wall_vertex_data(float depth); // ----------------------- // corner left -template<> std::array chunk::make_wall_vertex_data(float) +template<> std::array constexpr make_wall_vertex_data(float) { - constexpr float x_offset = (float)((unsigned)X)/2u; + constexpr float x_offset = (float)(unsigned)X; return {{ { -X + x_offset, -Y, Z }, { -X + x_offset, -Y, 0 }, @@ -45,9 +40,9 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float) +template<> std::array constexpr make_wall_vertex_data(float) { - constexpr float y_offset = Y - (float)((unsigned)Y)/2u; + constexpr float y_offset = TILE_SIZE.y() - (float)(unsigned)Y; return {{ {-X, -Y, Z }, {-X, -Y, 0 }, @@ -57,7 +52,7 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float) +template<> std::array constexpr make_wall_vertex_data(float) { return {{ { X, -Y, Z }, @@ -68,30 +63,30 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float) +template<> std::array constexpr make_wall_vertex_data(float) { return {{ - {-X, Y, Z }, - {-X, Y, 0 }, {-X, -Y, Z }, {-X, -Y, 0 }, + {-X, Y, Z }, + {-X, Y, 0 }, }}; } // overlay north -template<> std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { return make_wall_vertex_data(depth); } // overlay west -template<> std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { return make_wall_vertex_data(depth); } // side north -template<> std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { auto left = Vector2{X, -Y }, right = Vector2{left.x(), left.y() - depth }; @@ -104,7 +99,7 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { auto right = Vector2{ -X, Y }; auto left = Vector2{ right.x() - depth, right.y() }; @@ -117,7 +112,7 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { auto top_right = Vector2{X, Y - depth }, bottom_right = Vector2{top_right.x(), Y }, @@ -132,12 +127,12 @@ template<> std::array chunk::make_wall_vertex_data std::array chunk::make_wall_vertex_data(float depth) +template<> std::array constexpr make_wall_vertex_data(float depth) { - auto top_right = Vector2{-X, -Y }, - top_left = Vector2{top_right.x() - depth, top_right.y() }, - bottom_right = Vector2{-X, Y }, - bottom_left = Vector2{bottom_right.x() - depth, bottom_right.y() }; + auto top_right = Vector2{-X, -Y }, + top_left = Vector2{top_right.x() - depth, top_right.y() }, + bottom_right = Vector2{top_right.x(), Y }, + bottom_left = Vector2{top_left.x(), bottom_right.y() }; return {{ { bottom_right.x(), bottom_right.y(), Z }, @@ -149,6 +144,8 @@ template<> std::array chunk::make_wall_vertex_data