Make Environment a storage of referencing pointers instead of owned

Engine controls lifetime of managers therefore it should own them. Environment
is only access provider.

This allows to avoid redundant virtual calls and also some functions from
managers base classes can be removed if they are used only by Engine.
pull/3227/head
elsid 3 years ago
parent a9767f1ffc
commit 79676aee15
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -271,7 +271,7 @@ namespace
void OMW::Engine::executeLocalScripts()
{
MWWorld::LocalScripts& localScripts = mEnvironment.getWorld()->getLocalScripts();
MWWorld::LocalScripts& localScripts = mWorld->getLocalScripts();
localScripts.startIteration();
std::pair<std::string, MWWorld::Ptr> script;
@ -279,7 +279,7 @@ void OMW::Engine::executeLocalScripts()
{
MWScript::InterpreterContext interpreterContext (
&script.second.getRefData().getLocals(), script.second);
mEnvironment.getScriptManager()->run (script.first, interpreterContext);
mScriptManager->run (script.first, interpreterContext);
}
}
@ -297,7 +297,7 @@ bool OMW::Engine::frame(float frametime)
// update input
{
ScopedProfile<UserStatsType::Input> profile(frameStart, frameNumber, *timer, *stats);
mEnvironment.getInputManager()->update(frametime, false);
mInputManager->update(frametime, false);
}
// When the window is minimized, pause the game. Currently this *has* to be here to work around a MyGUI bug.
@ -306,21 +306,21 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile<UserStatsType::Sound> profile(frameStart, frameNumber, *timer, *stats);
if (!mEnvironment.getWindowManager()->isWindowVisible())
if (!mWindowManager->isWindowVisible())
{
mEnvironment.getSoundManager()->pausePlayback();
mSoundManager->pausePlayback();
return false;
}
else
mEnvironment.getSoundManager()->resumePlayback();
mSoundManager->resumePlayback();
// sound
if (mUseSound)
mEnvironment.getSoundManager()->update(frametime);
mSoundManager->update(frametime);
}
// Main menu opened? Then scripts are also paused.
bool paused = mEnvironment.getWindowManager()->containsMode(MWGui::GM_MainMenu);
bool paused = mWindowManager->containsMode(MWGui::GM_MainMenu);
// Should be called after input manager update and before any change to the game world.
// It applies to the game world queued changes from the previous frame.
@ -329,35 +329,35 @@ bool OMW::Engine::frame(float frametime)
// update game state
{
ScopedProfile<UserStatsType::State> profile(frameStart, frameNumber, *timer, *stats);
mEnvironment.getStateManager()->update (frametime);
mStateManager->update (frametime);
}
bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
bool guiActive = mWindowManager->isGuiMode();
{
ScopedProfile<UserStatsType::Script> profile(frameStart, frameNumber, *timer, *stats);
if (mEnvironment.getStateManager()->getState() != MWBase::StateManager::State_NoGame)
if (mStateManager->getState() != MWBase::StateManager::State_NoGame)
{
if (!paused)
{
if (mEnvironment.getWorld()->getScriptsEnabled())
if (mWorld->getScriptsEnabled())
{
// local scripts
executeLocalScripts();
// global scripts
mEnvironment.getScriptManager()->getGlobalScripts().run();
mScriptManager->getGlobalScripts().run();
}
mEnvironment.getWorld()->markCellAsUnchanged();
mWorld->markCellAsUnchanged();
}
if (!guiActive)
{
double hours = (frametime * mEnvironment.getWorld()->getTimeScaleFactor()) / 3600.0;
mEnvironment.getWorld()->advanceTime(hours, true);
mEnvironment.getWorld()->rechargeItems(frametime, true);
double hours = (frametime * mWorld->getTimeScaleFactor()) / 3600.0;
mWorld->advanceTime(hours, true);
mWorld->rechargeItems(frametime, true);
}
}
}
@ -366,16 +366,16 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile<UserStatsType::Mechanics> profile(frameStart, frameNumber, *timer, *stats);
if (mEnvironment.getStateManager()->getState() != MWBase::StateManager::State_NoGame)
if (mStateManager->getState() != MWBase::StateManager::State_NoGame)
{
mEnvironment.getMechanicsManager()->update(frametime, guiActive);
mMechanicsManager->update(frametime, guiActive);
}
if (mEnvironment.getStateManager()->getState() == MWBase::StateManager::State_Running)
if (mStateManager->getState() == MWBase::StateManager::State_Running)
{
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
MWWorld::Ptr player = mWorld->getPlayerPtr();
if(!guiActive && player.getClass().getCreatureStats(player).isDead())
mEnvironment.getStateManager()->endGame();
mStateManager->endGame();
}
}
@ -383,9 +383,9 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile<UserStatsType::Physics> profile(frameStart, frameNumber, *timer, *stats);
if (mEnvironment.getStateManager()->getState() != MWBase::StateManager::State_NoGame)
if (mStateManager->getState() != MWBase::StateManager::State_NoGame)
{
mEnvironment.getWorld()->updatePhysics(frametime, guiActive, frameStart, frameNumber, *stats);
mWorld->updatePhysics(frametime, guiActive, frameStart, frameNumber, *stats);
}
}
@ -393,16 +393,16 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile<UserStatsType::World> profile(frameStart, frameNumber, *timer, *stats);
if (mEnvironment.getStateManager()->getState() != MWBase::StateManager::State_NoGame)
if (mStateManager->getState() != MWBase::StateManager::State_NoGame)
{
mEnvironment.getWorld()->update(frametime, guiActive);
mWorld->update(frametime, guiActive);
}
}
// update GUI
{
ScopedProfile<UserStatsType::Gui> profile(frameStart, frameNumber, *timer, *stats);
mEnvironment.getWindowManager()->update(frametime);
mWindowManager->update(frametime);
}
if (stats->collectStats("resource"))
@ -443,7 +443,6 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mExportFonts(false)
, mRandomSeed(0)
, mScriptContext (nullptr)
, mLuaManager (nullptr)
, mFSStrict (false)
, mScriptBlacklistUse (true)
, mNewGame (false)
@ -471,6 +470,17 @@ OMW::Engine::~Engine()
mEnvironment.cleanup();
mMechanicsManager = nullptr;
mDialogueManager = nullptr;
mJournal = nullptr;
mScriptManager = nullptr;
mWindowManager = nullptr;
mWorld = nullptr;
mSoundManager = nullptr;
mInputManager = nullptr;
mStateManager = nullptr;
mLuaManager = nullptr;
delete mScriptContext;
mScriptContext = nullptr;
@ -701,8 +711,8 @@ void OMW::Engine::setWindowIcon()
void OMW::Engine::prepareEngine (Settings::Manager & settings)
{
mEnvironment.setStateManager (
std::make_unique<MWState::StateManager> (mCfgMgr.getUserDataPath() / "saves", mContentFiles));
mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles);
mEnvironment.setStateManager(*mStateManager);
mStereoManager = std::make_unique<Stereo::Manager>(mViewer);
@ -723,6 +733,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
Settings::Manager::getString("texture mipmap", "General"),
Settings::Manager::getInt("anisotropy", "General")
);
mEnvironment.setResourceSystem(*mResourceSystem);
int numThreads = Settings::Manager::getInt("preload num threads", "Cells");
if (numThreads <= 0)
@ -744,9 +755,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mViewer->addEventHandler(mScreenCaptureHandler);
auto luaMgr = std::make_unique<MWLua::LuaManager>(mVFS.get(), (mResDir / "lua_libs").string());
mLuaManager = luaMgr.get();
mEnvironment.setLuaManager(std::move(luaMgr));
mLuaManager = std::make_unique<MWLua::LuaManager>(mVFS.get(), (mResDir / "lua_libs").string());
mEnvironment.setLuaManager(*mLuaManager);
// Create input and UI first to set up a bootstrapping environment for
// showing a loading screen and keeping the window responsive while doing so
@ -799,34 +809,36 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mStereoManager->disableStereoForNode(guiRoot);
rootNode->addChild(guiRoot);
auto windowMgr = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
mWindowManager = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts,
Version::getOpenmwVersionDescription(mResDir.string()), mCfgMgr.getUserConfigPath().string(), shadersSupported);
auto* windowMgrInternal = windowMgr.get();
mEnvironment.setWindowManager (std::move(windowMgr));
mEnvironment.setWindowManager(*mWindowManager);
auto inputMgr = std::make_unique<MWInput::InputManager>(mWindow, mViewer, mScreenCaptureHandler, mScreenCaptureOperation, keybinderUser, keybinderUserExists, userGameControllerdb, gameControllerdb, mGrab);
mEnvironment.setInputManager(std::move(inputMgr));
mInputManager = std::make_unique<MWInput::InputManager>(mWindow, mViewer, mScreenCaptureHandler,
mScreenCaptureOperation, keybinderUser, keybinderUserExists, userGameControllerdb, gameControllerdb, mGrab);
mEnvironment.setInputManager(*mInputManager);
// Create sound system
mEnvironment.setSoundManager (std::make_unique<MWSound::SoundManager>(mVFS.get(), mUseSound));
mSoundManager = std::make_unique<MWSound::SoundManager>(mVFS.get(), mUseSound);
mEnvironment.setSoundManager(*mSoundManager);
if (!mSkipMenu)
{
const std::string& logo = Fallback::Map::getString("Movies_Company_Logo");
if (!logo.empty())
mEnvironment.getWindowManager()->playVideo(logo, true);
mWindowManager->playVideo(logo, true);
}
// Create the world
mEnvironment.setWorld(std::make_unique<MWWorld::World>(mViewer, rootNode, mResourceSystem.get(), mWorkQueue.get(),
mWorld = std::make_unique<MWWorld::World>(mViewer, rootNode, mResourceSystem.get(), mWorkQueue.get(),
mFileCollections, mContentFiles, mGroundcoverFiles, mEncoder, mActivationDistanceOverride, mCellName,
mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string()));
mEnvironment.getWorld()->setupPlayer();
mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string());
mWorld->setupPlayer();
mEnvironment.setWorld(*mWorld);
windowMgrInternal->setStore(mEnvironment.getWorld()->getStore());
windowMgrInternal->initUI();
mWindowManager->setStore(mWorld->getStore());
mWindowManager->initUI();
//Load translation data
mTranslationDataStorage.setEncoder(mEncoder);
@ -839,21 +851,25 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions);
mEnvironment.setScriptManager (std::make_unique<MWScript::ScriptManager>(mEnvironment.getWorld()->getStore(), *mScriptContext, mWarningsMode,
mScriptBlacklistUse ? mScriptBlacklist : std::vector<std::string>()));
mScriptManager = std::make_unique<MWScript::ScriptManager>(mWorld->getStore(), *mScriptContext, mWarningsMode,
mScriptBlacklistUse ? mScriptBlacklist : std::vector<std::string>());
mEnvironment.setScriptManager(*mScriptManager);
// Create game mechanics system
mEnvironment.setMechanicsManager (std::make_unique<MWMechanics::MechanicsManager>());
mMechanicsManager = std::make_unique<MWMechanics::MechanicsManager>();
mEnvironment.setMechanicsManager(*mMechanicsManager);
// Create dialog system
mEnvironment.setJournal (std::make_unique<MWDialogue::Journal>());
mEnvironment.setDialogueManager (std::make_unique<MWDialogue::DialogueManager>(mExtensions, mTranslationDataStorage));
mEnvironment.setResourceSystem(mResourceSystem.get());
mJournal = std::make_unique<MWDialogue::Journal>();
mEnvironment.setJournal(*mJournal);
mDialogueManager = std::make_unique<MWDialogue::DialogueManager>(mExtensions, mTranslationDataStorage);
mEnvironment.setDialogueManager(*mDialogueManager);
// scripts
if (mCompileAll)
{
std::pair<int, int> result = mEnvironment.getScriptManager()->compileAll();
std::pair<int, int> result = mScriptManager->compileAll();
if (result.first)
Log(Debug::Info)
<< "compiled " << result.second << " of " << result.first << " scripts ("
@ -1014,25 +1030,25 @@ void OMW::Engine::go()
// Start the game
if (!mSaveGameFile.empty())
{
mEnvironment.getStateManager()->loadGame(mSaveGameFile);
mStateManager->loadGame(mSaveGameFile);
}
else if (!mSkipMenu)
{
// start in main menu
mEnvironment.getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
mEnvironment.getSoundManager()->playTitleMusic();
mWindowManager->pushGuiMode (MWGui::GM_MainMenu);
mSoundManager->playTitleMusic();
const std::string& logo = Fallback::Map::getString("Movies_Morrowind_Logo");
if (!logo.empty())
mEnvironment.getWindowManager()->playVideo(logo, true);
mWindowManager->playVideo(logo, true);
}
else
{
mEnvironment.getStateManager()->newGame (!mNewGame);
mStateManager->newGame (!mNewGame);
}
if (!mStartupScript.empty() && mEnvironment.getStateManager()->getState() == MWState::StateManager::State_Running)
if (!mStartupScript.empty() && mStateManager->getState() == MWState::StateManager::State_Running)
{
mEnvironment.getWindowManager()->executeInConsole(mStartupScript);
mWindowManager->executeInConsole(mStartupScript);
}
LuaWorker luaWorker(this); // starts a separate lua thread if "lua num threads" > 0
@ -1041,7 +1057,7 @@ void OMW::Engine::go()
double simulationTime = 0.0;
Misc::FrameRateLimiter frameRateLimiter = Misc::makeFrameRateLimiter(mEnvironment.getFrameRateLimit());
const std::chrono::steady_clock::duration maxSimulationInterval(std::chrono::milliseconds(200));
while (!mViewer->done() && !mEnvironment.getStateManager()->hasQuitRequest())
while (!mViewer->done() && !mStateManager->hasQuitRequest())
{
const double dt = std::chrono::duration_cast<std::chrono::duration<double>>(std::min(
frameRateLimiter.getLastFrameDuration(),
@ -1060,7 +1076,7 @@ void OMW::Engine::go()
mViewer->eventTraversal();
mViewer->updateTraversal();
mEnvironment.getWorld()->updateWindowManager();
mWorld->updateWindowManager();
luaWorker.allowUpdate(); // if there is a separate Lua thread, it starts the update now
@ -1068,7 +1084,7 @@ void OMW::Engine::go()
luaWorker.finishUpdate();
bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
bool guiActive = mWindowManager->isGuiMode();
if (!guiActive)
simulationTime += dt;
}

@ -64,6 +64,51 @@ namespace SceneUtil
}
}
namespace MWState
{
class StateManager;
}
namespace MWGui
{
class WindowManager;
}
namespace MWInput
{
class InputManager;
}
namespace MWSound
{
class SoundManager;
}
namespace MWWorld
{
class World;
}
namespace MWScript
{
class ScriptManager;
}
namespace MWMechanics
{
class MechanicsManager;
}
namespace MWDialogue
{
class DialogueManager;
}
namespace MWDialogue
{
class Journal;
}
struct SDL_Window;
namespace OMW
@ -75,6 +120,16 @@ namespace OMW
std::unique_ptr<VFS::Manager> mVFS;
std::unique_ptr<Resource::ResourceSystem> mResourceSystem;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
std::unique_ptr<MWWorld::World> mWorld;
std::unique_ptr<MWSound::SoundManager> mSoundManager;
std::unique_ptr<MWScript::ScriptManager> mScriptManager;
std::unique_ptr<MWGui::WindowManager> mWindowManager;
std::unique_ptr<MWMechanics::MechanicsManager> mMechanicsManager;
std::unique_ptr<MWDialogue::DialogueManager> mDialogueManager;
std::unique_ptr<MWDialogue::Journal> mJournal;
std::unique_ptr<MWInput::InputManager> mInputManager;
std::unique_ptr<MWState::StateManager> mStateManager;
std::unique_ptr<MWLua::LuaManager> mLuaManager;
MWBase::Environment mEnvironment;
ToUTF8::FromType mEncoding;
ToUTF8::Utf8Encoder* mEncoder;
@ -111,8 +166,6 @@ namespace OMW
Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext;
MWLua::LuaManager* mLuaManager;
Files::Collections mFileCollections;
bool mFSStrict;
Translation::Storage mTranslationDataStorage;

@ -19,7 +19,7 @@ MWBase::Environment *MWBase::Environment::sThis = nullptr;
MWBase::Environment::Environment()
{
assert(!sThis);
assert(sThis == nullptr);
sThis = this;
}
@ -28,167 +28,21 @@ MWBase::Environment::~Environment()
sThis = nullptr;
}
void MWBase::Environment::setWorld (std::unique_ptr<World>&& world)
{
mWorld = std::move(world);
}
void MWBase::Environment::setSoundManager (std::unique_ptr<SoundManager>&& soundManager)
{
mSoundManager = std::move(soundManager);
}
void MWBase::Environment::setScriptManager (std::unique_ptr<ScriptManager>&& scriptManager)
{
mScriptManager = std::move(scriptManager);
}
void MWBase::Environment::setWindowManager (std::unique_ptr<WindowManager>&& windowManager)
{
mWindowManager = std::move(windowManager);
}
void MWBase::Environment::setMechanicsManager (std::unique_ptr<MechanicsManager>&& mechanicsManager)
{
mMechanicsManager = std::move(mechanicsManager);
}
void MWBase::Environment::setDialogueManager (std::unique_ptr<DialogueManager>&& dialogueManager)
{
mDialogueManager = std::move(dialogueManager);
}
void MWBase::Environment::setJournal (std::unique_ptr<Journal>&& journal)
{
mJournal = std::move(journal);
}
void MWBase::Environment::setInputManager (std::unique_ptr<InputManager>&& inputManager)
{
mInputManager = std::move(inputManager);
}
void MWBase::Environment::setStateManager (std::unique_ptr<StateManager>&& stateManager)
{
mStateManager = std::move(stateManager);
}
void MWBase::Environment::setLuaManager (std::unique_ptr<LuaManager>&& luaManager)
{
mLuaManager = std::move(luaManager);
}
void MWBase::Environment::setResourceSystem (Resource::ResourceSystem *resourceSystem)
{
mResourceSystem = resourceSystem;
}
void MWBase::Environment::setFrameDuration (float duration)
{
mFrameDuration = duration;
}
void MWBase::Environment::setFrameRateLimit(float limit)
{
mFrameRateLimit = limit;
}
float MWBase::Environment::getFrameRateLimit() const
{
return mFrameRateLimit;
}
MWBase::World *MWBase::Environment::getWorld() const
{
assert (mWorld);
return mWorld.get();
}
MWBase::SoundManager *MWBase::Environment::getSoundManager() const
{
assert (mSoundManager);
return mSoundManager.get();
}
MWBase::ScriptManager *MWBase::Environment::getScriptManager() const
{
assert (mScriptManager);
return mScriptManager.get();
}
MWBase::WindowManager *MWBase::Environment::getWindowManager() const
{
assert (mWindowManager);
return mWindowManager.get();
}
MWBase::MechanicsManager *MWBase::Environment::getMechanicsManager() const
{
assert (mMechanicsManager);
return mMechanicsManager.get();
}
MWBase::DialogueManager *MWBase::Environment::getDialogueManager() const
{
assert (mDialogueManager);
return mDialogueManager.get();
}
MWBase::Journal *MWBase::Environment::getJournal() const
{
assert (mJournal);
return mJournal.get();
}
MWBase::InputManager *MWBase::Environment::getInputManager() const
{
assert (mInputManager);
return mInputManager.get();
}
MWBase::StateManager *MWBase::Environment::getStateManager() const
{
assert (mStateManager);
return mStateManager.get();
}
MWBase::LuaManager *MWBase::Environment::getLuaManager() const
{
assert (mLuaManager);
return mLuaManager.get();
}
Resource::ResourceSystem *MWBase::Environment::getResourceSystem() const
{
return mResourceSystem;
}
float MWBase::Environment::getFrameDuration() const
{
return mFrameDuration;
}
void MWBase::Environment::cleanup()
{
mMechanicsManager.reset();
mDialogueManager.reset();
mJournal.reset();
mScriptManager.reset();
mWindowManager.reset();
mWorld.reset();
mSoundManager.reset();
mInputManager.reset();
mStateManager.reset();
mLuaManager.reset();
mMechanicsManager = nullptr;
mDialogueManager = nullptr;
mJournal = nullptr;
mScriptManager = nullptr;
mWindowManager = nullptr;
mWorld = nullptr;
mSoundManager = nullptr;
mInputManager = nullptr;
mStateManager = nullptr;
mLuaManager = nullptr;
mResourceSystem = nullptr;
}
const MWBase::Environment& MWBase::Environment::get()
{
assert (sThis);
return *sThis;
}
void MWBase::Environment::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
mMechanicsManager->reportStats(frameNumber, stats);

