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 ()
 
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)
 
std::string GenerateMeta () 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)
 
virtual void __FORCE_DESTROY__ ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 

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 17 of file SGameObject.h.

Member Enumeration Documentation

◆ STATUS

enum CSE::SGameObject::STATUS

Definition at line 19 of file SGameObject.h.

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

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 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 91 of file SGameObject.cpp.

91 {
92 if (object == nullptr) return;
93 object->RemoveParent();
94 m_children.push_back(object);
95 object->m_parent = this;
96}

◆ AddComponent()

void SGameObject::AddComponent ( SComponent component)

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

Parameters
component추가할 오브젝트

Definition at line 128 of file SGameObject.cpp.

128 {
129 auto str_class = component->GetClassType();
130 m_components.push_back(component);
131}

◆ CreateComponent()

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

Definition at line 161 of file SGameObject.h.

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

◆ DeleteComponent()

void SGameObject::DeleteComponent ( SComponent component)

Definition at line 152 of file SGameObject.cpp.

152 {
153 m_components.remove(component);
154}

◆ Destroy()

void SGameObject::Destroy ( )
overridevirtual

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

Reimplemented from CSE::SObject.

Definition at line 59 of file SGameObject.cpp.

59 {
60 {
61 auto iter = m_components.begin();
62 while (iter != m_components.end()) {
63 auto component = *iter;
64 m_components.erase(iter++);
65
66 if (component == nullptr) continue;
67 CORE->GetCore(MemoryMgr)->ReleaseObject(component);
68 }
69 }
70
71 m_components.clear();
72
73 if (m_parent != nullptr) {
74 RemoveParent();
75 }
76
77 {
78 auto iter = m_children.begin();
79 while (iter != m_children.end()) {
80 auto object = *iter;
81 m_children.erase(iter++);
82
83 if (object == nullptr) continue;
84 object->Destroy();
85 }
86 }
87 m_status = DESTROY;
88 CORE->GetCore(GameObjectMgr)->AddDestroyObject(this);
89}

◆ Exterminate()

void SGameObject::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 55 of file SGameObject.cpp.

55 {
56 CORE->GetCore(GameObjectMgr)->Remove(this);
57}

◆ Find()

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

Definition at line 174 of file SGameObject.cpp.

174 {
175 return CORE->GetCore(GameObjectMgr)->Find(ConvertSpaceStr(std::move(name), true));
176}

◆ FindByHash()

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

Definition at line 194 of file SGameObject.cpp.

194 {
195 return CORE->GetCore(GameObjectMgr)->FindByHash(ConvertSpaceStr(hash, true));
196}

◆ FindByID()

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

Definition at line 190 of file SGameObject.cpp.

190 {
191 return CORE->GetCore(GameObjectMgr)->FindByID(ConvertSpaceStr(std::move(id), true));
192}

◆ FindLocalByID()

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

Definition at line 179 of file SGameObject.cpp.

179 {
180 const auto& currentId = GetID();
181 if (currentId == id) return this;
182
183 for (const auto& child: m_children) {
184 const auto& result = child->FindLocalByID(id);
185 if (result != nullptr) return result;
186 }
187 return nullptr;
188}

◆ GenerateMeta()

std::string SGameObject::GenerateMeta ( )
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 290 of file SGameObject.cpp.

290 {
291 unsigned int startIndex = GetID().size() - GetName().size();
292 return GetMetaString(*this, startIndex);
293}

◆ GetChildren()

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

Definition at line 124 of file SGameObject.cpp.

124 {
125 return m_children;
126}

◆ GetComponent()

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

Definition at line 142 of file SGameObject.h.

142 {
143 for (const auto& component : m_components) {
144 if (component == nullptr) continue;
145 if (dynamic_cast<T*>(component)) {
146 return static_cast<T*>(component);
147 }
148 }
149
150 return nullptr;
151 }

◆ GetComponentByHash()

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

Definition at line 154 of file SGameObject.h.

154 {
155 return static_cast<T*>(GetSComponentByHash(id));
156 }

◆ GetComponents()

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

Definition at line 133 of file SGameObject.cpp.

133 {
134 return m_components;
135}

◆ GetCustomComponent()

HSQOBJECT SGameObject::GetCustomComponent ( const char *  className)

Definition at line 137 of file SGameObject.cpp.

137 {
138 for (const auto& component: m_components) {
139 if (component == nullptr) continue;
140 if (dynamic_cast<CustomComponent*>(component)) {
141 auto customComponent = static_cast<CustomComponent*>(component);
142 if (customComponent->SGetClassName() != className) continue;
143 return customComponent->GetClassInstance().GetObject();
144 }
145 }
146 auto obj = HSQOBJECT();
147 obj._type = OT_NULL;
148
149 return obj;
150}

