2#include "GameObjectMgr.h"
9GameObjectMgr::GameObjectMgr() =
default;
12GameObjectMgr::~GameObjectMgr() =
default;
15void GameObjectMgr::Init() {
17 for (
const auto& pair : m_objects) {
18 const auto&
object = pair.second;
19 if (
object ==
nullptr)
continue;
26void GameObjectMgr::Update(
float elapsedTime) {
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);
37void GameObjectMgr::DestroyQueuedObject() {
38 if (m_destroyObjectsQueue.empty())
return;
40 for (; !m_destroyObjectsQueue.empty(); m_destroyObjectsQueue.pop()) {
41 const auto&
object = m_destroyObjectsQueue.front();
44 CORE->GetCore(
MemoryMgr)->ReleaseObject(
object);
48void GameObjectMgr::AddDestroyObject(
SGameObject*
object) {
49 if(object->GetStatus() != SGameObject::DESTROY)
return;
50 m_destroyObjectsQueue.push(
object);
53SGameObject* GameObjectMgr::Find(
const std::string& name)
const {
54 for (
const auto& pair : m_objects) {
55 const auto&
object = pair.second;
56 if (object->GetName() == name)
64SGameObject* GameObjectMgr::FindByID(
const std::string&
id)
const {
65 std::string obj_id = split(
id,
'?')[0];
67 for (
const auto& pair : m_objects) {
68 const auto&
object = pair.second;
69 if (object->isPrefab())
continue;
70 auto id_ =
object->GetID();
78SGameObject* GameObjectMgr::FindByHash(
const std::string& hash)
const {
79 std::string obj_hash = split(hash,
'?')[0];
83SComponent* GameObjectMgr::FindComponentByID(
const std::string&
id)
const {
84 auto object = FindByID(
id);
85 if (
object ==
nullptr)
return nullptr;
87 auto components =
object->GetComponents();
88 auto split_str = split(
id,
'?');
90 for (
auto component : components) {
91 if (split_str[1] == component->GetClassType()) {
98SComponent* GameObjectMgr::FindComponentByHash(
const std::string& hash)
const {
99 auto object = FindByHash(hash);
100 if (
object ==
nullptr)
return nullptr;
102 auto components =
object->GetComponents();
103 auto split_str = split(hash,
'?');
105 for (
auto component : components) {
106 if (split_str[1] == component->GetClassType()) {