diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5be9317eb..d7ad97e6e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -391,8 +391,6 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings) mEnvironment.setJournal (new MWDialogue::Journal); mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage)); - //mOgre->getRoot()->addFrameListener (this); - // scripts if (mCompileAll) { @@ -466,13 +464,12 @@ void OMW::Engine::go() mViewer->setCameraManipulator(new osgGA::TrackballManipulator); mViewer->addEventHandler(new osgViewer::StatsHandler); - mViewer->realize(); osg::Timer frameTimer; while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { double dt = frameTimer.time_s(); frameTimer.setStartTick(); - //dt = std::min(dt, 0.2f); + //dt = std::min(dt, 0.2); frame(dt); mViewer->frame(/*simulationTime*/); diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index a7791d838..45bd5bf9d 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -30,8 +30,9 @@ namespace MWGui : WindowBase("openmw_loading_screen.layout") , mVFS(vfs) , mViewer(viewer) - , mLastRenderTime(0.0) , mLastWallpaperChangeTime(0.0) + , mLastRenderTime(0.0) + , mLoadingOnTime(0.0) , mProgress(0) , mVSyncWasEnabled(false) { @@ -97,6 +98,7 @@ namespace MWGui void LoadingScreen::loadingOn() { + mLoadingOnTime = mTimer.time_m(); // Early-out if already on if (mMainWidget->getVisible()) return; @@ -143,6 +145,7 @@ namespace MWGui void LoadingScreen::loadingOff() { + //std::cout << "loading took " << mTimer.time_m() - mLoadingOnTime << std::endl; setVisible(false); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Loading); @@ -215,6 +218,8 @@ namespace MWGui changeWallpaper(); } + mViewer->getIncrementalCompileOperation()->setMaximumNumOfObjectsToCompilePerFrame(80); + // Turn off rendering except the GUI int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask(); int oldCullMask = mViewer->getCamera()->getCullMask(); @@ -223,6 +228,8 @@ namespace MWGui MWBase::Environment::get().getInputManager()->update(0, true, true); + //std::cout << "num to compile " << mViewer->getIncrementalCompileOperation()->getToCompile().size() << std::endl; + mViewer->frame(); // resume 3d rendering diff --git a/apps/openmw/mwgui/loadingscreen.hpp b/apps/openmw/mwgui/loadingscreen.hpp index 4c9d45f66..7c49df027 100644 --- a/apps/openmw/mwgui/loadingscreen.hpp +++ b/apps/openmw/mwgui/loadingscreen.hpp @@ -53,6 +53,7 @@ namespace MWGui double mLastWallpaperChangeTime; double mLastRenderTime; osg::Timer mTimer; + double mLoadingOnTime; size_t mProgress; diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 6f4f4ef79..69311c111 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include #include @@ -78,6 +80,11 @@ Objects::~Objects() mCellSceneNodes.clear(); } +void Objects::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico) +{ + mIncrementalCompileOperation = ico; +} + void Objects::insertBegin(const MWWorld::Ptr& ptr) { osg::ref_ptr cellnode; @@ -108,6 +115,9 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool std::auto_ptr anim (new ObjectAnimation(ptr, mesh, mResourceSystem, allowLight)); + if (mIncrementalCompileOperation && anim->getObjectRoot()) + mIncrementalCompileOperation->add(anim->getObjectRoot()); + if (!allowLight) { RemoveParticlesVisitor visitor; @@ -130,6 +140,9 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b else anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem)); + if (mIncrementalCompileOperation && anim->getObjectRoot()) + mIncrementalCompileOperation->add(anim->getObjectRoot()); + mObjects.insert(std::make_pair(ptr, anim.release())); } @@ -139,6 +152,9 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr) std::auto_ptr anim (new NpcAnimation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), mResourceSystem, 0)); + if (mIncrementalCompileOperation && anim->getObjectRoot()) + mIncrementalCompileOperation->add(anim->getObjectRoot()); + mObjects.insert(std::make_pair(ptr, anim.release())); } diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 2acf10d10..fd6ceab54 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -12,6 +12,11 @@ namespace osg class Group; } +namespace osgUtil +{ + class IncrementalCompileOperation; +} + namespace Resource { class ResourceSystem; @@ -41,10 +46,14 @@ class Objects{ Resource::ResourceSystem* mResourceSystem; + osg::ref_ptr mIncrementalCompileOperation; + public: Objects(Resource::ResourceSystem* resourceSystem, osg::ref_ptr rootNode); ~Objects(); + void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico); + /// @param animated Attempt to load separate keyframes from a .kf file matching the model file? /// @param allowLight If false, no lights will be created, and particles systems will be removed. void insertModel(const MWWorld::Ptr& ptr, const std::string &model, bool animated=false, bool allowLight=true); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 5cb779545..4f13df8e7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -95,6 +97,10 @@ namespace MWRender mObjects.reset(new Objects(mResourceSystem, lightRoot)); + mViewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation); + + mObjects->setIncrementalCompileOperation(mViewer.getIncrementalCompileOperation()); + mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem)); mViewer.setLightingMode(osgViewer::View::NO_LIGHT);