@ -271,7 +271,7 @@ namespace
void OMW : : Engine : : executeLocalScripts ( )
{
MWWorld : : LocalScripts & localScripts = m Environment. get World( ) - > getLocalScripts ( ) ;
MWWorld : : LocalScripts & localScripts = m World- > 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 ) ;
m Environment. get ScriptManager( ) - > run ( script . first , interpreterContext ) ;
m ScriptManager- > run ( script . first , interpreterContext ) ;
}
}
@ -297,7 +297,7 @@ bool OMW::Engine::frame(float frametime)
// update input
{
ScopedProfile < UserStatsType : : Input > profile ( frameStart , frameNumber , * timer , * stats ) ;
m Environment. get InputManager( ) - > update ( frametime , false ) ;
m InputManager- > 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 ( ! m Environment. get WindowManager( ) - > isWindowVisible ( ) )
if ( ! m WindowManager- > isWindowVisible ( ) )
{
m Environment. get SoundManager( ) - > pausePlayback ( ) ;
m SoundManager- > pausePlayback ( ) ;
return false ;
}
else
m Environment. get SoundManager( ) - > resumePlayback ( ) ;
m SoundManager- > resumePlayback ( ) ;
// sound
if ( mUseSound )
m Environment. get SoundManager( ) - > update ( frametime ) ;
m SoundManager- > update ( frametime ) ;
}
// Main menu opened? Then scripts are also paused.
bool paused = m Environment. get WindowManager( ) - > containsMode ( MWGui : : GM_MainMenu ) ;
bool paused = m WindowManager- > 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 ) ;
m Environment. get StateManager( ) - > update ( frametime ) ;
m StateManager- > update ( frametime ) ;
}
bool guiActive = m Environment. get WindowManager( ) - > isGuiMode ( ) ;
bool guiActive = m WindowManager- > isGuiMode ( ) ;
{
ScopedProfile < UserStatsType : : Script > profile ( frameStart , frameNumber , * timer , * stats ) ;
if ( m Environment. get StateManager( ) - > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
if ( m StateManager- > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
{
if ( ! paused )
{
if ( m Environment. get World( ) - > getScriptsEnabled ( ) )
if ( m World- > getScriptsEnabled ( ) )
{
// local scripts
executeLocalScripts ( ) ;
// global scripts
m Environment. get ScriptManager( ) - > getGlobalScripts ( ) . run ( ) ;
m ScriptManager- > getGlobalScripts ( ) . run ( ) ;
}
m Environment. get World( ) - > markCellAsUnchanged ( ) ;
m World- > markCellAsUnchanged ( ) ;
}
if ( ! guiActive )
{
double hours = ( frametime * m Environment. get World( ) - > getTimeScaleFactor ( ) ) / 3600.0 ;
m Environment. get World( ) - > advanceTime ( hours , true ) ;
m Environment. get World( ) - > rechargeItems ( frametime , true ) ;
double hours = ( frametime * m World- > getTimeScaleFactor ( ) ) / 3600.0 ;
m World- > advanceTime ( hours , true ) ;
m World- > rechargeItems ( frametime , true ) ;
}
}
}
@ -366,16 +366,16 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile < UserStatsType : : Mechanics > profile ( frameStart , frameNumber , * timer , * stats ) ;
if ( m Environment. get StateManager( ) - > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
if ( m StateManager- > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
{
m Environment. get MechanicsManager( ) - > update ( frametime , guiActive ) ;
m MechanicsManager- > update ( frametime , guiActive ) ;
}
if ( m Environment. get StateManager( ) - > getState ( ) = = MWBase : : StateManager : : State_Running )
if ( m StateManager- > getState ( ) = = MWBase : : StateManager : : State_Running )
{
MWWorld : : Ptr player = m Environment. get World( ) - > getPlayerPtr ( ) ;
MWWorld : : Ptr player = m World- > getPlayerPtr ( ) ;
if ( ! guiActive & & player . getClass ( ) . getCreatureStats ( player ) . isDead ( ) )
m Environment. get StateManager( ) - > endGame ( ) ;
m StateManager- > endGame ( ) ;
}
}
@ -383,9 +383,9 @@ bool OMW::Engine::frame(float frametime)
{
ScopedProfile < UserStatsType : : Physics > profile ( frameStart , frameNumber , * timer , * stats ) ;
if ( m Environment. get StateManager( ) - > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
if ( m StateManager- > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
{
m Environment. get World( ) - > updatePhysics ( frametime , guiActive , frameStart , frameNumber , * stats ) ;
m World- > 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 ( m Environment. get StateManager( ) - > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
if ( m StateManager- > getState ( ) ! = MWBase : : StateManager : : State_NoGame )
{
m Environment. get World( ) - > update ( frametime , guiActive ) ;
m World- > update ( frametime , guiActive ) ;
}
}
// update GUI
{
ScopedProfile < UserStatsType : : Gui > profile ( frameStart , frameNumber , * timer , * stats ) ;
m Environment. get WindowManager( ) - > update ( frametime ) ;
m WindowManager- > 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 )
{
m Environment. setStateManager (
std : : make_unique < MWState : : StateManager > ( mCfgMgr . getUserDataPath ( ) / " saves " , mContentFiles ) ) ;
m StateManager = 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 windowMg r = std : : make_unique < MWGui : : WindowManager > ( mWindow , mViewer , guiRoot , mResourceSystem . get ( ) , mWorkQueue . get ( ) ,
mWindowManage r = 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 ( ) )
m Environment. get WindowManager( ) - > playVideo ( logo , true ) ;
m WindowManager- > playVideo ( logo , true ) ;
}
// Create the world
m Environment. setWorld ( std : : make_unique < MWWorld : : World > ( mViewer , rootNode , mResourceSystem . get ( ) , mWorkQueue . get ( ) ,
m World = 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 ( m Environment. get World( ) - > getStore ( ) ) ;
windowMgrInternal - > initUI ( ) ;
mWindowManager - > setStore ( m World- > 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 = m Environment. get ScriptManager( ) - > compileAll ( ) ;
std : : pair < int , int > result = m ScriptManager- > 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 ( ) )
{
m Environment. get StateManager( ) - > loadGame ( mSaveGameFile ) ;
m StateManager- > loadGame ( mSaveGameFile ) ;
}
else if ( ! mSkipMenu )
{
// start in main menu
m Environment. get WindowManager( ) - > pushGuiMode ( MWGui : : GM_MainMenu ) ;
m Environment. get SoundManager( ) - > playTitleMusic ( ) ;
m WindowManager- > pushGuiMode ( MWGui : : GM_MainMenu ) ;
m SoundManager- > playTitleMusic ( ) ;
const std : : string & logo = Fallback : : Map : : getString ( " Movies_Morrowind_Logo " ) ;
if ( ! logo . empty ( ) )
m Environment. get WindowManager( ) - > playVideo ( logo , true ) ;
m WindowManager- > playVideo ( logo , true ) ;
}
else
{
m Environment. get StateManager( ) - > newGame ( ! mNewGame ) ;
m StateManager- > newGame ( ! mNewGame ) ;
}
if ( ! mStartupScript . empty ( ) & & m Environment. get StateManager( ) - > getState ( ) = = MWState : : StateManager : : State_Running )
if ( ! mStartupScript . empty ( ) & & m StateManager- > getState ( ) = = MWState : : StateManager : : State_Running )
{
m Environment. get WindowManager( ) - > executeInConsole ( mStartupScript ) ;
m WindowManager- > 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 ( ) & & ! m Environment. get StateManager( ) - > hasQuitRequest ( ) )
while ( ! mViewer - > done ( ) & & ! m StateManager- > 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 ( ) ;
m Environment. get World( ) - > updateWindowManager ( ) ;
m World- > 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 = m Environment. get WindowManager( ) - > isGuiMode ( ) ;
bool guiActive = m WindowManager- > isGuiMode ( ) ;
if ( ! guiActive )
simulationTime + = dt ;
}