From d953b707c8cd5e42088245abb6527be211eee9cb Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 17 Oct 2022 17:07:04 +0200 Subject: a --- src/camera-offset.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/camera-offset.cpp') 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 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 -- cgit v1.2.3