1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Use unique_ptr to manage scripts context and encoder lifetime

This commit is contained in:
elsid 2022-05-22 01:47:06 +02:00
parent 8047a2138e
commit 68caff9c7b
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
2 changed files with 6 additions and 10 deletions

View File

@ -429,7 +429,6 @@ bool OMW::Engine::frame(float frametime)
OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
: mWindow(nullptr)
, mEncoding(ToUTF8::WINDOWS_1252)
, mEncoder(nullptr)
, mScreenCaptureOperation(nullptr)
, mSelectDepthFormatOperation(new SceneUtil::SelectDepthFormatOperation())
, mSelectColorFormatOperation(new SceneUtil::Color::SelectColorFormatOperation())
@ -444,7 +443,6 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mGrab(true)
, mExportFonts(false)
, mRandomSeed(0)
, mScriptContext (nullptr)
, mFSStrict (false)
, mScriptBlacklistUse (true)
, mNewGame (false)
@ -480,7 +478,6 @@ OMW::Engine::~Engine()
mStateManager = nullptr;
mLuaManager = nullptr;
delete mScriptContext;
mScriptContext = nullptr;
mWorkQueue = nullptr;
@ -489,7 +486,6 @@ OMW::Engine::~Engine()
mResourceSystem.reset();
delete mEncoder;
mEncoder = nullptr;
if (mWindow)
@ -833,7 +829,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
// Create the world
mWorld = std::make_unique<MWWorld::World>(mViewer, rootNode, mResourceSystem.get(), mWorkQueue.get(),
mFileCollections, mContentFiles, mGroundcoverFiles, mEncoder, mActivationDistanceOverride, mCellName,
mFileCollections, mContentFiles, mGroundcoverFiles, mEncoder.get(), mActivationDistanceOverride, mCellName,
mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string());
mWorld->setupPlayer();
mWorld->setRandomSeed(mRandomSeed);
@ -843,14 +839,14 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mWindowManager->initUI();
//Load translation data
mTranslationDataStorage.setEncoder(mEncoder);
mTranslationDataStorage.setEncoder(mEncoder.get());
for (size_t i = 0; i < mContentFiles.size(); i++)
mTranslationDataStorage.loadTranslationData(mFileCollections, mContentFiles[i]);
Compiler::registerExtensions (mExtensions);
// Create script system
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext = std::make_unique<MWScript::CompilerContext>(MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions);
mScriptManager = std::make_unique<MWScript::ScriptManager>(mWorld->getStore(), *mScriptContext, mWarningsMode,
@ -993,7 +989,7 @@ void OMW::Engine::go()
MWClass::registerClasses();
// Create encoder
mEncoder = new ToUTF8::Utf8Encoder(mEncoding);
mEncoder = std::make_unique<ToUTF8::Utf8Encoder>(mEncoding);
// Setup viewer
mViewer = new osgViewer::Viewer;

View File

@ -132,7 +132,7 @@ namespace OMW
std::unique_ptr<MWLua::LuaManager> mLuaManager;
MWBase::Environment mEnvironment;
ToUTF8::FromType mEncoding;
ToUTF8::Utf8Encoder* mEncoder;
std::unique_ptr<ToUTF8::Utf8Encoder> mEncoder;
Files::PathContainer mDataDirs;
std::vector<std::string> mArchives;
boost::filesystem::path mResDir;
@ -164,7 +164,7 @@ namespace OMW
unsigned int mRandomSeed;
Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext;
std::unique_ptr<Compiler::Context> mScriptContext;
Files::Collections mFileCollections;
bool mFSStrict;