diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 05:23:48 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 05:23:48 +0200 |
| commit | 40510b6e50ae9dd027c55e52c91433807ddf5c39 (patch) | |
| tree | 997d5100539bfd7e5cf11290e0bf8447204575c0 | |
| parent | cf14af7dc7b6ffa3ef899a57079bafc5a8d63c68 (diff) | |
a
| -rw-r--r-- | main/app.cpp | 4 | ||||
| -rw-r--r-- | main/camera.cpp | 23 | ||||
| -rw-r--r-- | shaders/tile-shader.cpp | 7 | ||||
| -rw-r--r-- | shaders/tile-shader.hpp | 4 | ||||
| -rw-r--r-- | shaders/tile-shader.vert | 2 | ||||
| -rw-r--r-- | src/camera-offset.cpp | 2 |
6 files changed, 12 insertions, 30 deletions
diff --git a/main/app.cpp b/main/app.cpp index 9fd9664d..f60b1287 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -81,7 +81,7 @@ void app::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event) void app::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event) { - if (_imgui.handleMouseMoveEvent(event)) + if (_imgui.handleMouseMoveEvent(event) && false) return _cursor_tile = std::nullopt, event.setAccepted(); _cursor_pos = event.position(); @@ -114,7 +114,7 @@ void app::anyEvent(SDL_Event& event) case SDL_WINDOWEVENT_ENTER: return event_mouse_enter(); default: - printf(""); break; // put breakpoint here + std::fputs("", stdout); break; // put breakpoint here } } diff --git a/main/camera.cpp b/main/camera.cpp index aa4cad00..7086b562 100644 --- a/main/camera.cpp +++ b/main/camera.cpp @@ -33,8 +33,11 @@ void app::do_camera(float dt_) void app::reset_camera_offset() { - //_shader.set_camera_offset(tile_shader::project({TILE_MAX_DIM*.25*dTILE_SIZE[0], TILE_MAX_DIM*.25*dTILE_SIZE[1], 0})); +#if 1 + _shader.set_camera_offset(tile_shader::project({TILE_MAX_DIM*-.5*dTILE_SIZE[0], TILE_MAX_DIM*-.5*dTILE_SIZE[1], 0})); +#else _shader.set_camera_offset({}); +#endif recalc_cursor_tile(); } @@ -59,24 +62,6 @@ global_coords app::pixel_to_tile(Vector2d position) const return { x, y }; } -namespace sqrt_detail -{ -constexpr double sqrt_Newton_Raphson(double x, double curr, double prev) -{ - constexpr auto abs = [](double x) constexpr { return x < 0 ? -x : x; }; - while (abs(curr - prev) > 1e-16) - { - prev = curr; - curr = .5 * (curr + x/curr); - } - return curr; -} -} // namespace sqrt_detail -constexpr double ce_sqrt(double x) -{ - return sqrt_detail::sqrt_Newton_Raphson(x, x, 0); -} - std::array<std::int16_t, 4> app::get_draw_bounds() const noexcept { const auto center = pixel_to_tile(Vector2d(windowSize()/2)).chunk(); diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp index 2218d463..12bc0a6d 100644 --- a/shaders/tile-shader.cpp +++ b/shaders/tile-shader.cpp @@ -39,11 +39,7 @@ tile_shader& tile_shader::set_scale(const Vector2& scale) tile_shader& tile_shader::set_camera_offset(Vector2d camera_offset) { - static constexpr auto MAX = std::numeric_limits<std::int32_t>::max(); - ASSERT(std::fabs(camera_offset[0]) <= MAX); - ASSERT(std::fabs(camera_offset[1]) <= MAX); _camera_offset = camera_offset; - return *this; } @@ -56,9 +52,10 @@ tile_shader& tile_shader::set_tint(const Vector4& tint) void tile_shader::_draw() { - if (const auto offset = Vector2i{(std::int32_t)_camera_offset[0], (std::int32_t)_camera_offset[1]}; + if (const auto offset = Vector2{(float)_camera_offset[0], (float)_camera_offset[1]}; offset != _real_camera_offset) { + ASSERT(offset[0] < 1 << 24 && offset[1] < 1 << 24); _real_camera_offset = offset; setUniform(OffsetUniform, offset); } diff --git a/shaders/tile-shader.hpp b/shaders/tile-shader.hpp index c8d609f3..d538c4cc 100644 --- a/shaders/tile-shader.hpp +++ b/shaders/tile-shader.hpp @@ -33,7 +33,7 @@ private: Vector2d _camera_offset; Vector4 _tint; Vector2 _scale; - Vector2i _real_camera_offset; + Vector2 _real_camera_offset; enum { ScaleUniform = 0, OffsetUniform = 1, TintUniform = 2, }; }; @@ -48,7 +48,7 @@ auto tile_shader::draw(T&& mesh, Xs&&... xs) -> constexpr Vector2d tile_shader::project(const Vector3d pt) { - const auto x = -pt[0], y = pt[1], z = pt[2]; + const auto x = pt[0], y = pt[1], z = pt[2]; return { (x-y), (x+y+z*2)*.59 }; } diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert index d28f25fb..8b3f2dba 100644 --- a/shaders/tile-shader.vert +++ b/shaders/tile-shader.vert @@ -1,7 +1,7 @@ precision highp float; layout (location = 0) uniform vec2 scale; -layout (location = 1) uniform ivec2 offset; +layout (location = 1) uniform vec2 offset; layout (location = 0) in vec4 position; layout (location = 1) in vec2 texcoords; diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index 63de0b8b..0f90768b 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -12,7 +12,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, shor _shader{shader}, _offset{shader.camera_offset()} { - const auto offset = _offset + tile_shader::project({-double(x)*TILE_MAX_DIM*dTILE_SIZE[0], + const auto offset = _offset + tile_shader::project({double(x)*TILE_MAX_DIM*dTILE_SIZE[0], double(y)*TILE_MAX_DIM*dTILE_SIZE[1], 0}); _shader.set_camera_offset(offset); |
