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) 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: 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/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; } } 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()); 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)); 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); } 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/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); diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 6ec89721a..594b2b755 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -163,25 +163,29 @@ 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) { + 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; @@ -203,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; 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;