From 31eb3e6f5dc4b4dc726570854640189270a29454 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Tue, 25 Apr 2023 23:35:51 +0200 Subject: [PATCH] Use typed settings storage for Lua settings --- apps/openmw/mwlua/engineevents.cpp | 5 ++--- apps/openmw/mwlua/luamanagerimp.cpp | 22 ++++++++++------------ apps/openmw/mwlua/worker.cpp | 4 ++-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwlua/engineevents.cpp b/apps/openmw/mwlua/engineevents.cpp index 2aafde2264..0c5abe6cef 100644 --- a/apps/openmw/mwlua/engineevents.cpp +++ b/apps/openmw/mwlua/engineevents.cpp @@ -1,7 +1,7 @@ #include "engineevents.hpp" #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwworld/class.hpp" @@ -75,7 +75,7 @@ namespace MWLua MWWorld::Ptr getPtr(const ESM::RefNum& id) const { MWWorld::Ptr res = mWorldModel->getPtr(id); - if (res.isEmpty() && mLuaDebug) + if (res.isEmpty() && Settings::lua().mLuaDebug) Log(Debug::Verbose) << "Can not find object" << id.toString() << " when calling engine hanglers"; return res; } @@ -91,7 +91,6 @@ namespace MWLua LocalScripts* getLocalScripts(const ESM::RefNum& id) const { return getLocalScripts(getPtr(id)); } GlobalScripts& mGlobalScripts; - bool mLuaDebug = Settings::Manager::getBool("lua debug", "Lua"); MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel(); }; diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 40e3f0f60a..0447a24260 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include @@ -38,12 +38,12 @@ namespace MWLua static LuaUtil::LuaStateSettings createLuaStateSettings() { - if (!Settings::Manager::getBool("lua profiler", "Lua")) + if (!Settings::lua().mLuaProfiler) LuaUtil::LuaState::disableProfiler(); - return { .mInstructionLimit = Settings::Manager::getUInt64("instruction limit per call", "Lua"), - .mMemoryLimit = Settings::Manager::getUInt64("memory limit", "Lua"), - .mSmallAllocMaxSize = Settings::Manager::getUInt64("small alloc max size", "Lua"), - .mLogMemoryUsage = Settings::Manager::getBool("log memory usage", "Lua") }; + return { .mInstructionLimit = Settings::lua().mInstructionLimitPerCall, + .mMemoryLimit = Settings::lua().mMemoryLimit, + .mSmallAllocMaxSize = Settings::lua().mSmallAllocMaxSize, + .mLogMemoryUsage = Settings::lua().mLogMemoryUsage }; } LuaManager::LuaManager(const VFS::Manager* vfs, const std::filesystem::path& libsDir) @@ -122,9 +122,8 @@ namespace MWLua void LuaManager::update() { - static const int gcStepCount = Settings::Manager::getInt("gc steps per frame", "Lua"); - if (gcStepCount > 0) - lua_gc(mLua.sol(), LUA_GCSTEP, gcStepCount); + if (Settings::lua().mGcStepsPerFrame > 0) + lua_gc(mLua.sol(), LUA_GCSTEP, Settings::lua().mGcStepsPerFrame); if (mPlayer.isEmpty()) return; // The game is not started yet. @@ -469,8 +468,7 @@ namespace MWLua : mFn(std::move(fn)) , mName(name) { - static const bool luaDebug = Settings::Manager::getBool("lua debug", "Lua"); - if (luaDebug) + if (Settings::lua().mLuaDebug) mCallerTraceback = state->debugTraceback(); } @@ -529,7 +527,7 @@ namespace MWLua out << (bytes / (1024 * 1024 * 1024)) << " GB"; }; - static const uint64_t smallAllocSize = Settings::Manager::getUInt64("small alloc max size", "Lua"); + const uint64_t smallAllocSize = Settings::lua().mSmallAllocMaxSize; out << "Total memory usage:"; outMemSize(mLua.getTotalMemoryUsage()); out << "\n"; diff --git a/apps/openmw/mwlua/worker.cpp b/apps/openmw/mwlua/worker.cpp index 0dbe78ad4b..66fbf0d55f 100644 --- a/apps/openmw/mwlua/worker.cpp +++ b/apps/openmw/mwlua/worker.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include @@ -14,7 +14,7 @@ namespace MWLua : mManager(manager) , mViewer(viewer) { - if (Settings::Manager::getInt("lua num threads", "Lua") > 0) + if (Settings::lua().mLuaNumThreads > 0) mThread = std::thread([this] { run(); }); }