From 4442cd2f213d39776f58e7cd0ba2263fe82d23e9 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Wed, 26 Apr 2017 07:30:57 +0200 Subject: [PATCH] updated order of execution implementation --- Documentation/ScriptingAPI-Documentation.md | 1 + WickedEngine/MainComponent.cpp | 18 ++++++++++-------- WickedEngine/wiLua.cpp | 4 ++++ WickedEngine/wiLua.h | 2 ++ WickedEngine/wiLua_Globals.h | 5 +++++ WickedEngine/wiVersion.cpp | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index e965c51ca..7a3c6d00d 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -68,6 +68,7 @@ This section describes the common tools for scripting which are not necessarily - getprops(table object) - len(table object) - backlog_post_list(table list) +- fixedupdate() - update() - render() - math.lerp(float a,b,t) diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index b3999de34..2bb5c6659 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -88,13 +88,6 @@ void MainComponent::run() const double elapsedTime = max(0, timer.elapsed() / 1000.0); timer.record(); - wiLua::GetGlobal()->SetDeltaTime(elapsedTime); - - // Variable-timed update: - wiProfiler::GetInstance().BeginRange("Update", wiProfiler::DOMAIN_CPU); - Update((float)elapsedTime); - wiProfiler::GetInstance().EndRange(); // Update - // Fixed time update: wiProfiler::GetInstance().BeginRange("Fixed Update", wiProfiler::DOMAIN_CPU); @@ -120,6 +113,13 @@ void MainComponent::run() } wiProfiler::GetInstance().EndRange(); // Fixed Update + wiLua::GetGlobal()->SetDeltaTime(elapsedTime); + + // Variable-timed update: + wiProfiler::GetInstance().BeginRange("Update", wiProfiler::DOMAIN_CPU); + Update((float)elapsedTime); + wiProfiler::GetInstance().EndRange(); // Update + wiProfiler::GetInstance().BeginRange("Render", wiProfiler::DOMAIN_CPU); Render(); wiProfiler::GetInstance().EndRange(); // Render @@ -141,12 +141,14 @@ void MainComponent::Update(float dt) { wiCpuInfo::Frame(); getActiveComponent()->Update(dt); + + wiLua::GetGlobal()->Update(); } void MainComponent::FixedUpdate() { wiBackLog::Update(); - wiLua::GetGlobal()->Update(); + wiLua::GetGlobal()->FixedUpdate(); getActiveComponent()->FixedUpdate(); diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 65912fb03..f8ef6a676 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -244,6 +244,10 @@ void wiLua::SetDeltaTime(double dt) lua_call(m_luaState, 1, 0); UNLOCK(); } +void wiLua::FixedUpdate() +{ + TrySignal("wickedengine_fixed_update_tick"); +} void wiLua::Update() { TrySignal("wickedengine_update_tick"); diff --git a/WickedEngine/wiLua.h b/WickedEngine/wiLua.h index c15755b82..60d36b982 100644 --- a/WickedEngine/wiLua.h +++ b/WickedEngine/wiLua.h @@ -60,6 +60,8 @@ public: //set delta time to use with lua void SetDeltaTime(double dt); + //update lua scripts which are waiting for a fixed game tick + void FixedUpdate(); //update lua scripts which are waiting for a game tick void Update(); //issue lua drawing commands which are waiting for a render tick diff --git a/WickedEngine/wiLua_Globals.h b/WickedEngine/wiLua_Globals.h index 44338d885..2e8c77fad 100644 --- a/WickedEngine/wiLua_Globals.h +++ b/WickedEngine/wiLua_Globals.h @@ -135,6 +135,11 @@ function signal(signalName) end end +-- Wait until the game engine fixed update function runs again +function fixedupdate() + waitSignal("wickedengine_fixed_update_tick") +end + -- Wait until the game engine update function runs again function update() waitSignal("wickedengine_update_tick") diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 9f791928c..83368bf12 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // minor features, major updates const int minor = 11; // minor bug fixes, alterations, refactors, updates - const int revision = 34; + const int revision = 35; long GetVersion()