summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-25 07:38:40 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-25 07:38:40 +0200
commitbcfd2f2ce953b0f9ed0a59a46d8db463aef4e714 (patch)
treee4a93a3f765c3aa2bf2b36bc045572477f0bc590
parent5e3cbab0d0f08bc06141a565a1ef1e7d14bba9b7 (diff)
some work on inspecting other enttiy subtypes
-rw-r--r--editor/inspect-draw.cpp12
-rw-r--r--editor/inspect-types.cpp110
-rw-r--r--editor/inspect.hpp8
-rw-r--r--entity/accessor.hpp2
-rw-r--r--src/light-falloff.hpp2
5 files changed, 101 insertions, 33 deletions
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index a1adbba3..1f1ccec3 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -53,17 +53,11 @@ void app::draw_inspector()
snformat(buf, "{} ({}x{}:{} -> {}x{})"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y);
bool is_open = true;
- if (e.type() == entity_type::scenery)
+ if (auto b2 = begin_window(buf, &is_open))
{
- auto& s2 = static_cast<scenery&>(e);
- if (auto b2 = begin_window(buf, &is_open))
- {
- bool ret = entities::inspect_type(s2);
- (void)ret;
- }
+ bool ret = entities::inspect_entity_subtype(e);
+ (void)ret;
}
- else
- is_open = false;
if (!is_open)
inspectors.erase(inspectors.begin() + (ptrdiff_t)i);
}
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index b93813b9..849dcfa3 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -6,6 +6,8 @@
#include "inspect.hpp"
#include "loader/loader.hpp"
#include "chunk.hpp"
+#include "src/character.hpp"
+#include "src/light.hpp"
#include <Corrade/Containers/ArrayViewStl.h>
namespace floormat::entities {
@@ -75,10 +77,20 @@ struct entity_accessors<scenery> {
};
template<typename T, typename = void> struct has_anim_atlas : std::false_type {};
+
+template<typename T>
+requires requires (const T& x) { { x.atlas } -> std::convertible_to<const std::shared_ptr<anim_atlas>&>; }
+struct has_anim_atlas<T> : std::true_type {
+ static const anim_atlas& get_atlas(const entity& x) { return *x.atlas; }
+};
+
+#if 0
template<> struct has_anim_atlas<entity> : std::true_type {
static const anim_atlas& get_atlas(const entity& x) { return *x.atlas; }
};
template<> struct has_anim_atlas<scenery> : has_anim_atlas<entity> {};
+template<> struct has_anim_atlas<character> : has_anim_atlas<entity> {};
+#endif
using enum_pair = std::pair<StringView, size_t>;
template<typename T, typename U> struct enum_values;
@@ -94,23 +106,26 @@ template<size_t N> enum_pair_array(std::array<enum_pair, N> array, size_t) -> en
template<typename T, typename U>
requires (!std::is_enum_v<T>)
-struct enum_values<T, U> : std::true_type {
- static constexpr std::array<enum_pair, 0> get() { return {}; }
+struct enum_values<T, U>
+{
+ static constexpr std::array<enum_pair, 0> get(const U&) { return {}; }
};
-template<typename U> struct enum_values<pass_mode, U> : std::true_type {
+template<typename U> struct enum_values<pass_mode, U>
+{
static constexpr auto ret = std::to_array<enum_pair>({
{ "blocked"_s, (size_t)pass_mode::blocked, },
{ "see-through"_s, (size_t)pass_mode::see_through, },
{ "shoot-through"_s, (size_t)pass_mode::shoot_through, },
{ "pass"_s, (size_t)pass_mode::pass },
});
- static constexpr const auto& get() { return ret; }
+ static constexpr const auto& get(const U&) { return ret; }
};
template<typename U>
requires has_anim_atlas<U>::value
-struct enum_values<rotation, U> : std::false_type {
+struct enum_values<rotation, U>
+{
static auto get(const U& x) {
const anim_atlas& atlas = has_anim_atlas<U>::get_atlas(x);
std::array<enum_pair, (size_t)rotation_COUNT> array;
@@ -132,27 +147,86 @@ struct enum_values<rotation, U> : std::false_type {
}
};
-template<typename T> bool inspect_type(T& x)
+template<typename T>
+static bool inspect_type(T& x)
{
bool ret = false;
visit_tuple([&](const auto& field) {
using type = typename std::decay_t<decltype(field)>::FieldType;
- using enum_type = enum_values<type, T>;
- if constexpr(enum_type::value)
- {
- constexpr auto list = enum_type::get();
- ret |= inspect_field<type>(&x, field.erased(), list);
- }
- else
- {
- const auto& list = enum_type::get(x);
- ret |= inspect_field<type>(&x, field.erased(), list);
- }
+ using enum_type = enum_values<type, T>;
+ const auto& list = enum_type::get(x);
+ ret |= inspect_field<type>(&x, field.erased(), list);
}, entity_metadata<T>::accessors);
return ret;
}
-template bool inspect_type(entity&);
+template<>
+struct entity_accessors<character> {
+ static constexpr auto accessors()
+ {
+ using E = Entity<character>;
+ auto tuple0 = entity_accessors<entity>::accessors();
+ auto tuple = std::tuple{
+ E::type<String>::field{"name"_s,
+ [](const character& x) { return x.name; },
+ [](character& x, const String& value) { x.name = value; }},
+ E::type<bool>::field{"playable"_s,
+ [](const character& x) { return x.playable; },
+ [](character& x, bool value) { x.playable = value; },
+ },
+ };
+ return std::tuple_cat(tuple0, tuple);
+ }
+};
+
+template<typename U> struct enum_values<light_falloff, U>
+{
+ static constexpr auto ret = std::to_array<enum_pair>({
+ { "constant"_s, (size_t)light_falloff::constant },
+ { "linear"_s, (size_t)light_falloff::linear },
+ { "quadratic"_s, (size_t)light_falloff::quadratic },
+ });
+ static constexpr const auto& get(const U&) { return ret; }
+};
+
+template<>
+struct entity_accessors<light> {
+ static constexpr auto accessors()
+ {
+ using E = Entity<light>;
+ auto tuple0 = entity_accessors<entity>::accessors();
+ auto tuple = std::tuple{
+ E::type<Vector3ub>::field{"color"_s,
+ [](const light& x) { return Vector3ub(x.color); },
+ [](light& x, Vector3ub value) { x.color = Color3ub{value}; },
+ constantly(constraints::range<Vector3ub>{{0, 0, 0}, {255, 255, 255}}),
+ },
+ E::type<light_falloff>::field{"falloff"_s,
+ [](const light& x) { return x.falloff; },
+ [](light& x, light_falloff value) { x.falloff = value; },
+ },
+ // half_dist
+ // symmetric
+ };
+ return std::tuple_cat(tuple0, tuple);
+ }
+};
+
+//template bool inspect_type(entity&);
template bool inspect_type(scenery&);
+template bool inspect_type(character&);
+template bool inspect_type(light&);
+
+bool inspect_entity_subtype(entity& x)
+{
+ switch (auto type = x.type())
+ {
+ default: fm_warn_once("unknown entity subtype '%d'", (int)type); return false;
+ //case entity_type::none: return inspect_type(x);
+ case entity_type::scenery: return inspect_type(static_cast<scenery&>(x));
+ case entity_type::character: return inspect_type(static_cast<character&>(x));
+ case entity_type::light: return inspect_type(static_cast<light&>(x));
+ }
+}
} // namespace floormat::entities
diff --git a/editor/inspect.hpp b/editor/inspect.hpp
index 98649e13..f7769fae 100644
--- a/editor/inspect.hpp
+++ b/editor/inspect.hpp
@@ -28,10 +28,12 @@ template<typename T> using field_repr_cbx = field_repr_<T, field_repr, field_rep
template<typename T> bool inspect_field(void* datum, const entities::erased_accessor& accessor,
const ArrayView<const std::pair<StringView, size_t>>& list);
-template<typename T> bool inspect_type(T& x);
+bool inspect_entity_subtype(entity& x);
-template<typename T> requires std::is_enum_v<T> bool inspect_field(void* datum, const entities::erased_accessor& accessor,
- const ArrayView<const std::pair<StringView, size_t>>& list)
+template<typename T>
+requires std::is_enum_v<T>
+bool inspect_field(void* datum, const entities::erased_accessor& accessor,
+ const ArrayView<const std::pair<StringView, size_t>>& list)
{
return inspect_field<field_repr_cbx<std::underlying_type_t<T>>>(datum, accessor, list);
}
diff --git a/entity/accessor.hpp b/entity/accessor.hpp
index 3a25cd22..468c51c3 100644
--- a/entity/accessor.hpp
+++ b/entity/accessor.hpp
@@ -170,6 +170,4 @@ field_status erased_accessor::is_enabled(const void* x) const noexcept { return
erased_constraints::range erased_accessor::get_range(const void* x) const noexcept { return range_fun(x,range); }
erased_constraints::max_length erased_accessor::get_max_length(const void* x) const noexcept { return length_fun(x,length); }
-template<typename T> void get_erased_accessors(std::vector<erased_accessor>& ret);
-
} // namespace floormat::entities
diff --git a/src/light-falloff.hpp b/src/light-falloff.hpp
index e90d11aa..b9b1c4bf 100644
--- a/src/light-falloff.hpp
+++ b/src/light-falloff.hpp
@@ -3,7 +3,7 @@
namespace floormat {
enum class light_falloff : uint8_t {
- linear, quadratic, constant,
+ constant = 1, linear = 0, quadratic = 2,
};
} // namespace floormat