1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

* faster and less memory-consuming def handling

* minor leak in battle interface fixed
This commit is contained in:
mateuszb
2009-09-18 12:50:00 +00:00
parent af1f53cd65
commit d5ba0fc4fb
5 changed files with 17 additions and 25 deletions

View File

@@ -227,6 +227,7 @@ void CSpellEffectAnim::endAnim()
for(int b=0; b<toDel.size(); ++b)
{
delete toDel[b]->anim;
owner->battleEffects.erase(toDel[b]);
}

View File

@@ -36,7 +36,7 @@ void CCreatureAnimation::setType(int type)
}
}
CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), internalFrame(0), once(false)
CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), once(false)
{
FDef = spriteh->giveFile(name); //load main file
@@ -91,7 +91,6 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), inte
curFrame = 0;
type = -1;
frames = totalEntries;
RLEntries = new int[fullHeight];
}
int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str) const
@@ -207,7 +206,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
{
ftcp+=FullWidth * TopMargin;
}
memcpy(RLEntries, FDef+BaseOffset, SpriteHeight*sizeof(int));
int * RLEntries = (int*)(FDef+BaseOffset);
BaseOffset += sizeof(int) * SpriteHeight;
for (int i=0;i<SpriteHeight;i++)
{
@@ -280,8 +279,6 @@ int CCreatureAnimation::framesInGroup(int group) const
CCreatureAnimation::~CCreatureAnimation()
{
delete [] FDef;
if (RLEntries)
delete [] RLEntries;
}
inline void CCreatureAnimation::putPixel(

View File

@@ -22,7 +22,6 @@ private:
int totalEntries, DEFType, totalBlocks;
int length;
BMPPalette palette[256];
int * RLEntries;
struct SEntry
{
int offset;

View File

@@ -26,15 +26,12 @@ static long long pow(long long a, int b)
CDefHandler::CDefHandler()
{
//FDef = NULL;
RWEntries = NULL;
notFreeImgs = false;
}
CDefHandler::~CDefHandler()
{
//if (FDef)
//delete [] FDef;
if (RWEntries)
delete [] RWEntries;
if (notFreeImgs)
return;
for (size_t i=0; i<ourImages.size(); ++i)
@@ -184,7 +181,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
{
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
}
RWEntries = new unsigned int[height];
//RWEntries = new unsigned int[height];
for(size_t i=0; i < SEntries.size(); ++i)
{
Cimage nimg;
@@ -339,11 +336,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
case 1:
{
memcpy(RWEntries, FDef+BaseOffset, SpriteHeight*sizeof(int));
unsigned int * RWEntriesLoc = (unsigned int *)(FDef+BaseOffset);
BaseOffset += sizeof(int) * SpriteHeight;
for (int i=0;i<SpriteHeight;i++)
{
BaseOffset=BaseOffsetor+RWEntries[i];
BaseOffset=BaseOffsetor+RWEntriesLoc[i];
if (LeftMargin>0)
ftcp += LeftMargin;
@@ -357,7 +354,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
if (SegmentType==0xFF)
{
for (int k=0;k<SegmentLength;k++)
for (int k=0; k<SegmentLength;k++)
{
((char*)(ret->pixels))[ftcp++]=FDef[BaseOffset+k];
if ((TotalRowLength+k)>=SpriteWidth)
@@ -387,12 +384,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
case 2:
{
for (int i=0;i<SpriteHeight;i++)
/*for (int i=0;i<SpriteHeight;i++)
{
BaseOffset=BaseOffsetor+i*2*(SpriteWidth/32);
RWEntries[i] = readNormalNr(BaseOffset,2,FDef);
}
BaseOffset = BaseOffsetor+RWEntries[0];
RWEntries[i] = readNormalNr(BaseOffsetor+i*2*(SpriteWidth/32), 2, FDef);
}*/
BaseOffset = BaseOffsetor + *(unsigned short*)( FDef + BaseOffsetor ); //was + RWEntries[0];
for (int i=0;i<SpriteHeight;i++)
{
//BaseOffset = BaseOffsetor+RWEntries[i];
@@ -433,14 +429,13 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
case 3:
{
/*for (int i=0;i<SpriteHeight;i++)
{
RWEntries[i] = readNormalNr(BaseOffsetor+i*2*(SpriteWidth/32), 2, FDef);
}*/
for (int i=0;i<SpriteHeight;i++)
{
BaseOffset=BaseOffsetor+i*2*(SpriteWidth/32);
RWEntries[i] = readNormalNr(BaseOffset,2,FDef);
}
for (int i=0;i<SpriteHeight;i++)
{
BaseOffset = BaseOffsetor+RWEntries[i];
BaseOffset = BaseOffsetor + *(unsigned short*)( FDef + BaseOffsetor+i*2*(SpriteWidth/32) ); //was + RWEntries[i] before speedup
if (LeftMargin>0)
ftcp += LeftMargin;

View File

@@ -28,7 +28,7 @@ private:
int totalEntries, DEFType, totalBlocks;
bool allowRepaint;
int length;
unsigned int * RWEntries;
//unsigned int * RWEntries;
struct SEntry
{
std::string name;