From 7d647088ab577357d48e437ef6579a60102e5006 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 5 Feb 2016 01:18:44 +0100 Subject: [PATCH] Make the local map cell distance configurable --- apps/openmw/mwgui/hud.cpp | 2 +- apps/openmw/mwgui/mapwindow.cpp | 59 ++++++++++++++++--------------- apps/openmw/mwgui/mapwindow.hpp | 5 ++- apps/openmw/mwrender/localmap.cpp | 5 +-- apps/openmw/mwrender/localmap.hpp | 2 ++ files/settings-default.cfg | 5 +++ 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 8d6ce6beb..b5c8dc8bb 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -159,7 +159,7 @@ namespace MWGui getWidget(mCrosshair, "Crosshair"); - LocalMapBase::init(mMinimap, mCompass, Settings::Manager::getInt("local map hud widget size", "Map")); + LocalMapBase::init(mMinimap, mCompass, Settings::Manager::getInt("local map hud widget size", "Map"), Settings::Manager::getInt("local map cell distance", "Map")); mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked); mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 469564d9d..3b5f0d8aa 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -181,20 +181,22 @@ namespace MWGui mCustomMarkers.eventMarkersChanged -= MyGUI::newDelegate(this, &LocalMapBase::updateCustomMarkers); } - void LocalMapBase::init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int mapWidgetSize) + void LocalMapBase::init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int mapWidgetSize, int cellDistance) { mLocalMap = widget; mCompass = compass; mMapWidgetSize = mapWidgetSize; + mCellDistance = cellDistance; + mNumCells = cellDistance * 2 + 1; - mLocalMap->setCanvasSize(mMapWidgetSize*3, mMapWidgetSize*3); + mLocalMap->setCanvasSize(mMapWidgetSize*mNumCells, mMapWidgetSize*mNumCells); mCompass->setDepth(Local_CompassLayer); mCompass->setNeedMouseFocus(false); - for (int mx=0; mx<3; ++mx) + for (int mx=0; mxcreateWidget("ImageBox", MyGUI::IntCoord(mx*mMapWidgetSize, my*mMapWidgetSize, mMapWidgetSize, mMapWidgetSize), @@ -231,13 +233,13 @@ namespace MWGui void LocalMapBase::applyFogOfWar() { TextureVector fogTextures; - for (int mx=0; mx<3; ++mx) + for (int mx=0; mx(nX * mMapWidgetSize + (1 + cellDx) * mMapWidgetSize), - static_cast(nY * mMapWidgetSize - (cellDy-1) * mMapWidgetSize)); + widgetPos = MyGUI::IntPoint(static_cast(nX * mMapWidgetSize + (mCellDistance + cellDx) * mMapWidgetSize), + static_cast(nY * mMapWidgetSize + (mCellDistance - cellDy) * mMapWidgetSize)); } else { @@ -297,8 +299,8 @@ namespace MWGui markerPos.cellY = cellY; // Image space is -Y up, cells are Y up - widgetPos = MyGUI::IntPoint(static_cast(nX * mMapWidgetSize + (1 + (cellX - mCurX)) * mMapWidgetSize), - static_cast(nY * mMapWidgetSize + (1-(cellY-mCurY)) * mMapWidgetSize)); + widgetPos = MyGUI::IntPoint(static_cast(nX * mMapWidgetSize + (mCellDistance + (cellX - mCurX)) * mMapWidgetSize), + static_cast(nY * mMapWidgetSize + (mCellDistance - (cellY - mCurY)) * mMapWidgetSize)); } markerPos.nX = nX; @@ -312,9 +314,9 @@ namespace MWGui MyGUI::Gui::getInstance().destroyWidget(*it); mCustomMarkerWidgets.clear(); - for (int dX = -1; dX <= 1; ++dX) + for (int dX = -mCellDistance; dX <= mCellDistance; ++dX) { - for (int dY =-1; dY <= 1; ++dY) + for (int dY =-mCellDistance; dY <= mCellDistance; ++dY) { ESM::CellId cellId; cellId.mPaged = !mInterior; @@ -372,14 +374,14 @@ namespace MWGui // Update the map textures TextureVector textures; - for (int mx=0; mx<3; ++mx) + for (int mx=0; mx texture = mLocalMapRender->getMapTexture(mapX, mapY); if (texture) @@ -406,9 +408,9 @@ namespace MWGui } else { - for (int dX=-1; dX<2; ++dX) + for (int dX=-mCellDistance; dX<=mCellDistance; ++dX) { - for (int dY=-1; dY<2; ++dY) + for (int dY=-mCellDistance; dY<=mCellDistance; ++dY) { MWWorld::CellStore* cell = world->getExterior (mCurX+dX, mCurY+dY); world->getDoorMarkers(cell, doors); @@ -461,9 +463,9 @@ namespace MWGui cells.insert(cell); else { - for (int dX=-1; dX<2; ++dX) + for (int dX=-mCellDistance; dX<=mCellDistance; ++dX) { - for (int dY=-1; dY<2; ++dY) + for (int dY=-mCellDistance; dY<=mCellDistance; ++dY) { const MWWorld::CellStore* gridCell = MWBase::Environment::get().getWorld()->getExterior (cell->getCell()->getGridX()+dX, cell->getCell()->getGridY()+dY); cells.insert(gridCell); @@ -482,7 +484,7 @@ namespace MWGui void LocalMapBase::setPlayerPos(int cellX, int cellY, const float nx, const float ny) { - MyGUI::IntPoint pos(static_cast(mMapWidgetSize + nx*mMapWidgetSize - 16), static_cast(mMapWidgetSize + ny*mMapWidgetSize - 16)); + MyGUI::IntPoint pos(static_cast(mMapWidgetSize * mCellDistance + nx*mMapWidgetSize - 16), static_cast(mMapWidgetSize * mCellDistance + ny*mMapWidgetSize - 16)); pos.left += (cellX - mCurX) * mMapWidgetSize; pos.top -= (cellY - mCurY) * mMapWidgetSize; @@ -663,7 +665,8 @@ namespace MWGui mEventBoxLocal->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart); mEventBoxLocal->eventMouseButtonDoubleClick += MyGUI::newDelegate(this, &MapWindow::onMapDoubleClicked); - LocalMapBase::init(mLocalMap, mPlayerArrowLocal, Settings::Manager::getInt("local map widget size", "Map")); } + LocalMapBase::init(mLocalMap, mPlayerArrowLocal, Settings::Manager::getInt("local map widget size", "Map"), Settings::Manager::getInt("local map cell distance", "Map")); + } void MapWindow::onNoteEditOk() { @@ -707,8 +710,8 @@ namespace MWGui MyGUI::IntPoint clickedPos = MyGUI::InputManager::getInstance().getMousePosition(); MyGUI::IntPoint widgetPos = clickedPos - mEventBoxLocal->getAbsolutePosition(); - int x = int(widgetPos.left/float(mMapWidgetSize))-1; - int y = (int(widgetPos.top/float(mMapWidgetSize))-1)*-1; + int x = int(widgetPos.left/float(mMapWidgetSize))-mCellDistance; + int y = (int(widgetPos.top/float(mMapWidgetSize))-mCellDistance)*-1; float nX = widgetPos.left/float(mMapWidgetSize) - int(widgetPos.left/float(mMapWidgetSize)); float nY = widgetPos.top/float(mMapWidgetSize) - int(widgetPos.top/float(mMapWidgetSize)); x += mCurX; diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index 96fd3c994..773522903 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -68,7 +68,7 @@ namespace MWGui public: LocalMapBase(CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender, bool fogOfWarEnabled = true); virtual ~LocalMapBase(); - void init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int mapWidgetSize); + void init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int mapWidgetSize, int cellDistance); void setCellPrefix(const std::string& prefix); void setActiveCell(const int x, const int y, bool interior=false); @@ -116,6 +116,9 @@ namespace MWGui int mMapWidgetSize; + int mNumCells; // for convenience, mCellDistance * 2 + 1 + int mCellDistance; + // Stores markers that were placed by a player. May be shared between multiple map views. CustomMarkerCollection& mCustomMarkers; diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 4efcf5d1b..fd224ba41 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -72,6 +72,7 @@ LocalMap::LocalMap(osgViewer::Viewer* viewer) : mViewer(viewer) , mMapResolution(Settings::Manager::getInt("local map resolution", "Map")) , mMapWorldSize(8192.f) + , mCellDistance(Settings::Manager::getInt("local map cell distance", "Map")) , mAngle(0.f) , mInterior(false) { @@ -533,9 +534,9 @@ void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orient const float exploreRadiusUV = exploreRadius / sFogOfWarResolution; // explore radius from 0 to 1 (UV space) // change the affected fog of war textures (in a 3x3 grid around the player) - for (int mx = -1; mx<2; ++mx) + for (int mx = -mCellDistance; mx<=mCellDistance; ++mx) { - for (int my = -1; my<2; ++my) + for (int my = -mCellDistance; my<=mCellDistance; ++my) { // is this texture affected at all? bool affected = false; diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index 52f570b0b..d946f4c2b 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -143,6 +143,8 @@ namespace MWRender // size of a map segment (for exteriors, 1 cell) float mMapWorldSize; + int mCellDistance; + float mAngle; const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index e4a8387b4..dddf1a29b 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -58,6 +58,11 @@ local map resolution = 256 # Size of local map in GUI window in pixels. (e.g. 256 to 1024). local map widget size = 512 +# Similar to "[Cells] exterior cell load distance", controls +# how many cells are rendered on the local map. Values higher than the default +# may result in longer loading times. +local map cell distance = 1 + [GUI] # Scales GUI window and widget size. (<1.0 is smaller, >1.0 is larger).