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

probably optimized code for battles

This commit is contained in:
mateuszb
2008-08-31 17:23:40 +00:00
parent bca18a31c3
commit 37753e6678
4 changed files with 59 additions and 20 deletions

View File

@@ -153,6 +153,30 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
}
}
}
//prepairing graphic with cell borders
cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
*cellBorders->format->palette = *cellBorder->format->palette;
for(int i=0; i<11; ++i) //rows
{
for(int j=0; j<15; ++j) //columns
{
int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
int y = 86 + 42 * i;
//SDL_BlitSurface(cellBorder, NULL, cellBorders, &genRect(cellBorder->h, cellBorder->w, x, y));
for(int cellX = 0; cellX < cellBorder->w; ++cellX)
{
for(int cellY = 0; cellY < cellBorder->h; ++cellY)
{
if(y+cellY < cellBorders->h && x+cellX < cellBorders->w)
* ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX);
}
}
}
}
shadedHexesGraphic = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
}
CBattleInterface::~CBattleInterface()
@@ -161,6 +185,8 @@ CBattleInterface::~CBattleInterface()
SDL_FreeSurface(menu);
SDL_FreeSurface(amountBasic);
SDL_FreeSurface(amountNormal);
SDL_FreeSurface(cellBorders);
SDL_FreeSurface(shadedHexesGraphic);
delete bOptions;
delete bSurrender;
delete bFlee;
@@ -230,17 +256,9 @@ void CBattleInterface::show(SDL_Surface * to)
//showing background
blitAt(background, 0, 0, to);
if(printCellBorders) //printing cell borders
if(printCellBorders)
{
for(int i=0; i<11; ++i) //rows
{
for(int j=0; j<15; ++j) //columns
{
int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
int y = 86 + 42 * i;
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorder, NULL, to, &genRect(cellBorder->h, cellBorder->w, x, y));
}
}
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
}
//printing hovered cell
for(int b=0; b<187; ++b)
@@ -475,6 +493,26 @@ void CBattleInterface::stackActivated(int number)
activeStack = number;
shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number);
myTurn = true;
//preparating graphic with shaded hexes
//prepairing graphic with cell borders
shadedHexesGraphic = CSDL_Ext::newSurface(background->w, background->h, cellShade);
*shadedHexesGraphic->format->palette = *cellShade->format->palette;
for(int m=0; m<shadedHexes.size(); ++m) //rows
{
int i = shadedHexes[m]/17; //row
int j = shadedHexes[m]%17-1; //column
int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
int y = 86 + 42 * i;
for(int cellX = 0; cellX < cellShade->w; ++cellX)
{
for(int cellY = 0; cellY < cellShade->h; ++cellY)
{
if(y+cellY < shadedHexesGraphic->h && x+cellX < shadedHexesGraphic->w)
* ((Uint8*)shadedHexesGraphic->pixels + (y+cellY) * shadedHexesGraphic->pitch + (x+cellX)) |= * ((Uint8*)cellShade->pixels + cellY * cellShade->pitch + cellX);
}
}
}
}
void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving)
@@ -830,10 +868,11 @@ void CBattleInterface::stackIsShooting(int ID, int dest)
void CBattleInterface::showRange(SDL_Surface * to, int ID)
{
for(int i=0; i<shadedHexes.size(); ++i)
/*for(int i=0; i<shadedHexes.size(); ++i)
{
CSDL_Ext::blit8bppAlphaTo24bpp(CBattleInterface::cellShade, NULL, to, &bfield[shadedHexes[i]].pos);
}
}*/
CSDL_Ext::blit8bppAlphaTo24bpp(shadedHexesGraphic, NULL, to, NULL);
}

View File

@@ -72,7 +72,7 @@ public:
class CBattleInterface : public CMainInterface
{
private:
SDL_Surface * background, * menu, * amountBasic, * amountNormal;
SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, *shadedHexesGraphic;
AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
CBattleConsole * console;

View File

@@ -165,7 +165,7 @@ int internalFunc(void * callback)
//SDL_Delay(100);
//delete p;
}
SDL_Delay(10);
SDL_Delay(100);
}
return -1;
}

View File

@@ -601,11 +601,11 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
if(dst->format->Rshift==0) //like in most surfaces
{
for(int y=0; y<sr.h; ++y)
for(Uint16 y=0; y<sr.h; ++y)
{
for(int x=0; x<sr.w; ++x)
for(Uint16 x=0; x<sr.w; ++x)
{
SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
SDL_Color & tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at
// According analyze, the values of tbc.unused are fixed,
@@ -650,11 +650,11 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
}
else if(dst->format->Rshift==16) //such as screen
{
for(int y=0; y<sr.h; ++y)
for(Uint16 y=0; y<sr.h; ++y)
{
for(int x=0; x<sr.w; ++x)
for(Uint16 x=0; x<sr.w; ++x)
{
SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
SDL_Color & tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at
switch ((Uint32)tbc.unused)