forked from teamnwah/openmw-tes3coop
use vector instead of array
This commit is contained in:
parent
28dfba55e0
commit
bf421d2873
2 changed files with 10 additions and 17 deletions
|
@ -29,11 +29,6 @@ LocalMap::~LocalMap()
|
||||||
|
|
||||||
void LocalMap::deleteBuffers()
|
void LocalMap::deleteBuffers()
|
||||||
{
|
{
|
||||||
for (std::map<std::string, uint32*>::iterator it=mBuffers.begin();
|
|
||||||
it != mBuffers.end(); ++it)
|
|
||||||
{
|
|
||||||
delete[] it->second;
|
|
||||||
}
|
|
||||||
mBuffers.clear();
|
mBuffers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,16 +197,16 @@ void LocalMap::render(const float x, const float y,
|
||||||
TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
|
TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
|
||||||
|
|
||||||
// create a buffer to use for dynamic operations
|
// create a buffer to use for dynamic operations
|
||||||
uint32* buffer = new uint32[sFogOfWarResolution*sFogOfWarResolution];
|
std::vector<uint32> buffer;
|
||||||
|
buffer.resize(sFogOfWarResolution*sFogOfWarResolution);
|
||||||
|
|
||||||
// initialize to (0, 0, 0, 1)
|
// initialize to (0, 0, 0, 1)
|
||||||
uint32* pointer = buffer;
|
|
||||||
for (int p=0; p<sFogOfWarResolution*sFogOfWarResolution; ++p)
|
for (int p=0; p<sFogOfWarResolution*sFogOfWarResolution; ++p)
|
||||||
{
|
{
|
||||||
*(pointer+p) = (255 << 24);
|
buffer[p] = (255 << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(tex2->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, sFogOfWarResolution*sFogOfWarResolution*4);
|
memcpy(tex2->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), &buffer[0], sFogOfWarResolution*sFogOfWarResolution*4);
|
||||||
tex2->getBuffer()->unlock();
|
tex2->getBuffer()->unlock();
|
||||||
|
|
||||||
mBuffers[texture] = buffer;
|
mBuffers[texture] = buffer;
|
||||||
|
@ -288,25 +283,23 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3&
|
||||||
{
|
{
|
||||||
// get its buffer
|
// get its buffer
|
||||||
if (mBuffers.find(texName) == mBuffers.end()) return;
|
if (mBuffers.find(texName) == mBuffers.end()) return;
|
||||||
uint32* buffer = mBuffers[texName];
|
int i=0;
|
||||||
uint32* pointer = buffer;
|
|
||||||
for (int texV = 0; texV<sFogOfWarResolution; ++texV)
|
for (int texV = 0; texV<sFogOfWarResolution; ++texV)
|
||||||
{
|
{
|
||||||
for (int texU = 0; texU<sFogOfWarResolution; ++texU)
|
for (int texU = 0; texU<sFogOfWarResolution; ++texU)
|
||||||
{
|
{
|
||||||
float sqrDist = Math::Sqr(texU - u*sFogOfWarResolution) + Math::Sqr(texV - v*sFogOfWarResolution);
|
float sqrDist = Math::Sqr(texU - u*sFogOfWarResolution) + Math::Sqr(texV - v*sFogOfWarResolution);
|
||||||
uint32 clr = *pointer;
|
uint32 clr = mBuffers[texName][i];
|
||||||
uint8 alpha = (clr >> 24);
|
uint8 alpha = (clr >> 24);
|
||||||
alpha = std::min( alpha, (uint8) (std::max(0.f, std::min(1.f, (sqrDist/sqrExploreRadius)))*255) );
|
alpha = std::min( alpha, (uint8) (std::max(0.f, std::min(1.f, (sqrDist/sqrExploreRadius)))*255) );
|
||||||
*((uint32*)pointer) = (alpha << 24);
|
mBuffers[texName][i] = (uint32) (alpha << 24);
|
||||||
|
|
||||||
// move to next texel
|
++i;
|
||||||
++pointer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy to the texture
|
// copy to the texture
|
||||||
memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), buffer, sFogOfWarResolution*sFogOfWarResolution*4);
|
memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), &mBuffers[texName][0], sFogOfWarResolution*sFogOfWarResolution*4);
|
||||||
tex->getBuffer()->unlock();
|
tex->getBuffer()->unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace MWRender
|
||||||
// a buffer for the "fog of war" texture of the current cell.
|
// a buffer for the "fog of war" texture of the current cell.
|
||||||
// interior cells could be divided into multiple textures,
|
// interior cells could be divided into multiple textures,
|
||||||
// so we store in a map.
|
// so we store in a map.
|
||||||
std::map <std::string, Ogre::uint32*> mBuffers;
|
std::map <std::string, std::vector<Ogre::uint32> > mBuffers;
|
||||||
|
|
||||||
void deleteBuffers();
|
void deleteBuffers();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue