mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-24 04:11:50 -04:00
Turn menu.saveGame into a delayed action
This commit is contained in:
parent
fbb726cee0
commit
32f54eb555
@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
|
|||||||
set(OPENMW_VERSION_MAJOR 0)
|
set(OPENMW_VERSION_MAJOR 0)
|
||||||
set(OPENMW_VERSION_MINOR 50)
|
set(OPENMW_VERSION_MINOR 50)
|
||||||
set(OPENMW_VERSION_RELEASE 0)
|
set(OPENMW_VERSION_RELEASE 0)
|
||||||
set(OPENMW_LUA_API_REVISION 95)
|
set(OPENMW_LUA_API_REVISION 96)
|
||||||
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
||||||
|
|
||||||
set(OPENMW_VERSION_COMMITHASH "")
|
set(OPENMW_VERSION_COMMITHASH "")
|
||||||
|
@ -316,6 +316,8 @@ namespace MWLua
|
|||||||
|
|
||||||
void LuaManager::applyDelayedActions()
|
void LuaManager::applyDelayedActions()
|
||||||
{
|
{
|
||||||
|
if (mApplyingDelayedActions)
|
||||||
|
return;
|
||||||
mApplyingDelayedActions = true;
|
mApplyingDelayedActions = true;
|
||||||
for (DelayedAction& action : mActionQueue)
|
for (DelayedAction& action : mActionQueue)
|
||||||
action.apply();
|
action.apply();
|
||||||
@ -324,6 +326,9 @@ namespace MWLua
|
|||||||
if (mTeleportPlayerAction)
|
if (mTeleportPlayerAction)
|
||||||
mTeleportPlayerAction->apply();
|
mTeleportPlayerAction->apply();
|
||||||
mTeleportPlayerAction.reset();
|
mTeleportPlayerAction.reset();
|
||||||
|
for (DelayedAction& action : mSaveActionQueue)
|
||||||
|
action.apply();
|
||||||
|
mSaveActionQueue.clear();
|
||||||
mApplyingDelayedActions = false;
|
mApplyingDelayedActions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,6 +829,11 @@ namespace MWLua
|
|||||||
mTeleportPlayerAction = DelayedAction(&mLua, std::move(action), "TeleportPlayer");
|
mTeleportPlayerAction = DelayedAction(&mLua, std::move(action), "TeleportPlayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaManager::addSaveGameAction(std::function<void()> action)
|
||||||
|
{
|
||||||
|
mSaveActionQueue.emplace_back(&mLua, std::move(action), "SaveGame");
|
||||||
|
}
|
||||||
|
|
||||||
void LuaManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const
|
void LuaManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const
|
||||||
{
|
{
|
||||||
stats.setAttribute(frameNumber, "Lua UsedMemory", mLua.getTotalMemoryUsage());
|
stats.setAttribute(frameNumber, "Lua UsedMemory", mLua.getTotalMemoryUsage());
|
||||||
|
@ -125,8 +125,9 @@ namespace MWLua
|
|||||||
|
|
||||||
// Some changes to the game world can not be done from the scripting thread (because it runs in parallel with
|
// Some changes to the game world can not be done from the scripting thread (because it runs in parallel with
|
||||||
// OSG Cull), so we need to queue it and apply from the main thread.
|
// OSG Cull), so we need to queue it and apply from the main thread.
|
||||||
void addAction(std::function<void()> action, std::string_view name = "");
|
void addAction(std::function<void()> action, std::string_view name = {});
|
||||||
void addTeleportPlayerAction(std::function<void()> action);
|
void addTeleportPlayerAction(std::function<void()> action);
|
||||||
|
void addSaveGameAction(std::function<void()> action);
|
||||||
|
|
||||||
// Saving
|
// Saving
|
||||||
void write(ESM::ESMWriter& writer, Loading::Listener& progress) override;
|
void write(ESM::ESMWriter& writer, Loading::Listener& progress) override;
|
||||||
@ -234,6 +235,7 @@ namespace MWLua
|
|||||||
};
|
};
|
||||||
std::vector<DelayedAction> mActionQueue;
|
std::vector<DelayedAction> mActionQueue;
|
||||||
std::optional<DelayedAction> mTeleportPlayerAction;
|
std::optional<DelayedAction> mTeleportPlayerAction;
|
||||||
|
std::vector<DelayedAction> mSaveActionQueue;
|
||||||
std::vector<std::pair<std::string, MWGui::ShowInDialogueMode>> mUIMessages;
|
std::vector<std::pair<std::string, MWGui::ShowInDialogueMode>> mUIMessages;
|
||||||
std::vector<std::pair<std::string, Misc::Color>> mInGameConsoleMessages;
|
std::vector<std::pair<std::string, Misc::Color>> mInGameConsoleMessages;
|
||||||
std::optional<ObjectId> mDelayedUiModeChangedArg;
|
std::optional<ObjectId> mDelayedUiModeChangedArg;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "../mwstate/character.hpp"
|
#include "../mwstate/character.hpp"
|
||||||
|
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
#include "luamanagerimp.hpp"
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
@ -72,13 +73,16 @@ namespace MWLua
|
|||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
};
|
};
|
||||||
|
|
||||||
api["saveGame"] = [](std::string_view description, sol::optional<std::string_view> slotName) {
|
api["saveGame"] = [context](std::string description, sol::optional<std::string> slotName) {
|
||||||
|
context.mLuaManager->addSaveGameAction(
|
||||||
|
[description = std::move(description), slotName = std::move(slotName)]() {
|
||||||
MWBase::StateManager* manager = MWBase::Environment::get().getStateManager();
|
MWBase::StateManager* manager = MWBase::Environment::get().getStateManager();
|
||||||
const MWState::Character* character = manager->getCurrentCharacter();
|
const MWState::Character* character = manager->getCurrentCharacter();
|
||||||
const MWState::Slot* slot = nullptr;
|
const MWState::Slot* slot = nullptr;
|
||||||
if (slotName)
|
if (slotName)
|
||||||
slot = findSlot(character, *slotName);
|
slot = findSlot(character, *slotName);
|
||||||
manager->saveGame(description, slot);
|
manager->saveGame(description, slot);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
auto getSaves = [](sol::state_view currentState, const MWState::Character& character) {
|
auto getSaves = [](sol::state_view currentState, const MWState::Character& character) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user