@ -1,6 +1,8 @@
#ifndef GAME_BASE_ENVIRONMENT_H
#define GAME_BASE_ENVIRONMENT_H
#include <components/misc/notnullptr.hpp>
#include <memory>
namespace osg
@ -34,25 +36,19 @@ namespace MWBase
{
static Environment *sThis;
std::unique_ptr<World> mWorld;
std::unique_ptr<SoundManager> mSoundManager;
std::unique_ptr<ScriptManager> mScriptManager;
std::unique_ptr<WindowManager> mWindowManager;
std::unique_ptr<MechanicsManager> mMechanicsManager;
std::unique_ptr<DialogueManager> mDialogueManager;
std::unique_ptr<Journal> mJournal;
std::unique_ptr<InputManager> mInputManager;
std::unique_ptr<StateManager> mStateManager;
std::unique_ptr<LuaManager> mLuaManager;
Resource::ResourceSystem* mResourceSystem{};
float mFrameDuration{};
float mFrameRateLimit{};
Environment (const Environment&);
///< not implemented
Environment& operator= (const Environment&);
///< not implemented
World* mWorld = nullptr;
SoundManager* mSoundManager = nullptr;
ScriptManager* mScriptManager = nullptr;
WindowManager* mWindowManager = nullptr;
MechanicsManager* mMechanicsManager = nullptr;
DialogueManager* mDialogueManager = nullptr;
Journal* mJournal = nullptr;
InputManager* mInputManager = nullptr;
StateManager* mStateManager = nullptr;
LuaManager* mLuaManager = nullptr;
Resource::ResourceSystem* mResourceSystem = nullptr;
float mFrameRateLimit = 0;
float mFrameDuration = 0;
public:
@ -60,63 +56,70 @@ namespace MWBase
~Environment();
void setWorld (std::unique_ptr<World>&& world);
Environment(const Environment&) = delete;
Environment& operator=(const Environment&) = delete;
void setWorld(World& value) { mWorld = &value; }
void setSoundManager(SoundManager& value) { mSoundManager = &value; }
void setSoundManager (std::unique_ptr<SoundManager>&& soundManager);
void setScriptManager(ScriptManager& value) { mScriptManager = &value; }
void setScriptManager (std::unique_ptr<ScriptManager>&& scriptManager);
void setWindowManager(WindowManager& value) { mWindowManager = &value; }
void setWindowManager (std::unique_ptr<WindowManager>&& windowManager);
void setMechanicsManager(MechanicsManager& value) { mMechanicsManager = &value; }
void setMechanicsManager (std::unique_ptr<MechanicsManager>&& mechanicsManager);
void setDialogueManager(DialogueManager& value) { mDialogueManager = &value; }
void setDialogueManager (std::unique_ptr<DialogueManager>&& dialogueManager);
void setJournal(Journal& value) { mJournal = &value; }
void setJournal (std::unique_ptr<Journal>&& journal);
void setInputManager(InputManager& value) { mInputManager = &value; }
void setInputManager (std::unique_ptr<InputManager>&& inputManager);
void setStateManager(StateManager& value) { mStateManager = &value; }
void setStateManager (std::unique_ptr<StateManager>&& stateManager);
void setLuaManager(LuaManager& value) { mLuaManager = &value; }
void setLuaManager (std::unique_ptr<LuaManager>&& luaManager);
void setResourceSystem(Resource::ResourceSystem& value) { mResourceSystem = &value; }
void setResourceSystem (Resource::ResourceSystem *resourceSystem);
Misc::NotNullPtr<World> getWorld() const { return mWorld; }
void setFrameDuration (float duration);
///< Set length of current frame in seconds.
Misc::NotNullPtr<SoundManager> getSoundManager() const { return mSoundManager; }
void setFrameRateLimit(float frameRateLimit);
float getFrameRateLimit() const;
Misc::NotNullPtr<ScriptManager> getScriptManager() const { return mScriptManager; }
World *getWorld() const;
Misc::NotNullPtr<WindowManager> getWindowManager() const { return mWindowManager; }
SoundManager *getSoundManager() const;
Misc::NotNullPtr<MechanicsManager> getMechanicsManager() const { return mMechanicsManager; }
ScriptManager *getScriptManager() const;
Misc::NotNullPtr<DialogueManager> getDialogueManager() const { return mDialogueManager; }
WindowManager *getWindowManager() const;
Misc::NotNullPtr<Journal> getJournal() const { return mJournal; }
MechanicsManager *getMechanicsManager() const;
Misc::NotNullPtr<InputManager> getInputManager() const { return mInputManager; }
DialogueManager *getDialogueManager() const;
Misc::NotNullPtr<StateManager> getStateManager() const { return mStateManager; }
Journal *getJournal() const;
Misc::NotNullPtr<LuaManager> getLuaManager() const { return mLuaManager; }
InputManager *getInputManager() const;
Misc::NotNullPtr<Resource::ResourceSystem> getResourceSystem() const { return mResourceSystem; }
StateManager *getStateManager() const;
float getFrameRateLimit() const { return mFrameRateLimit; }
LuaManager *getLuaManager() const;
void setFrameRateLimit(float value) { mFrameRateLimit = value; }
Resource::ResourceSystem *getResourceSystem() const;
float getFrameDuration() const { return mFrameDuration; }
float getFrameDuration() const;
void setFrameDuration(float value) { mFrameDuration = value; }
void cleanup();
///< Delete all mw*-subsystems.
static const Environment& get();
///< Return instance of this class.
/// Return instance of this class.
static const Environment& get()
{
assert(sThis != nullptr);
return *sThis;
}
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
};

