Unravel Engine C++ Reference
Loading...
Searching...
No Matches
seq_ex.h
Go to the documentation of this file.
1#pragma once
2#include "seq_common.h"
3#include "seq_core.h"
4#include "seq_math.h"
5#include "seq_updater.h"
6#include <hpp/utility.hpp>
7#include <vector>
8
9namespace seq
10{
11
12template<typename Object, typename T, typename Setter, typename Getter>
13seq_action create_from_to_impl(const std::string& creator_name,
14 Object* object,
15 const T& begin,
16 const T& end,
17 const Setter& setter_func,
18 const Getter& getter_func,
19 const duration_t& duration,
20 const sentinel_t& sentinel,
21 const ease_t& ease_func)
22{
23 if(!object)
24 {
25 return {};
26 }
27 auto creator = [object,
28 begin = begin,
29 end = end,
30 sentinel = sentinel,
31 ease_func = ease_func,
32 setter_func = setter_func,
33 getter_func = getter_func]()
34 {
35 auto initialize_func = [begin, setter_func](Object* object, const sentinel_t&, seq_action& self)
36 {
37 hpp::invoke(setter_func, *object, begin);
39 return begin;
40 };
41
42 auto updater_func = [setter_func, getter_func](Object* object, const T& next, seq_action& self) mutable
43 {
44 hpp::invoke(setter_func, *object, next);
45
46 // TODO move calc inside
47 inspector::update_action_status(self, hpp::invoke(getter_func, *object));
48 };
49
50 auto getter = [getter_func](Object* object, seq_action&) mutable
51 {
52 return hpp::invoke(getter_func, *object);
53 };
54
55 return create_action_updater(object,
56 end,
57 sentinel,
58 std::move(initialize_func),
59 std::move(updater_func),
60 std::move(getter),
61 ease_func);
62 };
63
64 auto action = seq_action(std::move(creator), duration, sentinel);
65 inspector::add_info(action, creator_name, *object, end, ease_func);
66 return action;
67}
68
69template<typename Object, typename T, typename Setter, typename Getter>
70seq_action create_to_impl(const std::string& creator_name,
71 Object* object,
72 const T& end,
73 const Setter& setter_func,
74 const Getter& getter_func,
75 const duration_t& duration,
76 const sentinel_t& sentinel,
77 const ease_t& ease_func)
78{
79 auto creator = [object,
80 end = end,
81 sentinel = sentinel,
82 ease_func = ease_func,
83 setter_func = setter_func,
84 getter_func = getter_func]()
85 {
86 auto initialize_func = [getter_func](Object* object, const sentinel_t& sentinel, seq_action& self)
87 {
88 if(sentinel.expired())
89 {
90 T out{};
92 return out;
93 }
94
95 // TODO move calc inside
96 T out = hpp::invoke(getter_func, *object);
98 return out;
99 };
100
101 auto updater_func = [setter_func, getter_func](Object* object, const T& next, seq_action& self) mutable
102 {
103 hpp::invoke(setter_func, *object, next);
104
105 // TODO move calc inside
106 inspector::update_action_status(self, hpp::invoke(getter_func, *object));
107 };
108
109 auto getter = [getter_func](Object* object, seq_action&) mutable
110 {
111 return hpp::invoke(getter_func, *object);
112 };
113
114 return create_action_updater(object,
115 end,
116 sentinel,
117 std::move(initialize_func),
118 std::move(updater_func),
119 std::move(getter),
120 ease_func);
121 };
122
123 auto action = seq_action(std::move(creator), duration, sentinel);
124 inspector::add_info(action, creator_name, *object, end, ease_func);
125 return action;
126}
127
128template<typename Object, typename T, typename Setter, typename Getter>
129seq_action create_by_impl(const std::string& creator_name,
130 Object* object,
131 const T& amount,
132 const Setter& setter_func,
133 const Getter& getter_func,
134 const duration_t& duration,
135 const sentinel_t& sentinel,
136 const ease_t& ease_func)
137{
138 if(!object)
139 {
140 return {};
141 }
142 auto creator = [object,
143 amount = amount,
144 sentinel = sentinel,
145 ease_func = ease_func,
146 setter_func = setter_func,
147 getter_func = getter_func]()
148 {
149 auto initialize_func = [](Object*, const sentinel_t&, seq_action& self)
150 {
151 T out{};
153 return out;
154 };
155
156 auto updater_func =
157 [setter_func, getter_func, prev = T{}](Object* object, const T& next, seq_action& self) mutable
158 {
159 T current = hpp::invoke(getter_func, *object);
160
161 const auto updated = current + (next - prev);
162 hpp::invoke(setter_func, *object, updated);
163
164 // TODO move calc inside
165 inspector::update_action_status(self, hpp::invoke(getter_func, *object));
166
167 prev = next;
168 };
169
170 auto getter = [getter_func](Object* object, seq_action&) mutable
171 {
172 return hpp::invoke(getter_func, *object);
173 };
174
175 return create_action_updater(object,
176 amount,
177 sentinel,
178 std::move(initialize_func),
179 std::move(updater_func),
180 std::move(getter),
181 ease_func);
182 };
183
184 auto action = seq_action(std::move(creator), duration, sentinel);
185 inspector::add_info(action, creator_name, *object, amount, ease_func);
186 return action;
187}
188
189} // namespace seq
const btCollisionObject * object
void update_begin_value(seq_action &action, const T &begin)
void add_info(seq_action &action, const std::string &updater_type, const Object &object, const T &end_value, const ease_t &ease_func)
void update_action_status(seq_action &action)
Provides a sequence-based action management system for controlling and scheduling actions.
hpp::sentinel sentinel_t
Alias for a sentinel object used for lifecycle management.
Definition seq_common.h:47
seq::seq_action creator(const std::string &type, values_t< T > &values, T &begin, const T &end, seq::duration_t duration)
Definition tests.cpp:195
std::function< float(float)> ease_t
Represents an easing function for interpolation.
Definition seq_common.h:61
seq_action create_to_impl(const std::string &creator_name, Object *object, const T &end, const Setter &setter_func, const Getter &getter_func, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func)
Definition seq_ex.h:70
seq_action create_by_impl(const std::string &creator_name, Object *object, const T &amount, const Setter &setter_func, const Getter &getter_func, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func)
Definition seq_ex.h:129
auto create_action_updater(Object *object, const TargetType &end, const sentinel_t &sentinel, InitializeFunc &&initialize_func, UpdateFunc &&update_func, Getter &&getter, const ease_t &ease_func=ease::linear, const interpolate_t< TargetType > &interpolate=lerp< TargetType >)
Definition seq_updater.h:11
seq_action create_from_to_impl(const std::string &creator_name, Object *object, const T &begin, const T &end, const Setter &setter_func, const Getter &getter_func, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func)
Definition seq_ex.h:13
std::chrono::nanoseconds duration_t
Represents a duration in nanoseconds.
Definition seq_common.h:41
Represents an action within the sequence management system. Contains lifecycle events and management ...
Definition seq_action.h:18