Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
10// Timer class
11struct timer final : entity {
12 using entity::entity;
13
14 timer& interval(ecs_ftime_t interval) {
15 ecs_set_interval(world_, id_, interval);
16 return *this;
17 }
18
19 ecs_ftime_t interval() {
20 return ecs_get_interval(world_, id_);
21 }
22
23 timer& timeout(ecs_ftime_t timeout) {
24 ecs_set_timeout(world_, id_, timeout);
25 return *this;
26 }
27
28 ecs_ftime_t timeout() {
29 return ecs_get_timeout(world_, id_);
30 }
31
32 timer& rate(int32_t rate, flecs::entity_t tick_source = 0) {
33 ecs_set_rate(world_, id_, rate, tick_source);
34 return *this;
35 }
36
37 void start() {
38 ecs_start_timer(world_, id_);
39 }
40
41 void stop() {
42 ecs_stop_timer(world_, id_);
43 }
44};
45
46template <typename T>
47inline flecs::timer world::timer() const {
48 return flecs::timer(world_, _::type<T>::id(world_));
49}
50
51template <typename... Args>
52inline flecs::timer world::timer(Args &&... args) const {
53 return flecs::timer(world_, FLECS_FWD(args)...);
54}
55
56inline void world::randomize_timers() const {
58}
59
60inline void system::interval(ecs_ftime_t interval) {
61 ecs_set_interval(world_, id_, interval);
62}
63
65 return ecs_get_interval(world_, id_);
66}
67
68inline void system::timeout(ecs_ftime_t timeout) {
69 ecs_set_timeout(world_, id_, timeout);
70}
71
73 return ecs_get_timeout(world_, id_);
74}
75
76inline void system::rate(int32_t rate) {
77 ecs_set_rate(world_, id_, rate, 0);
78}
79
80inline void system::start() {
81 ecs_start_timer(world_, id_);
82}
83
84inline void system::stop() {
85 ecs_stop_timer(world_, id_);
86}
87
88template<typename T>
89inline void system::set_tick_source() {
90 ecs_set_tick_source(world_, id_, _::type<T>::id(world_));
91}
92
94 ecs_set_tick_source(world_, id_, e);
95}
96
97namespace _ {
98
99inline void timer_init(flecs::world& world) {
100 world.component<RateFilter>("flecs::timer::RateFilter");
101 world.component<Timer>("flecs::timer::Timer");
102}
103
104}
105}
FLECS_API ecs_ftime_t ecs_get_timeout(const ecs_world_t *world, ecs_entity_t tick_source)
Get current timeout value for the specified timer.
FLECS_API ecs_entity_t ecs_set_interval(ecs_world_t *world, ecs_entity_t tick_source, ecs_ftime_t interval)
Set timer interval.
FLECS_API ecs_ftime_t ecs_get_interval(const ecs_world_t *world, ecs_entity_t tick_source)
Get current interval value for the specified timer.
FLECS_API void ecs_set_tick_source(ecs_world_t *world, ecs_entity_t system, ecs_entity_t tick_source)
Assign tick source to system.
FLECS_API ecs_entity_t ecs_set_rate(ecs_world_t *world, ecs_entity_t tick_source, int32_t rate, ecs_entity_t source)
Set rate filter.
FLECS_API void ecs_start_timer(ecs_world_t *world, ecs_entity_t tick_source)
Start timer.
FLECS_API void ecs_randomize_timers(ecs_world_t *world)
Enable randomizing initial time value of timers.
FLECS_API ecs_entity_t ecs_set_timeout(ecs_world_t *world, ecs_entity_t tick_source, ecs_ftime_t timeout)
Set timer timeout.
FLECS_API void ecs_stop_timer(ecs_world_t *world, ecs_entity_t tick_source)
Stop timer This operation stops a timer from triggering.
ecs_ftime_t timeout()
Get timeout.
ecs_ftime_t interval()
Get interval.
void start()
Start timer.
void stop()
Stop timer.
void set_tick_source()
Set external tick source.
void rate(int32_t rate)
Set system rate (system is its own tick source).
flecs::timer timer() const
Find or register a singleton timer.
flecs::component< T > component(Args &&... args) const
Find or register component.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
Entity.
Definition entity.hpp:30
The world.
Definition world.hpp:137