1#include <mutate_entity_handle.h>
2#include <iostream>
3#include <iomanip>
4
5
6
7
8struct Timeout {
10 double value;
11};
12
13struct Tag { };
14
15int main(int, char *[]) {
17
20 t.value -=
static_cast<double>(it.
delta_time());
21 if (t.value <= 0) {
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 t.to_delete.mut(it).destruct();
42 std::cout << "Expire: " << t.to_delete.name() << " deleted!\n";
43 }
44 });
45
46 ecs.
system<
const Timeout>()
47 .
each([](
const Timeout& t) {
48 std::cout << "PrintExpire: " << t.to_delete.name() << " has "
49 << std::fixed << std::setprecision(2) << t.value
50 << " seconds left\n";
51 });
52
54 .
event(flecs::OnRemove)
56 std::cout <<
"Expired: " << e.
name() <<
" actually deleted\n";
57 });
58
59
61 .add<Tag>();
62
64 .set<Timeout>({to_delete, 3.0});
65
67
69
71 break;
72 }
73
74 std::cout << "Tick...\n";
75 }
76
77
78
79
80
81
82
83
84
85}
void set_target_fps(ecs_ftime_t target_fps) const
Set the target FPS.
flecs::system system(flecs::entity e) const
Upcast an entity to a system.
flecs::entity entity(Args &&... args) const
Create an entity.
flecs::observer observer(flecs::entity e) const
Observer world mixin.
bool progress(ecs_ftime_t delta_time=0.0) const
Progress the world one tick.
flecs::string_view name() const
Return the entity name.
bool is_alive() const
Check if entity is alive.
Class for iterating over query results.
ecs_ftime_t delta_time() const
Get the time elapsed since the last frame.
void each(Func &&func) const
Iterate over all entities with components in the argument list of the function.
flecs::event_builder event(flecs::entity_t evt) const
Create a new event.