CSEngine
Loading...
Searching...
No Matches
CSE::SGameObject Class Reference
Inheritance diagram for CSE::SGameObject:
CSE::SObject CSE::SGameObjectFromSPrefab

Public Types

enum  STATUS { IDLE = 0 , INIT = 1 , DESTROY = -1 , UNKOWN = -2 }
 

Public Member Functions

 SGameObject (std::string name)
 
 SGameObject (std::string name, std::string hash)
 
virtual void Init ()
 
virtual void Tick (float elapsedTime)
 
void Exterminate () override
 
void Destroy () override
 자동 삭제가 아닌 특정한 상황에서 삭제될 때 호출되는 함수
 
void SetUndestroyable (bool enable) override
 
void AddChild (SGameObject *object)
 
void RemoveChildren (bool isAllLevel=false)
 
void RemoveChild (SGameObject *object)
 
SGameObjectGetParent () const
 
void SetParent (SGameObject *object)
 
void RemoveParent ()
 
const std::list< SGameObject * > & GetChildren () const
 
void AddComponent (SComponent *component)
 컴포넌트를 이 오브젝트에 추가합니다.
 
template<class T >
T * GetComponent ()
 
template<class T >
T * GetComponentByHash (const std::string &id) const
 
SComponentGetSComponentByHash (const std::string &hash) const
 
const std::list< SComponent * > & GetComponents () const
 
HSQOBJECT GetCustomComponent (const char *className)
 
void DeleteComponent (SComponent *component)
 
template<class T >
T * CreateComponent ()
 
SComponentCreateComponent (const char *type)
 
SGameObjectFind (std::string name) const
 
SGameObjectFindLocalByID (const std::string &id)
 
std::string GetName () const
 
std::string GetID () const
 
std::string GetID (const SComponent *component) const
 
void SetName (std::string name)
 
TransformInterfaceGetTransform () const
 
STATUS GetStatus () const
 
bool GetIsEnable () const
 
void SetIsEnable (bool is_enable)
 
void SetHash (std::string &hash) override
 
bool isPrefab (bool OnlyThisObject=false) const
 
void SetIsPrefab (bool m_isPrefab)
 
std::string GetResourceID () const
 
void SetResourceID (const std::string &resID, bool setChildren=false)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
std::string GetHash () const
 

Static Public Member Functions

static SGameObjectFindByID (std::string id)
 
static SGameObjectFindByHash (const std::string &hash)
 

Additional Inherited Members

- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 18 of file SGameObject.h.

Member Enumeration Documentation

◆ STATUS

enum CSE::SGameObject::STATUS

Definition at line 20 of file SGameObject.h.

20 {
21 IDLE = 0, INIT = 1, DESTROY = -1, UNKOWN = -2
22 };

Constructor & Destructor Documentation

◆ SGameObject() [1/3]

SGameObject::SGameObject ( )

Definition at line 14 of file SGameObject.cpp.

14 {
15 CORE->GetCore(GameObjectMgr)->Register(this);
16 m_transform = CreateComponent<TransformComponent>();
17
18 SGameObject::Init();
19}

◆ SGameObject() [2/3]

SGameObject::SGameObject ( std::string name)
explicit

Definition at line 21 of file SGameObject.cpp.

21 {
22 CORE->GetCore(GameObjectMgr)->Register(this);
23 m_name = std::move(name);
24 m_transform = CreateComponent<TransformComponent>();
25
26 SGameObject::Init();
27}

◆ SGameObject() [3/3]

SGameObject::SGameObject ( std::string name,
std::string hash )
explicit

Definition at line 29 of file SGameObject.cpp.

29 {
30 SObject::SetHash(hash);
31 CORE->GetCore(GameObjectMgr)->Register(this);
32 m_name = std::move(name);
33 m_transform = CreateComponent<TransformComponent>();
34
35 SGameObject::Init();
36}

Member Function Documentation

◆ AddChild()

void SGameObject::AddChild ( SGameObject * object)

