mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-28 19:21:04 +00:00
Run onNewGame handler in LuaManager::synchronizedUpdate
This commit is contained in:
parent
23f95cf762
commit
086fdb1f37
@ -22,8 +22,6 @@ namespace MWLua
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(const OnNewGame&) const { mGlobalScripts.newGameStarted(); }
|
||||
|
||||
void operator()(const OnActive& event) const
|
||||
{
|
||||
MWWorld::Ptr ptr = getPtr(event.mObject);
|
||||
|
@ -19,9 +19,6 @@ namespace MWLua
|
||||
{
|
||||
}
|
||||
|
||||
struct OnNewGame
|
||||
{
|
||||
};
|
||||
struct OnActive
|
||||
{
|
||||
ESM::RefNum mObject;
|
||||
@ -44,7 +41,7 @@ namespace MWLua
|
||||
{
|
||||
MWWorld::CellStore& mCell;
|
||||
};
|
||||
using Event = std::variant<OnNewGame, OnActive, OnInactive, OnConsume, OnActivate, OnNewExterior>;
|
||||
using Event = std::variant<OnActive, OnInactive, OnConsume, OnActivate, OnNewExterior>;
|
||||
|
||||
void clear() { mQueue.clear(); }
|
||||
void addToQueue(Event e) { mQueue.push_back(std::move(e)); }
|
||||
|
@ -194,6 +194,14 @@ namespace MWLua
|
||||
if (mPlayer.isEmpty())
|
||||
return; // The game is not started yet.
|
||||
|
||||
if (mNewGameStarted)
|
||||
{
|
||||
mNewGameStarted = false;
|
||||
// Run onNewGame handler in synchronizedUpdate (at the beginning of the frame), so it
|
||||
// can teleport the player to the starting location before the first frame is rendered.
|
||||
mGlobalScripts.newGameStarted();
|
||||
}
|
||||
|
||||
// We apply input events in `synchronizedUpdate` rather than in `update` in order to reduce input latency.
|
||||
mProcessingInputEvents = true;
|
||||
PlayerScripts* playerScripts = dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts());
|
||||
@ -237,6 +245,7 @@ namespace MWLua
|
||||
mWorldView.clear();
|
||||
mGlobalScripts.removeAllScripts();
|
||||
mGlobalScriptsStarted = false;
|
||||
mNewGameStarted = false;
|
||||
if (!mPlayer.isEmpty())
|
||||
{
|
||||
mPlayer.getCellRef().unsetRefNum();
|
||||
@ -273,7 +282,7 @@ namespace MWLua
|
||||
mInputEvents.clear();
|
||||
mGlobalScripts.addAutoStartedScripts();
|
||||
mGlobalScriptsStarted = true;
|
||||
mEngineEvents.addToQueue(EngineEvents::OnNewGame{});
|
||||
mNewGameStarted = true;
|
||||
}
|
||||
|
||||
void LuaManager::gameLoaded()
|
||||
|
@ -141,6 +141,7 @@ namespace MWLua
|
||||
bool mInitialized = false;
|
||||
bool mGlobalScriptsStarted = false;
|
||||
bool mProcessingInputEvents = false;
|
||||
bool mNewGameStarted = false;
|
||||
LuaUtil::ScriptsConfiguration mConfiguration;
|
||||
LuaUtil::LuaState mLua;
|
||||
LuaUi::ResourceManager mUiResourceManager;
|
||||
|
Loading…
x
Reference in New Issue
Block a user