Flecs: include/flecs/addons/cpp/mixins/meta/entity_builder.inl 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
entity_builder.inl
Go to the documentation of this file.
1
5
12
14 const 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
36 const 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
56 const 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
72 const 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>
79 const Self& quantity() const {
80 return this->quantity(_::type<Quantity>::id(this->world()));
81}
82
84 const Self& quantity() const {
85 ecs_add_id(this->world(), this->id(), flecs::Quantity);
86 return to_base();
87}
88
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
ecs_unit_prefix_init
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.
ecs_unit_init
FLECS_API ecs_entity_t ecs_unit_init(ecs_world_t *world, const ecs_unit_desc_t *desc)
Create a new unit.
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_add_pair
#define ecs_add_pair(world, subject, first, second)
Add a pair to an entity.
Definition flecs_c.h:322
ecs_unit_desc_t
Used with ecs_unit_init().
Definition meta.h:1212
ecs_unit_desc_t::base
ecs_entity_t base
Base unit, e.g., "meters" (optional).
Definition meta.h:1223
ecs_unit_desc_t::over
ecs_entity_t over
Over unit, e.g., "per second" (optional).
Definition meta.h:1226
ecs_unit_desc_t::symbol
const char * symbol
Unit symbol, e.g., "m", "%", "g".
Definition meta.h:1217
ecs_unit_desc_t::prefix
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1237
ecs_unit_desc_t::translation
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1229
ecs_unit_desc_t::entity
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1214
ecs_unit_prefix_desc_t
Used with ecs_unit_prefix_init().
Definition meta.h:1253
ecs_unit_prefix_desc_t::entity
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1255
ecs_unit_prefix_desc_t::symbol
const char * symbol
Unit prefix symbol, e.g., "K", "M", "Ki".
Definition meta.h:1258
ecs_unit_prefix_desc_t::translation
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1261
ecs_unit_translation_t::power
int32_t power
Power to apply to factor (e.g., "1", "3", "-9").
Definition meta.h:502
ecs_unit_translation_t::factor
int32_t factor
Factor to apply (e.g., "1000", "1000000", "1024").
Definition meta.h:501
flecs::_::type
Definition flecs.hpp:39
flecs::entity_builder::quantity
const Self & quantity(flecs::entity_t quantity) const
Add a quantity to a unit.
Definition entity_builder.inl:72
flecs::entity_builder::quantity
const Self & quantity() const
Make an entity a quantity.
Definition entity_builder.inl:84
flecs::entity_builder::unit
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 an entity a derived unit.
Definition entity_builder.inl:36
flecs::entity_builder::unit_prefix
const Self & unit_prefix(const char *symbol, int32_t factor=0, int32_t power=0) const
Make an entity a unit prefix.
Definition entity_builder.inl:56
flecs::entity_builder::quantity
const Self & quantity() const
Add a quantity to a unit.
Definition entity_builder.inl:79
flecs::entity_builder::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 an entity a unit.
Definition entity_builder.inl:14
flecs::entity_view::symbol
flecs::string_view symbol() const
Return the entity symbol.
Definition entity_view.hpp:96
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::world
The world.
Definition world.hpp:246