CSEngine
Loading...
Searching...
No Matches
SScene.cpp
1//
2// Created by ounols on 19. 2. 14.
3//
4
5#include "SScene.h"
6#include "../Manager/GameObjectMgr.h"
7#include "../Manager/MemoryMgr.h"
8
9using namespace CSE;
10
11SScene::SScene() {
12 m_root = new SGameObject("__ROOT_OF_SCENE__");
13}
14
15SScene::~SScene() = default;
16
17void SScene::Init() {
18 InitGameObject(m_root);
19}
20
21void SScene::Tick(float elapsedTime) {
22 TickGameObject(m_root, elapsedTime);
23}
24
25void SScene::Destroy() {
26 DestroyGameObjects(m_root);
27}
28
29void SScene::InitGameObject(SGameObject* obj) {
30 obj->Init();
31 const auto& children = obj->GetChildren();
32 for (const auto& child : children) {
33 InitGameObject(child);
34 }
35}
36
37void SScene::TickGameObject(SGameObject* obj, float elapsedTime) {
38 obj->Tick(elapsedTime);
39 const auto& children = obj->GetChildren();
40 for (const auto& child : children) {
41 TickGameObject(child, elapsedTime);
42 }
43}
44
45void SScene::DestroyGameObjects(SGameObject* obj) {
46 const auto& children = obj->GetChildren();
47 for (const auto& child : children) {
48 DestroyGameObjects(child);
49 }
50
51 CORE->GetCore(MemoryMgr)->ReleaseObject(obj);
52}