summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-14 07:33:47 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-14 07:33:47 +0100
commitdc5e66b5a29fd7de8ddf59852ceefd982289b7c3 (patch)
tree18bf0a274f1595d6d2d6cfb32a3b3825d843e315 /editor
parent29bdd5f2170b9d46a8b3b0973c4c0845d6a2b61e (diff)
a
Diffstat (limited to 'editor')
-rw-r--r--editor/app.cpp2
-rw-r--r--editor/app.hpp7
-rw-r--r--editor/character.cpp137
-rw-r--r--editor/character.hpp28
-rw-r--r--editor/draw.cpp8
-rw-r--r--editor/imgui-editors.cpp2
-rw-r--r--editor/imgui-inspect.cpp22
-rw-r--r--editor/imgui.cpp21
-rw-r--r--editor/inspect-types.cpp59
-rw-r--r--editor/scenery-editor.cpp17
-rw-r--r--editor/update.cpp67
11 files changed, 92 insertions, 278 deletions
diff --git a/editor/app.cpp b/editor/app.cpp
index 80599ed1..aa8608c5 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -33,7 +33,7 @@ app::app(fm_settings&& opts) :
maybe_initialize_chunk_(coord, w[coord]);
reset_camera_offset();
inspectors.reserve(16);
- _character = std::make_unique<character_wip>();
+ _character = w.make_entity<character>(global_coords{});
}
app::~app()
diff --git a/editor/app.hpp b/editor/app.hpp
index 56660845..9e6b1312 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -23,7 +23,7 @@ struct tile_atlas;
struct tile_editor;
struct fm_settings;
struct anim_atlas;
-struct character_wip;
+struct character;
struct cursor_state final {
Optional<Vector2i> pixel;
@@ -44,8 +44,7 @@ enum class popup_target_type : unsigned char {
};
struct popup_target final {
- chunk_coords c;
- local_coords pos;
+ std::shared_ptr<entity> e;
popup_target_type target = popup_target_type::none;
bool operator==(const popup_target&) const;
};
@@ -150,7 +149,7 @@ private:
key_set keys;
std::array<int, key_set::COUNT> key_modifiers = {};
std::vector<popup_target> inspectors;
- std::unique_ptr<character_wip> _character;
+ std::shared_ptr<character> _character;
cursor_state cursor;
popup_target _popup_target;
diff --git a/editor/character.cpp b/editor/character.cpp
deleted file mode 100644
index 845f8345..00000000
--- a/editor/character.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-#include "character.hpp"
-#include "src/anim-atlas.hpp"
-#include "loader/loader.hpp"
-#include "src/world.hpp"
-#include "src/RTree.hpp"
-#include <cmath>
-
-namespace floormat {
-
-namespace {
-
-template <typename T>
-constexpr T sgn(T val) { return T(T(0) < val) - T(val < T(0)); }
-
-constexpr int tile_size_1 = iTILE_SIZE2.sum()/2,
- framerate = 96, move_speed = tile_size_1 * 2;
-constexpr float frame_time = 1.f/framerate;
-constexpr auto inv_tile_size = 1 / TILE_SIZE2;
-constexpr Vector2b bbox_size(12);
-
-constexpr auto arrows_to_dir(bool L, bool R, bool U, bool D)
-{
- if (L == R)
- L = R = false;
- if (U == D)
- U = D = false;
-
- using enum rotation;
- struct {
- int lr = 0, ud = 0;
- rotation r = N;
- } dir;
-
- if (L && U)
- dir = { -1, 0, W };
- else if (L && D)
- dir = { 0, 1, S };
- else if (R && U)
- dir = { 0, -1, N };
- else if (R && D)
- dir = { 1, 0, E };
- else if (L)
- dir = { -1, 1, SW };
- else if (D)
- dir = { 1, 1, SE };
- else if (R)
- dir = { 1, -1, NE };
- else if (U)
- dir = { -1, -1, NW };
-
- return dir;
-}
-
-} // namespace
-
-character_wip::character_wip() :
- walk_anim{loader.anim_atlas("npc-walk", loader.ANIM_PATH)}
-{
-}
-
-character_wip::~character_wip() = default;
-
-int character_wip::allocate_frame_time(float dt)
-{
- int d = int(delta) + int(65535u * dt);
- constexpr int framerate_ = 65535/framerate;
- static_assert(framerate_ > 0);
- auto ret = d / framerate_;
- delta = (std::uint16_t)std::clamp(d - ret*65535, 0, 65535);
- return ret;
-}
-
-Vector2 character_wip::move_vec(int left_right, int top_bottom)
-{
- constexpr auto c = move_speed * frame_time;
- return c * Vector2(sgn(left_right), sgn(top_bottom)).normalized();
-}
-
-void character_wip::tick(world& w, float dt, bool L, bool R, bool U, bool D)
-{
- auto [lr, ud, rot] = arrows_to_dir(L, R, U, D);
-
- if (!lr & !ud)
- {
- delta = 0;
- return;
- }
-
- int nframes = allocate_frame_time(dt);
-
- if (!nframes)
- return;
-
- const auto vec = move_vec(lr, ud);
- r = rot;
-
- for (int i = 0; i < nframes; i++)
- {
- auto pos_ = pos;
- Vector2 offset_ = offset;
- offset_ += vec;
- auto pos_1 = Vector2i(offset_ * inv_tile_size);
- pos_ += pos_1;
- offset_ = Vector2(std::fmod(offset_[0], TILE_SIZE2[0]), std::fmod(offset_[1], TILE_SIZE2[1]));
- constexpr auto half_tile = TILE_SIZE2/2;
- if (auto off = offset_[0]; std::fabs(off) > half_tile[0])
- {
- pos_ += Vector2i(offset_[0] < 0 ? -1 : 1, 0);
- offset_[0] = std::copysign(TILE_SIZE[0] - std::fabs(offset_[0]), -off);
- }
- if (auto off = offset_[1]; std::fabs(off) > half_tile[1])
- {
- pos_ += Vector2i(0, offset_[1] < 0 ? -1 : 1);
- offset_[1] = std::copysign(TILE_SIZE[1] - std::fabs(offset_[1]), -off);
- }
- auto [c, t] = w[pos_];
- const auto& r = c.rtree();
- auto center = Vector2(pos_.local()) * TILE_SIZE2 + offset_;
- auto half_bbox = Vector2(bbox_size)*.5f;
- auto min = center - half_bbox;
- auto max = center + half_bbox;
- bool is_blocked = false;
- r->Search(min.data(), max.data(), [&](const std::uint64_t data, const auto&) {
- auto cdata = std::bit_cast<collision_data>(data);
- is_blocked |= (pass_mode)cdata.pass != pass_mode::pass;
- return !is_blocked;
- });
- if (is_blocked)
- break;
- pos = pos_;
- offset = offset_;
- ++frame %= walk_anim->info().nframes;
- }
- //Debug{} << "pos" << Vector2i(pos.local());
-}
-
-} // namespace floormat
diff --git a/editor/character.hpp b/editor/character.hpp
deleted file mode 100644
index 7172415c..00000000
--- a/editor/character.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-#include "src/global-coords.hpp"
-#include "src/rotation.hpp"
-#include <memory>
-
-namespace floormat {
-
-struct anim_atlas;
-struct world;
-
-struct character_wip final
-{
- character_wip();
- ~character_wip();
- void tick(world& w, float dt, bool L, bool R, bool U, bool D);
-
- std::shared_ptr<anim_atlas> walk_anim;
- global_coords pos;
- Vector2 offset;
- std::uint16_t delta = 0, frame = 0;
- rotation r = rotation::NE;
-
-private:
- int allocate_frame_time(float dt);
- static Vector2 move_vec(int left_right, int top_bottom);
-};
-
-} // namespace floormat
diff --git a/editor/draw.cpp b/editor/draw.cpp
index 7ce5c7bf..dd286edf 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -54,7 +54,7 @@ void app::draw_cursor()
shader.set_tint({1, 1, 1, 0.75f});
auto [_f, _w, anim_mesh] = M->meshes();
const auto pos = cursor.tile->to_signed3()*iTILE_SIZE;
- anim_mesh.draw(shader, *sel.atlas, sel.frame.r, sel.frame.frame, Vector3(pos), 1);
+ anim_mesh.draw(shader, *sel.atlas, sel.r, sel.frame, Vector3(pos), 1);
}
}
@@ -153,9 +153,9 @@ void app::draw_character()
auto& c = *_character;
const auto [minx, maxx, miny, maxy] = M->get_draw_bounds();
- const with_shifted_camera_offset o{shader, c.pos.chunk(), {minx, miny}, {maxx, maxy}};
+ const with_shifted_camera_offset o{shader, c.coord.chunk(), {minx, miny}, {maxx, maxy}};
if (floormat_main::check_chunk_visible(shader.camera_offset(), sz))
- mesh.draw(shader, *c.walk_anim, c.r, c.frame, c.pos.local(), Vector2b(c.offset), tile_shader::character_depth_offset);
+ mesh.draw(shader, *c.atlas, c.r, c.frame, c.coord.local(), Vector2b(c.offset), tile_shader::character_depth_offset);
GL::Renderer::setDepthMask(true);
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
@@ -163,7 +163,7 @@ void app::draw_character()
void app::draw()
{
- draw_character();
+ //draw_character();
if (_render_bboxes)
draw_collision_boxes();
if (_editor.current_tile_editor() || _editor.current_scenery_editor())
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index cdc99c69..77658680 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -69,7 +69,7 @@ void app::draw_editor_scenery_pane(scenery_editor& ed)
}
if (ImGui::TableSetColumnIndex(2))
{
- switch (scenery.proto.frame.type)
+ switch (scenery.proto.sc_type)
{
case scenery_type::none: text("none"); break;
case scenery_type::generic: text("generic"); break;
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp
index b673c9d5..0d1ab6cf 100644
--- a/editor/imgui-inspect.cpp
+++ b/editor/imgui-inspect.cpp
@@ -29,15 +29,11 @@ void app::draw_inspector()
for (auto i = inspectors.size()-1; i != -1_uz; i--)
{
- auto [ch, pos, target] = inspectors[i];
- auto [c, t] = w[{ch, pos}];
- auto s = t.scenery();
-
- if (!s)
- {
- inspectors.erase(inspectors.begin() + (int)i);
- continue;
- }
+ auto [e, target] = inspectors[i];
+ auto& s = *e;
+ chunk_coords ch = e->coord.chunk();
+ local_coords pos = e->coord.local();
+ auto& c = w[ch];
char buf[128];
snformat(buf, "i-{}-{}x{}-{}x{}"_cf, (int)target, ch.x, ch.y, (int)pos.x, (int)pos.y);
@@ -48,7 +44,13 @@ void app::draw_inspector()
snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
bool is_open = true;
if (auto b2 = begin_window(buf, &is_open))
- c.with_scenery_update(s.index(), [&] { return entities::inspect_type(s); });
+ {
+ if (s.type == entity_type::scenery)
+ {
+ auto& s2 = static_cast<scenery&>(s);
+ c.with_scenery_update(s, [&] { return entities::inspect_type(s2); });
+ }
+ }
if (!is_open)
inspectors.erase(inspectors.begin() + (int)i);
}
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 753475d3..4ce19403 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -138,19 +138,14 @@ bool app::check_inspector_exists(popup_target p)
void app::do_popup_menu()
{
fm_assert(_popup_target.target != popup_target_type::none);
- auto& w = M->world();
-
auto b0 = push_id(SCENERY_POPUP_NAME);
-
- const auto [ch, pos, type] = _popup_target;
- auto [c, t] = w[{ch, pos}];
+ const auto [sc, target] = _popup_target;
//if (_popup_target.target != popup_target_type::scenery) {...}
- auto sc = t.scenery();
if (_pending_popup)
{
_pending_popup = false;
- fm_assert(type != popup_target_type::none);
+ fm_assert(target != popup_target_type::none);
//if (type != popup_target_type::scenery) {...}
if (sc)
ImGui::OpenPopup(SCENERY_POPUP_NAME.data());
@@ -158,11 +153,13 @@ void app::do_popup_menu()
if (auto b1 = begin_popup(SCENERY_POPUP_NAME))
{
- if (ImGui::MenuItem("Activate", nullptr, false, sc.can_activate()))
- sc.activate();
- if (auto next_rot = sc.atlas->next_rotation_from(sc.frame.r);
- ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc.frame.r))
- sc.rotate(next_rot);
+ auto iter = sc->iter();
+ auto& c = sc->chunk();
+ if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(iter, c)))
+ sc->activate(iter, c);
+ if (auto next_rot = sc->atlas->next_rotation_from(sc->r);
+ ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r))
+ sc->rotate(iter, c, next_rot);
ImGui::Separator();
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index 110ebabf..9b14c132 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -20,53 +20,52 @@ static Corrade::Containers::String my_str;
namespace floormat::entities {
template<>
-struct entity_accessors<scenery_ref> {
+struct entity_accessors<scenery> {
static constexpr auto accessors()
{
- using entity = Entity<scenery_ref>;
- using frame_t = scenery::frame_t;
+ using entity = Entity<scenery>;
return std::tuple{
entity::type<StringView>::field{"name"_s,
- [](const scenery_ref& x) { return loader.strip_prefix(x.atlas->name()); },
- [](scenery_ref&, StringView) {},
+ [](const scenery& x) { return loader.strip_prefix(x.atlas->name()); },
+ [](scenery&, StringView) {},
constantly(field_status::readonly),
},
entity::type<rotation>::field{"rotation"_s,
- [](const scenery_ref& x) { return x.frame.r; },
- [](scenery_ref& x, rotation r) { x.rotate(r); },
+ [](const scenery& x) { return x.r; },
+ [](scenery& x, rotation r) { x.rotate(x.iter(), x.chunk(), r); },
},
- entity::type<scenery::frame_t>::field{"frame"_s,
- [](const scenery_ref& x) { return x.frame.frame; },
- [](scenery_ref& x, frame_t value) { x.frame.frame = value; },
- [](const scenery_ref& x) { return constraints::range<frame_t>{0, !x.atlas ? frame_t(0) : frame_t(x.atlas->info().nframes-1)}; }
+ entity::type<std::uint16_t>::field{"frame"_s,
+ [](const scenery& x) { return x.frame; },
+ [](scenery& x, std::uint16_t value) { x.frame = value; },
+ [](const scenery& x) { return constraints::range<std::uint16_t>{0, !x.atlas ? std::uint16_t(0) : std::uint16_t(x.atlas->info().nframes-1)}; }
},
entity::type<Vector2b>::field{"offset"_s,
- [](const scenery_ref& x) { return x.frame.offset; },
- [](scenery_ref& x, Vector2b value) { x.frame.offset = value; },
+ [](const scenery& x) { return x.offset; },
+ [](scenery& x, Vector2b value) { x.offset = value; },
constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)})
},
entity::type<pass_mode>::field{"pass-mode"_s,
- [](const scenery_ref& x) { return x.frame.passability; },
- [](scenery_ref& x, pass_mode value) { x.chunk().with_scenery_update(x.index(), [&] { x.frame.passability = value; }); },
+ [](const scenery& x) { return x.pass; },
+ [](scenery& x, pass_mode value) { x.chunk().with_scenery_update(x, [&] { x.pass = value; }); },
},
entity::type<Vector2b>::field{"bbox-offset"_s,
- [](const scenery_ref& x) { return x.frame.bbox_offset; },
- [](scenery_ref& x, Vector2b value) { x.chunk().with_scenery_update(x.index(), [&] { x.frame.bbox_offset = value; }); },
- [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; },
+ [](const scenery& x) { return x.bbox_offset; },
+ [](scenery& x, Vector2b value) { x.chunk().with_scenery_update(x, [&] { x.bbox_offset = value; }); },
+ [](const scenery& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; },
},
entity::type<Vector2ub>::field{"bbox-size"_s,
- [](const scenery_ref& x) { return x.frame.bbox_size; },
- [](scenery_ref& x, Vector2ub value) { x.chunk().with_scenery_update(x.index(), [&] { x.frame.bbox_size = value; }); },
- [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; },
+ [](const scenery& x) { return x.bbox_size; },
+ [](scenery& x, Vector2ub value) { x.chunk().with_scenery_update(x, [&] { x.bbox_size = value; }); },
+ [](const scenery& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; },
},
entity::type<bool>::field{"interactive"_s,
- [](const scenery_ref& x) { return x.frame.interactive; },
- [](scenery_ref& x, bool value) { x.frame.interactive = value; }
+ [](const scenery& x) { return x.interactive; },
+ [](scenery& x, bool value) { x.interactive = value; }
},
#ifdef TEST_STR
entity::type<String>::field{"string"_s,
- [](const scenery_ref&) { return my_str; },
- [](scenery_ref&, String value) { my_str = std::move(value); },
+ [](const scenery&) { return my_str; },
+ [](scenery&, String value) { my_str = std::move(value); },
constantly(constraints::max_length{8}),
},
#endif
@@ -75,8 +74,8 @@ struct entity_accessors<scenery_ref> {
};
template<typename T, typename = void> struct has_anim_atlas : std::false_type {};
-template<> struct has_anim_atlas<scenery_ref> : std::true_type {
- static const anim_atlas& get_atlas(const scenery_ref& x) {
+template<> struct has_anim_atlas<scenery> : std::true_type {
+ static const anim_atlas& get_atlas(const scenery& x) {
fm_assert(x.atlas);
return *x.atlas;
}
@@ -135,12 +134,12 @@ struct enum_values<rotation, U> : std::false_type {
};
template<>
-bool inspect_type<scenery_ref>(scenery_ref& x)
+bool inspect_type<scenery>(scenery& x)
{
bool ret = false;
visit_tuple([&](const auto& field) {
using type = typename std::decay_t<decltype(field)>::FieldType;
- using enum_type = enum_values<type, scenery_ref>;
+ using enum_type = enum_values<type, scenery>;
if constexpr(enum_type::value)
{
constexpr auto list = enum_type::get();
@@ -151,7 +150,7 @@ bool inspect_type<scenery_ref>(scenery_ref& x)
const auto& list = enum_type::get(x);
ret |= inspect_field<type>(&x, field.erased(), list);
}
- }, entity_metadata<scenery_ref>::accessors);
+ }, entity_metadata<scenery>::accessors);
return ret;
}
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp
index 1d0635a6..9e9aa47b 100644
--- a/editor/scenery-editor.cpp
+++ b/editor/scenery-editor.cpp
@@ -22,7 +22,7 @@ scenery_editor::scenery_editor() noexcept
void scenery_editor::set_rotation(rotation_ r)
{
- auto& s = _selected.proto.frame;
+ auto& s = _selected.proto;
s.bbox_offset = rotate_point(s.bbox_offset, s.r, r);
s.bbox_size = rotate_size(s.bbox_size, s.r, r);
s.r = r;
@@ -30,24 +30,24 @@ void scenery_editor::set_rotation(rotation_ r)
rotation_ scenery_editor::rotation() const
{
- return _selected.proto.frame.r;
+ return _selected.proto.r;
}
void scenery_editor::next_rotation()
{
- set_rotation(_selected.proto.atlas->next_rotation_from(_selected.proto.frame.r));
+ set_rotation(_selected.proto.atlas->next_rotation_from(_selected.proto.r));
}
void scenery_editor::prev_rotation()
{
- set_rotation(_selected.proto.atlas->prev_rotation_from(_selected.proto.frame.r));
+ set_rotation(_selected.proto.atlas->prev_rotation_from(_selected.proto.r));
}
void scenery_editor::select_tile(const scenery_& s)
{
- const auto r = s.proto.atlas && s.proto.atlas->check_rotation(_selected.proto.frame.r)
- ? _selected.proto.frame.r
- : s.proto.frame.r;
+ const auto r = s.proto.atlas && s.proto.atlas->check_rotation(_selected.proto.r)
+ ? _selected.proto.r
+ : s.proto.r;
_selected = s;
set_rotation(r);
}
@@ -80,7 +80,8 @@ bool scenery_editor::is_anything_selected() const
void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s)
{
auto [c, t] = w[pos];
- t.scenery() = s.proto;
+ // todo check collision at pos
+ auto sc = w.make_entity<scenery>(pos, s.proto);
c.mark_scenery_modified();
}
diff --git a/editor/update.cpp b/editor/update.cpp
index e9f178a1..24fd3086 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -69,28 +69,12 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods)
if (button == mouse_button_left)
{
if (auto* cl = find_clickable_scenery(*cursor.pixel))
- {
- auto [c, t] = w[{cl->chunk, cl->pos}];
- if (auto s = t.scenery())
- return (void)s.activate();
- }
+ return (void)cl->e->activate(cl->e->iter(), cl->e->chunk());
}
// TODO it should open on mouseup if still on the same item as on mousedown
else if (button == mouse_button_right)
- {
if (auto* cl = find_clickable_scenery(*cursor.pixel))
- {
- auto [c, t] = w[{cl->chunk, cl->pos}];
- if (auto s = t.scenery())
- {
- _popup_target = {
- .c = cl->chunk, .pos = cl->pos,
- .target = popup_target_type::scenery,
- };
- do_open_popup();
- }
- }
- }
+ _popup_target = { .e = cl->e, .target = popup_target_type::scenery, };
break;
case editor_mode::floor:
case editor_mode::walls:
@@ -120,18 +104,14 @@ void app::do_rotate(bool backward)
{
if (ed->is_anything_selected())
backward ? ed->prev_rotation() : ed->next_rotation();
- else if (cursor.tile)
+ else if (auto* cl = find_clickable_scenery(*cursor.pixel))
{
- auto [c, t] = M->world()[*cursor.tile];
- if (auto sc = t.scenery())
+ auto& e = *cl->e;
+ auto r = backward ? e.atlas->prev_rotation_from(e.r) : e.atlas->next_rotation_from(e.r);
+ if (r != e.r)
{
- auto [atlas, s] = sc;
- auto r = backward ? atlas->prev_rotation_from(s.r) : atlas->next_rotation_from(s.r);
- if (r != s.r)
- {
- sc.rotate(r);
- c.mark_scenery_modified();
- }
+ e.rotate(e.iter(), e.chunk(), r);
+ e.chunk().mark_scenery_modified();
}
}
}
@@ -204,16 +184,24 @@ void app::update_world(float dt)
minx--; miny--; maxx++; maxy++;
for (std::int16_t y = miny; y <= maxy; y++)
for (std::int16_t x = minx; x <= maxx; x++)
- for (auto& c = world[chunk_coords{x, y}]; auto [x, k, pt] : c)
- if (auto sc = x.scenery(); sc && sc.can_activate())
- c.with_scenery_update(sc.index(), [&] { return sc.update(dt); });
+ {
+ auto& c = world[chunk_coords{x, y}];
+ const auto& es = c.entities();
+ const auto size = es.size();
+ for (auto i = size-1; i != (std::size_t)-1; i--)
+ {
+ auto iter = es.cbegin() + std::ptrdiff_t(i);
+ auto& e = *es[i];
+ c.with_scenery_update(e, [&] { return e.update(iter, c, dt); });
+ }
+ }
}
-void app::update_character(float dt)
+void app::update_character([[maybe_unused]] float dt)
{
- _character->tick(M->world(), dt, keys[key_left], keys[key_right], keys[key_up], keys[key_down]);
+ _character->set_keys(keys[key_left], keys[key_right], keys[key_up], keys[key_down]);
}
void app::set_cursor()
@@ -221,16 +209,9 @@ void app::set_cursor()
if (!cursor.in_imgui)
{
if (auto* cl = find_clickable_scenery(cursor.pixel))
- {
- auto& w = M->world();
- auto [c, t] = w[{cl->chunk, cl->pos}];
- if (auto sc = t.scenery())
- {
- M->set_cursor(std::uint32_t(Cursor::Hand));
- return;
- }
- }
- M->set_cursor(std::uint32_t(Cursor::Arrow));
+ M->set_cursor(std::uint32_t(Cursor::Hand));
+ else
+ M->set_cursor(std::uint32_t(Cursor::Arrow));
}
else
set_cursor_from_imgui();