summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-08 11:12:50 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-08 11:12:50 +0200
commitd1984938e4f0cbc24b7b8cc6e219fa873d39418a (patch)
treed00c6cf0ba66c3285d145527360a0e3aeaef6671 /src
parentd17ed6b4ba01a73d33e3ff3ca8f0f6fb25259223 (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/camera-offset.cpp7
-rw-r--r--src/camera-offset.hpp2
-rw-r--r--src/global-coords.hpp2
-rw-r--r--src/world.cpp2
-rw-r--r--src/world.hpp2
5 files changed, 9 insertions, 6 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index bf700138..88ebd0e4 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -4,16 +4,17 @@
namespace floormat {
-with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords c, chunk_coords first, chunk_coords last) :
+with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c, chunk_coords first, chunk_coords last) :
_shader{shader},
_camera{shader.camera_offset()}
{
fm_assert(shader.depth_offset() == 0.f);
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
- const auto offset = _camera + tile_shader::project(Vector3d(c) * chunk_size);
+ const auto offset = _camera + tile_shader::project(Vector3d(c.x, c.y, 0) * chunk_size);
first.x -= 8; first.y -= 8; last.x += 8; last.y += 8; // Z levels
- const auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
+ auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
+ cx += c.z; cy += c.z;
const float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
_shader.set_camera_offset(offset, depth_offset);
diff --git a/src/camera-offset.hpp b/src/camera-offset.hpp
index 80fc004e..f3b64177 100644
--- a/src/camera-offset.hpp
+++ b/src/camera-offset.hpp
@@ -9,7 +9,7 @@ struct tile_shader;
struct with_shifted_camera_offset final
{
- explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords c, chunk_coords first, chunk_coords last);
+ explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c, chunk_coords first, chunk_coords last);
~with_shifted_camera_offset();
private:
tile_shader& _shader; // NOLINT
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 9bdc311a..81ed1a70 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -38,6 +38,8 @@ struct chunk_coords_ final {
constexpr bool operator==(const chunk_coords_&) const noexcept = default;
};
+constexpr inline int8_t chunk_min_z = -8, chunk_max_z = 7;
+
struct global_coords final {
using u0 = std::integral_constant<uint32_t, (1<<15)>;
using s0 = std::integral_constant<int32_t, int32_t(u0::value)>;
diff --git a/src/world.cpp b/src/world.cpp
index ef78f313..f0818b44 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -81,7 +81,7 @@ world::world(size_t capacity) : _chunks{capacity}
chunk& world::operator[](chunk_coords_ coord) noexcept
{
- fm_debug_assert(coord.z >= -8 && coord.z < 8);
+ fm_debug_assert(coord.z >= chunk_min_z && coord.z <= chunk_max_z);
auto& [c, coord2] = _last_chunk;
if (coord != coord2)
c = &_chunks.try_emplace(coord, *this).first->second;
diff --git a/src/world.hpp b/src/world.hpp
index 793b3605..e6ec4f5b 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -21,7 +21,7 @@ struct world final
{
private:
struct chunk_tuple final {
- static constexpr chunk_coords_ invalid_coords = { -1 << 15, -1 << 15, -8 };
+ static constexpr chunk_coords_ invalid_coords = { -1 << 15, -1 << 15, chunk_min_z };
chunk* c = nullptr;
chunk_coords_ pos = invalid_coords;
} _last_chunk;