From 7d4f172bd280e77175f617f36673d99f50580d36 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 23 Feb 2023 09:05:17 +0100 Subject: wip --- entity/accessor.hpp | 7 +++++-- entity/chunk.cpp | 24 ++++++++++++++++++++++++ entity/concepts.hpp | 1 + entity/erased-constraints.cpp | 12 ++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 entity/chunk.cpp 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 #include +#include #include namespace floormat::erased_constraints { @@ -81,8 +82,8 @@ struct erased_accessor final { template void read(const Obj& x, FieldType& value) const noexcept; template void write(Obj& x, move_qualified 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 void get_erased_accessors(std::vector& 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 { + static constexpr auto accessors() + { + using entity = Entity; + using frame_t = scenery::frame_t; + constexpr auto tuple = std::make_tuple( + entity::type::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{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 #include 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 std::pair 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 -- cgit v1.2.3