Definition at line 101 of file SGameObject.cpp.

101 {
102 if (object == nullptr) return;
103 object->RemoveParent();
104 m_children.push_back(object);
105 object->m_parent = this;
106}

◆ AddComponent()

void SGameObject::AddComponent ( SComponent * component)

컴포넌트를 이 오브젝트에 추가합니다.

Parameters
component추가할 오브젝트

Definition at line 138 of file SGameObject.cpp.

138 {
139 m_components.push_back(component);
140}

◆ CreateComponent() [1/2]

template<class T >
T * CSE::SGameObject::CreateComponent ( )

Definition at line 163 of file SGameObject.h.

163 {
164 T* component = new T(this);
165 AddComponent(component);
166 if (m_status == IDLE)
167 component->Init();
168 return component;
169 }
void AddComponent(SComponent *component)
컴포넌트를 이 오브젝트에 추가합니다.

◆ CreateComponent() [2/2]

SComponent * SGameObject::CreateComponent ( const char * type)

Definition at line 165 of file SGameObject.cpp.

165 {
166 SComponent* component = static_cast<SComponent*>(ReflectionObject::NewObject(type));
167 component->SetGameObject(this);
168 AddComponent(component);
169 if (m_status == IDLE)
170 component->Init();
171 return component;
172}

◆ DeleteComponent()

void SGameObject::DeleteComponent ( SComponent * component)

Definition at line 161 of file SGameObject.cpp.

161 {
162 m_components.remove(component);
163}

◆ Destroy()

void SGameObject::Destroy ( )
overridevirtual

자동 삭제가 아닌 특정한 상황에서 삭제될 때 호출되는 함수

Reimplemented from CSE::SObject.

Definition at line 69 of file SGameObject.cpp.

69 {
70 {
71 auto iter = m_components.begin();
72 while (iter != m_components.end()) {
73 auto component = *iter;
74 m_components.erase(iter++);
75
76 if (component == nullptr) continue;
77 CORE->GetCore(MemoryMgr)->ReleaseObject(component);
78 }
79 }
80
81 m_components.clear();
82
83 if (m_parent != nullptr) {
84 RemoveParent();
85 }
86
87 {
88 auto iter = m_children.begin();
89 while (iter != m_children.end()) {
90 auto object = *iter;
91 m_children.erase(iter++);
92
93 if (object == nullptr) continue;
94 object->Destroy();
95 }
96 }
97 m_status = DESTROY;
98 CORE->GetCore(GameObjectMgr)->AddDestroyObject(this);
99}

◆ Exterminate()

void SGameObject::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 55 of file SGameObject.cpp.

55 {
56 {
57 auto iter = m_components.begin();
58 while (iter != m_components.end()) {
59 auto component = *iter;
60 m_components.erase(iter++);
61
62 if (component == nullptr) continue;
63 CORE->GetCore(MemoryMgr)->ReleaseObject(component);
64 }
65 }
66 CORE->GetCore(GameObjectMgr)->Remove(this);
67}

◆ Find()

SGameObject * SGameObject::Find ( std::string name) const

Definition at line 192 of file SGameObject.cpp.

192 {
193 return CORE->GetCore(GameObjectMgr)->Find(ConvertSpaceStr(std::move(name), true));
194}

◆ FindByHash()

SGameObject * SGameObject::FindByHash ( const std::string & hash)
static

Definition at line 212 of file SGameObject.cpp.

212 {
213 return CORE->GetCore(GameObjectMgr)->FindByHash(ConvertSpaceStr(hash, true));
214}

◆ FindByID()

SGameObject * SGameObject::FindByID ( std::string id)
static

Definition at line 208 of file SGameObject.cpp.

208 {
209 return CORE->GetCore(GameObjectMgr)->FindByID(ConvertSpaceStr(std::move(id), true));
210}

◆ FindLocalByID()

SGameObject * SGameObject::FindLocalByID ( const std::string & id)

Definition at line 197 of file SGameObject.cpp.

