Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
entity_builder.inl
Go to the documentation of this file.
1
14const Self& unit(
15 const char *symbol,
16 flecs::entity_t prefix = 0,
17 flecs::entity_t base = 0,
18 flecs::entity_t over = 0,
19 int32_t factor = 0,
20 int32_t power = 0) const
21{
22 ecs_unit_desc_t desc = {};
23 desc.entity = this->id_;
24 desc.symbol = const_cast<char*>(symbol); /* safe, will be copied in */
25 desc.base = base;
26 desc.over = over;
27 desc.prefix = prefix;
28 desc.translation.factor = factor;
29 desc.translation.power = power;
30 ecs_unit_init(this->world(), &desc);
31
32 return to_base();
33}
34
36const Self& unit(
37 flecs::entity_t prefix = 0,
38 flecs::entity_t base = 0,
39 flecs::entity_t over = 0,
40 int32_t factor = 0,
41 int32_t power = 0) const
42{
43 ecs_unit_desc_t desc = {};
44 desc.entity = this->id_;
45 desc.base = base;
46 desc.over = over;
47 desc.prefix = prefix;
48 desc.translation.factor = factor;
49 desc.translation.power = power;
50 ecs_unit_init(this->world(), &desc);
51
52 return to_base();
53}
54
56const Self& unit_prefix(
57 const char *symbol,
58 int32_t factor = 0,
59 int32_t power = 0) const
60{
61 ecs_unit_prefix_desc_t desc = {};
62 desc.entity = this->id_;
63 desc.symbol = const_cast<char*>(symbol); /* safe, will be copied in */
64 desc.translation.factor = factor;
65 desc.translation.power = power;
66 ecs_unit_prefix_init(this->world(), &desc);
67
68 return to_base();
69}
70
72const Self& quantity(flecs::entity_t quantity) const {
73 ecs_add_pair(this->world(), this->id(), flecs::Quantity, quantity);
74 return to_base();
75}
76
78template <typename Quantity>
79const Self& quantity() const {
80 return this->quantity(_::type<Quantity>::id(this->world()));
81}
82
84const Self& quantity() const {
85 ecs_add_id(this->world(), this->id(), flecs::Quantity);
86 return to_base();
87}
88
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
FLECS_API ecs_entity_t ecs_unit_prefix_init(ecs_world_t *world, const ecs_unit_prefix_desc_t *desc)
Create a new unit prefix.
FLECS_API ecs_entity_t ecs_unit_init(ecs_world_t *world, const ecs_unit_desc_t *desc)
Create a new unit.
const Self & quantity(flecs::entity_t quantity) const
Add quantity to unit.
const Self & unit(const char *symbol, flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
Make entity a unit.
const Self & quantity() const
Make entity a quantity.
const Self & unit(flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
Make entity a derived unit.
const Self & unit_prefix(const char *symbol, int32_t factor=0, int32_t power=0) const
Make entity a derived unit.
const Self & quantity() const
Make entity a unity prefix.
Used with ecs_unit_init().
Definition meta.h:1094
ecs_entity_t base
Base unit, e.g.
Definition meta.h:1105
ecs_entity_t over
Over unit, e.g.
Definition meta.h:1108
const char * symbol
Unit symbol, e.g.
Definition meta.h:1099
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1119
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1111
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1096
Used with ecs_unit_prefix_init().
Definition meta.h:1135
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1137
const char * symbol
Unit symbol, e.g.
Definition meta.h:1140
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1143
int32_t power
Power to apply to factor (e.g.
Definition meta.h:482
int32_t factor
Factor to apply (e.g.
Definition meta.h:481
The world.
Definition world.hpp:137