◆ GetID() [1/2]

std::string SGameObject::GetID ( ) const

Definition at line 156 of file SGameObject.cpp.

156 {
157 std::string id;
158 for (const SGameObject* node = const_cast<SGameObject*>(this);; node = node->GetParent()) {
159 if (node == nullptr) break;
160
161 id = node->GetName() + (id.empty() ? "" : "/") + id;
162 }
163
164 return id;
165}

◆ GetID() [2/2]

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

Definition at line 167 of file SGameObject.cpp.

167 {
168 if (component == nullptr) return "";
169
170 const auto& object = component->GetGameObject();
171 return object->m_hash + "?" + component->GetClassType();
172}

◆ GetIsEnable()

bool SGameObject::GetIsEnable ( ) const

Definition at line 198 of file SGameObject.cpp.

198 {
199 return isEnable;
200}

◆ GetName()

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

Definition at line 90 of file SGameObject.h.

90 {
91 return m_name;
92 }

◆ GetParent()

SGameObject * SGameObject::GetParent ( ) const

Definition at line 111 of file SGameObject.cpp.

111 {
112 return m_parent;
113}

◆ GetResourceID()

std::string SGameObject::GetResourceID ( ) const

Definition at line 249 of file SGameObject.cpp.

249 {
250 return m_resourceID;
251}

◆ GetSComponentByHash()

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

Definition at line 263 of file SGameObject.cpp.

263 {
264 const auto& object = CORE->GetCore(GameObjectMgr)->FindByHash(ConvertSpaceStr(hash, true));
265 if (object == nullptr) return nullptr;
266
267 std::string componentName = split(hash, '?')[1];
268
269 for (const auto& component: object->m_components) {
270 if (componentName == component->GetClassType()) {
271 return component;
272 }
273 }
274 return nullptr;
275}

◆ GetStatus()

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

Definition at line 106 of file SGameObject.h.

106 {
107 return m_status;
108 }

◆ GetTransform()

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

Definition at line 102 of file SGameObject.h.

102 {
103 return m_transform;
104 }

◆ 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 239 of file SGameObject.cpp.

239 {
240 if (m_isPrefab || m_parent == nullptr || OnlyThisObject) return m_isPrefab;
241
242 return m_parent->isPrefab();
243}

◆ RemoveChild()

void SGameObject::RemoveChild ( SGameObject object)

Definition at line 105 of file SGameObject.cpp.

105 {
106 if (object == nullptr) return;
107 m_children.remove(object);
108 object->m_parent = nullptr;
109}

◆ RemoveChildren()

void SGameObject::RemoveChildren ( bool  isAllLevel = false)

Definition at line 98 of file SGameObject.cpp.

98 {
99 for (const auto& child: m_children) {
100 child->RemoveChildren(isAllLevel);
101 }
102 m_children.clear();
103}

◆ RemoveParent()

void SGameObject::RemoveParent ( )

Definition at line 119 of file SGameObject.cpp.

119 {
120 if (m_parent == nullptr) return;
121 m_parent->RemoveChild(this);
122}

◆ SetIsEnable()

void SGameObject::SetIsEnable ( bool  is_enable)

Definition at line 202 of file SGameObject.cpp.

202 {
203 isEnable = is_enable;
204 for (const auto& component: m_components) {
205 if (component == nullptr) continue;
206 component->SetIsEnable(is_enable);
207 }
208}

◆ SetIsPrefab()

void SGameObject::SetIsPrefab ( bool  m_isPrefab)

Definition at line 245 of file SGameObject.cpp.

245 {
246 SGameObject::m_isPrefab = m_isPrefab;
247}

◆ SetName()

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

Definition at line 98 of file SGameObject.h.

98 {
99 m_name = std::move(name);
100 }

◆ SetParent()

void SGameObject::SetParent ( SGameObject object)

Definition at line 115 of file SGameObject.cpp.

115 {
116 object->AddChild(this);
117}

◆ SetResourceID()

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

Definition at line 253 of file SGameObject.cpp.

253 {
254 m_resourceID = resID;
255
256 if (setChildren) {
257 for (const auto& child: m_children) {
258 child->SetResourceID(resID, setChildren);
259 }
260 }
261}

◆ SetUndestroyable()

void SGameObject::SetUndestroyable ( bool  enable)
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 227 of file SGameObject.cpp.

227 {
228 SObject::SetUndestroyable(enable);
229
230 for (const auto& component: m_components) {
231 component->SetUndestroyable(enable);
232 }
233
234 for (const auto& child: m_children) {
235 child->SetUndestroyable(enable);
236 }
237}

◆ 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: