8 #ifndef GAMEOBJECT_HPP_
9 #define GAMEOBJECT_HPP_
11 #include "Component.hpp"
16 #if KAPENGINE_BETA_ACTIVE
17 #if KAPENGINE_THREAD_ACTIVE
28 namespace SceneManagement {
85 template<typename T, typename = std::enable_if<std::is_base_of<Component, T>::value>>
87 PROFILER_FUNC_START();
99 template<typename T, typename = std::enable_if<std::is_base_of<Component, T>::value>>
101 std::size_t hash = Type::getHashCode<T>();
102 for (std::size_t i = 0; i < _components.size(); i++) {
103 std::size_t componentHash = Type::getHashCode(*_components[i]);
104 if (_components[i] && componentHash == hash) {
105 return dynamic_cast<T &
>(*_components[i]);
108 for (std::size_t i = 0; i < _componentsRun.size(); i++) {
109 std::size_t componentHash = Type::getHashCode(*_componentsRun[i]);
110 if (_componentsRun[i] && componentHash == hash) {
111 return dynamic_cast<T &
>(*_componentsRun[i]);
124 template<typename T, typename = std::enable_if<std::is_base_of<Component, T>::value>>
126 PROFILER_FUNC_START();
127 std::vector<std::shared_ptr<T>> components;
128 std::size_t hash = Type::getHashCode<T>();
129 for (std::size_t i = 0; i < _components.size(); i++) {
130 std::size_t componentHash = Type::getHashCode(*_components[i]);
131 if (_components[i] && componentHash == hash)
132 components.push_back(std::dynamic_pointer_cast<T>(_components[i]));
134 for (std::size_t i = 0; i < _componentsRun.size(); i++) {
135 std::size_t componentHash = Type::getHashCode(*_componentsRun[i]);
136 if (_componentsRun[i] && componentHash == hash)
137 components.push_back(std::dynamic_pointer_cast<T>(_componentsRun[i]));
151 bool hasComponent(std::string
const& componentName)
const;
162 template<typename T, typename = std::enable_if<std::is_base_of<Component, T>::value>>
164 PROFILER_FUNC_START();
165 std::size_t hash = Type::getHashCode<T>();
166 for (std::size_t i = 0; i < _components.size(); i++) {
167 std::size_t componentHash = Type::getHashCode(*_components[i]);
168 if (_components[i] && componentHash == hash) {
173 for (std::size_t i = 0; i < _componentsRun.size(); i++) {
174 std::size_t componentHash = Type::getHashCode(*_componentsRun[i]);
175 if (_componentsRun[i] && componentHash == hash) {
190 #if KAPENGINE_BETA_ACTIVE
191 #if KAPENGINE_THREAD_ACTIVE
192 void __updatePhysics();
193 void __updateComponents();
206 void __update(
bool physics =
false,
bool runDisplay =
true);
244 PROFILER_FUNC_START();
255 PROFILER_FUNC_START();
287 PROFILER_FUNC_START();
319 void dump(
bool displayComponent =
false, std::string prefix =
"");
347 PROFILER_FUNC_START();
358 PROFILER_FUNC_START();
359 #if KAPENGINE_BETA_ACTIVE
360 #if KAPENGINE_THREAD_ACTIVE
365 #if KAPENGINE_BETA_ACTIVE
366 #if KAPENGINE_THREAD_ACTIVE
379 PROFILER_FUNC_START();
380 #if KAPENGINE_BETA_ACTIVE
381 #if KAPENGINE_THREAD_ACTIVE
386 #if KAPENGINE_BETA_ACTIVE
387 #if KAPENGINE_THREAD_ACTIVE
400 PROFILER_FUNC_START();
415 bool _startActive =
true;
416 bool _destroyed =
false;
417 bool _firstUpdateDone =
false;
418 std::vector<std::shared_ptr<Component>> _components;
419 std::vector<std::shared_ptr<Component>> _componentsRun;
421 std::size_t _idComp = 0;
422 std::string _prefabName;
424 #if KAPENGINE_BETA_ACTIVE
425 #if KAPENGINE_THREAD_ACTIVE
void removeComponent(std::shared_ptr< Component > comp)
remove component from its shared_ptr
T & getComponent(std::string const &componentName)
Get the Component by its type.
Definition: GameObject.hpp:86
Entity & getEntity() const
Get the Entity of GameObject.
Definition: GameObject.hpp:286
std::string getPrefabName() const
Get the Prefab Name.
Definition: GameObject.hpp:346
void __onSceneChanged()
call when scene changed to another scene
Definition: GameObject.cpp:644
void __engineStop()
Definition: GameObject.cpp:470
void __update(bool physics=false, bool runDisplay=true)
Definition: GameObject.cpp:288
void __onSceneGonnaUpdated()
Definition: GameObject.cpp:629
void destroy()
destroy the GameObject
Definition: GameObject.cpp:602
bool isDestroyed() const
return if GameObject is destroyed
Definition: GameObject.hpp:234
bool isActive() const
return if GameObject is active
Definition: GameObject.hpp:225
void __destroyIt()
Definition: GameObject.cpp:499
Definition: GameObject.hpp:40
KEngine & getEngine()
Get the Engine.
Definition: GameObject.cpp:454
std::vector< std::shared_ptr< T > > getComponents()
Get the Components by there type.
Definition: GameObject.hpp:125
T & getComponent()
Get the Component by its type.
Definition: GameObject.hpp:100
std::vector< std::shared_ptr< Component > > getAllComponents() const
Get the All Components of GameObject.
Definition: GameObject.cpp:589
Definition: Errors.hpp:52
void __init()
Definition: GameObject.cpp:512
void __stoppingGame()
Definition: GameObject.cpp:548
void __updateDisplay()
Definition: GameObject.cpp:363
SceneManagement::Scene & getScene()
Get the Scene.
Definition: GameObject.hpp:243
void __setPrefab(std::string const &name)
set prefab name
Definition: GameObject.cpp:608
Definition: Component.hpp:38
void setName(std::string const &name)
Set the Name of GameObject.
Definition: GameObject.hpp:357
std::string getName() const
Get GameObject Name.
Definition: GameObject.hpp:277
void dump(bool displayComponent=false, std::string prefix="")
display GameObject in log
Definition: GameObject.cpp:559
SceneManagement::Scene & getSceneConst() const
Get the Scene.
Definition: GameObject.hpp:254
void setActive(bool b)
Set the Active status of GameObject.
Definition: GameObject.cpp:523
std::string getTag() const
Get the GameObject Tag.
Definition: GameObject.hpp:399
Component & getTransform()
Get the Transform.
Definition: GameObject.cpp:446
void addComponent(std::shared_ptr< Component > comp)
add new component to GameObject
Definition: GameObject.cpp:458
main namespace
Definition: Component.hpp:17
void setTag(std::string const &tag)
Set the GameObject Tag.
Definition: GameObject.hpp:378
bool hasComponent() const
return if GameObject has component from its type
Definition: GameObject.hpp:163
void __onSceneUpdated()
Definition: GameObject.cpp:614
Class of engine.
Definition: Engine.hpp:60
Definition: Entity.hpp:15