197 {
198 const auto& currentId = GetID();
199 if (currentId == id) return this;
200
201 for (const auto& child: m_children) {
202 const auto& result = child->FindLocalByID(id);
203 if (result != nullptr) return result;
204 }
205 return nullptr;
206}

◆ GetChildren()

const std::list< SGameObject * > & SGameObject::GetChildren ( ) const

Definition at line 134 of file SGameObject.cpp.

134 {
135 return m_children;
136}

◆ GetComponent()

template<class T >
T * CSE::SGameObject::GetComponent ( )

Definition at line 145 of file SGameObject.h.

145 {
146 const auto& ref = ReflectionRef<T>();
147 for (const auto& component : m_components) {
148 if (component == nullptr) continue;
149 if (ref.IsSameClass(component)) {
150 return static_cast<T*>(component);
151 }
152 }
153
154 return nullptr;
155 }

◆ GetComponentByHash()

template<class T >
T * CSE::SGameObject::GetComponentByHash ( const std::string & id) const

Definition at line 158 of file SGameObject.h.

158 {
159 return static_cast<T*>(GetSComponentByHash(id));
160 }

◆ GetComponents()

const std::list< SComponent * > & SGameObject::GetComponents ( ) const

Definition at line 142 of file SGameObject.cpp.

142 {
143 return m_components;
144}

◆ GetCustomComponent()

HSQOBJECT SGameObject::GetCustomComponent ( const char * className)

Definition at line 146 of file SGameObject.cpp.

146 {
147 for (const auto& component: m_components) {
148 if (component == nullptr) continue;
149 if (dynamic_cast<CustomComponent*>(component)) {
150 auto customComponent = static_cast<CustomComponent*>(component);
151 if (customComponent->SGetClassName() != className) continue;
152 return customComponent->GetClassInstance().GetObject();
153 }
154 }
155 auto obj = HSQOBJECT();
156 obj._type = OT_NULL;
157
158 return obj;
159}

◆ GetID() [1/2]

std::string SGameObject::GetID ( ) const

Definition at line 174 of file SGameObject.cpp.

174 {
175 std::string id;
176 for (const SGameObject* node = const_cast<SGameObject*>(this);; node = node->GetParent()) {
177 if (node == nullptr) break;
178
179 id = node->GetName() + (id.empty() ? "" : "/") + id;
180 }
181
182 return id;
183}

◆ GetID() [2/2]

std::string SGameObject::GetID ( const SComponent * component) const

Definition at line 185 of file SGameObject.cpp.

185 {
186 if (component == nullptr) return "";
187
188 const auto& object = component->GetGameObject();
189 return object->m_hash + "?" + component->GetClassType();
190}

◆ GetIsEnable()

bool SGameObject::GetIsEnable ( ) const

Definition at line 216 of file SGameObject.cpp.

216 {
217 return isEnable;
218}

◆ GetName()

std::string CSE::SGameObject::GetName ( ) const
inline

Definition at line 93 of file SGameObject.h.

93 {
94 return m_name;
95 }

◆ GetParent()

SGameObject * SGameObject::GetParent ( ) const

Definition at line 121 of file SGameObject.cpp.

121 {
122 return m_parent;
123}

◆ GetResourceID()

std::string SGameObject::GetResourceID ( ) const

Definition at line 267 of file SGameObject.cpp.

267 {
268 return m_resourceID;
269}

◆ GetSComponentByHash()

SComponent * SGameObject::GetSComponentByHash ( const std::string & hash) const

Definition at line 281 of file SGameObject.cpp.

281 {
282 const auto& object = CORE->GetCore(GameObjectMgr)->FindByHash(ConvertSpaceStr(hash, true));
283 if (object == nullptr) return nullptr;
284
285 std::string componentName = split(hash, '?')[1];
286
287 for (const auto& component: object->m_components) {
288 if (componentName == component->GetClassType()) {
289 return component;
290 }
291 }
292 return nullptr;
293}

◆ GetStatus()

STATUS CSE::SGameObject::GetStatus ( ) const
inline

