Make the local map cell distance configurable

coverity_scan
scrawl 9 years ago
parent bd655c20fd
commit 7d647088ab

@ -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);

@ -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; mx<mNumCells; ++mx)
{
for (int my=0; my<3; ++my)
for (int my=0; my<mNumCells; ++my)
{
MyGUI::ImageBox* map = mLocalMap->createWidget<MyGUI::ImageBox>("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<mNumCells; ++mx)
{
for (int my=0; my<3; ++my)
for (int my=0; my<mNumCells; ++my)
{
int x = mCurX + (mx-1);
int y = mCurY + (-1*(my-1));
MyGUI::ImageBox* fog = mFogWidgets[my + 3*mx];
int x = mCurX + (mx - mCellDistance);
int y = mCurY + (-1*(my - mCellDistance));
MyGUI::ImageBox* fog = mFogWidgets[my + mNumCells*mx];
if (!mFogOfWarToggled || !mFogOfWarEnabled)
{
@ -284,8 +286,8 @@ namespace MWGui
markerPos.cellX = cellX;
markerPos.cellY = cellY;
widgetPos = MyGUI::IntPoint(static_cast<int>(nX * mMapWidgetSize + (1 + cellDx) * mMapWidgetSize),
static_cast<int>(nY * mMapWidgetSize - (cellDy-1) * mMapWidgetSize));
widgetPos = MyGUI::IntPoint(static_cast<int>(nX * mMapWidgetSize + (mCellDistance + cellDx) * mMapWidgetSize),
static_cast<int>(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<int>(nX * mMapWidgetSize + (1 + (cellX - mCurX)) * mMapWidgetSize),
static_cast<int>(nY * mMapWidgetSize + (1-(cellY-mCurY)) * mMapWidgetSize));
widgetPos = MyGUI::IntPoint(static_cast<int>(nX * mMapWidgetSize + (mCellDistance + (cellX - mCurX)) * mMapWidgetSize),
static_cast<int>(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<mNumCells; ++mx)
{
for (int my=0; my<3; ++my)
for (int my=0; my<mNumCells; ++my)
{
int mapX = x + (mx-1);
int mapY = y + (-1*(my-1));
int mapX = x + (mx - mCellDistance);
int mapY = y + (-1*(my - mCellDistance));
MyGUI::ImageBox* box = mMapWidgets[my + 3*mx];
MyGUI::ImageBox* box = mMapWidgets[my + mNumCells*mx];
osg::ref_ptr<osg::Texture2D> 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<int>(mMapWidgetSize + nx*mMapWidgetSize - 16), static_cast<int>(mMapWidgetSize + ny*mMapWidgetSize - 16));
MyGUI::IntPoint pos(static_cast<int>(mMapWidgetSize * mCellDistance + nx*mMapWidgetSize - 16), static_cast<int>(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;

@ -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;

@ -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;

@ -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);

@ -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).

Loading…
Cancel
Save