@ -157,8 +157,8 @@ namespace MWInput
void ActionManager::executeAction(int action)
{
MWBase::Environment::get().getLuaManager()->inputEvent({MWBase::LuaManager::InputEvent::Action, action});
auto* inputManager = MWBase::Environment::get().getInputManager();
auto* windowManager = MWBase::Environment::get().getWindowManager();
const auto inputManager = MWBase::Environment::get().getInputManager();
const auto windowManager = MWBase::Environment::get().getWindowManager();
// trigger action activated
switch (action)
{

@ -200,7 +200,7 @@ namespace MWLua
};
api["setConsoleSelectedObject"] = [luaManager=context.mLuaManager](const sol::object& obj)
{
auto* wm = MWBase::Environment::get().getWindowManager();
const auto wm = MWBase::Environment::get().getWindowManager();
if (obj == sol::nil)
luaManager->addAction([wm]{ wm->setConsoleSelectedObject(MWWorld::Ptr()); });
else

@ -495,7 +495,7 @@ namespace MWMechanics
getActorsSidingWith(actor1, allies1, cachedAllies);
auto* mechanicsManager = MWBase::Environment::get().getMechanicsManager();
const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager();
// If an ally of actor1 has been attacked by actor2 or has attacked actor2, start combat between actor1 and actor2
for (const MWWorld::Ptr& ally : allies1)
{
@ -583,7 +583,7 @@ namespace MWMechanics
}
// Make guards go aggressive with creatures that are in combat, unless the creature is a follower or escorter
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
if (!aggressive && actor1.getClass().isClass(actor1, "Guard") && !actor2.getClass().isNpc() && creatureStats2.getAiSequence().isInCombat())
{
// Check if the creature is too far
@ -917,7 +917,7 @@ namespace MWMechanics
//If holding a light...
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
{
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
// Use time from the player's light
if(isPlayer)
{
@ -974,8 +974,8 @@ namespace MWMechanics
if (playerStats.isWerewolf())
return;
auto* mechanicsManager = MWBase::Environment::get().getMechanicsManager();
auto* world = MWBase::Environment::get().getWorld();
const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager();
const auto world = MWBase::Environment::get().getWorld();
if (actorClass.isClass(ptr, "Guard") && creatureStats.getAiSequence().isInPursuit() && !creatureStats.getAiSequence().isInCombat()
&& creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() == 0)

@ -207,7 +207,7 @@ std::string CharacterController::chooseRandomGroup (const std::string& prefix, i
void CharacterController::refreshHitRecoilAnims(CharacterState& idle)
{
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
auto& charClass = mPtr.getClass();
auto& stats = charClass.getCreatureStats(mPtr);
bool recovery = stats.getHitRecovery();
@ -1101,7 +1101,7 @@ void CharacterController::updateIdleStormState(bool inwater)
return;
}
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
if (world->isInStorm())
{
osg::Vec3f stormDirection = world->getStormDirection();
@ -1139,7 +1139,7 @@ bool CharacterController::updateCarriedLeftVisible(const int weaptype) const
bool CharacterController::updateState(CharacterState idle)
{
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
auto& prng = world->getPrng();
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();

@ -789,7 +789,7 @@ namespace MWPhysics
void PhysicsSystem::moveActors()
{
auto* player = getActor(MWMechanics::getPlayer());
auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
// copy new ptr position in temporary vector. player is handled separately as its movement might change active cell.
std::vector<std::pair<MWWorld::Ptr, osg::Vec3f>> newPositions;

@ -25,7 +25,7 @@ osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(int x, int y)
return static_cast<ESMTerrain::LandObject*>(obj.get());
else
{
const auto* world = MWBase::Environment::get().getWorld();
const auto world = MWBase::Environment::get().getWorld();
if (!world)
return nullptr;
const ESM::Land* land = world->getStore().get<ESM::Land>().search(x,y);

@ -804,7 +804,7 @@ namespace MWRender
}
else if (mode == Render_Scene)
{
auto* wm = MWBase::Environment::get().getWindowManager();
const auto wm = MWBase::Environment::get().getWindowManager();
unsigned int mask = wm->getCullMask();
bool enabled = !(mask&sToggleWorldMask);
if (enabled)

@ -522,11 +522,11 @@ namespace MWWorld
void Player::update()
{
auto player = getPlayer();
auto* world = MWBase::Environment::get().getWorld();
auto* rendering = world->getRenderingManager();
const auto world = MWBase::Environment::get().getWorld();
const auto rendering = world->getRenderingManager();
auto& store = world->getStore();
auto& playerClass = player.getClass();
auto* windowMgr = MWBase::Environment::get().getWindowManager();
const auto windowMgr = MWBase::Environment::get().getWindowManager();
if (player.getCell()->isExterior())
{

@ -0,0 +1,33 @@
#ifndef OPENMW_COMPONENTS_MISC_NOTNULLPTR_H
#define OPENMW_COMPONENTS_MISC_NOTNULLPTR_H
#include <cassert>
#include <cstddef>
#include <type_traits>
namespace Misc
{
template <class T>
class NotNullPtr
{
public:
NotNullPtr(T* value)
: mValue(value)
{
assert(mValue != nullptr);
}
NotNullPtr(std::nullptr_t) = delete;
operator T*() const { return mValue; }
T* operator->() const { return mValue; }
T& operator*() const { return *mValue; }
private:
T* mValue;
};
}
#endif
Loading…
Cancel
Save