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
11const 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
37const 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>
52const 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>
65const 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>
81const 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>
97const 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}
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.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
const Self & set_json_second(flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from 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.
const Self & set_json(flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
const Self & set_json(flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, size_t size)
Get a mutable pointer to a component.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:41
Type that contains component information (passed to ctors/dtors/...)
Definition flecs.h:998
ecs_size_t size
Size of type.
Definition flecs.h:999
ecs_entity_t component
Handle to component (do not set)
Definition flecs.h:1002
Type class.
Definition type.hpp:21