From 9ff017f1d4c1502fca9797aa4b38351c97e57982 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 2 Mar 2024 10:20:40 +0100 Subject: a --- editor/app.cpp | 46 +--------------------------------------------- editor/inspect-types.cpp | 14 +++++++++++--- editor/update.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 53 deletions(-) (limited to 'editor') diff --git a/editor/app.cpp b/editor/app.cpp index 5e06d93a..dafea3d9 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -30,51 +30,7 @@ const cursor_state& app::cursor_state() { return cursor; } shared_ptr_wrapper app::ensure_player_character(world& w) { - if (_character_id) - { - std::shared_ptr tmp; - if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter) - { - auto ptr = std::static_pointer_cast(C); - return {ptr}; - } - } - _character_id = 0; - - auto id = (object_id)-1; - - shared_ptr_wrapper ret; - - for (const auto& [coord, c] : w.chunks()) - { - for (const auto& e_ : c.objects()) - { - const auto& e = *e_; - if (e.type() == object_type::critter) - { - const auto& C = static_cast(e); - if (C.playable) - { - id = std::min(id, C.id); - ret.ptr = std::static_pointer_cast(e_); - } - } - } - } - - if (id != (object_id)-1) - _character_id = id; - else - { - critter_proto cproto; - cproto.name = "Player"_s; - cproto.speed = 10; - cproto.playable = true; - ret.ptr = w.make_object(w.make_id(), global_coords{}, cproto); - _character_id = ret.ptr->id; - } - fm_debug_assert(ret.ptr); - return ret; + return w.ensure_player_character(_character_id); } void app::reset_world(class world&& w_) diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index fe33a760..44e85678 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -28,7 +28,7 @@ struct entity_accessors { }, E::type::field{"atlas"_s, [](const object& x) { return loader.strip_prefix(x.atlas->name()); }, - [](object&, StringView) {}, + ignored_write, constantly(st::readonly), }, E::type::field{"rotation"_s, @@ -36,14 +36,22 @@ struct entity_accessors { [](object& x, rotation r) { x.rotate(x.index(), r); }, }, E::type::field{"frame"_s, - [](const object& x) { return x.frame; }, + &object::frame, [](object& x, uint16_t value) { x.frame = value; }, [](const object& x) { return constraints::range{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)}; }, }, + E::type::field{"chunk"_s, + [](const object& x) { return Vector3i(x.chunk().coord()); }, + ignored_write, + }, + E::type::field{"tile"_s, + [](const object& x) { return Vector2i(x.coord.local()); }, + ignored_write, + }, E::type::field{"offset"_s, - [](const object& x) { return Vector2i(x.offset); }, + [](const object& x) { return Vector2i(x.offset); }, // todo return Vector2b //[](object& x, Vector2i value) { x.set_bbox(value, x.bbox_offset, x.bbox_size, x.pass); }, [](object& x, Vector2i value) { x.move_to(value - Vector2i(x.offset)); }, //constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}), diff --git a/editor/update.cpp b/editor/update.cpp index 8c3349e5..beb7c048 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -132,16 +132,16 @@ void app::do_emit_timestamp() char buf[fm_DATETIME_BUF_SIZE]; format_datetime_to_string(buf); - if (time >= 1e5f) + if (time >= 1e5) + fm_debug("%s%s0x%08x %.1f" " s", buf, prefix, counter++, time*1e-3); + else if (time >= 1e4) fm_debug("%s%s0x%08x %.2f" " s", buf, prefix, counter++, time*1e-3); - else if (time >= 1e4f) - fm_debug("%s%s0x%08x %.2f" " s", buf, prefix, counter++, time*1e-3); - else if (time >= 1e3f) + else if (time >= 1e3) fm_debug("%s%s0x%08x %.2f" " ms", buf, prefix, counter++, time); else if (time > 0) fm_debug("%s%s0x%08x %.4f" " ms", buf, prefix, counter++, time); else - fm_debug("%s%s0x%08x 0" " ms", buf, prefix, counter++); + fm_debug("%s%s0x%08x 0 ms", buf, prefix, counter++); _timestamp = now.stamp; } -- cgit v1.2.3