From 723beb1cac998a92320b83f9ff14aa0d80d86ff4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 26 May 2015 20:20:18 +0200 Subject: [PATCH] Move IncrementalCompileOperation to SceneManager --- apps/openmw/mwgui/loadingscreen.cpp | 3 ++- apps/openmw/mwrender/objects.cpp | 16 ---------------- apps/openmw/mwrender/objects.hpp | 4 ---- apps/openmw/mwrender/renderingmanager.cpp | 3 ++- components/resource/scenemanager.cpp | 12 +++++++++++- components/resource/scenemanager.hpp | 10 ++++++++++ 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 1f084402b..f6a9f5ccd 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -181,7 +181,8 @@ namespace MWGui void LoadingScreen::setProgress (size_t value) { - if (value - mProgress < mProgressBar->getScrollRange()/100.f) + // skip expensive update if there isn't enough visible progress + if (value - mProgress < mProgressBar->getScrollRange()/200.f) return; mProgress = value; mProgressBar->setScrollPosition(0); diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 816002753..47a54fdbf 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -7,8 +7,6 @@ #include #include -#include - #include #include @@ -81,11 +79,6 @@ Objects::~Objects() mCellSceneNodes.clear(); } -void Objects::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico) -{ - mIncrementalCompileOperation = ico; -} - void Objects::insertBegin(const MWWorld::Ptr& ptr) { osg::ref_ptr cellnode; @@ -118,9 +111,6 @@ 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; @@ -144,9 +134,6 @@ 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())); } @@ -157,9 +144,6 @@ 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 b3799d0ef..5c7ea32f4 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -69,14 +69,10 @@ 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 6a1ed89a2..e1f1e13d1 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -17,6 +17,7 @@ #include #include +#include #include @@ -101,7 +102,7 @@ namespace MWRender mViewer->setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation); - mObjects->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation()); + mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation()); mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem)); diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 8a0d526fa..5c3d9f151 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -6,6 +6,8 @@ #include +#include + #include #include @@ -88,7 +90,10 @@ namespace Resource // TODO: add support for non-NIF formats NifOsg::Loader loader; - osg::ref_ptr loaded = loader.load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)), mTextureManager); + osg::ref_ptr loaded = loader.load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)), mTextureManager); + + if (mIncrementalCompileOperation) + mIncrementalCompileOperation->add(loaded); mIndex[normalized] = loaded; return loaded; @@ -147,6 +152,11 @@ namespace Resource } } + void SceneManager::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico) + { + mIncrementalCompileOperation = ico; + } + const VFS::Manager* SceneManager::getVFS() const { return mVFS; diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 9f3c5387e..625c1cd5e 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -24,6 +24,11 @@ namespace NifOsg class KeyframeHolder; } +namespace osgUtil +{ + class IncrementalCompileOperation; +} + namespace Resource { @@ -56,6 +61,9 @@ namespace Resource /// in cases where multiple contexts are used over the lifetime of the application. void releaseGLObjects(osg::State* state); + /// Set up an IncrementalCompileOperation for background compiling of loaded scenes. + void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico); + const VFS::Manager* getVFS() const; Resource::TextureManager* getTextureManager(); @@ -64,6 +72,8 @@ namespace Resource const VFS::Manager* mVFS; Resource::TextureManager* mTextureManager; + osg::ref_ptr mIncrementalCompileOperation; + // observer_ptr? typedef std::map > Index; Index mIndex;