Unravel Engine C++ Reference
Loading...
Searching...
No Matches
entity.hpp
Go to the documentation of this file.
1#pragma once
3#include <engine/ecs/scene.h>
4
7
8#include <string_view>
9
10namespace unravel
11{
12
13
14template<typename Entity>
16{
17 Entity entity;
18};
19
20template<typename Entity>
33{
35 {
36 return clone_mode;
37 }
38
39 auto is_cloning() const -> bool
40 {
42 }
43
44 auto is_saving_to_prefab() const -> bool
45 {
46 return to_prefab;
47 }
49 bool to_prefab{};
50 entt::const_handle save_source{};
51};
52
54{
56 {
57 return clone_mode;
58 }
59
60 auto is_cloning() const -> bool
61 {
63 }
64
65 auto is_updating_prefab() const -> bool
66 {
67 return !mapping_by_prefab_uid.empty();
68 }
69
70
71 std::vector<entity_data<entt::handle>> entities;
73 entt::registry* reg{};
74
75 // The ids are not globally unique, so we need to map them to the handles
76 std::map<entt::entity, entt::handle> mapping_by_eid;
77
78 // The entity uids (from id_component) are globally unique, so we can use them to map entities
79 std::map<hpp::uuid, entt::handle> mapping_by_uid;
80
82 {
83 entt::handle handle;
84 bool consumed{};
85 };
86
87 // The uids are globally unique, so we can use them to map the entities
88 std::map<hpp::uuid, prefab_uid_mapping_t> mapping_by_prefab_uid;
89
90};
91
93{
94 std::function<void(hpp::span<const entt::handle> new_entities)> callback;
95};
96void push_on_load_callbacks(const post_load_callbacks& callbacks);
99
100auto push_load_context(entt::registry& registry) -> bool;
101void pop_load_context(bool push_result);
103
104auto push_save_context() -> bool;
105void pop_save_context(bool push_result);
107
108template<typename T>
109concept HasCharAndTraits = requires {
110 typename T::char_type;
111 typename T::traits_type;
112};
113template<typename T>
114concept HasView = HasCharAndTraits<T> && requires(const T& t) {
115 {
116 t.view()
117 } noexcept -> std::same_as<std::basic_string_view<typename T::char_type, typename T::traits_type>>;
118};
119
120void save_to_stream(std::ostream& stream, entt::const_handle obj);
121void save_to_file(const std::string& absolute_path, entt::const_handle obj);
122void save_to_stream_bin(std::ostream& stream, entt::const_handle obj);
123void save_to_file_bin(const std::string& absolute_path, entt::const_handle obj);
124
125void load_from_view(std::string_view view, entt::handle& obj);
126void load_from_stream(std::istream& stream, entt::handle& obj);
127void load_from_file(const std::string& absolute_path, entt::handle& obj);
128void load_from_stream_bin(std::istream& stream, entt::handle& obj);
129void load_from_file_bin(const std::string& absolute_path, entt::handle& obj);
130
132 entt::registry& registry,
133 entt::handle& obj) -> bool;
134
135auto load_from_prefab(const asset_handle<prefab>& pfb, entt::registry& registry) -> entt::handle;
136auto load_from_prefab_bin(const asset_handle<prefab>& pfb, entt::registry& registry) -> entt::handle;
137
138void clone_entity_from_stream(entt::const_handle src_obj, entt::handle& dst_obj);
139
140void save_to_stream(std::ostream& stream, const scene& scn);
141void save_to_file(const std::string& absolute_path, const scene& scn);
142void save_to_stream_bin(std::ostream& stream, const scene& scn);
143void save_to_file_bin(const std::string& absolute_path, const scene& scn);
144
145void load_from_view(std::string_view view, scene& scn);
146void load_from_stream(std::istream& stream, scene& scn);
147
148void load_from_file(const std::string& absolute_path, scene& scn);
149void load_from_stream_bin(std::istream& stream, scene& scn);
150void load_from_file_bin(const std::string& absolute_path, scene& scn);
151
152auto load_from_prefab(const asset_handle<scene_prefab>& pfb, scene& scn) -> bool;
153auto load_from_prefab_bin(const asset_handle<scene_prefab>& pfb, scene& scn) -> bool;
154
155void clone_scene_from_stream(const scene& src_scene, scene& dst_scene);
156
157template<typename Stream, typename T>
158void load_from(Stream& stream, T& scn)
159{
160 stream.seekg(0);
161
162 if constexpr(HasView<Stream>)
163 {
164 load_from_view(stream.view(), scn);
165 }
166 else
167 {
168 load_from_stream(stream, scn);
169 }
170}
171} // namespace unravel
172
173namespace ser20
174{
175
176SAVE_EXTERN(entt::const_handle);
177LOAD_EXTERN(entt::handle);
178
179template<typename T>
181{
183};
184struct const_entity_handle_link : basic_handle_link<entt::const_handle>
185{
186};
188{
189};
190
193
194} // namespace ser20
uint16_t view
Definition yaml.hpp:46
auto push_save_context() -> bool
Definition entity.cpp:118
void save_to_stream_bin(std::ostream &stream, entt::const_handle obj)
Definition entity.cpp:940
void load_from(Stream &stream, T &scn)
Definition entity.hpp:158
void clone_scene_from_stream(const scene &src_scene, scene &dst_scene)
Definition entity.cpp:1395
void pop_load_context(bool push_result)
Definition entity.cpp:69
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
auto get_post_load_callbacks() -> const post_load_callbacks *
Definition entity.cpp:113
auto push_load_context(entt::registry &registry) -> bool
Definition entity.cpp:58
void pop_on_load_callbacks()
Definition entity.cpp:104
auto get_save_context() -> save_context &
Definition entity.cpp:139
void load_from_file(const std::string &absolute_path, animation_clip &obj)
auto get_load_context() -> load_context &
Definition entity.cpp:90
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
auto load_from_prefab_bin(const asset_handle< prefab > &pfb, entt::registry &registry) -> entt::handle
Definition entity.cpp:1139
auto load_from_stream(std::istream &stream, entt::handle e, script_component::script_object &obj) -> bool
void load_from_stream_bin(std::istream &stream, entt::handle &obj)
Definition entity.cpp:1010
auto load_from_prefab_out(const asset_handle< prefab > &pfb, entt::registry &registry, entt::handle &obj) -> bool
Definition entity.cpp:1037
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
void pop_save_context(bool push_result)
Definition entity.cpp:129
clone_mode_t
Definition entity.hpp:26
void load_from_view(std::string_view view, entt::handle &obj)
Definition entity.cpp:965
void push_on_load_callbacks(const post_load_callbacks &callbacks)
Definition entity.cpp:96
auto load_from_prefab(const asset_handle< prefab > &pfb, entt::registry &registry) -> entt::handle
Definition entity.cpp:1101
void clone_entity_from_stream(entt::const_handle src_obj, entt::handle &dst_obj)
Definition entity.cpp:1198
auto save_to_stream(std::ostream &stream, entt::const_handle e, const script_component::script_object &obj) -> bool
#define LOAD_EXTERN(cls)
#define SAVE_EXTERN(cls)
Thread-safe handle to an asset.
entity_components< Entity > components
Definition entity.hpp:23
auto is_cloning() const -> bool
Definition entity.hpp:60
clone_mode_t clone_mode
Definition entity.hpp:72
auto get_clone_mode() const -> clone_mode_t
Definition entity.hpp:55
std::map< entt::entity, entt::handle > mapping_by_eid
Definition entity.hpp:76
entt::registry * reg
Definition entity.hpp:73
std::vector< entity_data< entt::handle > > entities
Definition entity.hpp:71
auto is_updating_prefab() const -> bool
Definition entity.hpp:65
std::map< hpp::uuid, prefab_uid_mapping_t > mapping_by_prefab_uid
Definition entity.hpp:88
std::map< hpp::uuid, entt::handle > mapping_by_uid
Definition entity.hpp:79
std::function< void(hpp::span< const entt::handle > new_entities)> callback
Definition entity.hpp:94
entt::const_handle save_source
Definition entity.hpp:50
auto get_clone_mode() const -> clone_mode_t
Definition entity.hpp:34
clone_mode_t clone_mode
Definition entity.hpp:48
auto is_cloning() const -> bool
Definition entity.hpp:39
auto is_saving_to_prefab() const -> bool
Definition entity.hpp:44
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:70