mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* minor speedups
This commit is contained in:
parent
d2d076cd23
commit
de69d6f639
@ -200,44 +200,70 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
ftcp+=LeftMargin;
|
ftcp+=LeftMargin;
|
||||||
}
|
}
|
||||||
TotalRowLength=0;
|
TotalRowLength=0;
|
||||||
|
|
||||||
|
int yB = ftcp/FullWidth + y;
|
||||||
|
|
||||||
|
bool omitIteration = false; //if true, we shouldn't try to blit this line to screen
|
||||||
|
|
||||||
|
if(yB < 0 || yB >= dest->h || (destRect && (destRect->y > yB || destRect->y + destRect->h <= yB ) ) )
|
||||||
|
{
|
||||||
|
//update variables
|
||||||
|
omitIteration = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
SegmentType=FDef[BaseOffset++];
|
SegmentType=FDef[BaseOffset++];
|
||||||
SegmentLength=FDef[BaseOffset++];
|
SegmentLength=FDef[BaseOffset++];
|
||||||
|
|
||||||
|
|
||||||
|
if(omitIteration)
|
||||||
|
{
|
||||||
|
ftcp += SegmentLength+1;
|
||||||
|
if(SegmentType == 0xFF)
|
||||||
|
{
|
||||||
|
BaseOffset += SegmentLength+1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int xB = (attacker ? ftcp%FullWidth : FullWidth - ftcp%FullWidth - 1) + x;
|
||||||
|
|
||||||
|
|
||||||
unsigned char aCountMod = (animCount & 0x20) ? ((animCount & 0x1e)>>1)<<4 : 0x0f - ((animCount & 0x1e)>>1)<<4;
|
unsigned char aCountMod = (animCount & 0x20) ? ((animCount & 0x1e)>>1)<<4 : 0x0f - ((animCount & 0x1e)>>1)<<4;
|
||||||
if (SegmentType==0xFF)
|
|
||||||
|
for (int k=0; k<=SegmentLength; k++)
|
||||||
{
|
{
|
||||||
for (int k=0;k<=SegmentLength;k++)
|
if(xB>=0 && xB<dest->w)
|
||||||
{
|
{
|
||||||
int xB = (attacker ? ftcp%FullWidth : FullWidth - ftcp%FullWidth - 1) + x;
|
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB ))
|
||||||
int yB = ftcp/FullWidth + y;
|
|
||||||
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
|
||||||
{
|
{
|
||||||
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
if (SegmentType == 0xFF)
|
||||||
|
{
|
||||||
putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder, blueBorder, aCountMod);
|
putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder, blueBorder, aCountMod);
|
||||||
}
|
}
|
||||||
ftcp++; //increment pos
|
else
|
||||||
if ((TotalRowLength+k+1)>=SpriteWidth)
|
{
|
||||||
break;
|
|
||||||
}
|
|
||||||
BaseOffset+=SegmentLength+1;////
|
|
||||||
TotalRowLength+=SegmentLength+1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int k=0;k<SegmentLength+1;k++)
|
|
||||||
{
|
|
||||||
int xB = (attacker ? ftcp%FullWidth : FullWidth - ftcp%FullWidth - 1) + x;
|
|
||||||
int yB = ftcp/FullWidth + y;
|
|
||||||
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
|
||||||
{
|
|
||||||
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
|
||||||
putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder, blueBorder, aCountMod);
|
putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder, blueBorder, aCountMod);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ftcp++; //increment pos
|
|
||||||
}
|
}
|
||||||
TotalRowLength+=SegmentLength+1;
|
ftcp++; //increment pos
|
||||||
|
if(attacker)
|
||||||
|
xB++;
|
||||||
|
else
|
||||||
|
xB--;
|
||||||
|
if ( SegmentType == 0xFF && TotalRowLength+k+1 >= SpriteWidth )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (SegmentType == 0xFF)
|
||||||
|
{
|
||||||
|
BaseOffset += SegmentLength+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TotalRowLength+=SegmentLength+1;
|
||||||
}while(TotalRowLength<SpriteWidth);
|
}while(TotalRowLength<SpriteWidth);
|
||||||
if (RightMargin>0)
|
if (RightMargin>0)
|
||||||
{
|
{
|
||||||
|
@ -320,27 +320,19 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co
|
|||||||
SegmentType=FDef[BaseOffset++];
|
SegmentType=FDef[BaseOffset++];
|
||||||
unsigned char code = SegmentType / 32;
|
unsigned char code = SegmentType / 32;
|
||||||
unsigned char value = (SegmentType & 31) + 1;
|
unsigned char value = (SegmentType & 31) + 1;
|
||||||
|
|
||||||
|
int len = std::min<unsigned int>(value, SpriteWidth - TotalRowLength) - std::max(0, -LeftMargin);
|
||||||
|
|
||||||
if(code==7)
|
if(code==7)
|
||||||
{
|
{
|
||||||
for(int h=0; h<value; ++h)
|
memcpy((ui8*)ret->pixels + ftcp, FDef + BaseOffset, len);
|
||||||
{
|
ftcp += len;
|
||||||
if(h<-LeftMargin)
|
BaseOffset += len;
|
||||||
continue;
|
|
||||||
if(h+TotalRowLength>=SpriteWidth)
|
|
||||||
break;
|
|
||||||
((char*)(ret->pixels))[ftcp++]=FDef[BaseOffset++];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(int h=0; h<value; ++h)
|
memset((ui8*)ret->pixels + ftcp, code, len);
|
||||||
{
|
ftcp += len;
|
||||||
if(h<-LeftMargin)
|
|
||||||
continue;
|
|
||||||
if(h+TotalRowLength>=SpriteWidth)
|
|
||||||
break;
|
|
||||||
((char*)(ret->pixels))[ftcp++]=code;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TotalRowLength+=( LeftMargin>=0 ? value : value+LeftMargin );
|
TotalRowLength+=( LeftMargin>=0 ? value : value+LeftMargin );
|
||||||
}while(TotalRowLength<SpriteWidth);
|
}while(TotalRowLength<SpriteWidth);
|
||||||
|
Loading…
Reference in New Issue
Block a user