-
Notifications
You must be signed in to change notification settings - Fork 4
/
Scene.cpp
121 lines (94 loc) · 2.63 KB
/
Scene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "Scene.h"
#include <memory>
#include <memory>
namespace yougine
{
Scene::Scene(std::string name)
{
LayerManager::Create();
this->name = name;
component_list = new managers::ComponentList();
this->user_script_component_entry_point_manager = std::make_shared<managers::UserScriptComponentEntryPointManager>();
this->input_manager = std::make_shared<InputManager>();
}
GameObject* Scene::CreateGameObject(std::string name, GameObject* parent)
{
GameObject* gameobject = new GameObject(this, name, parent);
if (parent == nullptr)
{
gameobject_list.push_back(gameobject);
}
else
{
parent->AddChild(gameobject);
}
return gameobject;
}
//処理変える
void Scene::RemoveGameObject(GameObject* gameobject)
{
std::list<GameObject*> new_list;
for (GameObject* obj : gameobject_list)
{
if (gameobject == obj)
{
new_list.push_back(obj);
}
}
gameobject_list = new_list;
}
managers::ComponentList* Scene::GetComponentList()
{
return component_list;
}
std::string Scene::GetName()
{
return name;
}
void Scene::SetName(std::string name)
{
this->name = name;
}
std::list<GameObject*> Scene::GetGameObjects()
{
return gameobject_list;
}
GameObject* Scene::GetGameObjectByName(std::string name)
{
if (name.empty()) return nullptr;
GameObject* r_obj = nullptr;
for (GameObject* game_object : gameobject_list)
{
r_obj = RecursiveGameObjects({ game_object }, name);
}
return r_obj;
}
void Scene::InitializeAllGameObjcts()
{
for (auto gameobject : this->gameobject_list)
{
gameobject->InitializeComponents();
}
}
void Scene::RegisterOnlyUpdate(components::userscriptcomponents::IUpdatable* i_updatable)
{
this->user_script_component_entry_point_manager->SetUpdate(i_updatable);
}
void Scene::Update()
{
this->input_manager->UpdateInput();
this->user_script_component_entry_point_manager->Update();
}
GameObject* Scene::RecursiveGameObjects(std::list<GameObject*> game_objects, std::string name)
{
for (GameObject* obj : game_objects)
{
if (obj->GetName() == name)
{
return obj;
}
RecursiveGameObjects(obj->GetChildObjects(), name);
}
return nullptr;
}
}