Flecs: include/flecs/addons/cpp/mixins/timer/impl.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
5
6#pragma once
7
8namespace flecs {
9
10// Timer class
11 struct 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>
47 inline flecs::timer world::timer() const {
48 return flecs::timer(world_, _::type<T>::id(world_));
49}
50
51template <typename... Args>
52 inline flecs::timer world::timer(Args &&... args) const {
53 return flecs::timer(world_, FLECS_FWD(args)...);
54}
55
56 inline void world::randomize_timers() const {
57 ecs_randomize_timers(world_);
58}
59
60 inline void system::interval(ecs_ftime_t interval) {
61 ecs_set_interval(world_, id_, interval);
62}
63
64 inline ecs_ftime_t system::interval() {
65 return ecs_get_interval(world_, id_);
66}
67
68 inline void system::timeout(ecs_ftime_t timeout) {
69 ecs_set_timeout(world_, id_, timeout);
70}
71
72 inline ecs_ftime_t system::timeout() {
73 return ecs_get_timeout(world_, id_);
74}
75
76 inline void system::rate(int32_t rate) {
77 ecs_set_rate(world_, id_, rate, 0);
78}
79
80 inline void system::start() {
81 ecs_start_timer(world_, id_);
82}
83
84 inline void system::stop() {
85 ecs_stop_timer(world_, id_);
86}
87
88template<typename T>
89 inline void system::set_tick_source() {
90 ecs_set_tick_source(world_, id_, _::type<T>::id(world_));
91}
92
93 inline void system::set_tick_source(flecs::entity e) {
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}
ecs_get_timeout
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.
ecs_set_interval
FLECS_API ecs_entity_t ecs_set_interval(ecs_world_t *world, ecs_entity_t tick_source, ecs_ftime_t interval)
Set timer interval.
ecs_get_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.
ecs_set_tick_source
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.
ecs_set_rate
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.
ecs_start_timer
FLECS_API void ecs_start_timer(ecs_world_t *world, ecs_entity_t tick_source)
Start timer.
ecs_randomize_timers
FLECS_API void ecs_randomize_timers(ecs_world_t *world)
Enable randomizing initial time value of timers.
ecs_set_timeout
FLECS_API ecs_entity_t ecs_set_timeout(ecs_world_t *world, ecs_entity_t tick_source, ecs_ftime_t timeout)
Set timer timeout.
ecs_stop_timer
FLECS_API void ecs_stop_timer(ecs_world_t *world, ecs_entity_t tick_source)
Stop timer This operation stops a timer from triggering.
flecs::system::stop
void stop()
Stop timer.
Definition impl.hpp:84
flecs::system::interval
void interval(ecs_ftime_t interval)
Set interval.
Definition impl.hpp:60
flecs::system::set_tick_source
void set_tick_source()
Set external tick source.
Definition impl.hpp:89
flecs::world::timer
flecs::timer timer() const
Find or register a singleton timer.
Definition impl.hpp:47
flecs::system::rate
void rate(int32_t rate)
Set system rate (system is its own tick source).
Definition impl.hpp:76
flecs::system::start
void start()
Start timer.
Definition impl.hpp:80
flecs::system::timeout
void timeout(ecs_ftime_t timeout)
Set timeout.
Definition impl.hpp:68
flecs::system::interval
ecs_ftime_t interval()
Get interval.
Definition impl.hpp:64
flecs::system::timeout
ecs_ftime_t timeout()
Get timeout.
Definition impl.hpp:72
flecs::world::component
flecs::component< T > component(Args &&... args) const
Find or register component.
Definition impl.hpp:11
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
flecs::_
Int to enum.
Definition component.hpp:18
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::timer
Definition impl.hpp:11
flecs::world
The world.
Definition world.hpp:172
flecs::world::randomize_timers
void randomize_timers() const
Enable randomization of initial time values for timers.
Definition impl.hpp:56