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

| Flecs v4.1 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
14 struct timer final : entity {
15 using entity::entity;
16
18 timer& interval(ecs_ftime_t interval) {
19 ecs_set_interval(world_, id_, interval);
20 return *this;
21 }
22
24 ecs_ftime_t interval() {
25 return ecs_get_interval(world_, id_);
26 }
27
29 timer& timeout(ecs_ftime_t timeout) {
30 ecs_set_timeout(world_, id_, timeout);
31 return *this;
32 }
33
35 ecs_ftime_t timeout() {
36 return ecs_get_timeout(world_, id_);
37 }
38
40 timer& rate(int32_t rate, flecs::entity_t tick_source = 0) {
41 ecs_set_rate(world_, id_, rate, tick_source);
42 return *this;
43 }
44
46 void start() {
47 ecs_start_timer(world_, id_);
48 }
49
51 void stop() {
52 ecs_stop_timer(world_, id_);
53 }
54};
55
56template <typename T>
57 inline flecs::timer world::timer() const {
58 return flecs::timer(world_, _::type<T>::id(world_));
59}
60
61template <typename... Args>
62 inline flecs::timer world::timer(Args &&... args) const {
63 return flecs::timer(world_, FLECS_FWD(args)...);
64}
65
67 inline void world::randomize_timers() const {
68 ecs_randomize_timers(world_);
69}
70
72 inline void system::interval(ecs_ftime_t interval) {
73 ecs_set_interval(world_, id_, interval);
74}
75
77 inline ecs_ftime_t system::interval() {
78 return ecs_get_interval(world_, id_);
79}
80
82 inline void system::timeout(ecs_ftime_t timeout) {
83 ecs_set_timeout(world_, id_, timeout);
84}
85
87 inline ecs_ftime_t system::timeout() {
88 return ecs_get_timeout(world_, id_);
89}
90
92 inline void system::rate(int32_t rate) {
93 ecs_set_rate(world_, id_, rate, 0);
94}
95
97 inline void system::start() {
98 ecs_start_timer(world_, id_);
99}
100
102 inline void system::stop() {
103 ecs_stop_timer(world_, id_);
104}
105
107template<typename T>
108 inline void system::set_tick_source() {
109 ecs_set_tick_source(world_, id_, _::type<T>::id(world_));
110}
111
113 inline void system::set_tick_source(flecs::entity e) {
114 ecs_set_tick_source(world_, id_, e);
115}
116
117namespace _ {
118
119inline void timer_init(flecs::world& world) {
120 world.component<RateFilter>("flecs::timer::RateFilter");
121 world.component<Timer>("flecs::timer::Timer");
122}
123
124}
125}
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.
flecs::system::stop
void stop()
Stop timer.
Definition impl.hpp:102
flecs::system::interval
void interval(ecs_ftime_t interval)
Set interval.
Definition impl.hpp:72
flecs::system::set_tick_source
void set_tick_source()
Set external tick source.
Definition impl.hpp:108
flecs::world::timer
flecs::timer timer() const
Find or register a singleton timer.
Definition impl.hpp:57
flecs::system::rate
void rate(int32_t rate)
Set system rate (system is its own tick source).
Definition impl.hpp:92
flecs::system::start
void start()
Start timer.
Definition impl.hpp:97
flecs::system::timeout
void timeout(ecs_ftime_t timeout)
Set timeout.
Definition impl.hpp:82
flecs::system::interval
ecs_ftime_t interval()
Get interval.
Definition impl.hpp:77
flecs::system::timeout
ecs_ftime_t timeout()
Get timeout.
Definition impl.hpp:87
flecs::RateFilter
EcsRateFilter RateFilter
Rate filter component.
Definition decl.hpp:21
flecs::Timer
EcsTimer Timer
Timer component.
Definition decl.hpp:19
flecs::world::component
flecs::component< T > component(Args &&... args) const
Find or register a component.
Definition impl.hpp:11
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
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::entity::entity
entity()
Default constructor.
Definition entity.hpp:32
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::id::world_
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
flecs::timer
Timer class.
Definition impl.hpp:14
flecs::timer::rate
timer & rate(int32_t rate, flecs::entity_t tick_source=0)
Set the timer rate.
Definition impl.hpp:40
flecs::timer::stop
void stop()
Stop the timer.
Definition impl.hpp:51
flecs::timer::start
void start()
Start the timer.
Definition impl.hpp:46
flecs::timer::interval
timer & interval(ecs_ftime_t interval)
Set the timer interval.
Definition impl.hpp:18
flecs::timer::interval
ecs_ftime_t interval()
Get the timer interval.
Definition impl.hpp:24
flecs::timer::timeout
timer & timeout(ecs_ftime_t timeout)
Set the timer timeout.
Definition impl.hpp:29
flecs::timer::timeout
ecs_ftime_t timeout()
Get the timer timeout.
Definition impl.hpp:35
flecs::timer::entity
entity()
Default constructor.
Definition entity.hpp:32
flecs::world
The world.
Definition world.hpp:246
flecs::world::world_
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1545
flecs::world::randomize_timers
void randomize_timers() const
Enable randomization of initial time values for timers.
Definition impl.hpp:67