CSEngine
Loading...
Searching...
No Matches
EngineCore.cpp
1//
2// Created by ounol on 2021-03-22.
3//
4
5#include "EngineCore.h"
6#include "ResMgr.h"
7#include "GameObjectMgr.h"
8#include "OGLMgr.h"
9#include "ScriptMgr.h"
10#include "CameraMgr.h"
11#include "LightMgr.h"
12#include "Render/RenderMgr.h"
13#include "SceneMgr.h"
14#include "MemoryMgr.h"
15#include "../Sample/FirstDemoScene.h"
16#include "../Sample/WebDemoScene.h"
17#include "../Util/Loader/SCENE/SSceneLoader.h"
18#include "../Util/AssetsDef.h"
19
20#ifdef __EMSCRIPTEN__
21#include "../Sample/WebDemoScene.h"
22#endif
23
24using namespace CSE;
25IMPLEMENT_SINGLETON(EngineCore);
26
27constexpr short ENGINE_COUNT = 9;
28
29EngineCore::EngineCore() {
30}
31
32EngineCore::~EngineCore() {
33
34}
35
36void EngineCore::Init(unsigned int width, unsigned int height) {
37 GenerateCores();
38
39 for (const auto& core : m_cores) {
40 core->Init();
41 }
42
43 m_oglMgr->ResizeWindow(width, height);
44 static_cast<RenderMgr*>(m_renderMgr)->SetViewport();
45
46
47#ifdef __EMSCRIPTEN__
48 static_cast<SceneMgr*>(m_sceneMgr)->SetScene(new WebDemoScene());
49#else
50 static_cast<SceneMgr*>(m_sceneMgr)->SetScene(new FirstDemoScene());
51// SScene* scene = SSceneLoader::LoadScene(CSE::AssetsPath() + "Scene/animation.scene");
52// m_sceneMgr->SetScene(scene);
53#endif
54}
55
56void EngineCore::Update(float elapsedTime) {
57 for (const auto& core : m_updateCores) {
58 core->Update(elapsedTime);
59 }
60}
61
62void EngineCore::LateUpdate(float elapsedTime) {
63 m_gameObjectMgr->DestroyQueuedObject();
64}
65
66void EngineCore::Render() const {
67 for (const auto& core : m_renderCores) {
68 core->Render();
69 }
70}
71
72void EngineCore::Exterminate() {
73 static_cast<MemoryMgr*>(m_memoryMgr)->ExterminateObjects(true);
74 for (auto core : m_cores) {
75 SAFE_DELETE(core);
76 }
77 m_cores.clear();
78}
79
80void EngineCore::GenerateCores() {
81 if(m_isGenerated) return;
82 m_isGenerated = true;
83 m_cores = std::vector<CoreBase*>();
84 m_cores.reserve(ENGINE_COUNT);
85
86 m_resMgr = new ResMgr();
87 m_gameObjectMgr = new GameObjectMgr();
88 m_oglMgr = new OGLMgr();
89 m_renderMgr = new RenderMgr();
90 m_cameraMgr = new CameraMgr();
91 m_lightMgr = new LightMgr();
92 m_sceneMgr = new SceneMgr();
93 m_memoryMgr = new MemoryMgr();
94 m_scriptMgr = new ScriptMgr();
95
96 m_cores.push_back(m_resMgr);
97 m_cores.push_back(m_gameObjectMgr);
98 m_updateCores.push_back(m_gameObjectMgr);
99
100 m_cores.push_back(m_oglMgr);
101 m_renderCores.push_back(m_oglMgr);
102 m_cores.push_back(m_renderMgr);
103 m_renderCores.push_back(dynamic_cast<RenderCoreBase* const>(m_renderMgr));
104 m_cores.push_back(m_cameraMgr);
105 m_cores.push_back(m_lightMgr);
106
107 m_cores.push_back(m_sceneMgr);
108 m_updateCores.push_back(m_sceneMgr);
109 m_cores.push_back(m_memoryMgr);
110
111 m_cores.push_back(m_scriptMgr);
112}
113
114void EngineCore::ResizeWindow(unsigned int width, unsigned int height) {
115 m_oglMgr->ResizeWindow(width, height);
116 static_cast<RenderMgr*>(m_renderMgr)->SetViewport();
117}
118
Class for managing rendering operations.
Definition RenderMgr.h:21