Use typed settings storage for Lua settings

simplify_debugging
Petr Mikheev 2 years ago
parent 003f611bdb
commit 31eb3e6f5d

@ -1,7 +1,7 @@
#include "engineevents.hpp" #include "engineevents.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/settings/settings.hpp> #include <components/settings/values.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
@ -75,7 +75,7 @@ namespace MWLua
MWWorld::Ptr getPtr(const ESM::RefNum& id) const MWWorld::Ptr getPtr(const ESM::RefNum& id) const
{ {
MWWorld::Ptr res = mWorldModel->getPtr(id); 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"; Log(Debug::Verbose) << "Can not find object" << id.toString() << " when calling engine hanglers";
return res; return res;
} }
@ -91,7 +91,6 @@ namespace MWLua
LocalScripts* getLocalScripts(const ESM::RefNum& id) const { return getLocalScripts(getPtr(id)); } LocalScripts* getLocalScripts(const ESM::RefNum& id) const { return getLocalScripts(getPtr(id)); }
GlobalScripts& mGlobalScripts; GlobalScripts& mGlobalScripts;
bool mLuaDebug = Settings::Manager::getBool("lua debug", "Lua");
MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel();
}; };

@ -12,7 +12,7 @@
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp> #include <components/esm3/esmwriter.hpp>
#include <components/settings/settings.hpp> #include <components/settings/values.hpp>
#include <components/l10n/manager.hpp> #include <components/l10n/manager.hpp>
@ -38,12 +38,12 @@ namespace MWLua
static LuaUtil::LuaStateSettings createLuaStateSettings() static LuaUtil::LuaStateSettings createLuaStateSettings()
{ {
if (!Settings::Manager::getBool("lua profiler", "Lua")) if (!Settings::lua().mLuaProfiler)
LuaUtil::LuaState::disableProfiler(); LuaUtil::LuaState::disableProfiler();
return { .mInstructionLimit = Settings::Manager::getUInt64("instruction limit per call", "Lua"), return { .mInstructionLimit = Settings::lua().mInstructionLimitPerCall,
.mMemoryLimit = Settings::Manager::getUInt64("memory limit", "Lua"), .mMemoryLimit = Settings::lua().mMemoryLimit,
.mSmallAllocMaxSize = Settings::Manager::getUInt64("small alloc max size", "Lua"), .mSmallAllocMaxSize = Settings::lua().mSmallAllocMaxSize,
.mLogMemoryUsage = Settings::Manager::getBool("log memory usage", "Lua") }; .mLogMemoryUsage = Settings::lua().mLogMemoryUsage };
} }
LuaManager::LuaManager(const VFS::Manager* vfs, const std::filesystem::path& libsDir) LuaManager::LuaManager(const VFS::Manager* vfs, const std::filesystem::path& libsDir)
@ -122,9 +122,8 @@ namespace MWLua
void LuaManager::update() void LuaManager::update()
{ {
static const int gcStepCount = Settings::Manager::getInt("gc steps per frame", "Lua"); if (Settings::lua().mGcStepsPerFrame > 0)
if (gcStepCount > 0) lua_gc(mLua.sol(), LUA_GCSTEP, Settings::lua().mGcStepsPerFrame);
lua_gc(mLua.sol(), LUA_GCSTEP, gcStepCount);
if (mPlayer.isEmpty()) if (mPlayer.isEmpty())
return; // The game is not started yet. return; // The game is not started yet.
@ -469,8 +468,7 @@ namespace MWLua
: mFn(std::move(fn)) : mFn(std::move(fn))
, mName(name) , mName(name)
{ {
static const bool luaDebug = Settings::Manager::getBool("lua debug", "Lua"); if (Settings::lua().mLuaDebug)
if (luaDebug)
mCallerTraceback = state->debugTraceback(); mCallerTraceback = state->debugTraceback();
} }
@ -529,7 +527,7 @@ namespace MWLua
out << (bytes / (1024 * 1024 * 1024)) << " GB"; 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:"; out << "Total memory usage:";
outMemSize(mLua.getTotalMemoryUsage()); outMemSize(mLua.getTotalMemoryUsage());
out << "\n"; out << "\n";

@ -4,7 +4,7 @@
#include <apps/openmw/profile.hpp> #include <apps/openmw/profile.hpp>
#include <components/settings/settings.hpp> #include <components/settings/values.hpp>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
@ -14,7 +14,7 @@ namespace MWLua
: mManager(manager) : mManager(manager)
, mViewer(viewer) , mViewer(viewer)
{ {
if (Settings::Manager::getInt("lua num threads", "Lua") > 0) if (Settings::lua().mLuaNumThreads > 0)
mThread = std::thread([this] { run(); }); mThread = std::thread([this] { run(); });
} }

Loading…
Cancel
Save