summaryrefslogtreecommitdiffhomepage
path: root/main/update.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-17 13:28:37 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-17 13:28:37 +0200
commit7f01dc47b0fd322d8c2b3f27eb1a94cd450a26a5 (patch)
treeac6201f9179a0315449ad46d742d2db325775eff /main/update.cpp
parente65ebe30d3f2af77d57cb15e5e2b30efa454b6a8 (diff)
a
Diffstat (limited to 'main/update.cpp')
-rw-r--r--main/update.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/main/update.cpp b/main/update.cpp
index 1c7bb500..28e1d985 100644
--- a/main/update.cpp
+++ b/main/update.cpp
@@ -2,10 +2,9 @@
namespace floormat {
-chunk app::make_test_chunk()
+void app::make_test_chunk(chunk& c)
{
constexpr auto N = TILE_MAX_DIM;
- chunk c;
for (auto [x, k, pt] : c) {
const auto& atlas = pt.x > N/2 && pt.y >= N/2 ? floor2 : floor1;
x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) };
@@ -15,10 +14,9 @@ chunk app::make_test_chunk()
c[{K, K }].wall_west = { wall2, 0 };
c[{K, K+1}].wall_north = { wall1, 0 };
c[{K+1, K }].wall_west = { wall2, 0 };
- return c;
}
-void app::do_mouse_click(const Vector2 pos, int button)
+void app::do_mouse_click(const global_coords pos, int button)
{
_editor.click_at_tile(pos, button);
}
@@ -31,23 +29,18 @@ void app::update(float dt)
Platform::Sdl2Application::exit(0);
}
-Vector2 app::pixel_to_tile(Vector2 position) const
+global_coords app::pixel_to_tile(Vector2 position) const
{
- const auto px = position - Vector2{windowSize()}*.5f - camera_offset;
- return unproject(px) / Vector2{TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f} + Vector2{.5f, .5f};
+ const Vector2 px = position - Vector2{windowSize()}*.5f - camera_offset;
+ const Vector2 vec = unproject(px) / Vector2{TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f} + Vector2{.5f, .5f};
+ const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]);
+ return { x, y };
}
void app::draw_cursor_tile()
{
if (_cursor_pos)
- {
- const auto tile = pixel_to_tile(Vector2(*_cursor_pos));
- if (std::min(tile[0], tile[1]) >= 0 && std::max(tile[0], tile[1]) < (int)TILE_MAX_DIM)
- {
- const auto x = std::uint8_t(tile[0]), y = std::uint8_t(tile[1]);
- draw_wireframe_quad({x, y});
- }
- }
+ draw_wireframe_quad(pixel_to_tile(Vector2(*_cursor_pos)));
}
} // namespace floormat