Definition at line 109 of file SGameObject.h.

109 {
110 return m_status;
111 }

◆ GetTransform()

TransformInterface * CSE::SGameObject::GetTransform ( ) const
inline

Definition at line 105 of file SGameObject.h.

105 {
106 return m_transform;
107 }

◆ Init()

void SGameObject::Init ( )
virtual

Definition at line 40 of file SGameObject.cpp.

40 {
41 // for (auto component : m_components) {
42 // if (component == nullptr) continue;
43 //
44 // component->Init();
45 //
46 // }
47}

◆ isPrefab()

bool SGameObject::isPrefab ( bool OnlyThisObject = false) const

Definition at line 257 of file SGameObject.cpp.

257 {
258 if (m_isPrefab || m_parent == nullptr || OnlyThisObject) return m_isPrefab;
259
260 return m_parent->isPrefab();
261}

◆ RemoveChild()

void SGameObject::RemoveChild ( SGameObject * object)

Definition at line 115 of file SGameObject.cpp.

115 {
116 if (object == nullptr) return;
117 m_children.remove(object);
118 object->m_parent = nullptr;
119}

◆ RemoveChildren()

void SGameObject::RemoveChildren ( bool isAllLevel = false)

Definition at line 108 of file SGameObject.cpp.

108 {
109 for (const auto& child: m_children) {
110 child->RemoveChildren(isAllLevel);
111 }
112 m_children.clear();
113}

◆ RemoveParent()

void SGameObject::RemoveParent ( )

Definition at line 129 of file SGameObject.cpp.

129 {
130 if (m_parent == nullptr) return;
131 m_parent->RemoveChild(this);
132}

◆ SetHash()

void SGameObject::SetHash ( std::string & hash)
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 295 of file SGameObject.cpp.

295 {
296 const std::string prevHash = std::string(m_hash);
297 SObject::SetHash(hash);
298 CORE->GetCore(GameObjectMgr)->ChangeHash(prevHash, hash);
299}

◆ SetIsEnable()

void SGameObject::SetIsEnable ( bool is_enable)

Definition at line 220 of file SGameObject.cpp.

220 {
221 isEnable = is_enable;
222 for (const auto& component: m_components) {
223 if (component == nullptr) continue;
224 component->SetIsEnable(is_enable);
225 }
226}

◆ SetIsPrefab()

void SGameObject::SetIsPrefab ( bool m_isPrefab)

Definition at line 263 of file SGameObject.cpp.

263 {
264 SGameObject::m_isPrefab = m_isPrefab;
265}

◆ SetName()

void CSE::SGameObject::SetName ( std::string name)
inline

Definition at line 101 of file SGameObject.h.

101 {
102 m_name = std::move(name);
103 }

◆ SetParent()

void SGameObject::SetParent ( SGameObject * object)

Definition at line 125 of file SGameObject.cpp.

125 {
126 object->AddChild(this);
127}

◆ SetResourceID()

void SGameObject::SetResourceID ( const std::string & resID,
bool setChildren = false )

Definition at line 271 of file SGameObject.cpp.

271 {
272 m_resourceID = resID;
273
274 if (setChildren) {
275 for (const auto& child: m_children) {
276 child->SetResourceID(resID, setChildren);
277 }
278 }
279}

◆ SetUndestroyable()

void SGameObject::SetUndestroyable ( bool enable)
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 245 of file SGameObject.cpp.

245 {
246 SObject::SetUndestroyable(enable);
247
248 for (const auto& component: m_components) {
249 component->SetUndestroyable(enable);
250 }
251
252 for (const auto& child: m_children) {
253 child->SetUndestroyable(enable);
254 }
255}

◆ Tick()

void SGameObject::Tick ( float elapsedTime)
virtual

Definition at line 49 of file SGameObject.cpp.

49 {
50 if (!isEnable) return;
51 if (isPrefab()) return;
52 UpdateComponent(elapsedTime);
53}

The documentation for this class was generated from the following files: