sculpto
scene_object.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file scene_object.h
3 * \brief Application scene object class defintion module.
4 *
5 * \author Sabitov Kirill
6 * \date 02 July 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "base.h"
12#include "scene.h"
13#include "../components/native_script_component.h"
14
15namespace scl
16{
19 {
20 friend class scene;
22
23 private:
24 scene_object_handle Entity { entt::null };
25 scene *Scene {};
26
27 private:
28 /*!*
29 * Scene object constructor by entity and scene.
30 *
31 * \param Entity - entity for scene object.
32 * \param Scene - scene connected to scene object.
33 */
35 : Entity(Entity), Scene(Scene) {}
36
37 public:
39 scene_object() = default;
40
42 scene_object(const scene_object &Other) = default;
43
45 ~scene_object() = default;
46
47 /*!*
48 * Scene object inner scene_object_handle getter function.
49 *
50 * \param None.
51 * \return object inner scene_object_handle.
52 */
53 scene_object_handle GetHandle() const { return Entity; }
54
55 /*!*
56 * Check if scene object is valid function.
57 *
58 * \param None.
59 * \return wheather object is valid or not.
60 */
61 bool IsOk() const { return Scene && Scene->Registry.valid(Entity); }
62
63 /*!*
64 * Check if object has specified component function.
65 *
66 * \tparam component to check.
67 * \param None.
68 * \return None.
69 */
70 template <typename T>
71 const bool HasComponent() const
72 {
73 return Scene->Registry.all_of<T>(Entity);
74 }
75
76 /*!*
77 * Add component to object function.
78 *
79 * \tparam component to add to object.
80 * \param None.
81 * \return None.
82 */
83 template <typename T, typename... Targs>
84 decltype(auto) AddComponent(Targs&&... Args)
85 {
86 return Scene->Registry.emplace<T>(Entity, std::forward<Targs>(Args)...);
87 }
88
89 /*!*
90 * Get object component function.
91 *
92 * \tparam component to get from object.
93 * \param None.
94 * \return None.
95 */
96 template <typename T>
98 {
99 SCL_CORE_ASSERT(HasComponent<T>(), "Scene object don't have \"{}\" component!", typeid(T).name());
100 return Scene->Registry.get<T>(Entity);
101 }
102
103 /*!*
104 * Gect object component function.
105 *
106 * \tparam component to get from object.
107 * \param None.
108 * \return None.
109 */
110 template <typename T>
111 const T &GetComponent() const
112 {
113 SCL_CORE_ASSERT(HasComponent<T>(), "Scene object don't have \"{}\" component!", typeid(T).name());
114 return Scene->Registry.get<T>(Entity);
115 }
116
117 /*!*
118 * Remove component from scene object function.
119 *
120 * \tparam component to remove from object.
121 * \param None.
122 * \return None.
123 */
124 template <typename T>
126 {
127 Scene->Registry.remove<T>(Entity);
128 }
129
130 /*!*
131 * Check if scene object exists function.
132 *
133 * \param None.
134 * \return wheather scene object exists or not.
135 */
136 operator bool() const { return Entity != entt::null; }
137
138 /*!*
139 * Getting scene object inner scene_object_handle.
140 *
141 * \param None.
142 * \return inner object scene_object_handle.
143 */
144 operator u32() const { return (u32)Entity; }
145
146 /*!*
147 * Getting scene object inner scene_object_handle.
148 *
149 * \param None.
150 * \return inner object scene_object_handle.
151 */
152 operator scene_object_handle() const { return Entity; }
153
154 /*!*
155 * Scene objects compare function.
156 *
157 * \param Other - scene object to compare with.
158 * \return wheather scene objects are the same or not.
159 */
160 bool operator==(const scene_object &Other) const
161 {
162 return Entity == Other.Entity && Scene == Other.Scene;
163 }
164
165 /*!*
166 * Scene objects compare function.
167 *
168 * \param Other - scene object to compare with.
169 * \return wheather scene objects are the same or not.
170 */
171 bool operator!=(const scene_object &Other) const
172 {
173 return Entity != Other.Entity || Scene != Other.Scene;
174 }
175 };
176}
#define SCL_CORE_ASSERT(expr,...)
Definition: assert.h:69
Topology object basis class for mesh creating implementation module.
const T & GetComponent() const
Definition: scene_object.h:111
scene_object_handle GetHandle() const
Definition: scene_object.h:53
bool operator==(const scene_object &Other) const
Definition: scene_object.h:160
bool IsOk() const
Definition: scene_object.h:61
decltype(auto) AddComponent(Targs &&... Args)
Definition: scene_object.h:84
const bool HasComponent() const
Definition: scene_object.h:71
~scene_object()=default
scene_object(const scene_object &Other)=default
friend class scene
Definition: scene_object.h:20
scene_object()=default
bool operator!=(const scene_object &Other) const
Definition: scene_object.h:171
Definition: base.h:33
entt::entity scene_object_handle
Definition: scene.h:23
uint32_t u32
Definition: math_common.h:21
Scene class defintion module.