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:
@@ -227,6 +227,7 @@ void CSpellEffectAnim::endAnim()
|
|||||||
|
|
||||||
for(int b=0; b<toDel.size(); ++b)
|
for(int b=0; b<toDel.size(); ++b)
|
||||||
{
|
{
|
||||||
|
delete toDel[b]->anim;
|
||||||
owner->battleEffects.erase(toDel[b]);
|
owner->battleEffects.erase(toDel[b]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
FDef = spriteh->giveFile(name); //load main file
|
||||||
|
|
||||||
@@ -91,7 +91,6 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), inte
|
|||||||
curFrame = 0;
|
curFrame = 0;
|
||||||
type = -1;
|
type = -1;
|
||||||
frames = totalEntries;
|
frames = totalEntries;
|
||||||
RLEntries = new int[fullHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str) const
|
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;
|
ftcp+=FullWidth * TopMargin;
|
||||||
}
|
}
|
||||||
memcpy(RLEntries, FDef+BaseOffset, SpriteHeight*sizeof(int));
|
int * RLEntries = (int*)(FDef+BaseOffset);
|
||||||
BaseOffset += sizeof(int) * SpriteHeight;
|
BaseOffset += sizeof(int) * SpriteHeight;
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
{
|
{
|
||||||
@@ -280,8 +279,6 @@ int CCreatureAnimation::framesInGroup(int group) const
|
|||||||
CCreatureAnimation::~CCreatureAnimation()
|
CCreatureAnimation::~CCreatureAnimation()
|
||||||
{
|
{
|
||||||
delete [] FDef;
|
delete [] FDef;
|
||||||
if (RLEntries)
|
|
||||||
delete [] RLEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CCreatureAnimation::putPixel(
|
inline void CCreatureAnimation::putPixel(
|
||||||
|
@@ -22,7 +22,6 @@ private:
|
|||||||
int totalEntries, DEFType, totalBlocks;
|
int totalEntries, DEFType, totalBlocks;
|
||||||
int length;
|
int length;
|
||||||
BMPPalette palette[256];
|
BMPPalette palette[256];
|
||||||
int * RLEntries;
|
|
||||||
struct SEntry
|
struct SEntry
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
|
@@ -26,15 +26,12 @@ static long long pow(long long a, int b)
|
|||||||
CDefHandler::CDefHandler()
|
CDefHandler::CDefHandler()
|
||||||
{
|
{
|
||||||
//FDef = NULL;
|
//FDef = NULL;
|
||||||
RWEntries = NULL;
|
|
||||||
notFreeImgs = false;
|
notFreeImgs = false;
|
||||||
}
|
}
|
||||||
CDefHandler::~CDefHandler()
|
CDefHandler::~CDefHandler()
|
||||||
{
|
{
|
||||||
//if (FDef)
|
//if (FDef)
|
||||||
//delete [] FDef;
|
//delete [] FDef;
|
||||||
if (RWEntries)
|
|
||||||
delete [] RWEntries;
|
|
||||||
if (notFreeImgs)
|
if (notFreeImgs)
|
||||||
return;
|
return;
|
||||||
for (size_t i=0; i<ourImages.size(); ++i)
|
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);
|
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)
|
for(size_t i=0; i < SEntries.size(); ++i)
|
||||||
{
|
{
|
||||||
Cimage nimg;
|
Cimage nimg;
|
||||||
@@ -339,11 +336,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
memcpy(RWEntries, FDef+BaseOffset, SpriteHeight*sizeof(int));
|
unsigned int * RWEntriesLoc = (unsigned int *)(FDef+BaseOffset);
|
||||||
BaseOffset += sizeof(int) * SpriteHeight;
|
BaseOffset += sizeof(int) * SpriteHeight;
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
{
|
{
|
||||||
BaseOffset=BaseOffsetor+RWEntries[i];
|
BaseOffset=BaseOffsetor+RWEntriesLoc[i];
|
||||||
if (LeftMargin>0)
|
if (LeftMargin>0)
|
||||||
ftcp += LeftMargin;
|
ftcp += LeftMargin;
|
||||||
|
|
||||||
@@ -387,12 +384,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
|
|||||||
|
|
||||||
case 2:
|
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(BaseOffsetor+i*2*(SpriteWidth/32), 2, FDef);
|
||||||
RWEntries[i] = readNormalNr(BaseOffset,2,FDef);
|
}*/
|
||||||
}
|
BaseOffset = BaseOffsetor + *(unsigned short*)( FDef + BaseOffsetor ); //was + RWEntries[0];
|
||||||
BaseOffset = BaseOffsetor+RWEntries[0];
|
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
{
|
{
|
||||||
//BaseOffset = BaseOffsetor+RWEntries[i];
|
//BaseOffset = BaseOffsetor+RWEntries[i];
|
||||||
@@ -433,14 +429,13 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
|
|||||||
|
|
||||||
case 3:
|
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++)
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
{
|
{
|
||||||
BaseOffset=BaseOffsetor+i*2*(SpriteWidth/32);
|
BaseOffset = BaseOffsetor + *(unsigned short*)( FDef + BaseOffsetor+i*2*(SpriteWidth/32) ); //was + RWEntries[i] before speedup
|
||||||
RWEntries[i] = readNormalNr(BaseOffset,2,FDef);
|
|
||||||
}
|
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
|
||||||
{
|
|
||||||
BaseOffset = BaseOffsetor+RWEntries[i];
|
|
||||||
if (LeftMargin>0)
|
if (LeftMargin>0)
|
||||||
ftcp += LeftMargin;
|
ftcp += LeftMargin;
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ private:
|
|||||||
int totalEntries, DEFType, totalBlocks;
|
int totalEntries, DEFType, totalBlocks;
|
||||||
bool allowRepaint;
|
bool allowRepaint;
|
||||||
int length;
|
int length;
|
||||||
unsigned int * RWEntries;
|
//unsigned int * RWEntries;
|
||||||
struct SEntry
|
struct SEntry
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
|
Reference in New Issue
Block a user