diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index d4a25750f..e08559d26 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -10,18 +10,6 @@ using namespace MWRender; using namespace Ogre; -#define MAP_RESOLUTION 1024 // 1024*1024 pixels for a SIZE*SIZE area in world units - -// warning: don't set this too high! dynamic textures are a bottleneck -#define FOGOFWAR_RESOLUTION 32 - -// how many frames to skip before rendering the fog of war. -// example: at 60 fps, a value of 2 would mean to render it at 20 fps. -#define FOGOFWAR_SKIP 2 - -// size of a map segment (for exterior regions, this equals 1 cell) -#define SIZE 8192.f - LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* env) { mRendering = rend; @@ -88,8 +76,8 @@ void LocalMap::saveFogOfWar(MWWorld::Ptr::CellStore* cell) Vector2 length = max-min; // divide into segments - const int segsX = std::ceil( length.x / SIZE ); - const int segsY = std::ceil( length.y / SIZE ); + const int segsX = std::ceil( length.x / sSize ); + const int segsY = std::ceil( length.y / sSize ); for (int x=0; xcell->data.gridX; int y = cell->cell->data.gridY; - render((x+0.5)*SIZE, (-y-0.5)*SIZE, -10000, 10000, SIZE, SIZE, name); + render((x+0.5)*sSize, (-y-0.5)*sSize, -10000, 10000, sSize, sSize, name); } void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, @@ -133,8 +121,8 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, Vector2 center(bounds.getCenter().x, bounds.getCenter().z); // divide into segments - const int segsX = std::ceil( length.x / SIZE ); - const int segsY = std::ceil( length.y / SIZE ); + const int segsX = std::ceil( length.x / sSize ); + const int segsY = std::ceil( length.y / sSize ); mInteriorName = cell->cell->name; @@ -142,10 +130,10 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, { for (int y=0; ycell->name + "_" + coordStr(x,y)); } } @@ -187,7 +175,7 @@ void LocalMap::render(const float x, const float y, texture, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, - xw*MAP_RESOLUTION/SIZE, yw*MAP_RESOLUTION/SIZE, + xw*sMapResolution/sSize, yw*sMapResolution/sSize, 0, PF_R8G8B8, TU_RENDERTARGET); @@ -207,22 +195,22 @@ void LocalMap::render(const float x, const float y, texture + "_fog", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, - xw*FOGOFWAR_RESOLUTION/SIZE, yw*FOGOFWAR_RESOLUTION/SIZE, + xw*sFogOfWarResolution/sSize, yw*sFogOfWarResolution/sSize, 0, PF_A8R8G8B8, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); // create a buffer to use for dynamic operations - uint32* buffer = new uint32[FOGOFWAR_RESOLUTION*FOGOFWAR_RESOLUTION]; + uint32* buffer = new uint32[sFogOfWarResolution*sFogOfWarResolution]; // initialize to (0, 0, 0, 1) uint32* pointer = buffer; - for (int p=0; pgetBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, FOGOFWAR_RESOLUTION*FOGOFWAR_RESOLUTION*4); + memcpy(tex2->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, sFogOfWarResolution*sFogOfWarResolution*4); tex2->getBuffer()->unlock(); mBuffers[texture] = buffer; @@ -239,19 +227,20 @@ void LocalMap::render(const float x, const float y, void LocalMap::setPlayerPosition (const Ogre::Vector3& position) { - #if FOGOFWAR_SKIP != 0 - static int count=0; - if (++count % FOGOFWAR_SKIP != 0) - return; - #endif + if (sFogOfWarSkip != 0) + { + static int count=0; + if (++count % sFogOfWarSkip != 0) + return; + } // retrieve the x,y grid coordinates the player is in int x,y; Vector2 pos(position.x, position.z); if (!mInterior) { - x = std::ceil(pos.x / SIZE)-1; - y = std::ceil(-pos.y / SIZE)-1; + x = std::ceil(pos.x / sSize)-1; + y = std::ceil(-pos.y / sSize)-1; mCellX = x; mCellY = y; } @@ -260,8 +249,8 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); min *= 1.3; - x = std::ceil((pos.x - min.x)/SIZE)-1; - y = std::ceil((pos.y - min.y)/SIZE)-1; + x = std::ceil((pos.x - min.x)/sSize)-1; + y = std::ceil((pos.y - min.y)/sSize)-1; mEnvironment->mWindowManager->setInteriorMapTexture(x,y); } @@ -271,8 +260,8 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) std::string texName; if (!mInterior) { - u = std::abs((pos.x - (SIZE*x))/SIZE); - v = 1-std::abs((pos.y + (SIZE*y))/SIZE); + u = std::abs((pos.x - (sSize*x))/sSize); + v = 1-std::abs((pos.y + (sSize*y))/sSize); texName = "Cell_"+coordStr(x,y); } else @@ -280,14 +269,14 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); min *= 1.3; - u = (pos.x - min.x - SIZE*x)/SIZE; - v = (pos.y - min.y - SIZE*y)/SIZE; + u = (pos.x - min.x - sSize*x)/sSize; + v = (pos.y - min.y - sSize*y)/sSize; texName = mInteriorName + "_" + coordStr(x,y); } // explore radius (squared) - const float sqrExploreRadius = 0.01 * FOGOFWAR_RESOLUTION*FOGOFWAR_RESOLUTION; + const float sqrExploreRadius = 0.01 * sFogOfWarResolution*sFogOfWarResolution; // get the appropriate fog of war texture TexturePtr tex = TextureManager::getSingleton().getByName(texName+"_fog"); @@ -297,11 +286,11 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) if (mBuffers.find(texName) == mBuffers.end()) return; uint32* buffer = mBuffers[texName]; uint32* pointer = buffer; - for (int texV = 0; texV> 24); alpha = std::min( alpha, (uint8) (std::max(0.f, std::min(1.f, (sqrDist/sqrExploreRadius)))*255) ); @@ -313,7 +302,7 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) } // copy to the texture - memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, FOGOFWAR_RESOLUTION*FOGOFWAR_RESOLUTION*4); + memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, sFogOfWarResolution*sFogOfWarResolution*4); tex->getBuffer()->unlock(); } } diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index fd5d4770b..13e01b7f4 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -59,6 +59,18 @@ namespace MWRender OEngine::Render::OgreRenderer* mRendering; MWWorld::Environment* mEnvironment; + // 1024*1024 pixels for a cell + static const int sMapResolution = 1024; + + // the dynamic texture is a bottleneck, so don't set this too high + static const int sFogOfWarResolution = 32; + + // frames to skip before rendering fog of war + static const int sFogOfWarSkip = 2; + + // size of a map segment (for exteriors, 1 cell) + static const int sSize = 8192; + Ogre::Camera* mCellCamera; void render(const float x, const float y,