diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 10:20:40 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 10:20:40 +0100 |
| commit | 9ff017f1d4c1502fca9797aa4b38351c97e57982 (patch) | |
| tree | 5b122d52ddec31c988e23a70531a968466e73bf6 /editor | |
| parent | 58d95d559276b556f584411d5c3ea0a986f3fbc4 (diff) | |
a
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.cpp | 46 | ||||
| -rw-r--r-- | editor/inspect-types.cpp | 14 | ||||
| -rw-r--r-- | editor/update.cpp | 10 |
3 files changed, 17 insertions, 53 deletions
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<critter> app::ensure_player_character(world& w) { - if (_character_id) - { - std::shared_ptr<critter> tmp; - if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter) - { - auto ptr = std::static_pointer_cast<critter>(C); - return {ptr}; - } - } - _character_id = 0; - - auto id = (object_id)-1; - - shared_ptr_wrapper<critter> 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<const critter&>(e); - if (C.playable) - { - id = std::min(id, C.id); - ret.ptr = std::static_pointer_cast<critter>(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<critter>(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<object, inspect_intent_t> { }, E::type<StringView>::field{"atlas"_s, [](const object& x) { return loader.strip_prefix(x.atlas->name()); }, - [](object&, StringView) {}, + ignored_write, constantly(st::readonly), }, E::type<rotation>::field{"rotation"_s, @@ -36,14 +36,22 @@ struct entity_accessors<object, inspect_intent_t> { [](object& x, rotation r) { x.rotate(x.index(), r); }, }, E::type<uint16_t>::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<uint16_t>{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)}; }, }, + E::type<Vector3i>::field{"chunk"_s, + [](const object& x) { return Vector3i(x.chunk().coord()); }, + ignored_write, + }, + E::type<Vector2i>::field{"tile"_s, + [](const object& x) { return Vector2i(x.coord.local()); }, + ignored_write, + }, E::type<Vector2i>::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; } |
