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
6#pragma once
7
8namespace flecs {
9
14struct timer final : entity {
15 using entity::entity;
16
22
27
33
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() {
48 }
49
51 void stop() {
53 }
54};
55
56template <typename T>
57inline flecs::timer world::timer() const {
58 return flecs::timer(world_, _::type<T>::id(world_));
59}
60
61template <typename... Args>
62inline flecs::timer world::timer(Args &&... args) const {
63 return flecs::timer(world_, FLECS_FWD(args)...);
64}
65
67inline void world::randomize_timers() const {
69}
70
72inline void system::interval(ecs_ftime_t interval) {
74}
75
79}
80
82inline void system::timeout(ecs_ftime_t timeout) {
84}
85
88 return ecs_get_timeout(world_, id_);
89}
90
92inline void system::rate(int32_t rate) {
94}
95
97inline void system::start() {
99}
100
102inline void system::stop() {
104}
105
107template<typename T>
108inline void system::set_tick_source() {
109 ecs_set_tick_source(world_, id_, _::type<T>::id(world_));
110}
111
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}
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.
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).
EcsRateFilter RateFilter
Rate filter component.
Definition decl.hpp:21
EcsTimer Timer
Timer component.
Definition decl.hpp:19
flecs::timer timer() const
Find or register a singleton timer.
flecs::component< T > component(Args &&... args) const
Find or register a component.
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
Entity.
Definition entity.hpp:30
entity()
Default constructor.
Definition entity.hpp:32
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
Timer class.
Definition impl.hpp:14
timer & rate(int32_t rate, flecs::entity_t tick_source=0)
Set the timer rate.
Definition impl.hpp:40
void stop()
Stop the timer.
Definition impl.hpp:51
void start()
Start the timer.
Definition impl.hpp:46
timer & interval(ecs_ftime_t interval)
Set the timer interval.
Definition impl.hpp:18
ecs_ftime_t interval()
Get the timer interval.
Definition impl.hpp:24
timer & timeout(ecs_ftime_t timeout)
Set the timer timeout.
Definition impl.hpp:29
ecs_ftime_t timeout()
Get the timer timeout.
Definition impl.hpp:35
The world.
Definition world.hpp:246
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1545