Unravel Engine C++ Reference
Loading...
Searching...
No Matches
seq_core.hpp
Go to the documentation of this file.
1#pragma once
2#include "seq_core.h"
3#include "seq_ease.h"
4#include "seq_inspector.h"
5#include "seq_updater.h"
6
7namespace seq
8{
9
10template<typename T>
11auto change_from_to(T& object,
12 const std::decay_t<T>& begin,
13 const std::decay_t<T>& end,
14 const duration_t& duration,
15 const sentinel_t& sentinel,
16 const ease_t& ease_func) -> seq_action
17{
18 if(sentinel.expired())
19 {
20 return {};
21 }
22 auto creator = [&object, begin, end, sentinel, ease_func]()
23 {
24 auto initialize_func = [begin](T* object, const sentinel_t& sentinel, seq_action& self)
25 {
26 if(!sentinel.expired())
27 {
28 *object = begin;
29 }
31 return begin;
32 };
33
34 auto updater_func = [](T* object, const T& next, seq_action& self)
35 {
36 (*object) = next;
38 };
39
40 auto getter_func = [](T* object, seq_action&)
41 {
42 return *object;
43 };
44
45 auto updater = create_action_updater(&object,
46 end,
47 sentinel,
48 std::move(initialize_func),
49 std::move(updater_func),
50 std::move(getter_func),
51 ease_func);
52 return updater;
53 };
54
55 auto action = seq_action(std::move(creator), duration, sentinel);
56 inspector::add_info(action, __func__, object, end, ease_func);
57
58 return action;
59}
60
61template<typename T>
62auto change_from_to(const std::shared_ptr<T>& object,
63 const std::decay_t<T>& begin,
64 const std::decay_t<T>& end,
65 const duration_t& duration,
66 const ease_t& ease_func) -> seq_action
67{
68 if(!object)
69 {
70 return {};
71 }
72 return change_from_to(*object.get(), begin, end, duration, object, ease_func);
73}
74
75template<typename T>
76auto change_to(T& object,
77 const std::decay_t<T>& end,
78 const duration_t& duration,
79 const sentinel_t& sentinel,
80 const ease_t& ease_func) -> seq_action
81{
82 if(sentinel.expired())
83 {
84 return {};
85 }
86 auto creator = [&object, end, sentinel, ease_func]()
87 {
88 auto initialize_func = [](T* object, const sentinel_t& sentinel, seq_action& self)
89 {
90 if(sentinel.expired())
91 {
92 return T{};
93 }
94
95 auto begin = (*object);
97 return begin;
98 };
99
100 auto updater_func = [](T* object, T next, seq_action& self)
101 {
102 (*object) = next;
103 inspector::update_action_status(self, *object);
104 };
105
106 auto getter_func = [](T* object, seq_action&)
107 {
108 return *object;
109 };
110 auto updater = create_action_updater(&object,
111 end,
112 sentinel,
113 std::move(initialize_func),
114 std::move(updater_func),
115 std::move(getter_func),
116 ease_func);
117 return updater;
118 };
119
120 auto action = seq_action(std::move(creator), duration, sentinel);
121 inspector::add_info(action, __func__, object, end, ease_func);
122 return action;
123}
124
125template<typename T>
126auto change_to(const std::shared_ptr<T>& object,
127 const std::decay_t<T>& end,
128 const duration_t& duration,
129 const ease_t& ease_func) -> seq_action
130{
131 if(!object)
132 {
133 return {};
134 }
135 return change_to(*object.get(), end, duration, object, ease_func);
136}
137
138template<typename T>
139auto change_by(T& object,
140 const std::decay_t<T>& amount,
141 const duration_t& duration,
142 const sentinel_t& sentinel,
143 const ease_t& ease_func) -> seq_action
144{
145 if(sentinel.expired())
146 {
147 return {};
148 }
149 auto creator = [&object, amount, sentinel, ease_func]()
150 {
151 auto initialize_func = [](T*, const sentinel_t&, seq_action& self)
152 {
153 auto begin = T{};
155 return begin;
156 };
157
158 auto updater_func = [prev = T{}](T* object, T next, seq_action& self) mutable
159 {
160 T step = (next - prev);
161 (*object) += step;
162 prev = next;
163
164 inspector::update_action_status(self, *object);
165 };
166
167 auto getter_func = [](T* object, seq_action&)
168 {
169 return *object;
170 };
171
172 auto updater = create_action_updater(&object,
173 amount,
174 sentinel,
175 std::move(initialize_func),
176 std::move(updater_func),
177 std::move(getter_func),
178 ease_func);
179 return updater;
180 };
181
182 auto action = seq_action(std::move(creator), duration, sentinel);
183 inspector::add_info(action, __func__, object, amount, ease_func);
184 return action;
185}
186
187template<typename T>
188auto change_by(const std::shared_ptr<T>& object,
189 const std::decay_t<T>& amount,
190 const duration_t& duration,
191 const ease_t& ease_func) -> seq_action
192{
193 if(!object)
194 {
195 return {};
196 }
197 return change_by(*object.get(), amount, duration, object, ease_func);
198}
199} // 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
auto change_by(T &object, const std::decay_t< T > &amount, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func=ease::linear) -> seq_action
Creates an action to change an object by a specified amount over a specified duration.
Definition seq_core.hpp:139
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
auto change_from_to(T &object, const std::decay_t< T > &begin, const std::decay_t< T > &end, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func=ease::linear) -> seq_action
Creates an action to change an object from one value to another over a specified duration.
Definition seq_core.hpp:11
std::chrono::nanoseconds duration_t
Represents a duration in nanoseconds.
Definition seq_common.h:41
auto change_to(T &object, const std::decay_t< T > &end, const duration_t &duration, const sentinel_t &sentinel, const ease_t &ease_func=ease::linear) -> seq_action
Creates an action to change an object to a specified value over a specified duration.
Definition seq_core.hpp:76
Represents an action within the sequence management system. Contains lifecycle events and management ...
Definition seq_action.h:18