summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-17 17:07:04 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-17 17:07:04 +0200
commitd953b707c8cd5e42088245abb6527be211eee9cb (patch)
tree94e84ea83294f86a1b8ef2fecde561279b6416ed /src
parentd9f58950e8cd58b7048f5f505db91323e0237063 (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/camera-offset.cpp22
-rw-r--r--src/camera-offset.hpp10
2 files changed, 15 insertions, 17 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index 47cb690d..f4c3271e 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -1,27 +1,25 @@
#include "camera-offset.hpp"
+#include "tile-defs.hpp"
#include "shaders/tile-shader.hpp"
+#include <Magnum/Math/Vector2.h>
namespace floormat {
-with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, std::int32_t x, std::int32_t y) :
- with_shifted_camera_offset{shader, chunk_coords{std::int16_t(x), std::int16_t(y)}}
-{
- ASSERT(std::abs(x) < (1 << 15) && std::abs(y) < (1 << 15));
-}
+static_assert(sizeof(short) == 2);
-with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, const chunk_coords c) :
- s{shader},
- orig_offset(shader.camera_offset())
+with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, short x, short y) :
+ _shader{shader},
+ _offset{shader.camera_offset()}
{
- const auto offset = tile_shader::project({float(c.x)*TILE_MAX_DIM*TILE_SIZE[0],
- float(c.y)*TILE_MAX_DIM*TILE_SIZE[1],
+ const auto offset = tile_shader::project({float(x)*TILE_MAX_DIM*TILE_SIZE[0],
+ float(y)*TILE_MAX_DIM*TILE_SIZE[1],
0});
- s.set_camera_offset(orig_offset + offset);
+ _shader.set_camera_offset(_offset + Vector2(x, y));
}
with_shifted_camera_offset::~with_shifted_camera_offset()
{
- s.set_camera_offset(orig_offset);
+ _shader.set_camera_offset(_offset);
}
} // namespace floormat
diff --git a/src/camera-offset.hpp b/src/camera-offset.hpp
index da07cec0..927d5693 100644
--- a/src/camera-offset.hpp
+++ b/src/camera-offset.hpp
@@ -1,5 +1,6 @@
#pragma once
-#include "src/global-coords.hpp"
+#include <Magnum/Magnum.h>
+#include <Magnum/Math/Vector2.h>
namespace floormat {
@@ -7,12 +8,11 @@ struct tile_shader;
struct with_shifted_camera_offset final
{
- explicit with_shifted_camera_offset(tile_shader& shader, std::int32_t, std::int32_t);
- explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords c);
+ explicit with_shifted_camera_offset(tile_shader& shader, short x, short y);
~with_shifted_camera_offset();
private:
- tile_shader& s; // NOLINT
- Vector2 orig_offset;
+ tile_shader& _shader; // NOLINT
+ Vector2 _offset;
};
} // namespace floormat