summaryrefslogtreecommitdiffhomepage
path: root/editor
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 /editor
parentd17ed6b4ba01a73d33e3ff3ca8f0f6fb25259223 (diff)
a
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp3
-rw-r--r--editor/draw.cpp99
-rw-r--r--editor/events.cpp2
-rw-r--r--editor/update.cpp48
4 files changed, 83 insertions, 69 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index 17dd80fe..a4d7c440 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -72,6 +72,7 @@ private:
void update(float dt) override;
void update_world(float dt);
void update_cursor_tile(const Optional<Vector2i>& pixel);
+ z_bounds get_z_bounds() override;
void set_cursor();
void maybe_initialize_chunk(const chunk_coords_& pos, chunk& c) override;
void maybe_initialize_chunk_(const chunk_coords_& pos, chunk& c);
@@ -86,7 +87,7 @@ private:
void on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept override;
void on_mouse_scroll(const mouse_scroll_event& event) noexcept override;
void on_key_up_down(const key_event& event, bool is_down) noexcept override;
- std::tuple<key, int> resolve_keybinding(int k, int mods) const;
+ std::tuple<key, int> resolve_keybinding(int k, int mods);
void on_text_input_event(const text_input_event& event) noexcept override;
//bool on_text_editing_event(const text_editing_event& event) noexcept override;
void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept override;
diff --git a/editor/draw.cpp b/editor/draw.cpp
index 285299b6..adbc7b60 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -66,6 +66,7 @@ void app::draw_cursor()
void app::draw_collision_boxes()
{
+ const auto [z_min, z_max] = get_z_bounds();
const auto [minx, maxx, miny, maxy] = M->get_draw_bounds();
const auto sz = M->window_size();
auto& world = M->world();
@@ -76,30 +77,31 @@ void app::draw_collision_boxes()
using rtree_type = std::decay_t<decltype(*world[chunk_coords{}].rtree())>;
using rect_type = typename rtree_type::Rect;
- for (int16_t y = miny; y <= maxy; y++)
- for (int16_t x = minx; x <= maxx; x++)
- {
- const chunk_coords pos{x, y};
- auto* c_ = world.at(pos);
- if (!c_)
- continue;
- auto& c = *c_;
- c.ensure_passability();
- const with_shifted_camera_offset o{shader, pos, {minx, miny}, {maxx, maxy}};
- if (floormat_main::check_chunk_visible(shader.camera_offset(), sz))
+ for (int8_t z = z_min; z <= z_max; z++)
+ for (int16_t y = miny; y <= maxy; y++)
+ for (int16_t x = minx; x <= maxx; x++)
{
- constexpr float maxf = 1 << 24, max2f[] = { maxf, maxf }, min2f[] = { -maxf, -maxf };
- const auto* rtree = c.rtree();
- rtree->Search(min2f, max2f, [&](object_id data, const rect_type& rect) {
- [[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
- Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
- auto size = (end - start);
- auto center = Vector3(start + size*.5f, 0.f);
- _wireframe_rect.draw(shader, { center, size, 3 });
- return true;
- });
+ const chunk_coords_ pos{x, y, z};
+ auto* c_ = world.at(pos);
+ if (!c_)
+ continue;
+ auto& c = *c_;
+ c.ensure_passability();
+ const with_shifted_camera_offset o{shader, pos, {minx, miny}, {maxx, maxy}};
+ if (floormat_main::check_chunk_visible(shader.camera_offset(), sz))
+ {
+ constexpr float maxf = 1 << 24, max2f[] = { maxf, maxf }, min2f[] = { -maxf, -maxf };
+ const auto* rtree = c.rtree();
+ rtree->Search(min2f, max2f, [&](object_id data, const rect_type& rect) {
+ [[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
+ Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
+ auto size = (end - start);
+ auto center = Vector3(start + size*.5f, 0.f);
+ _wireframe_rect.draw(shader, { center, size, 3 });
+ return true;
+ });
+ }
}
- }
shader.set_tint({1, 0, 1, 1});
@@ -113,34 +115,35 @@ void app::draw_collision_boxes()
const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f));
const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0],
curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]);
- for (int16_t y = miny; y <= maxy; y++)
- for (int16_t x = minx; x <= maxx; x++)
- {
- const chunk_coords c_pos{x, y};
- auto* c_ = world.at(c_pos);
- if (!c_)
- continue;
- auto& c = *c_;
- c.ensure_passability();
- const with_shifted_camera_offset o{shader, c_pos, {minx, miny}, {maxx, maxy}};
- if (floormat_main::check_chunk_visible(shader.camera_offset(), sz))
+ for (int8_t z = z_min; z <= z_max; z++)
+ for (int16_t y = miny; y <= maxy; y++)
+ for (int16_t x = minx; x <= maxx; x++)
{
- constexpr auto half_tile = TILE_SIZE2/2;
- constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM;
- auto chunk_dist = (curchunk - Vector2(c_pos))*chunk_size;
- auto t0 = chunk_dist + curtile*TILE_SIZE2 + subpixel - half_tile;
- auto t1 = t0+Vector2(1e-4f);
- const auto* rtree = c.rtree();
- rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) {
- [[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
- Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
- auto size = end - start;
- auto center = Vector3(start + size*.5f, 0.f);
- _wireframe_rect.draw(shader, { center, size, 3 });
- return true;
- });
+ const chunk_coords_ c_pos{x, y, z};
+ auto* c_ = world.at(c_pos);
+ if (!c_)
+ continue;
+ auto& c = *c_;
+ c.ensure_passability();
+ const with_shifted_camera_offset o{shader, c_pos, {minx, miny}, {maxx, maxy}};
+ if (floormat_main::check_chunk_visible(shader.camera_offset(), sz))
+ {
+ constexpr auto half_tile = TILE_SIZE2/2;
+ constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM;
+ auto chunk_dist = (curchunk - Vector2(c_pos.x, c_pos.y))*chunk_size;
+ auto t0 = chunk_dist + curtile*TILE_SIZE2 + subpixel - half_tile;
+ auto t1 = t0+Vector2(1e-4f);
+ const auto* rtree = c.rtree();
+ rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) {
+ [[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
+ Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
+ auto size = end - start;
+ auto center = Vector3(start + size*.5f, 0.f);
+ _wireframe_rect.draw(shader, { center, size, 3 });
+ return true;
+ });
+ }
}
- }
}
shader.set_tint({1, 1, 1, 1});
diff --git a/editor/events.cpp b/editor/events.cpp
index 89bdf4a3..275ddf57 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -102,7 +102,7 @@ void app::on_mouse_scroll(const mouse_scroll_event& event) noexcept
do_mouse_scroll((int)e.offset()[1]);
}
-auto app::resolve_keybinding(int k_, int mods_) const -> std::tuple<key, int>
+auto app::resolve_keybinding(int k_, int mods_) -> std::tuple<key, int>
{
[[maybe_unused]] constexpr int CTRL = kmod_ctrl;
[[maybe_unused]] constexpr int SHIFT = kmod_shift;
diff --git a/editor/update.cpp b/editor/update.cpp
index 6bb1ff66..f36b2905 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -185,33 +185,35 @@ void app::update_world(float dt)
{
auto& world = M->world();
const auto curframe = world.increment_frame_no();
+ auto [z_min, z_max] = get_z_bounds();
auto [minx, maxx, miny, maxy] = M->get_draw_bounds();
minx--; miny--; maxx++; maxy++;
- for (int16_t y = miny; y <= maxy; y++)
- for (int16_t x = minx; x <= maxx; x++)
- {
- auto* c_ = world.at(chunk_coords{x, y});
- if (!c_)
- continue;
- auto& c = *c_;
- const auto& es = c.entities();
-start: const auto size = es.size();
- for (auto i = size-1; i != (size_t)-1; i--)
+ for (int8_t z = z_min; z <= z_max; z++)
+ for (int16_t y = miny; y <= maxy; y++)
+ for (int16_t x = minx; x <= maxx; x++)
{
- auto& e = *es[i];
- fm_debug_assert(!(e.last_update > curframe));
- if (curframe > e.last_update) [[likely]]
+ auto* c_ = world.at({x, y, z});
+ if (!c_)
+ continue;
+ auto& c = *c_;
+ const auto& es = c.entities();
+start: const auto size = es.size();
+ for (auto i = size-1; i != (size_t)-1; i--)
{
- e.last_update = curframe;
- auto status = e.update(i, dt);
- if (status)
+ auto& e = *es[i];
+ fm_debug_assert(!(e.last_update > curframe));
+ if (curframe > e.last_update) [[likely]]
{
- //Debug{} << "goto start";
- goto start;
+ e.last_update = curframe;
+ auto status = e.update(i, dt);
+ if (status)
+ {
+ //Debug{} << "goto start";
+ goto start;
+ }
}
}
}
- }
}
void app::update_character([[maybe_unused]] float dt)
@@ -238,6 +240,14 @@ void app::set_cursor()
set_cursor_from_imgui();
}
+auto app::get_z_bounds() -> z_bounds
+{
+ if (_render_all_z_levels)
+ return { chunk_min_z, chunk_max_z };
+ else
+ return { _z_level, _z_level };
+}
+
void app::update(float dt)
{
apply_commands(keys);