diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d8f801420..02e0737ee 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -148,16 +148,16 @@ namespace MWWorld ToUTF8::Utf8Encoder* encoder, const std::map& fallbackMap, int activationDistanceOverride, const std::string& startCell, const std::string& startupScript, const std::string& resourcePath, const std::string& userDataPath) - : mResourceSystem(resourceSystem), mFallback(fallbackMap), mPlayer (0), mLocalScripts (mStore), + : mResourceSystem(resourceSystem), mFallback(fallbackMap), mLocalScripts (mStore), mSky (true), mCells (mStore, mEsm), mGodMode(false), mScriptsEnabled(true), mContentFiles (contentFiles), mUserDataPath(userDataPath), mActivationDistanceOverride (activationDistanceOverride), mStartupScript(startupScript), mStartCell (startCell), mDistanceToFacedObject(-1), mTeleportEnabled(true), mLevitationEnabled(true), mGoToJail(false), mDaysInPrison(0), mSpellPreloadTimer(0.f) { - mPhysics = new MWPhysics::PhysicsSystem(resourceSystem, rootNode); - mRendering = new MWRender::RenderingManager(viewer, rootNode, resourceSystem, workQueue, &mFallback, resourcePath); - mProjectileManager.reset(new ProjectileManager(mRendering->getLightRoot(), resourceSystem, mRendering, mPhysics)); + mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode)); + mRendering.reset(new MWRender::RenderingManager(viewer, rootNode, resourceSystem, workQueue, &mFallback, resourcePath)); + mProjectileManager.reset(new ProjectileManager(mRendering->getLightRoot(), resourceSystem, mRendering.get(), mPhysics.get())); mRendering->preloadCommonAssets(); @@ -189,9 +189,9 @@ namespace MWWorld mSwimHeightScale = mStore.get().find("fSwimHeightScale")->getFloat(); - mWeatherManager = new MWWorld::WeatherManager(*mRendering, mFallback, mStore); + mWeatherManager.reset(new MWWorld::WeatherManager(*mRendering, mFallback, mStore)); - mWorldScene = new Scene(*mRendering, mPhysics); + mWorldScene.reset(new Scene(*mRendering.get(), mPhysics.get())); } void World::fillGlobalVariables() @@ -224,8 +224,8 @@ namespace MWWorld // we don't want old weather to persist on a new game // Note that if reset later, the initial ChangeWeather that the chargen script calls will be lost. - delete mWeatherManager; - mWeatherManager = new MWWorld::WeatherManager(*mRendering, mFallback, mStore); + mWeatherManager.reset(); + mWeatherManager.reset(new MWWorld::WeatherManager(*mRendering.get(), mFallback, mStore)); if (!bypass) { @@ -492,12 +492,6 @@ namespace MWWorld { // Must be cleared before mRendering is destroyed mProjectileManager->clear(); - delete mWeatherManager; - delete mWorldScene; - delete mRendering; - delete mPhysics; - - delete mPlayer; } const ESM::Cell *World::getExterior (const std::string& cellName) const @@ -2214,7 +2208,7 @@ namespace MWWorld { const ESM::NPC *player = mStore.get().find("player"); if (!mPlayer) - mPlayer = new MWWorld::Player(player); + mPlayer.reset(new MWWorld::Player(player)); else { // Remove the old CharacterController @@ -3478,17 +3472,17 @@ namespace MWWorld if (MWMechanics::isSummoningEffect(it->mEffectID)) { - preload(mWorldScene, mStore, "VFX_Summon_Start"); - preload(mWorldScene, mStore, MWMechanics::getSummonedCreature(it->mEffectID)); + preload(mWorldScene.get(), mStore, "VFX_Summon_Start"); + preload(mWorldScene.get(), mStore, MWMechanics::getSummonedCreature(it->mEffectID)); } - preload(mWorldScene, mStore, effect->mCasting); - preload(mWorldScene, mStore, effect->mHit); + preload(mWorldScene.get(), mStore, effect->mCasting); + preload(mWorldScene.get(), mStore, effect->mHit); if (it->mArea > 0) - preload(mWorldScene, mStore, effect->mArea); + preload(mWorldScene.get(), mStore, effect->mArea); if (it->mRange == ESM::RT_Target) - preload(mWorldScene, mStore, effect->mBolt); + preload(mWorldScene.get(), mStore, effect->mBolt); } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 7af7b2968..02b3756d5 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -74,17 +74,11 @@ namespace MWWorld Resource::ResourceSystem* mResourceSystem; Fallback::Map mFallback; - MWRender::RenderingManager* mRendering; - MWWorld::WeatherManager* mWeatherManager; - - MWWorld::Scene *mWorldScene; - MWWorld::Player *mPlayer; std::vector mEsm; MWWorld::ESMStore mStore; LocalScripts mLocalScripts; MWWorld::Globals mGlobalVariables; - MWPhysics::PhysicsSystem *mPhysics; bool mSky; ESM::Variant* mGameHour; @@ -98,6 +92,11 @@ namespace MWWorld std::string mCurrentWorldSpace; + std::unique_ptr mPlayer; + std::unique_ptr mPhysics; + std::unique_ptr mRendering; + std::unique_ptr mWorldScene; + std::unique_ptr mWeatherManager; std::shared_ptr mProjectileManager; bool mGodMode;