summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/inspect.cpp5
-rw-r--r--entity/chunk.cpp13
-rw-r--r--entity/constraints.hpp2
-rw-r--r--entity/erased-constraints.cpp97
-rw-r--r--entity/erased-constraints.hpp10
5 files changed, 112 insertions, 15 deletions
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index 69734866..41986a19 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -79,8 +79,7 @@ template<typename T> void do_inspect_field(void* datum, const erased_accessor& a
}
else
{
- auto [min_, max_] = accessor.get_range(datum).convert<typename T::Type>();
- Math::Vector<T::Size, typename T::Type> min(min_), max(max_);
+ auto [min, max] = accessor.get_range(datum).convert<T>();
constexpr auto igdt = IGDT<typename T::Type>;
switch (repr)
{
@@ -94,6 +93,8 @@ template<typename T> void do_inspect_field(void* datum, const erased_accessor& a
ret = ImGui::SliderScalarN(label.data(), igdt, &value, T::Size, &min, &max);
break;
}
+ for (std::size_t i = 0; i < T::Size; i++)
+ value[i] = std::clamp(value[i], min[i], max[i]);
}
ImGui::NewLine();
diff --git a/entity/chunk.cpp b/entity/chunk.cpp
index 6857ac1d..f7b9aadc 100644
--- a/entity/chunk.cpp
+++ b/entity/chunk.cpp
@@ -2,6 +2,7 @@
#include "entity/accessor.hpp"
#include "src/scenery.hpp"
#include "src/anim-atlas.hpp"
+#include "src/tile-defs.hpp"
namespace floormat::entities {
@@ -11,10 +12,20 @@ template<> struct entity_accessors<scenery_ref> {
using entity = Entity<scenery_ref>;
using frame_t = scenery::frame_t;
constexpr auto tuple = std::make_tuple(
- entity::type<scenery::frame_t>::field{"frame",
+ entity::type<scenery::frame_t>::field{"frame"_s,
[](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)}; }
+ },
+ entity::type<Vector2b>::field{"offset"_s,
+ [](const scenery_ref& x) { return x.frame.offset; },
+ [](scenery_ref& x, Vector2b value) { x.frame.offset = value; },
+ constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)})
+ },
+ // todo pass_mode enum
+ entity::type<bool>::field{"interactive"_s,
+ [](const scenery_ref& x) { return x.frame.interactive; },
+ [](scenery_ref& x, bool value) { x.frame.interactive = value; }
}
);
return tuple;
diff --git a/entity/constraints.hpp b/entity/constraints.hpp
index 99705047..cfe33bfe 100644
--- a/entity/constraints.hpp
+++ b/entity/constraints.hpp
@@ -18,6 +18,8 @@ template<typename T> struct range
constexpr bool operator==(const range&) const noexcept = default;
};
+template<typename T> range(T min, T max) -> range<T>;
+
template<typename T>
constexpr range<T>::operator erased_constraints::range() const noexcept
{
diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp
index 031197eb..0826075e 100644
--- a/entity/erased-constraints.cpp
+++ b/entity/erased-constraints.cpp
@@ -3,15 +3,28 @@
#include <cstdint>
#include <cmath>
#include <limits>
+#include <Magnum/Magnum.h>
+#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
+#include <Magnum/Math/Vector4.h>
static_assert(sizeof(std::size_t) == sizeof(std::uintptr_t));
static_assert(sizeof(std::size_t) == sizeof(std::ptrdiff_t));
namespace floormat::entities::erased_constraints {
+namespace {
+template<typename T> struct is_magnum_vector_ final : std::false_type {};
+template<std::size_t N, typename T> struct is_magnum_vector_<Math::Vector<N, T>> : std::true_type {};
+template<typename T> struct is_magnum_vector_<Math::Vector2<T>> : std::true_type {};
+template<typename T> struct is_magnum_vector_<Math::Vector3<T>> : std::true_type {};
+template<typename T> struct is_magnum_vector_<Math::Vector4<T>> : std::true_type {};
+template<typename T> constexpr bool is_magnum_vector = is_magnum_vector_<T>::value;
+} // namespace
+
template<typename T> std::pair<T, T> range::convert() const
{
- static_assert(sizeof(T) <= sizeof(std::size_t));
+ static_assert(sizeof(T)*2 <= sizeof(*this));
using limits = std::numeric_limits<T>;
if (type == type_none)
@@ -39,6 +52,47 @@ template<typename T> std::pair<T, T> range::convert() const
}
}
}
+ else if constexpr(is_magnum_vector<T>)
+ {
+ using U = typename T::Type;
+ constexpr auto Size = T::Size;
+ static_assert(Size >= 2 && Size <= 4);
+ T a, b;
+ if constexpr(std::is_integral_v<U>)
+ {
+ if constexpr(std::is_signed_v<U>)
+ {
+ fm_assert(type == type_int4);
+ for (std::size_t i = 0; i < Size; i++)
+ a[i] = U(min.i4[i]), b[i] = U(max.i4[i]);
+ }
+ else
+ {
+ if (type == type_int4)
+ {
+ for (std::size_t i = 0; i < Size; i++)
+ {
+ fm_assert(min.i4[i] >= 0 && max.i4[i] >= 0);
+ a[i] = U(min.i4[i]), b[i] = U(max.i4[i]);
+ }
+ }
+ else
+ {
+ fm_assert(type == type_uint4);
+ for (std::size_t i = 0; i < Size; i++)
+ a[i] = U(min.i4[i]), b[i] = U(max.i4[i]);
+ }
+ }
+ }
+ else
+ {
+ static_assert(std::is_floating_point_v<U>);
+ fm_assert(type == type_float4);
+ for (std::size_t i = 0; i < Size; i++)
+ a[i] = U(min.f4[i]), b[i] = U(max.f4[i]);
+ }
+ return { a, b };
+ }
else
{
static_assert(std::is_floating_point_v<T>);
@@ -48,16 +102,37 @@ template<typename T> std::pair<T, T> range::convert() const
}
}
-template std::pair<std::uint8_t, std::uint8_t> range::convert() const;
-template std::pair<std::uint16_t, std::uint16_t> range::convert() const;
-template std::pair<std::uint32_t, std::uint32_t> range::convert() const;
-template std::pair<std::uint64_t, std::uint64_t> range::convert() const;
-template std::pair<std::int8_t, std::int8_t> range::convert() const;
-template std::pair<std::int16_t, std::int16_t> range::convert() const;
-template std::pair<std::int32_t, std::int32_t> range::convert() const;
-template std::pair<std::int64_t, std::int64_t> range::convert() const;
-template std::pair<float, float> range::convert() const;
-template std::pair<double, double> range::convert() const;
+template<typename T> using pair2 = std::pair<T, T>;
+
+template pair2<std::uint8_t> range::convert() const;
+template pair2<std::uint16_t> range::convert() const;
+template pair2<std::uint32_t> range::convert() const;
+template pair2<std::uint64_t> range::convert() const;
+template pair2<std::int8_t> range::convert() const;
+template pair2<std::int16_t> range::convert() const;
+template pair2<std::int32_t> range::convert() const;
+template pair2<float> range::convert() const;
+template pair2<Vector2ub> range::convert() const;
+template pair2<Vector2us> range::convert() const;
+template pair2<Vector2ui> range::convert() const;
+template pair2<Vector2b> range::convert() const;
+template pair2<Vector2s> range::convert() const;
+template pair2<Vector2i> range::convert() const;
+template pair2<Vector2> range::convert() const;
+template pair2<Vector3ub> range::convert() const;
+template pair2<Vector3us> range::convert() const;
+template pair2<Vector3ui> range::convert() const;
+template pair2<Vector3b> range::convert() const;
+template pair2<Vector3s> range::convert() const;
+template pair2<Vector3i> range::convert() const;
+template pair2<Vector3> range::convert() const;
+template pair2<Vector4ub> range::convert() const;
+template pair2<Vector4us> range::convert() const;
+template pair2<Vector4ui> range::convert() const;
+template pair2<Vector4b> range::convert() const;
+template pair2<Vector4s> range::convert() const;
+template pair2<Vector4i> range::convert() const;
+template pair2<Vector4> range::convert() const;
bool operator==(const range& a, const range& b)
{
diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp
index 5a6cb939..c77d8166 100644
--- a/entity/erased-constraints.hpp
+++ b/entity/erased-constraints.hpp
@@ -1,5 +1,6 @@
#pragma once
#include <Corrade/Containers/StringView.h>
+#include <Magnum/Math/Vector4.h>
namespace floormat::entities::erased_constraints {
@@ -7,11 +8,18 @@ struct range final
{
using U = std::size_t;
using I = std::make_signed_t<U>;
- enum type_ : unsigned char { type_none, type_float, type_uint, type_int, };
+ enum type_ : unsigned char {
+ type_none,
+ type_float, type_uint, type_int,
+ type_float4, type_uint4, type_int4,
+ };
union element {
float f;
U u;
I i;
+ Math::Vector4<float> f4;
+ Math::Vector4<U> u4;
+ Math::Vector4<I> i4;
};
element min {.i = 0}, max {.i = 0};