Flecs: include/flecs/addons/cpp/mixins/json/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
11 const Self& set_json(
12 flecs::id_t e,
13 const char *json,
14 flecs::from_json_desc_t *desc = nullptr) const
15{
16 const flecs::type_info_t *ti = ecs_get_type_info(world_, e);
17 if (!ti) {
18 ecs_err("id is not a type");
19 return to_base();
20 }
21
22 flecs::entity_t type = ti->component;
23
24 void *ptr = ecs_ensure_id(world_, id_, e, static_cast<size_t>(ti->size));
25 ecs_assert(ptr != NULL, ECS_INTERNAL_ERROR, NULL);
26 ecs_ptr_from_json(world_, type, ptr, json, desc);
27 ecs_modified_id(world_, id_, e);
28
29 return to_base();
30}
31
37 const Self& set_json(
38 flecs::entity_t r,
39 flecs::entity_t t,
40 const char *json,
41 flecs::from_json_desc_t *desc = nullptr) const
42{
43 return set_json(ecs_pair(r, t), json, desc);
44}
45
51template <typename T>
52 const Self& set_json(
53 const char *json,
54 flecs::from_json_desc_t *desc = nullptr) const
55{
56 return set_json(_::type<T>::id(world_), json, desc);
57}
58
64template <typename R, typename T>
65 const Self& set_json(
66 const char *json,
67 flecs::from_json_desc_t *desc = nullptr) const
68{
69 return set_json(
70 _::type<R>::id(world_),
71 _::type<T>::id(world_),
72 json, desc);
73}
74
80template <typename R>
81 const Self& set_json(
82 flecs::entity_t t,
83 const char *json,
84 flecs::from_json_desc_t *desc = nullptr) const
85{
86 return set_json(
87 _::type<R>::id(world_), t,
88 json, desc);
89}
90
96template <typename T>
97 const Self& set_json_second(
98 flecs::entity_t r,
99 const char *json,
100 flecs::from_json_desc_t *desc = nullptr) const
101{
102 return set_json(
103 r, _::type<T>::id(world_),
104 json, desc);
105}
ecs_ptr_from_json
FLECS_API const char * ecs_ptr_from_json(const ecs_world_t *world, ecs_entity_t type, void *ptr, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON string into value.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
ecs_get_type_info
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t component)
Get the type info for an component.
ecs_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
ecs_ensure_id
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size)
Ensure entity has component, return pointer.
ecs_type_info_t::size
ecs_size_t size
Size of type.
Definition flecs.h:996
ecs_type_info_t::component
ecs_entity_t component
Handle to component (do not set).
Definition flecs.h:999
flecs::_::type
Definition flecs.hpp:39
flecs::entity_builder::set_json_second
const Self & set_json_second(flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
Definition entity_builder.inl:97
flecs::entity_builder::set_json
const Self & set_json(flecs::entity_t r, flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
Definition entity_builder.inl:37
flecs::entity_builder::set_json
const Self & set_json(flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
Definition entity_builder.inl:11
flecs::entity_builder::set_json
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
Definition entity_builder.inl:65
flecs::entity_builder::set_json
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
Definition entity_builder.inl:52
flecs::entity_builder::set_json
const Self & set_json(flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
Definition entity_builder.inl:81
flecs::entity_view::type
flecs::type type() const
Get the entity's type.
Definition impl.hpp:94