Make OnControlPhase take a float, representing the delta time.

This is not ACTUALLY the amount of time that has passed, since things in the gameplay loop appear to assume they are being called thirty times per second, even if more or less time has passed. Thus to keep the scripts in sync with the the rest of the engine, we force a 1/30 second delta time.
This commit is contained in:
hispidence 2021-08-12 18:20:14 +01:00
parent 196646297b
commit 582b000fb9
3 changed files with 10 additions and 7 deletions

View file

@ -650,8 +650,9 @@ void GameScript::ExecuteFunction(std::string const & name)
}
}
static void doCallback(sol::protected_function const & func) {
auto r = func();
static void doCallback(sol::protected_function const & func, std::optional<float> dt = std::nullopt) {
auto r = dt.has_value() ? func(dt) : func();
if (!r.valid())
{
sol::error err = r;
@ -671,10 +672,10 @@ void GameScript::OnLoad()
doCallback(m_onLoad);
}
void GameScript::OnControlPhase()
void GameScript::OnControlPhase(float dt)
{
if(m_onControlPhase.valid())
doCallback(m_onControlPhase);
doCallback(m_onControlPhase, dt);
}
void GameScript::OnSave()