diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-27 21:04:41 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-27 21:06:57 +0100 |
commit | b7f3cff0904214f7161fed16bb5162b26260d386 (patch) | |
tree | b44ed9506e6fb1782987667ef92ebab9af1b8579 | |
parent | 11eb5a82f0cdddd79f051192110f9f3f4da7d58c (diff) |
add speed field to object (yet unused)
-rw-r--r-- | editor/inspect-types.cpp | 23 | ||||
-rw-r--r-- | serialize/savegame.cpp | 25 | ||||
-rw-r--r-- | src/critter.hpp | 1 | ||||
-rw-r--r-- | src/object.cpp | 2 | ||||
-rw-r--r-- | src/object.hpp | 2 |
5 files changed, 36 insertions, 17 deletions
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 5668d6b2..41a236b0 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -52,6 +52,10 @@ struct entity_accessors<object, inspect_intent_t> { [](const object& x) { return x.pass; }, [](object& x, pass_mode value) { x.set_bbox(x.offset, x.bbox_offset, x.bbox_size, value); }, }, + E::type<float>::field{"speed"_s, + [](const object& x) { return x.speed; }, + [](object& x, float value) { x.speed = Math::clamp(value, 0.f, 1e6f); } + }, E::type<Vector2b>::field{"bbox-offset"_s, [](const object& x) { return x.bbox_offset; }, [](object& x, Vector2b value) { x.set_bbox(x.offset, value, x.bbox_size, x.pass); }, @@ -202,18 +206,19 @@ struct entity_accessors<critter, inspect_intent_t> { static constexpr auto accessors() { using E = Entity<critter>; - auto tuple0 = entity_accessors<object, inspect_intent_t>::accessors(); - auto tuple = std::tuple{ + auto prev = entity_accessors<object, inspect_intent_t>::accessors(); + auto t0 = std::tuple{ E::type<String>::field{"name"_s, - [](const critter& x) { return x.name; }, - [](critter& x, const String& value) { x.name = value; }}, + [](const critter& x) { return x.name; }, + [](critter& x, const String& value) { x.name = value; } }, + }; + auto t1 = std::tuple{ E::type<bool>::field{"playable"_s, - [](const critter& x) { return x.playable; }, - [](critter& x, bool value) { x.playable = value; }, - constantly(constraints::max_length{128}), - }, + [](const critter& x) { return x.playable; }, + [](critter& x, bool value) { x.playable = value; }, + constantly(constraints::max_length{ 128 }) }, }; - return std::tuple_cat(tuple0, tuple); + return std::tuple_cat(t0, prev, t1); } }; diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index c737db57..ba126746 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -108,8 +108,11 @@ struct visitor_ // 19: see old-savegame.cpp // 20: complete rewrite // 21: oops, forgot the object counter + // 22: add object::speed - static constexpr inline proto_t proto_version = 21; + static constexpr inline proto_t proto_version = 22; + const proto_t& PROTO; + visitor_(const proto_t& proto) : PROTO{proto} {} template<typename T, typename F> CORRADE_ALWAYS_INLINE void do_visit_nonconst(const T& value, F&& fun) @@ -166,9 +169,12 @@ struct visitor_ fm_throw("invalid object type {}"_cf, (int)type); //do_visit(*obj.c, f); - auto pt = obj.coord.local(); - do_visit(pt, f); - non_const(obj.coord) = {ch, pt}; + { auto pt = obj.coord.local(); + do_visit(pt, f); + non_const(obj.coord) = {ch, pt}; + } + if (PROTO >= 22) [[likely]] + do_visit(obj.speed, f); do_visit_nonconst(obj.offset, f); do_visit_nonconst(obj.bbox_offset, f); do_visit_nonconst(obj.bbox_size, f); @@ -338,6 +344,8 @@ constexpr size_t vector_initial_size = 128, hash_initial_size = vector_initial_s struct writer final : visitor_<writer> { + static const proto_t fake_proto; + const world& w; struct serialized_atlas @@ -363,7 +371,10 @@ struct writer final : visitor_<writer> buffer header_buf{}, string_buf{}; - writer(const world& w) : w{w} {} // avoid spurious warning until GCC 14: warning: missing initializer for member ::<anonymous> + writer(const world& w) : + visitor_{ fake_proto }, + w{ w } + {} struct size_counter { @@ -663,6 +674,8 @@ void my_fwrite(FILE_raii& f, const buffer& buf, char(&errbuf)[128]) fm_abort("fwrite: %s", get_error_string(errbuf, error).data()); } +const visitor_<writer>::proto_t writer::fake_proto = proto_version; + } // namespace void world::serialize(StringView filename) @@ -738,7 +751,7 @@ struct reader final : visitor_<reader> class world& w; loader_policy asset_policy; - reader(class world& w, loader_policy asset_policy) : w{w}, asset_policy{asset_policy} {} + reader(class world& w, loader_policy asset_policy) : visitor_{PROTO}, w{w}, asset_policy{asset_policy} {} using visitor_<reader>::visit; diff --git a/src/critter.hpp b/src/critter.hpp index 00e01cd1..b2f356e4 100644 --- a/src/critter.hpp +++ b/src/critter.hpp @@ -1,6 +1,5 @@ #pragma once #include "src/global-coords.hpp" -#include "src/rotation.hpp" #include "src/object.hpp" #include <Corrade/Containers/String.h> diff --git a/src/object.cpp b/src/object.cpp index 307a2155..96acd4b9 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -47,7 +47,7 @@ object_proto::object_proto(const object_proto&) = default; object_type object_proto::type_of() const noexcept { return type; } object::object(object_id id, class chunk& c, const object_proto& proto) : - id{id}, c{&c}, atlas{proto.atlas}, + id{id}, c{&c}, atlas{proto.atlas}, speed{proto.speed}, offset{proto.offset}, bbox_offset{proto.bbox_offset}, bbox_size{proto.bbox_size}, delta{proto.delta}, frame{proto.frame}, r{proto.r}, pass{proto.pass} diff --git a/src/object.hpp b/src/object.hpp index 2d33885d..c915b134 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -18,6 +18,7 @@ class chunk; struct object_proto { std::shared_ptr<anim_atlas> atlas; + float speed = 1; Vector2b offset, bbox_offset; Vector2ub bbox_size = Vector2ub(tile_size_xy); uint16_t delta = 0, frame = 0; @@ -44,6 +45,7 @@ struct object class chunk* const c; const std::shared_ptr<anim_atlas> atlas; const global_coords coord; + float speed = 1; const Vector2b offset, bbox_offset; const Vector2ub bbox_size; uint16_t delta = 0, frame = 0; |