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{
20{
22 {
23 return clone_mode;
24 }
25
26 auto is_cloning() const -> bool
27 {
29 }
30
31 auto is_saving_to_prefab() const -> bool
32 {
33 return to_prefab;
34 }
36 bool to_prefab{};
37 entt::const_handle save_source{};
38};
39
41{
43 {
44 return clone_mode;
45 }
46
47 auto is_cloning() const -> bool
48 {
50 }
51
52 auto is_updating_prefab() const -> bool
53 {
54 return !mapping_by_uid.empty();
55 }
56
58 entt::registry* reg{};
59
60 // The ids are not globally unique, so we need to map them to the handles
61 std::map<entt::entity, entt::handle> mapping_by_eid;
62
64 {
65 entt::handle handle;
66 bool consumed{};
67 };
68
69 // The uids are globally unique, so we can use them to map the entities
70 std::map<hpp::uuid, uid_mapping_t> mapping_by_uid;
71};
72
73
74auto push_load_context(entt::registry& registry) -> bool;
75void pop_load_context(bool push_result);
77
78auto push_save_context() -> bool;
79void pop_save_context(bool push_result);
81
82template<typename T>
83concept HasCharAndTraits = requires {
84 typename T::char_type;
85 typename T::traits_type;
86};
87template<typename T>
88concept HasView = HasCharAndTraits<T> && requires(const T& t) {
89 {
90 t.view()
91 } noexcept -> std::same_as<std::basic_string_view<typename T::char_type, typename T::traits_type>>;
92};
93
94void save_to_stream(std::ostream& stream, entt::const_handle obj);
95void save_to_file(const std::string& absolute_path, entt::const_handle obj);
96void save_to_stream_bin(std::ostream& stream, entt::const_handle obj);
97void save_to_file_bin(const std::string& absolute_path, entt::const_handle obj);
98
99void load_from_view(std::string_view view, entt::handle& obj);
100void load_from_stream(std::istream& stream, entt::handle& obj);
101void load_from_file(const std::string& absolute_path, entt::handle& obj);
102void load_from_stream_bin(std::istream& stream, entt::handle& obj);
103void load_from_file_bin(const std::string& absolute_path, entt::handle& obj);
104
106 entt::registry& registry,
107 entt::handle& obj) -> bool;
108
109auto load_from_prefab(const asset_handle<prefab>& pfb, entt::registry& registry) -> entt::handle;
110auto load_from_prefab_bin(const asset_handle<prefab>& pfb, entt::registry& registry) -> entt::handle;
111
112void clone_entity_from_stream(entt::const_handle src_obj, entt::handle& dst_obj);
113
114void save_to_stream(std::ostream& stream, const scene& scn);
115void save_to_file(const std::string& absolute_path, const scene& scn);
116void save_to_stream_bin(std::ostream& stream, const scene& scn);
117void save_to_file_bin(const std::string& absolute_path, const scene& scn);
118
119void load_from_view(std::string_view view, scene& scn);
120void load_from_stream(std::istream& stream, scene& scn);
121
122void load_from_file(const std::string& absolute_path, scene& scn);
123void load_from_stream_bin(std::istream& stream, scene& scn);
124void load_from_file_bin(const std::string& absolute_path, scene& scn);
125
126auto load_from_prefab(const asset_handle<scene_prefab>& pfb, scene& scn) -> bool;
127auto load_from_prefab_bin(const asset_handle<scene_prefab>& pfb, scene& scn) -> bool;
128
129void clone_scene_from_stream(const scene& src_scene, scene& dst_scene);
130
131template<typename Stream, typename T>
132void load_from(Stream& stream, T& scn)
133{
134 if constexpr(HasView<Stream>)
135 {
136 load_from_view(stream.view(), scn);
137 }
138 else
139 {
140 load_from_stream(stream, scn);
141 }
142}
143} // namespace unravel
144
145namespace ser20
146{
147
148SAVE_EXTERN(entt::const_handle);
149LOAD_EXTERN(entt::handle);
150
151template<typename T>
153{
155};
156struct const_entity_handle_link : basic_handle_link<entt::const_handle>
157{
158};
160{
161};
162
165
166} // namespace ser20
Definition yaml.hpp:46
auto push_save_context() -> bool
Definition entity.cpp:90
void save_to_stream_bin(std::ostream &stream, entt::const_handle obj)
Definition entity.cpp:843
void load_from(Stream &stream, T &scn)
Definition entity.hpp:132
void clone_scene_from_stream(const scene &src_scene, scene &dst_scene)
Definition entity.cpp:1253
void pop_load_context(bool push_result)
Definition entity.cpp:75
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
auto push_load_context(entt::registry &registry) -> bool
Definition entity.cpp:64
auto get_save_context() -> save_context &
Definition entity.cpp:111
void load_from_file(const std::string &absolute_path, animation_clip &obj)
auto get_load_context() -> load_context &
Definition entity.cpp:84
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:1023
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:909
auto load_from_prefab_out(const asset_handle< prefab > &pfb, entt::registry &registry, entt::handle &obj) -> bool
Definition entity.cpp:934
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
void pop_save_context(bool push_result)
Definition entity.cpp:101
clone_mode_t
Definition entity.hpp:13
void load_from_view(std::string_view view, entt::handle &obj)
Definition entity.cpp:868
auto load_from_prefab(const asset_handle< prefab > &pfb, entt::registry &registry) -> entt::handle
Definition entity.cpp:985
void clone_entity_from_stream(entt::const_handle src_obj, entt::handle &dst_obj)
Definition entity.cpp:1056
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)
Represents a handle to an asset, providing access and management functions.
auto is_cloning() const -> bool
Definition entity.hpp:47
clone_mode_t clone_mode
Definition entity.hpp:57
auto get_clone_mode() const -> clone_mode_t
Definition entity.hpp:42
std::map< entt::entity, entt::handle > mapping_by_eid
Definition entity.hpp:61
entt::registry * reg
Definition entity.hpp:58
auto is_updating_prefab() const -> bool
Definition entity.hpp:52
std::map< hpp::uuid, uid_mapping_t > mapping_by_uid
Definition entity.hpp:70
entt::const_handle save_source
Definition entity.hpp:37
auto get_clone_mode() const -> clone_mode_t
Definition entity.hpp:21
clone_mode_t clone_mode
Definition entity.hpp:35
auto is_cloning() const -> bool
Definition entity.hpp:26
auto is_saving_to_prefab() const -> bool
Definition entity.hpp:31
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:21