Nebula
Loading...
Searching...
No Matches
componentinspection.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13//------------------------------------------------------------------------------
14#include "util/delegate.h"
15#include "util/stringatom.h"
16#include "game/entity.h"
17#include "game/componentid.h"
22#include "util/colour.h"
23#include "imgui.h"
24
25namespace Game
26{
27
29{
30public:
31 using DrawFunc = void(*)(Game::ComponentId, void*, bool*);
32
34 static void Destroy();
35
36 static void Register(ComponentId component, DrawFunc);
37
38 static void DrawInspector(ComponentId component, void* data, bool* commit);
39
40private:
43
45
47};
48
49template<typename TYPE>
50void
51ComponentDrawFuncT(ComponentId component, void* data, bool* commit);
52
53template<typename TYPE, std::size_t i = 0>
54void InspectorDrawField(ComponentId component, void* data, bool* commit)
55{
56 if constexpr (i < TYPE::Traits::num_fields)
57 {
58 using field_tuple = typename TYPE::Traits::field_types;
59 using field_type = typename std::tuple_element<i, field_tuple>::type;
60 ImGui::Text(TYPE::Traits::field_names[i]);
61 ImGui::SameLine();
62 ComponentDrawFuncT<field_type>(component, (byte*)data + TYPE::Traits::field_byte_offsets[i], commit);
63 InspectorDrawField<TYPE, i + 1>(component, data, commit);
64 }
65}
66
67//------------------------------------------------------------------------------
70template<typename TYPE>
71void
72ComponentDrawFuncT(ComponentId component, void* data, bool* commit)
73{
74 if constexpr (requires { &TYPE::Traits::num_fields; })
75 {
76 if constexpr (TYPE::Traits::num_fields > 0 && !std::is_enum<TYPE>())
77 {
78 //UnrollTypesAndInspect<TYPE>(std::make_index_sequence<TYPE::Traits::num_fields>(), component, data, commit);
79 InspectorDrawField<TYPE>(component, data, commit);
80 }
81 }
82 return;
83}
84
85template<> void ComponentDrawFuncT<Game::Entity>(ComponentId, void*, bool*);
86template<> void ComponentDrawFuncT<bool>(ComponentId, void*, bool*);
87template<> void ComponentDrawFuncT<int>(ComponentId, void*, bool*);
88template<> void ComponentDrawFuncT<uint>(ComponentId, void*, bool*);
89template<> void ComponentDrawFuncT<float>(ComponentId, void*, bool*);
90template<> void ComponentDrawFuncT<Util::StringAtom>(ComponentId, void*, bool*);
91template<> void ComponentDrawFuncT<Math::mat4>(ComponentId, void*, bool*);
92template<> void ComponentDrawFuncT<Math::vec3>(ComponentId, void*, bool*);
93template<> void ComponentDrawFuncT<Game::Position>(ComponentId, void*, bool*);
94template<> void ComponentDrawFuncT<Game::Orientation>(ComponentId, void*, bool*);
95template<> void ComponentDrawFuncT<Game::Scale>(ComponentId, void*, bool*);
96template<> void ComponentDrawFuncT<Util::Colour>(ComponentId, void*, bool*);
97
98} // namespace Game
Component inspection functions.
Definition componentinspection.h:29
Util::Array< DrawFunc > inspectors
Definition componentinspection.h:46
ComponentInspection()
Definition componentinspection.cc:88
static ComponentInspection * Singleton
Definition componentinspection.h:44
static void Register(ComponentId component, DrawFunc)
Definition componentinspection.cc:55
void(*)(Game::ComponentId, void *, bool *) DrawFunc
Definition componentinspection.h:31
static void DrawInspector(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:74
static void Destroy()
This static method is used to destroy the registry object and should be called right before the main ...
Definition componentinspection.cc:42
~ComponentInspection()
Definition componentinspection.cc:96
static ComponentInspection * Instance()
The registry's constructor is called by the Instance() method, and nobody else.
Definition componentinspection.cc:25
Nebula's dynamic array class.
Definition array.h:60
Game::EditorState.
Definition orientation.h:7
MemDb::AttributeId ComponentId
Definition componentid.h:15
void ComponentDrawFuncT< Util::Colour >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:289
void ComponentDrawFuncT< Game::Entity >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:106
void ComponentDrawFuncT< Math::mat4 >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:205
void ComponentDrawFuncT(ComponentId component, void *data, bool *commit)
Definition componentinspection.h:72
void ComponentDrawFuncT< bool >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:122
void ComponentDrawFuncT< Game::Position >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:241
void ComponentDrawFuncT< Util::StringAtom >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:181
void ComponentDrawFuncT< int >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:136
void ComponentDrawFuncT< Game::Orientation >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:257
void ComponentDrawFuncT< float >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:166
void InspectorDrawField(ComponentId component, void *data, bool *commit)
Definition componentinspection.h:54
void ComponentDrawFuncT< uint >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:151
void ComponentDrawFuncT< Game::Scale >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:273
void ComponentDrawFuncT< Math::vec3 >(ComponentId component, void *data, bool *commit)
Definition componentinspection.cc:226
Definition attributeid.h:19