forked from teamnwah/openmw-tes3coop
Move global map render to the worker thread
This commit is contained in:
parent
026a05718f
commit
72c6b11cf8
7 changed files with 218 additions and 141 deletions
|
@ -496,7 +496,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||||
guiRoot->setName("GUI Root");
|
guiRoot->setName("GUI Root");
|
||||||
guiRoot->setNodeMask(MWRender::Mask_GUI);
|
guiRoot->setNodeMask(MWRender::Mask_GUI);
|
||||||
rootNode->addChild(guiRoot);
|
rootNode->addChild(guiRoot);
|
||||||
MWGui::WindowManager* window = new MWGui::WindowManager(mViewer, guiRoot, mResourceSystem.get(),
|
MWGui::WindowManager* window = new MWGui::WindowManager(mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
|
||||||
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
|
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
|
||||||
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap,
|
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap,
|
||||||
Version::getOpenmwVersionDescription(mResDir.string()));
|
Version::getOpenmwVersionDescription(mResDir.string()));
|
||||||
|
|
|
@ -622,7 +622,7 @@ namespace MWGui
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
MapWindow::MapWindow(CustomMarkerCollection &customMarkers, DragAndDrop* drag, MWRender::LocalMap* localMapRender)
|
MapWindow::MapWindow(CustomMarkerCollection &customMarkers, DragAndDrop* drag, MWRender::LocalMap* localMapRender, SceneUtil::WorkQueue* workQueue)
|
||||||
: WindowPinnableBase("openmw_map_window.layout")
|
: WindowPinnableBase("openmw_map_window.layout")
|
||||||
, LocalMapBase(customMarkers, localMapRender)
|
, LocalMapBase(customMarkers, localMapRender)
|
||||||
, NoDrop(drag, mMainWidget)
|
, NoDrop(drag, mMainWidget)
|
||||||
|
@ -632,7 +632,7 @@ namespace MWGui
|
||||||
, mGlobal(false)
|
, mGlobal(false)
|
||||||
, mEventBoxGlobal(NULL)
|
, mEventBoxGlobal(NULL)
|
||||||
, mEventBoxLocal(NULL)
|
, mEventBoxLocal(NULL)
|
||||||
, mGlobalMapRender(new MWRender::GlobalMap(localMapRender->getRoot()))
|
, mGlobalMapRender(new MWRender::GlobalMap(localMapRender->getRoot(), workQueue))
|
||||||
, mEditNoteDialog()
|
, mEditNoteDialog()
|
||||||
{
|
{
|
||||||
static bool registered = false;
|
static bool registered = false;
|
||||||
|
@ -774,19 +774,11 @@ namespace MWGui
|
||||||
mLastScrollWindowCoordinates = currentCoordinates;
|
mLastScrollWindowCoordinates = currentCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::renderGlobalMap(Loading::Listener* loadingListener)
|
void MapWindow::renderGlobalMap()
|
||||||
{
|
{
|
||||||
mGlobalMapRender->render(loadingListener);
|
mGlobalMapRender->render();
|
||||||
mGlobalMap->setCanvasSize (mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
mGlobalMap->setCanvasSize (mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
||||||
mGlobalMapImage->setSize(mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
mGlobalMapImage->setSize(mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
||||||
|
|
||||||
mGlobalMapTexture.reset(new osgMyGUI::OSGTexture(mGlobalMapRender->getBaseTexture()));
|
|
||||||
mGlobalMapImage->setRenderItemTexture(mGlobalMapTexture.get());
|
|
||||||
mGlobalMapImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
|
||||||
|
|
||||||
mGlobalMapOverlayTexture.reset(new osgMyGUI::OSGTexture(mGlobalMapRender->getOverlayTexture()));
|
|
||||||
mGlobalMapOverlay->setRenderItemTexture(mGlobalMapOverlayTexture.get());
|
|
||||||
mGlobalMapOverlay->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapWindow::~MapWindow()
|
MapWindow::~MapWindow()
|
||||||
|
@ -940,6 +932,8 @@ namespace MWGui
|
||||||
|
|
||||||
void MapWindow::open()
|
void MapWindow::open()
|
||||||
{
|
{
|
||||||
|
ensureGlobalMapLoaded();
|
||||||
|
|
||||||
globalMapUpdatePlayer();
|
globalMapUpdatePlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -984,6 +978,20 @@ namespace MWGui
|
||||||
rotatingSubskin->setAngle(angle);
|
rotatingSubskin->setAngle(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWindow::ensureGlobalMapLoaded()
|
||||||
|
{
|
||||||
|
if (!mGlobalMapTexture.get())
|
||||||
|
{
|
||||||
|
mGlobalMapTexture.reset(new osgMyGUI::OSGTexture(mGlobalMapRender->getBaseTexture()));
|
||||||
|
mGlobalMapImage->setRenderItemTexture(mGlobalMapTexture.get());
|
||||||
|
mGlobalMapImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
||||||
|
|
||||||
|
mGlobalMapOverlayTexture.reset(new osgMyGUI::OSGTexture(mGlobalMapRender->getOverlayTexture()));
|
||||||
|
mGlobalMapOverlay->setRenderItemTexture(mGlobalMapOverlayTexture.get());
|
||||||
|
mGlobalMapOverlay->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MapWindow::clear()
|
void MapWindow::clear()
|
||||||
{
|
{
|
||||||
mMarkers.clear();
|
mMarkers.clear();
|
||||||
|
|
|
@ -33,6 +33,11 @@ namespace Loading
|
||||||
class Listener;
|
class Listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SceneUtil
|
||||||
|
{
|
||||||
|
class WorkQueue;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -193,14 +198,14 @@ namespace MWGui
|
||||||
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
|
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapWindow(CustomMarkerCollection& customMarkers, DragAndDrop* drag, MWRender::LocalMap* localMapRender);
|
MapWindow(CustomMarkerCollection& customMarkers, DragAndDrop* drag, MWRender::LocalMap* localMapRender, SceneUtil::WorkQueue* workQueue);
|
||||||
virtual ~MapWindow();
|
virtual ~MapWindow();
|
||||||
|
|
||||||
void setCellName(const std::string& cellName);
|
void setCellName(const std::string& cellName);
|
||||||
|
|
||||||
virtual void setAlpha(float alpha);
|
virtual void setAlpha(float alpha);
|
||||||
|
|
||||||
void renderGlobalMap(Loading::Listener* loadingListener);
|
void renderGlobalMap();
|
||||||
|
|
||||||
/// adds the marker to the global map
|
/// adds the marker to the global map
|
||||||
/// @param name The ESM::Cell::mName
|
/// @param name The ESM::Cell::mName
|
||||||
|
@ -212,6 +217,8 @@ namespace MWGui
|
||||||
void setGlobalMapPlayerPosition (float worldX, float worldY);
|
void setGlobalMapPlayerPosition (float worldX, float worldY);
|
||||||
void setGlobalMapPlayerDir(const float x, const float y);
|
void setGlobalMapPlayerDir(const float x, const float y);
|
||||||
|
|
||||||
|
void ensureGlobalMapLoaded();
|
||||||
|
|
||||||
virtual void open();
|
virtual void open();
|
||||||
|
|
||||||
void onFrame(float dt);
|
void onFrame(float dt);
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include <components/resource/resourcesystem.hpp>
|
#include <components/resource/resourcesystem.hpp>
|
||||||
#include <components/resource/imagemanager.hpp>
|
#include <components/resource/imagemanager.hpp>
|
||||||
|
|
||||||
|
#include <components/sceneutil/workqueue.hpp>
|
||||||
|
|
||||||
#include <components/translation/translation.hpp>
|
#include <components/translation/translation.hpp>
|
||||||
|
|
||||||
#include <components/myguiplatform/myguiplatform.hpp>
|
#include <components/myguiplatform/myguiplatform.hpp>
|
||||||
|
@ -115,11 +117,12 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
|
|
||||||
WindowManager::WindowManager(
|
WindowManager::WindowManager(
|
||||||
osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem
|
osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||||
, const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts,
|
const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts,
|
||||||
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap, const std::string& versionDescription)
|
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap, const std::string& versionDescription)
|
||||||
: mStore(NULL)
|
: mStore(NULL)
|
||||||
, mResourceSystem(resourceSystem)
|
, mResourceSystem(resourceSystem)
|
||||||
|
, mWorkQueue(workQueue)
|
||||||
, mViewer(viewer)
|
, mViewer(viewer)
|
||||||
, mConsoleOnlyScripts(consoleOnlyScripts)
|
, mConsoleOnlyScripts(consoleOnlyScripts)
|
||||||
, mCurrentModals()
|
, mCurrentModals()
|
||||||
|
@ -285,7 +288,7 @@ namespace MWGui
|
||||||
mRecharge = new Recharge();
|
mRecharge = new Recharge();
|
||||||
mMenu = new MainMenu(w, h, mResourceSystem->getVFS(), mVersionDescription);
|
mMenu = new MainMenu(w, h, mResourceSystem->getVFS(), mVersionDescription);
|
||||||
mLocalMapRender = new MWRender::LocalMap(mViewer->getSceneData()->asGroup());
|
mLocalMapRender = new MWRender::LocalMap(mViewer->getSceneData()->asGroup());
|
||||||
mMap = new MapWindow(mCustomMarkers, mDragAndDrop, mLocalMapRender);
|
mMap = new MapWindow(mCustomMarkers, mDragAndDrop, mLocalMapRender, mWorkQueue);
|
||||||
trackWindow(mMap, "map");
|
trackWindow(mMap, "map");
|
||||||
mStatsWindow = new StatsWindow(mDragAndDrop);
|
mStatsWindow = new StatsWindow(mDragAndDrop);
|
||||||
trackWindow(mStatsWindow, "stats");
|
trackWindow(mStatsWindow, "stats");
|
||||||
|
@ -373,7 +376,7 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::renderWorldMap()
|
void WindowManager::renderWorldMap()
|
||||||
{
|
{
|
||||||
mMap->renderGlobalMap(mLoadingScreen);
|
mMap->renderGlobalMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::setNewGame(bool newgame)
|
void WindowManager::setNewGame(bool newgame)
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
@ -57,6 +59,11 @@ namespace Resource
|
||||||
class ResourceSystem;
|
class ResourceSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SceneUtil
|
||||||
|
{
|
||||||
|
class WorkQueue;
|
||||||
|
}
|
||||||
|
|
||||||
namespace SDLUtil
|
namespace SDLUtil
|
||||||
{
|
{
|
||||||
class SDLCursorManager;
|
class SDLCursorManager;
|
||||||
|
@ -119,7 +126,7 @@ namespace MWGui
|
||||||
typedef std::pair<std::string, int> Faction;
|
typedef std::pair<std::string, int> Faction;
|
||||||
typedef std::vector<Faction> FactionList;
|
typedef std::vector<Faction> FactionList;
|
||||||
|
|
||||||
WindowManager(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem,
|
WindowManager(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||||
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
|
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
|
||||||
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap, const std::string& versionDescription);
|
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap, const std::string& versionDescription);
|
||||||
virtual ~WindowManager();
|
virtual ~WindowManager();
|
||||||
|
@ -382,6 +389,7 @@ namespace MWGui
|
||||||
private:
|
private:
|
||||||
const MWWorld::ESMStore* mStore;
|
const MWWorld::ESMStore* mStore;
|
||||||
Resource::ResourceSystem* mResourceSystem;
|
Resource::ResourceSystem* mResourceSystem;
|
||||||
|
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
|
||||||
|
|
||||||
osgMyGUI::Platform* mGuiPlatform;
|
osgMyGUI::Platform* mGuiPlatform;
|
||||||
osgViewer::Viewer* mViewer;
|
osgViewer::Viewer* mViewer;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
#include <components/files/memorystream.hpp>
|
#include <components/files/memorystream.hpp>
|
||||||
|
|
||||||
|
#include <components/sceneutil/workqueue.hpp>
|
||||||
|
|
||||||
#include <components/esm/globalmap.hpp>
|
#include <components/esm/globalmap.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
@ -95,52 +97,16 @@ namespace
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
GlobalMap::GlobalMap(osg::Group* root)
|
class CreateMapWorkItem : public SceneUtil::WorkItem
|
||||||
: mRoot(root)
|
{
|
||||||
, mWidth(0)
|
public:
|
||||||
, mHeight(0)
|
CreateMapWorkItem(int width, int height, int minX, int minY, int maxX, int maxY, int cellSize, const MWWorld::Store<ESM::Land>& landStore)
|
||||||
, mMinX(0), mMaxX(0)
|
: mWidth(width), mHeight(height), mMinX(minX), mMinY(minY), mMaxX(maxX), mMaxY(maxY), mCellSize(cellSize), mLandStore(landStore)
|
||||||
, mMinY(0), mMaxY(0)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
mCellSize = Settings::Manager::getInt("global map cell size", "Map");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalMap::~GlobalMap()
|
virtual void doWork()
|
||||||
{
|
{
|
||||||
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
|
|
||||||
removeCamera(*it);
|
|
||||||
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
|
|
||||||
removeCamera(*it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalMap::render (Loading::Listener* loadingListener)
|
|
||||||
{
|
|
||||||
const MWWorld::ESMStore &esmStore =
|
|
||||||
MWBase::Environment::get().getWorld()->getStore();
|
|
||||||
|
|
||||||
// get the size of the world
|
|
||||||
MWWorld::Store<ESM::Cell>::iterator it = esmStore.get<ESM::Cell>().extBegin();
|
|
||||||
for (; it != esmStore.get<ESM::Cell>().extEnd(); ++it)
|
|
||||||
{
|
|
||||||
if (it->getGridX() < mMinX)
|
|
||||||
mMinX = it->getGridX();
|
|
||||||
if (it->getGridX() > mMaxX)
|
|
||||||
mMaxX = it->getGridX();
|
|
||||||
if (it->getGridY() < mMinY)
|
|
||||||
mMinY = it->getGridY();
|
|
||||||
if (it->getGridY() > mMaxY)
|
|
||||||
mMaxY = it->getGridY();
|
|
||||||
}
|
|
||||||
|
|
||||||
mWidth = mCellSize*(mMaxX-mMinX+1);
|
|
||||||
mHeight = mCellSize*(mMaxY-mMinY+1);
|
|
||||||
|
|
||||||
loadingListener->loadingOn();
|
|
||||||
loadingListener->setLabel("Creating map");
|
|
||||||
loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1));
|
|
||||||
loadingListener->setProgress(0);
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||||
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
||||||
unsigned char* data = image->data();
|
unsigned char* data = image->data();
|
||||||
|
@ -153,7 +119,7 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
for (int y = mMinY; y <= mMaxY; ++y)
|
for (int y = mMinY; y <= mMaxY; ++y)
|
||||||
{
|
{
|
||||||
const ESM::Land* land = esmStore.get<ESM::Land>().search (x,y);
|
const ESM::Land* land = mLandStore.search (x,y);
|
||||||
|
|
||||||
for (int cellY=0; cellY<mCellSize; ++cellY)
|
for (int cellY=0; cellY<mCellSize; ++cellY)
|
||||||
{
|
{
|
||||||
|
@ -207,7 +173,6 @@ namespace MWRender
|
||||||
alphaData[texelY * mWidth+ texelX] = (y2 < 0) ? static_cast<unsigned char>(0) : static_cast<unsigned char>(255);
|
alphaData[texelY * mWidth+ texelX] = (y2 < 0) ? static_cast<unsigned char>(0) : static_cast<unsigned char>(255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadingListener->increaseProgress();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,9 +192,78 @@ namespace MWRender
|
||||||
mAlphaTexture->setImage(alphaImage);
|
mAlphaTexture->setImage(alphaImage);
|
||||||
mAlphaTexture->setResizeNonPowerOfTwoHint(false);
|
mAlphaTexture->setResizeNonPowerOfTwoHint(false);
|
||||||
|
|
||||||
clear();
|
mOverlayImage = new osg::Image;
|
||||||
|
mOverlayImage->allocateImage(mWidth, mHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||||
|
assert(mOverlayImage->isDataContiguous());
|
||||||
|
|
||||||
loadingListener->loadingOff();
|
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
||||||
|
|
||||||
|
mOverlayTexture = new osg::Texture2D;
|
||||||
|
mOverlayTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||||
|
mOverlayTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||||
|
mOverlayTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
||||||
|
mOverlayTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||||
|
mOverlayTexture->setResizeNonPowerOfTwoHint(false);
|
||||||
|
mOverlayTexture->setInternalFormat(GL_RGBA);
|
||||||
|
mOverlayTexture->setTextureSize(mWidth, mHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mWidth, mHeight;
|
||||||
|
int mMinX, mMinY, mMaxX, mMaxY;
|
||||||
|
int mCellSize;
|
||||||
|
const MWWorld::Store<ESM::Land>& mLandStore;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Texture2D> mBaseTexture;
|
||||||
|
osg::ref_ptr<osg::Texture2D> mAlphaTexture;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Image> mOverlayImage;
|
||||||
|
osg::ref_ptr<osg::Texture2D> mOverlayTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
GlobalMap::GlobalMap(osg::Group* root, SceneUtil::WorkQueue* workQueue)
|
||||||
|
: mRoot(root)
|
||||||
|
, mWorkQueue(workQueue)
|
||||||
|
, mWidth(0)
|
||||||
|
, mHeight(0)
|
||||||
|
, mMinX(0), mMaxX(0)
|
||||||
|
, mMinY(0), mMaxY(0)
|
||||||
|
|
||||||
|
{
|
||||||
|
mCellSize = Settings::Manager::getInt("global map cell size", "Map");
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalMap::~GlobalMap()
|
||||||
|
{
|
||||||
|
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
|
||||||
|
removeCamera(*it);
|
||||||
|
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
|
||||||
|
removeCamera(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalMap::render ()
|
||||||
|
{
|
||||||
|
const MWWorld::ESMStore &esmStore =
|
||||||
|
MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
|
||||||
|
// get the size of the world
|
||||||
|
MWWorld::Store<ESM::Cell>::iterator it = esmStore.get<ESM::Cell>().extBegin();
|
||||||
|
for (; it != esmStore.get<ESM::Cell>().extEnd(); ++it)
|
||||||
|
{
|
||||||
|
if (it->getGridX() < mMinX)
|
||||||
|
mMinX = it->getGridX();
|
||||||
|
if (it->getGridX() > mMaxX)
|
||||||
|
mMaxX = it->getGridX();
|
||||||
|
if (it->getGridY() < mMinY)
|
||||||
|
mMinY = it->getGridY();
|
||||||
|
if (it->getGridY() > mMaxY)
|
||||||
|
mMaxY = it->getGridY();
|
||||||
|
}
|
||||||
|
|
||||||
|
mWidth = mCellSize*(mMaxX-mMinX+1);
|
||||||
|
mHeight = mCellSize*(mMaxY-mMinY+1);
|
||||||
|
|
||||||
|
mWorkItem = new CreateMapWorkItem(mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, mCellSize, esmStore.get<ESM::Land>());
|
||||||
|
mWorkQueue->addWorkItem(mWorkItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
|
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
|
||||||
|
@ -334,6 +368,8 @@ namespace MWRender
|
||||||
|
|
||||||
void GlobalMap::exploreCell(int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture)
|
void GlobalMap::exploreCell(int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture)
|
||||||
{
|
{
|
||||||
|
ensureLoaded();
|
||||||
|
|
||||||
if (!localMapTexture)
|
if (!localMapTexture)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -348,25 +384,9 @@ namespace MWRender
|
||||||
|
|
||||||
void GlobalMap::clear()
|
void GlobalMap::clear()
|
||||||
{
|
{
|
||||||
if (!mOverlayImage)
|
ensureLoaded();
|
||||||
{
|
|
||||||
mOverlayImage = new osg::Image;
|
|
||||||
mOverlayImage->allocateImage(mWidth, mHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
|
||||||
assert(mOverlayImage->isDataContiguous());
|
|
||||||
}
|
|
||||||
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
|
||||||
|
|
||||||
if (!mOverlayTexture)
|
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
||||||
{
|
|
||||||
mOverlayTexture = new osg::Texture2D;
|
|
||||||
mOverlayTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
||||||
mOverlayTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
||||||
mOverlayTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
||||||
mOverlayTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
||||||
mOverlayTexture->setResizeNonPowerOfTwoHint(false);
|
|
||||||
mOverlayTexture->setInternalFormat(GL_RGBA);
|
|
||||||
mOverlayTexture->setTextureSize(mWidth, mHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
mPendingImageDest.clear();
|
mPendingImageDest.clear();
|
||||||
|
|
||||||
|
@ -377,6 +397,8 @@ namespace MWRender
|
||||||
|
|
||||||
void GlobalMap::write(ESM::GlobalMap& map)
|
void GlobalMap::write(ESM::GlobalMap& map)
|
||||||
{
|
{
|
||||||
|
ensureLoaded();
|
||||||
|
|
||||||
map.mBounds.mMinX = mMinX;
|
map.mBounds.mMinX = mMinX;
|
||||||
map.mBounds.mMaxX = mMaxX;
|
map.mBounds.mMaxX = mMaxX;
|
||||||
map.mBounds.mMinY = mMinY;
|
map.mBounds.mMinY = mMinY;
|
||||||
|
@ -417,6 +439,8 @@ namespace MWRender
|
||||||
|
|
||||||
void GlobalMap::read(ESM::GlobalMap& map)
|
void GlobalMap::read(ESM::GlobalMap& map)
|
||||||
{
|
{
|
||||||
|
ensureLoaded();
|
||||||
|
|
||||||
const ESM::GlobalMap::Bounds& bounds = map.mBounds;
|
const ESM::GlobalMap::Bounds& bounds = map.mBounds;
|
||||||
|
|
||||||
if (bounds.mMaxX-bounds.mMinX < 0)
|
if (bounds.mMaxX-bounds.mMinX < 0)
|
||||||
|
@ -513,14 +537,33 @@ namespace MWRender
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> GlobalMap::getBaseTexture()
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getBaseTexture()
|
||||||
{
|
{
|
||||||
|
ensureLoaded();
|
||||||
return mBaseTexture;
|
return mBaseTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> GlobalMap::getOverlayTexture()
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getOverlayTexture()
|
||||||
{
|
{
|
||||||
|
ensureLoaded();
|
||||||
return mOverlayTexture;
|
return mOverlayTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlobalMap::ensureLoaded()
|
||||||
|
{
|
||||||
|
if (mWorkItem)
|
||||||
|
{
|
||||||
|
mWorkItem->waitTillDone();
|
||||||
|
|
||||||
|
mOverlayImage = mWorkItem->mOverlayImage;
|
||||||
|
mBaseTexture = mWorkItem->mBaseTexture;
|
||||||
|
mAlphaTexture = mWorkItem->mAlphaTexture;
|
||||||
|
mOverlayTexture = mWorkItem->mOverlayTexture;
|
||||||
|
|
||||||
|
requestOverlayTextureUpdate(0, 0, mWidth, mHeight, osg::ref_ptr<osg::Texture2D>(), true, false);
|
||||||
|
|
||||||
|
mWorkItem = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GlobalMap::markForRemoval(osg::Camera *camera)
|
void GlobalMap::markForRemoval(osg::Camera *camera)
|
||||||
{
|
{
|
||||||
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera);
|
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera);
|
||||||
|
@ -549,6 +592,7 @@ namespace MWRender
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureLoaded();
|
||||||
mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage);
|
mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage);
|
||||||
|
|
||||||
it = mPendingImageDest.erase(it);
|
it = mPendingImageDest.erase(it);
|
||||||
|
|
|
@ -14,26 +14,28 @@ namespace osg
|
||||||
class Camera;
|
class Camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Loading
|
|
||||||
{
|
|
||||||
class Listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
struct GlobalMap;
|
struct GlobalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SceneUtil
|
||||||
|
{
|
||||||
|
class WorkQueue;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class CreateMapWorkItem;
|
||||||
|
|
||||||
class GlobalMap
|
class GlobalMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlobalMap(osg::Group* root);
|
GlobalMap(osg::Group* root, SceneUtil::WorkQueue* workQueue);
|
||||||
~GlobalMap();
|
~GlobalMap();
|
||||||
|
|
||||||
void render(Loading::Listener* loadingListener);
|
void render();
|
||||||
|
|
||||||
int getWidth() const { return mWidth; }
|
int getWidth() const { return mWidth; }
|
||||||
int getHeight() const { return mHeight; }
|
int getHeight() const { return mHeight; }
|
||||||
|
@ -69,6 +71,8 @@ namespace MWRender
|
||||||
osg::ref_ptr<osg::Texture2D> getBaseTexture();
|
osg::ref_ptr<osg::Texture2D> getBaseTexture();
|
||||||
osg::ref_ptr<osg::Texture2D> getOverlayTexture();
|
osg::ref_ptr<osg::Texture2D> getOverlayTexture();
|
||||||
|
|
||||||
|
void ensureLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Request rendering a 2d quad onto mOverlayTexture.
|
* Request rendering a 2d quad onto mOverlayTexture.
|
||||||
|
@ -116,6 +120,9 @@ namespace MWRender
|
||||||
// CPU copy of overlay
|
// CPU copy of overlay
|
||||||
osg::ref_ptr<osg::Image> mOverlayImage;
|
osg::ref_ptr<osg::Image> mOverlayImage;
|
||||||
|
|
||||||
|
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
|
||||||
|
osg::ref_ptr<CreateMapWorkItem> mWorkItem;
|
||||||
|
|
||||||
int mWidth;
|
int mWidth;
|
||||||
int mHeight;
|
int mHeight;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue