From 5ffb40e8bab4f1891cdec2493d99d5895fb552d6 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 01/10] Don't preload terrain when loading an interior save --- apps/openmw/mwworld/worldimp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index e3658285d..502ff8843 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -409,7 +409,8 @@ namespace MWWorld if (getPlayerPtr().isInCell()) { mWorldScene->preloadCell(getPlayerPtr().getCell(), true); - mWorldScene->preloadTerrain(getPlayerPtr().getRefData().getPosition().asVec3()); + if (getPlayerPtr().getCell()->isExterior()) + mWorldScene->preloadTerrain(getPlayerPtr().getRefData().getPosition().asVec3()); } break; default: From 5bce3cbc6830ce0dfffd7698be4a18ffa55698a7 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 02/10] Don't use MWRender namespace in common terrain components --- components/terrain/cellborder.cpp | 2 +- components/terrain/cellborder.hpp | 3 --- components/terrain/terraingrid.cpp | 2 +- components/terrain/terraingrid.hpp | 2 +- components/terrain/world.cpp | 2 +- components/terrain/world.hpp | 2 +- 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/terrain/cellborder.cpp b/components/terrain/cellborder.cpp index d9e6d52fc..64434727e 100644 --- a/components/terrain/cellborder.cpp +++ b/components/terrain/cellborder.cpp @@ -7,7 +7,7 @@ #include "world.hpp" #include "../esm/loadland.hpp" -namespace MWRender +namespace Terrain { CellBorder::CellBorder(Terrain::World *world, osg::Group *root, int borderMask): diff --git a/components/terrain/cellborder.hpp b/components/terrain/cellborder.hpp index 530ea31ca..908cdea09 100644 --- a/components/terrain/cellborder.hpp +++ b/components/terrain/cellborder.hpp @@ -7,10 +7,7 @@ namespace Terrain { class World; -} -namespace MWRender -{ /** * @Brief Handles the debug cell borders. */ diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index dbc1429da..1888a02b3 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -84,7 +84,7 @@ void TerrainGrid::loadCell(int x, int y) void TerrainGrid::unloadCell(int x, int y) { - MWRender::CellBorder::CellGrid::iterator it = mGrid.find(std::make_pair(x,y)); + CellBorder::CellGrid::iterator it = mGrid.find(std::make_pair(x,y)); if (it == mGrid.end()) return; diff --git a/components/terrain/terraingrid.hpp b/components/terrain/terraingrid.hpp index 87e3b432c..eb30fb97d 100644 --- a/components/terrain/terraingrid.hpp +++ b/components/terrain/terraingrid.hpp @@ -33,7 +33,7 @@ namespace Terrain // split each ESM::Cell into mNumSplits*mNumSplits terrain chunks unsigned int mNumSplits; - MWRender::CellBorder::CellGrid mGrid; + CellBorder::CellGrid mGrid; }; } diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index cc81dbef8..6a8322bb5 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -47,7 +47,7 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager())); mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer)); - mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get(),borderMask)); + mCellBorder.reset(new CellBorder(this,mTerrainRoot.get(),borderMask)); mResourceSystem->addResourceManager(mChunkManager.get()); mResourceSystem->addResourceManager(mTextureManager.get()); diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index da1004783..4fb724ebb 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -116,7 +116,7 @@ namespace Terrain std::unique_ptr mTextureManager; std::unique_ptr mChunkManager; - std::unique_ptr mCellBorder; + std::unique_ptr mCellBorder; bool mBorderVisible; From a567111400ff7ebf93fbd58203b04f417d05be7c Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 03/10] Use emplace instead of find-assign --- components/nifosg/nifloader.cpp | 4 +--- components/sceneutil/visitor.cpp | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index eef678b36..a1aa74cab 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -244,10 +244,8 @@ namespace NifOsg osg::ref_ptr callback(new NifOsg::KeyframeController(key->data.getPtr())); callback->setFunction(std::shared_ptr(new NifOsg::ControllerFunction(key))); - if (target.mKeyframeControllers.find(strdata->string) != target.mKeyframeControllers.end()) + if (!target.mKeyframeControllers.emplace(strdata->string, callback).second) Log(Debug::Verbose) << "Controller " << strdata->string << " present more than once in " << nif->getFilename() << ", ignoring later version"; - else - target.mKeyframeControllers[strdata->string] = callback; } } diff --git a/components/sceneutil/visitor.cpp b/components/sceneutil/visitor.cpp index 3c3559a08..876ea920f 100644 --- a/components/sceneutil/visitor.cpp +++ b/components/sceneutil/visitor.cpp @@ -61,10 +61,7 @@ namespace SceneUtil { // Take transformation for first found node in file const std::string nodeName = Misc::StringUtils::lowerCase(trans.getName()); - if (mMap.find(nodeName) == mMap.end()) - { - mMap[nodeName] = &trans; - } + mMap.emplace(nodeName, &trans); traverse(trans); } From 8c649f05e60963e5f250dde8e0dd3adcc22037d7 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 04/10] Don't reallocate light list vector unnecessarily --- components/sceneutil/lightmanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index cb6a12c87..f0fd0ef9f 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -234,6 +234,7 @@ namespace SceneUtil { osg::ref_ptr stateset = new osg::StateSet; std::vector > lights; + lights.reserve(lightList.size()); for (unsigned int i=0; imLightSource->getLight(frameNum)); From bcbee08a1be469eb11708485525ce1d3c652c1ff Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 05/10] Fix creature model instance preloading --- apps/openmw/mwrender/animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4b0eec7b9..f6df24358 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1436,7 +1436,7 @@ namespace MWRender return sceneMgr->createInstance(found->second); } else - return sceneMgr->createInstance(model); + return sceneMgr->getInstance(model); } void Animation::setObjectRoot(const std::string &model, bool forceskeleton, bool baseonly, bool isCreature) From aecbc2f01c098eda8acec02f025516647ead89b0 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 06/10] Fix crash when incremental compile operation is not used --- components/resource/scenemanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 328a10cd1..d360e92b1 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -729,6 +729,7 @@ namespace Resource void SceneManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const { + if (mIncrementalCompileOperation) { OpenThreads::ScopedLock lock(*mIncrementalCompileOperation->getToCompiledMutex()); stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size()); From 4f387fdf1cf99629fc0177b5a1fa79381db57eff Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 07/10] Prune empty quad tree nodes --- components/terrain/quadtreeworld.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 6ec89721a..0c99ca66d 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -163,7 +163,10 @@ public: boundingBox.expandBy(child->getBoundingBox()); } - parent->setBoundingBox(boundingBox); + if (!boundingBox.valid()) + parent->removeChildren(0, 4); + else + parent->setBoundingBox(boundingBox); } QuadTreeNode* addChild(QuadTreeNode* parent, ChildDirection direction, float size) From 172cb747633467f0afe029b54a82e56b5e098423 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 08/10] Delete composite map layers on demand --- components/terrain/compositemaprenderer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 3dc0aa41c..0ef649197 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -122,6 +122,8 @@ void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo & ++compositeMap.mCompiled; + compositeMap.mDrawables[i] = nullptr; + if (timeLeft) { *timeLeft -= timer.time_s(); @@ -131,6 +133,8 @@ void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo & break; } } + if (compositeMap.mCompiled == compositeMap.mDrawables.size()) + compositeMap.mDrawables = std::vector>(); state.haveAppliedAttribute(osg::StateAttribute::VIEWPORT); From b2000b7642d9361800ede31984b8d37614d50766 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 09/10] Fix quad tree node child bounding box dimensions --- components/terrain/quadtreeworld.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 0c99ca66d..594b2b755 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -171,20 +171,21 @@ public: QuadTreeNode* addChild(QuadTreeNode* parent, ChildDirection direction, float size) { + float halfSize = size/2.f; osg::Vec2f center; switch (direction) { case SW: - center = parent->getCenter() + osg::Vec2f(-size/2.f,-size/2.f); + center = parent->getCenter() + osg::Vec2f(-halfSize,-halfSize); break; case SE: - center = parent->getCenter() + osg::Vec2f(size/2.f, -size/2.f); + center = parent->getCenter() + osg::Vec2f(halfSize, -halfSize); break; case NW: - center = parent->getCenter() + osg::Vec2f(-size/2.f, size/2.f); + center = parent->getCenter() + osg::Vec2f(-halfSize, halfSize); break; case NE: - center = parent->getCenter() + osg::Vec2f(size/2.f, size/2.f); + center = parent->getCenter() + osg::Vec2f(halfSize, halfSize); break; default: break; @@ -206,8 +207,8 @@ public: mStorage->getMinMaxHeights(size, center, minZ, maxZ); float cellWorldSize = mStorage->getCellWorldSize(); - osg::BoundingBox boundingBox(osg::Vec3f((center.x()-size)*cellWorldSize, (center.y()-size)*cellWorldSize, minZ), - osg::Vec3f((center.x()+size)*cellWorldSize, (center.y()+size)*cellWorldSize, maxZ)); + osg::BoundingBox boundingBox(osg::Vec3f((center.x()-halfSize)*cellWorldSize, (center.y()-halfSize)*cellWorldSize, minZ), + osg::Vec3f((center.x()+halfSize)*cellWorldSize, (center.y()+halfSize)*cellWorldSize, maxZ)); node->setBoundingBox(boundingBox); return node; From 567ad293fdf4f5d58d2520d0b0c8fbc0080bccef Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 10/10] Don't discard object cache with uninitialized timestamp This can happen during terrain loading --- components/resource/objectcache.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/resource/objectcache.cpp b/components/resource/objectcache.cpp index e8c082f91..ffe150c74 100644 --- a/components/resource/objectcache.cpp +++ b/components/resource/objectcache.cpp @@ -75,10 +75,11 @@ void ObjectCache::updateTimeStampOfObjectsInCacheWithExternalReferences(double r itr!=_objectCache.end(); ++itr) { - // if ref count is greater the 1 the object has an external reference. - if (itr->second.first->referenceCount()>1) + // If ref count is greater than 1, the object has an external reference. + // If the timestamp is yet to be initialized, it needs to be updated too. + if (itr->second.first->referenceCount()>1 || itr->second.second == 0.0) { - // so update it time stamp. + // So update it. itr->second.second = referenceTime; } }