mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-23 03:47:34 -04:00
Reuse BoolScopeGuard
This commit is contained in:
parent
51a4f8749e
commit
f73f4ae415
@ -44,16 +44,16 @@ namespace MWLua
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct AllowSaving
|
||||
struct BoolScopeGuard
|
||||
{
|
||||
bool& mAllowSaving;
|
||||
AllowSaving(bool& allowSaving)
|
||||
: mAllowSaving(allowSaving)
|
||||
bool& mValue;
|
||||
BoolScopeGuard(bool& value)
|
||||
: mValue(value)
|
||||
{
|
||||
mAllowSaving = true;
|
||||
mValue = true;
|
||||
}
|
||||
|
||||
~AllowSaving() { mAllowSaving = false; }
|
||||
~BoolScopeGuard() { mValue = false; }
|
||||
};
|
||||
}
|
||||
|
||||
@ -278,32 +278,33 @@ namespace MWLua
|
||||
// can teleport the player to the starting location before the first frame is rendered.
|
||||
mGlobalScripts.newGameStarted();
|
||||
}
|
||||
AllowSaving savingGuard(mAllowSaving);
|
||||
BoolScopeGuard updateGuard(mRunningSynchronizedUpdates);
|
||||
|
||||
// We apply input events in `synchronizedUpdate` rather than in `update` in order to reduce input latency.
|
||||
mProcessingInputEvents = true;
|
||||
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
|
||||
PlayerScripts* playerScripts
|
||||
= mPlayer.isEmpty() ? nullptr : dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts());
|
||||
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
|
||||
|
||||
for (const auto& event : mMenuInputEvents)
|
||||
mMenuScripts.processInputEvent(event);
|
||||
mMenuInputEvents.clear();
|
||||
if (playerScripts && !windowManager->containsMode(MWGui::GM_MainMenu))
|
||||
// We apply input events in `synchronizedUpdate` rather than in `update` in order to reduce input latency.
|
||||
{
|
||||
for (const auto& event : mInputEvents)
|
||||
playerScripts->processInputEvent(event);
|
||||
BoolScopeGuard processingGuard(mProcessingInputEvents);
|
||||
|
||||
for (const auto& event : mMenuInputEvents)
|
||||
mMenuScripts.processInputEvent(event);
|
||||
mMenuInputEvents.clear();
|
||||
if (playerScripts && !windowManager->containsMode(MWGui::GM_MainMenu))
|
||||
{
|
||||
for (const auto& event : mInputEvents)
|
||||
playerScripts->processInputEvent(event);
|
||||
}
|
||||
mInputEvents.clear();
|
||||
mLuaEvents.callMenuEventHandlers();
|
||||
double frameDuration = MWBase::Environment::get().getWorld()->getTimeManager()->isPaused()
|
||||
? 0.0
|
||||
: MWBase::Environment::get().getFrameDuration();
|
||||
mInputActions.update(frameDuration);
|
||||
mMenuScripts.onFrame(frameDuration);
|
||||
if (playerScripts)
|
||||
playerScripts->onFrame(frameDuration);
|
||||
}
|
||||
mInputEvents.clear();
|
||||
mLuaEvents.callMenuEventHandlers();
|
||||
double frameDuration = MWBase::Environment::get().getWorld()->getTimeManager()->isPaused()
|
||||
? 0.0
|
||||
: MWBase::Environment::get().getFrameDuration();
|
||||
mInputActions.update(frameDuration);
|
||||
mMenuScripts.onFrame(frameDuration);
|
||||
if (playerScripts)
|
||||
playerScripts->onFrame(frameDuration);
|
||||
mProcessingInputEvents = false;
|
||||
|
||||
for (const auto& [message, mode] : mUIMessages)
|
||||
windowManager->messageBox(message, mode);
|
||||
@ -331,7 +332,7 @@ namespace MWLua
|
||||
|
||||
void LuaManager::applyDelayedActions()
|
||||
{
|
||||
mApplyingDelayedActions = true;
|
||||
BoolScopeGuard applyingGuard(mApplyingDelayedActions);
|
||||
for (DelayedAction& action : mActionQueue)
|
||||
action.apply();
|
||||
mActionQueue.clear();
|
||||
@ -339,7 +340,6 @@ namespace MWLua
|
||||
if (mTeleportPlayerAction)
|
||||
mTeleportPlayerAction->apply();
|
||||
mTeleportPlayerAction.reset();
|
||||
mApplyingDelayedActions = false;
|
||||
}
|
||||
|
||||
void LuaManager::clear()
|
||||
|
@ -174,7 +174,7 @@ namespace MWLua
|
||||
void sendLocalEvent(
|
||||
const MWWorld::Ptr& target, const std::string& name, const std::optional<sol::table>& data = std::nullopt);
|
||||
|
||||
bool isSynchronizedUpdateRunning() const { return mAllowSaving; }
|
||||
bool isSynchronizedUpdateRunning() const { return mRunningSynchronizedUpdates; }
|
||||
|
||||
private:
|
||||
void initConfiguration();
|
||||
@ -189,7 +189,7 @@ namespace MWLua
|
||||
bool mApplyingDelayedActions = false;
|
||||
bool mNewGameStarted = false;
|
||||
bool mReloadAllScriptsRequested = false;
|
||||
bool mAllowSaving = false;
|
||||
bool mRunningSynchronizedUpdates = false;
|
||||
LuaUtil::ScriptsConfiguration mConfiguration;
|
||||
LuaUtil::LuaState mLua;
|
||||
LuaUi::ResourceManager mUiResourceManager;
|
||||
|
Loading…
x
Reference in New Issue
Block a user