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 <components/debug/debuglog.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#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();
};

@ -12,7 +12,7 @@
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include <components/l10n/manager.hpp>
@ -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";

@ -4,7 +4,7 @@
#include <apps/openmw/profile.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include <osgViewer/Viewer>
@ -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(); });
}

Loading…
Cancel
Save