mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Allow Lua scripts to work on pause (except timers and onUpdate handlers)
This commit is contained in:
parent
3ade72a7ad
commit
32839cc727
@ -80,32 +80,28 @@ namespace MWLua
|
|||||||
|
|
||||||
void LuaManager::update(bool paused, float dt)
|
void LuaManager::update(bool paused, float dt)
|
||||||
{
|
{
|
||||||
|
if (mPlayer.isEmpty())
|
||||||
|
return; // The game is not started yet.
|
||||||
|
|
||||||
ObjectRegistry* objectRegistry = mWorldView.getObjectRegistry();
|
ObjectRegistry* objectRegistry = mWorldView.getObjectRegistry();
|
||||||
|
|
||||||
if (!mPlayer.isEmpty())
|
MWWorld::Ptr newPlayerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
|
if (!(getId(mPlayer) == getId(newPlayerPtr)))
|
||||||
|
throw std::logic_error("Player Refnum was changed unexpectedly");
|
||||||
|
if (!mPlayer.isInCell() || !newPlayerPtr.isInCell() || mPlayer.getCell() != newPlayerPtr.getCell())
|
||||||
{
|
{
|
||||||
MWWorld::Ptr newPlayerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
mPlayer = newPlayerPtr; // player was moved to another cell, update ptr in registry
|
||||||
if (!(getId(mPlayer) == getId(newPlayerPtr)))
|
objectRegistry->registerPtr(mPlayer);
|
||||||
throw std::logic_error("Player Refnum was changed unexpectedly");
|
|
||||||
if (!mPlayer.isInCell() || !newPlayerPtr.isInCell() || mPlayer.getCell() != newPlayerPtr.getCell())
|
|
||||||
{
|
|
||||||
mPlayer = newPlayerPtr; // player was moved to another cell, update ptr in registry
|
|
||||||
objectRegistry->registerPtr(mPlayer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mWorldView.update();
|
|
||||||
|
|
||||||
if (paused)
|
mWorldView.update();
|
||||||
{
|
|
||||||
mInputEvents.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GlobalEvent> globalEvents = std::move(mGlobalEvents);
|
std::vector<GlobalEvent> globalEvents = std::move(mGlobalEvents);
|
||||||
std::vector<LocalEvent> localEvents = std::move(mLocalEvents);
|
std::vector<LocalEvent> localEvents = std::move(mLocalEvents);
|
||||||
mGlobalEvents = std::vector<GlobalEvent>();
|
mGlobalEvents = std::vector<GlobalEvent>();
|
||||||
mLocalEvents = std::vector<LocalEvent>();
|
mLocalEvents = std::vector<LocalEvent>();
|
||||||
|
|
||||||
|
if (!paused)
|
||||||
{ // Update time and process timers
|
{ // Update time and process timers
|
||||||
double seconds = mWorldView.getGameTimeInSeconds() + dt;
|
double seconds = mWorldView.getGameTimeInSeconds() + dt;
|
||||||
mWorldView.setGameTimeInSeconds(seconds);
|
mWorldView.setGameTimeInSeconds(seconds);
|
||||||
@ -137,7 +133,7 @@ namespace MWLua
|
|||||||
|
|
||||||
// Engine handlers in local scripts
|
// Engine handlers in local scripts
|
||||||
PlayerScripts* playerScripts = dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts());
|
PlayerScripts* playerScripts = dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts());
|
||||||
if (playerScripts)
|
if (playerScripts && !paused)
|
||||||
{
|
{
|
||||||
for (const auto& event : mInputEvents)
|
for (const auto& event : mInputEvents)
|
||||||
playerScripts->processInputEvent(event);
|
playerScripts->processInputEvent(event);
|
||||||
@ -158,8 +154,11 @@ namespace MWLua
|
|||||||
}
|
}
|
||||||
mLocalEngineEvents.clear();
|
mLocalEngineEvents.clear();
|
||||||
|
|
||||||
for (LocalScripts* scripts : mActiveLocalScripts)
|
if (!paused)
|
||||||
scripts->update(dt);
|
{
|
||||||
|
for (LocalScripts* scripts : mActiveLocalScripts)
|
||||||
|
scripts->update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
// Engine handlers in global scripts
|
// Engine handlers in global scripts
|
||||||
if (mPlayerChanged)
|
if (mPlayerChanged)
|
||||||
@ -177,7 +176,8 @@ namespace MWLua
|
|||||||
mGlobalScripts.actorActive(GObject(id, objectRegistry));
|
mGlobalScripts.actorActive(GObject(id, objectRegistry));
|
||||||
mActorAddedEvents.clear();
|
mActorAddedEvents.clear();
|
||||||
|
|
||||||
mGlobalScripts.update(dt);
|
if (!paused)
|
||||||
|
mGlobalScripts.update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::applyQueuedChanges()
|
void LuaManager::applyQueuedChanges()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user