Unravel Engine C++ Reference
Loading...
Searching...
No Matches
seq_common.h
Go to the documentation of this file.
1#pragma once
2#include <chrono>
3#include <functional>
4#include <hpp/sentinel.hpp>
5#include <hpp/type_name.hpp>
6#include <memory>
7#include <string>
8#include <vector>
9
10using namespace std::chrono_literals;
11
16namespace seq
17{
18
23using clock_t = std::chrono::steady_clock;
24
29using timepoint_t = clock_t::time_point;
30
35using duraiton_secs_t = std::chrono::duration<float>;
36
41using duration_t = std::chrono::nanoseconds;
42
47using sentinel_t = hpp::sentinel;
48
53using seq_id_t = size_t;
54
61using ease_t = std::function<float(float)>;
62
73template<typename T>
74using interpolate_t = std::function<T(const T&, const T&, float, const ease_t&)>;
75
80enum class state_t
81{
82 running,
83 paused,
85};
86
92{
97 enum class policy_t
98 {
99 stacked,
101 };
102
106 std::string scope;
107
112
116 seq_scope_policy() noexcept = default;
117
122 seq_scope_policy(const char* _scope) noexcept : scope(_scope)
123 {
124 }
125
130 seq_scope_policy(const std::string& _scope) noexcept : scope(_scope)
131 {
132 }
133};
134
140{
142 using ptr = std::shared_ptr<seq_inspect_info>;
143
145 using weak_ptr = std::weak_ptr<seq_inspect_info>;
146
150 std::string file_name;
151
155 std::string function_name;
156
160 uint32_t line_number = 0;
161
165 uint32_t column_offset = 0;
166
170 seq_id_t id = 1;
171
175 float speed_multiplier = 1.0f;
176
180 bool stop_when_finished = false;
181
185 std::string state = "finished";
186
190 std::string modified_type;
191
195 std::string updater_type;
196
201
206
210 float progress{};
211
215 std::string current_value;
216
220 std::string begin_value;
221
225 std::string end_value;
226
231
235 std::vector<weak_ptr> children;
236};
237
242namespace inspector
243{
244namespace adl_helper
245{
246using std::to_string;
247
254template<typename T>
255auto as_string(const T& t) -> std::string
256{
257 return to_string(t);
258}
259
266template<typename T>
267auto type_as_string(const T&) -> std::string
268{
269 return hpp::type_name_unqualified_str<T>();
270}
271} // namespace adl_helper
272
279template<typename T>
280auto to_str(const T& t) -> std::string
281{
282 return adl_helper::as_string(t);
283}
284
290template<>
291inline auto to_str(const state_t& t) -> std::string
292{
293 if (t == state_t::running)
294 {
295 return "running";
296 }
297 if (t == state_t::paused)
298 {
299 return "paused";
300 }
301 return "finished";
302}
303
310template<typename T>
311auto type_to_str(const T& t) -> std::string
312{
314}
315
316} // namespace inspector
317
318} // namespace seq
Provides utilities for inspecting and converting sequence-related types to strings.
auto as_string(const T &t) -> std::string
Converts a value to a string.
Definition seq_common.h:255
auto type_as_string(const T &) -> std::string
Gets the type of a value as a string.
Definition seq_common.h:267
auto to_str(const T &t) -> std::string
Converts a value to a string using ADL (Argument-Dependent Lookup).
Definition seq_common.h:280
auto type_to_str(const T &t) -> std::string
Gets the type of a value as a string using ADL.
Definition seq_common.h:311
Provides a sequence-based action management system for controlling and scheduling actions.
size_t seq_id_t
Represents a unique identifier for sequence actions.
Definition seq_common.h:53
hpp::sentinel sentinel_t
Alias for a sentinel object used for lifecycle management.
Definition seq_common.h:47
state_t
Represents the state of a sequence action.
Definition seq_common.h:81
@ running
The action is running.
@ finished
The action has finished.
@ paused
The action is paused.
std::chrono::duration< float > duraiton_secs_t
Represents a duration in seconds as a floating-point value.
Definition seq_common.h:35
std::function< float(float)> ease_t
Represents an easing function for interpolation.
Definition seq_common.h:61
std::function< T(const T &, const T &, float, const ease_t &)> interpolate_t
Represents a function for interpolating values.
Definition seq_common.h:74
clock_t::time_point timepoint_t
Represents a point in time using the steady clock.
Definition seq_common.h:29
std::chrono::steady_clock clock_t
Alias for the steady clock used for timing actions.
Definition seq_common.h:23
std::chrono::nanoseconds duration_t
Represents a duration in nanoseconds.
Definition seq_common.h:41
Contains information for inspecting and debugging sequence actions.
Definition seq_common.h:140
bool stop_when_finished
Whether the action should stop when finished.
Definition seq_common.h:180
std::string state
The current state of the action.
Definition seq_common.h:185
std::vector< weak_ptr > children
The child actions of this action.
Definition seq_common.h:235
std::string file_name
The file name where the action was defined.
Definition seq_common.h:150
duration_t duration
The total duration of the action.
Definition seq_common.h:205
std::string function_name
The function name where the action was defined.
Definition seq_common.h:155
float progress
The progress of the action (0 to 1).
Definition seq_common.h:210
std::string modified_type
The type of modification applied to the action.
Definition seq_common.h:190
duration_t elapsed
The elapsed duration of the action.
Definition seq_common.h:200
std::string current_value
The current value of the action.
Definition seq_common.h:215
std::shared_ptr< seq_inspect_info > ptr
Shared pointer type.
Definition seq_common.h:142
uint32_t line_number
The line number where the action was defined.
Definition seq_common.h:160
uint32_t column_offset
The column offset where the action was defined.
Definition seq_common.h:165
std::string begin_value
The beginning value of the action.
Definition seq_common.h:220
std::string end_value
The ending value of the action.
Definition seq_common.h:225
float speed_multiplier
The speed multiplier for the action.
Definition seq_common.h:175
std::string updater_type
The type of updater function used by the action.
Definition seq_common.h:195
std::weak_ptr< seq_inspect_info > weak_ptr
Weak pointer type.
Definition seq_common.h:145
ease_t ease_func
The easing function applied to the action.
Definition seq_common.h:230
Defines policies for scoping actions in a sequence.
Definition seq_common.h:92
std::string scope
The name of the scope.
Definition seq_common.h:106
policy_t
Represents the policy for scoping actions.
Definition seq_common.h:98
@ stacked
Actions share the same scope and stack behavior.
@ independent
Actions operate independently within their scope.
seq_scope_policy(const std::string &_scope) noexcept
Constructs a scope policy with a specified scope.
Definition seq_common.h:130
policy_t policy
The scoping policy (default is stacked).
Definition seq_common.h:111
seq_scope_policy() noexcept=default
Default constructor.