1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-30 07:21:12 +00:00

global map explored overlay

This commit is contained in:
scrawl 2012-11-16 19:34:09 +01:00
parent aefde3f5bc
commit dc67a547b0
3 changed files with 30 additions and 39 deletions

View File

@ -624,7 +624,7 @@ void WindowManager::changeCell(MWWorld::Ptr::CellStore* cell)
name = getGameSettingString("sDefaultCellname", "Wilderness"); name = getGameSettingString("sDefaultCellname", "Wilderness");
} }
mMap->cellExplored(cell->cell->getGridX(), cell->cell->getGridY()); mMap->cellExplored(cell->mCell->getGridX(), cell->mCell->getGridY());
mMap->setCellName( name ); mMap->setCellName( name );
mHud->setCellName( name ); mHud->setCellName( name );

View File

@ -1,6 +1,7 @@
#include "globalmap.hpp" #include "globalmap.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <OgreImage.h> #include <OgreImage.h>
#include <OgreTextureManager.h> #include <OgreTextureManager.h>
@ -159,13 +160,30 @@ namespace MWRender
//image.save (mCacheDir + "/GlobalMap.png"); //image.save (mCacheDir + "/GlobalMap.png");
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_DEFAULT); Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_STATIC);
tex->loadImage(image); tex->loadImage(image);
} }
else else
tex = Ogre::TextureManager::getSingleton ().getByName ("GlobalMap.png"); tex = Ogre::TextureManager::getSingleton ().getByName ("GlobalMap.png");
tex->load(); tex->load();
mOverlayTexture = Ogre::TextureManager::getSingleton().createManual("GlobalMapOverlay", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_A8B8G8R8, Ogre::TU_DYNAMIC_WRITE_ONLY);
std::vector<Ogre::uint32> buffer;
buffer.resize(mWidth * mHeight);
// initialize to (0, 0, 0, 0)
for (int p=0; p<mWidth * mHeight; ++p)
buffer[p] = 0;
memcpy(mOverlayTexture->getBuffer()->lock(Ogre::HardwareBuffer::HBL_DISCARD), &buffer[0], mWidth*mHeight*4);
mOverlayTexture->getBuffer()->unlock();
} }
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY) void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
@ -185,44 +203,18 @@ namespace MWRender
void GlobalMap::exploreCell(int cellX, int cellY) void GlobalMap::exploreCell(int cellX, int cellY)
{ {
mExploredCells.push_back(std::make_pair(cellX, cellY)); float originX = (cellX - mMinX) * 24;
int width = mMaxX-mMinX+1; // NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
int height = mMaxY-mMinY+1; float originY = mHeight - (cellY+1 - mMinY) * 24;
if (mOverlayTexture.isNull()) if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
{ return;
mOverlayTexture = Ogre::TextureManager::getSingleton().createManual("GlobalMapOverlay", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_A8B8G8R8, Ogre::TU_DYNAMIC_WRITE_ONLY);
}
for (int x = mMinX; x <= mMaxX; ++x) Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
{ + boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));
for (int y = mMinY; y <= mMaxY; ++y)
{
unsigned char r,g,b,a;
r = 0;
g = 0;
b = 0;
if (std::find(mExploredCells.begin(), mExploredCells.end(), std::make_pair(x, y)) != mExploredCells.end())
a = 0;
else
a = 128;
int texelX = (x-mMinX);
int texelY = (height-1) - (y-mMinY);
assert( static_cast<unsigned int>(texelY * width * 4 + texelX * 4+3) < mExploredBuffer.size()); if (!localMapTexture.isNull())
mExploredBuffer[texelY * width * 4 + texelX * 4] = r; mOverlayTexture->getBuffer()->blit(localMapTexture->getBuffer(), Ogre::Image::Box(0,0,1024, 1024),
mExploredBuffer[texelY * width * 4 + texelX * 4+1] = g; Ogre::Image::Box(originX,originY,originX+24,originY+24));
mExploredBuffer[texelY * width * 4 + texelX * 4+2] = b;
mExploredBuffer[texelY * width * 4 + texelX * 4+3] = a;
}
}
Ogre::Image image;
image.loadDynamicImage(&mExploredBuffer[0], width, height, Ogre::PF_A8B8G8R8);
memcpy(mOverlayTexture->getBuffer()->lock(Ogre::HardwareBuffer::HBL_DISCARD),
&mExploredBuffer[0], width*height*4);
mOverlayTexture->getBuffer()->unlock();
} }
} }

View File

@ -18,7 +18,6 @@ namespace MWRender
: mCamera(camera), : mCamera(camera),
mPlayerNode(node), mPlayerNode(node),
mCameraNode(mPlayerNode->createChildSceneNode()), mCameraNode(mPlayerNode->createChildSceneNode()),
mAnimation(0),
mFirstPersonView(true), mFirstPersonView(true),
mPreviewMode(false), mPreviewMode(false),
mFreeLook(true), mFreeLook(true),