From 12f9184d003c1180cd2b75574dc5fc3319d224ab Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 9 Mar 2019 13:13:39 +0400 Subject: [PATCH] Allow to interrupt terrain preloading --- apps/openmw/mwworld/cellpreloader.cpp | 2 +- components/terrain/quadtreeworld.cpp | 4 ++-- components/terrain/quadtreeworld.hpp | 2 +- components/terrain/world.hpp | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 65ba19b4ac..98e9c73684 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -381,7 +381,7 @@ namespace MWWorld { for (unsigned int i=0; ipreload(mTerrainViews[i], mPreloadPositions[i]); + mWorld->preload(mTerrainViews[i], mPreloadPositions[i], mAbort); mTerrainViews[i]->reset(0); } } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 8d54f62ce2..fa3972a34a 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -478,14 +478,14 @@ View* QuadTreeWorld::createView() return new ViewData; } -void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint) +void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint, std::atomic &abort) { ensureQuadTreeBuilt(); ViewData* vd = static_cast(view); traverse(mRootNode.get(), vd, nullptr, mRootNode->getLodCallback(), eyePoint, false); - for (unsigned int i=0; igetNumEntries(); ++i) + for (unsigned int i=0; igetNumEntries() && !abort; ++i) { ViewData::Entry& entry = vd->getEntry(i); loadRenderingNode(entry, vd, mVertexLodMod, mChunkManager.get()); diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index f724c44b1c..b2c0b4f14d 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -30,7 +30,7 @@ namespace Terrain void cacheCell(View *view, int x, int y); View* createView(); - void preload(View* view, const osg::Vec3f& eyePoint); + void preload(View* view, const osg::Vec3f& eyePoint, std::atomic& abort); void reportStats(unsigned int frameNumber, osg::Stats* stats); diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index 4fb724ebbf..d5d4e245ca 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -93,7 +94,7 @@ namespace Terrain virtual View* createView() { return nullptr; } /// @note Thread safe, as long as you do not attempt to load into the same view from multiple threads. - virtual void preload(View* view, const osg::Vec3f& eyePoint) {} + virtual void preload(View* view, const osg::Vec3f& eyePoint, std::atomic& abort) {} virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) {}