TheAtlasEngine
 
Loading...
Searching...
No Matches
state.hpp
1#pragma once
2#include <functional>
3#include <type_traits>
4
5namespace atlas {
6
7 namespace detail {
25 void invoke_on_update();
26 void invoke_defer_update();
27 void invoke_physics_update();
28 void invoke_ui_update();
29 void invoke_start();
30
31 // TODO: Look into a different way of doing this
32 void poll_update(void* p_address,
33 const std::function<void()>& p_callback);
34
35 void poll_defer_update(void* p_address,
36 const std::function<void()>& p_callback);
37
38 void poll_physics_update(void* p_address,
39 const std::function<void()>& p_callback);
40
41 void poll_ui_update(void* p_address,
42 const std::function<void()>& p_callback);
43
44 void poll_start(void* p_address,
45 const std::function<void()>& p_callback);
46
47 // TEMP: This is a temporary solution, should look into doing this
48 // differently
49 void remove_update(void* p_address);
50
51 void remove_defer_update(void* p_address);
52
53 void remove_physics_update(void* p_address);
54
55 void remove_ui_update(void* p_address);
56
57 void remove_start(void* p_address);
58
59 };
60
86 template<typename UObject, typename UCallback>
87 void register_start(UObject* p_instance, const UCallback& p_callable) {
88 static_assert(std::is_member_pointer_v<UCallback>,
89 "Cannot register a function that is not a member "
90 "function of a class object");
91 detail::poll_start(p_instance, [p_instance, p_callable]() {
92 (p_instance->*p_callable)();
93 });
94 }
95
118 template<typename UObject, typename UCallback>
119 void register_update(UObject* p_instance, const UCallback& p_callable) {
120 static_assert(std::is_member_pointer_v<UCallback>,
121 "Cannot register a function that is not a member "
122 "function of a class object");
123 detail::poll_update(p_instance, [p_instance, p_callable]() {
124 (p_instance->*p_callable)();
125 });
126 }
127
148 template<typename UObject, typename UCallback>
149 void register_physics(UObject* p_instance, const UCallback& p_callable) {
150 static_assert(std::is_member_pointer_v<UCallback>,
151 "Cannot register a function that is not a member "
152 "function of a class object");
153 detail::poll_physics_update(p_instance, [p_instance, p_callable]() {
154 (p_instance->*p_callable)();
155 });
156 }
157
180 template<typename UObject, typename UCallback>
181 void register_deferred(UObject* p_instance, const UCallback& p_callable) {
182 static_assert(std::is_member_pointer_v<UCallback>,
183 "Cannot register a function that is not a member "
184 "function of a class object");
185 detail::poll_defer_update(p_instance, [p_instance, p_callable]() {
186 (p_instance->*p_callable)();
187 });
188 }
189
214 template<typename UObject, typename UCallback>
215 void register_ui(UObject* p_instance, const UCallback& p_callable) {
216 static_assert(std::is_member_pointer_v<UCallback>,
217 "Cannot register a function that is not a member "
218 "function of a class object");
219 detail::poll_ui_update(p_instance, [p_instance, p_callable]() {
220 (p_instance->*p_callable)();
221 });
222 }
223
224};