diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-23 09:05:17 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-23 09:05:17 +0100 |
commit | 7d4f172bd280e77175f617f36673d99f50580d36 (patch) | |
tree | 0b4cd3e8978119e0c38173b70666c68b715ce945 | |
parent | 06ccfd8b34c702da9ad695982e8210823d7b501c (diff) |
wip
-rw-r--r-- | entity/accessor.hpp | 7 | ||||
-rw-r--r-- | entity/chunk.cpp | 24 | ||||
-rw-r--r-- | entity/concepts.hpp | 1 | ||||
-rw-r--r-- | entity/erased-constraints.cpp | 12 |
4 files changed, 40 insertions, 4 deletions
diff --git a/entity/accessor.hpp b/entity/accessor.hpp index f70dee72..84c599c2 100644 --- a/entity/accessor.hpp +++ b/entity/accessor.hpp @@ -4,6 +4,7 @@ #include "name-of.hpp" #include <type_traits> #include <utility> +#include <vector> #include <Corrade/Containers/StringView.h> namespace floormat::erased_constraints { @@ -81,8 +82,8 @@ struct erased_accessor final { template<typename Obj, typename FieldType> void read(const Obj& x, FieldType& value) const noexcept; template<typename Obj, typename FieldType> void write(Obj& x, move_qualified<FieldType> value) const noexcept; - field_status is_enabled(const void* x) const noexcept; - constexpr bool can_write() const noexcept { return writer != nullptr; } + inline field_status is_enabled(const void* x) const noexcept; + inline bool can_write() const noexcept { return writer != nullptr; } inline erased_constraints::range get_range(const void* x) const noexcept; inline erased_constraints::max_length get_max_length(const void* x) const noexcept; inline erased_constraints::group get_group(const void* x) const noexcept; @@ -175,4 +176,6 @@ erased_constraints::range erased_accessor::get_range(const void* x) const noexce erased_constraints::max_length erased_accessor::get_max_length(const void* x) const noexcept { return length_fun(x,length); } erased_constraints::group erased_accessor::get_group(const void* x) const noexcept { return group_fun(x, group); } +template<typename T> void get_erased_accessors(std::vector<erased_accessor>& ret); + } // namespace floormat::entities diff --git a/entity/chunk.cpp b/entity/chunk.cpp new file mode 100644 index 00000000..6857ac1d --- /dev/null +++ b/entity/chunk.cpp @@ -0,0 +1,24 @@ +#include "entity/metadata.hpp" +#include "entity/accessor.hpp" +#include "src/scenery.hpp" +#include "src/anim-atlas.hpp" + +namespace floormat::entities { + +template<> struct entity_accessors<scenery_ref> { + static constexpr auto accessors() + { + using entity = Entity<scenery_ref>; + using frame_t = scenery::frame_t; + constexpr auto tuple = std::make_tuple( + entity::type<scenery::frame_t>::field{"frame", + [](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)}; } + } + ); + return tuple; + } +}; + +} // namespace floormat::entities diff --git a/entity/concepts.hpp b/entity/concepts.hpp index 46ec4f6a..8ab13df9 100644 --- a/entity/concepts.hpp +++ b/entity/concepts.hpp @@ -1,6 +1,7 @@ #pragma once #include "util.hpp" #include "compat/function2.hpp" +#include "compat/assert.hpp" #include <concepts> #include <type_traits> diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp index 599b4164..031197eb 100644 --- a/entity/erased-constraints.cpp +++ b/entity/erased-constraints.cpp @@ -27,8 +27,16 @@ template<typename T> std::pair<T, T> range::convert() const } else { - fm_assert(type == type_uint); - return { T(min.u), T(max.u) }; + if (type == type_int) + { + fm_assert(min.i >= 0 && max.i >= 0); + return { T(min.i), T(max.i) }; + } + else + { + fm_assert(type == type_uint); + return { T(min.u), T(max.u) }; + } } } else |