CSEngine
Loading...
Searching...
No Matches
CSE::GameObjectMgr Class Reference
Inheritance diagram for CSE::GameObjectMgr:
CSE::GameObjectContainer CSE::CoreBase CSE::SContainerHash< SGameObject * > CSE::SIContainer< S, T, M >

Public Member Functions

void Init () override
 
void Update (float elapsedTime) override
 
void DestroyQueuedObject ()
 
void AddDestroyObject (SGameObject *object)
 
SGameObjectFind (const std::string &name) const
 
SGameObjectFindByID (const std::string &id) const
 
SGameObjectFindByHash (const std::string &hash) const
 
SComponentFindComponentByID (const std::string &id) const
 
SComponentFindComponentByHash (const std::string &hash) const
 
- Public Member Functions inherited from CSE::SContainerHash< SGameObject * >
void Register (SGameObject * object) override
 
void Remove (SGameObject * object) override
 
bool HasHash (const std::string &hash) const
 
SGameObjectGet (std::string index) const override
 
std::unordered_map< std::string, SGameObject * > GetAll () const override
 
std::string GetID (SGameObject * object) const override
 
int GetSize () const override
 
void ChangeHash (const std::string &srcHash, const std::string &dstHash)
 
- Public Member Functions inherited from CSE::SIContainer< S, T, M >
virtual void Register (T object)=0
 
virtual void Remove (T object)=0
 
virtual T Get (M index) const =0
 
virtual M GetID (T object) const =0
 

Additional Inherited Members

- Protected Attributes inherited from CSE::SContainerHash< SGameObject * >
std::unordered_map< std::string, SGameObject * > m_objects
 
int m_size
 

Detailed Description

Definition at line 12 of file GameObjectMgr.h.

Member Function Documentation

◆ AddDestroyObject()

void GameObjectMgr::AddDestroyObject ( SGameObject object)

Definition at line 48 of file GameObjectMgr.cpp.

48 {
49 if(object->GetStatus() != SGameObject::DESTROY) return;
50 m_destroyObjectsQueue.push(object);
51}

◆ DestroyQueuedObject()

void GameObjectMgr::DestroyQueuedObject ( )

Definition at line 37 of file GameObjectMgr.cpp.

37 {
38 if (m_destroyObjectsQueue.empty()) return;
39
40 for (; !m_destroyObjectsQueue.empty(); m_destroyObjectsQueue.pop()) {
41 const auto& object = m_destroyObjectsQueue.front();
42
44 CORE->GetCore(MemoryMgr)->ReleaseObject(object);
45 }
46}

◆ Find()

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

Definition at line 53 of file GameObjectMgr.cpp.

53 {
54 for (const auto& pair : m_objects) {
55 const auto& object = pair.second;
56 if (object->GetName() == name)
57 return object;
58 }
59
60 return nullptr;
61
62}

◆ FindByHash()

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

Definition at line 78 of file GameObjectMgr.cpp.

78 {
79 std::string obj_hash = split(hash, '?')[0];
80 return SContainerHash<SGameObject*>::Get(obj_hash);
81}

◆ FindByID()

SGameObject * GameObjectMgr::FindByID ( const std::string &  id) const

Definition at line 64 of file GameObjectMgr.cpp.

64 {
65 std::string obj_id = split(id, '?')[0];
66
67 for (const auto& pair : m_objects) {
68 const auto& object = pair.second;
69 if (object->isPrefab()) continue;
70 auto id_ = object->GetID();
71 if (id_ == obj_id)
72 return object;
73 }
74
75 return nullptr;
76}

◆ FindComponentByHash()

SComponent * GameObjectMgr::FindComponentByHash ( const std::string &  hash) const

Definition at line 98 of file GameObjectMgr.cpp.

98 {
99 auto object = FindByHash(hash);
100 if (object == nullptr) return nullptr;
101
102 auto components = object->GetComponents();
103 auto split_str = split(hash, '?');
104
105 for (auto component : components) {
106 if (split_str[1] == component->GetClassType()) {
107 return component;
108 }
109 }
110 return nullptr;
111}

◆ FindComponentByID()

SComponent * GameObjectMgr::FindComponentByID ( const std::string &  id) const

Definition at line 83 of file GameObjectMgr.cpp.

83 {
84 auto object = FindByID(id);
85 if (object == nullptr) return nullptr;
86
87 auto components = object->GetComponents();
88 auto split_str = split(id, '?');
89
90 for (auto component : components) {
91 if (split_str[1] == component->GetClassType()) {
92 return component;
93 }
94 }
95 return nullptr;
96}

◆ Init()

void GameObjectMgr::Init ( )
overridevirtual

Implements CSE::CoreBase.

Definition at line 15 of file GameObjectMgr.cpp.

15 {
16
17 for (const auto& pair : m_objects) {
18 const auto& object = pair.second;
19 if (object == nullptr) continue;
20 object->Init();
21 }
22
23}

◆ Update()

void GameObjectMgr::Update ( float  elapsedTime)
overridevirtual

Reimplemented from CSE::CoreBase.

Definition at line 26 of file GameObjectMgr.cpp.

26 {
27 auto iterator = m_objects.begin();
28 while (iterator != m_objects.end()) {
29 const auto& object = iterator->second;
30 if (object == nullptr) continue;
31 object->Tick(elapsedTime);
32 ++iterator;
33 }
34}

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