65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
|
|
#include "Scene/SceneRuntime.h"
|
||
|
|
|
||
|
|
#include "Scripting/ScriptEngine.h"
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace Components {
|
||
|
|
|
||
|
|
void SceneRuntime::Start(Scene* scene) {
|
||
|
|
if (m_running && m_scene == scene) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Stop();
|
||
|
|
|
||
|
|
if (!scene) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_scene = scene;
|
||
|
|
m_running = true;
|
||
|
|
Scripting::ScriptEngine::Get().OnRuntimeStart(scene);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SceneRuntime::Stop() {
|
||
|
|
if (!m_running) {
|
||
|
|
m_scene = nullptr;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Scripting::ScriptEngine::Get().OnRuntimeStop();
|
||
|
|
m_running = false;
|
||
|
|
m_scene = nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
void SceneRuntime::FixedUpdate(float fixedDeltaTime) {
|
||
|
|
if (!m_running || !m_scene || !m_scene->IsActive()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Scripts run first so their state changes are visible to native components in the same frame.
|
||
|
|
Scripting::ScriptEngine::Get().OnFixedUpdate(fixedDeltaTime);
|
||
|
|
m_scene->FixedUpdate(fixedDeltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SceneRuntime::Update(float deltaTime) {
|
||
|
|
if (!m_running || !m_scene || !m_scene->IsActive()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Scripting::ScriptEngine::Get().OnUpdate(deltaTime);
|
||
|
|
m_scene->Update(deltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SceneRuntime::LateUpdate(float deltaTime) {
|
||
|
|
if (!m_running || !m_scene || !m_scene->IsActive()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Scripting::ScriptEngine::Get().OnLateUpdate(deltaTime);
|
||
|
|
m_scene->LateUpdate(deltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace Components
|
||
|
|
} // namespace XCEngine
|