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

very significant optimization of battles

This commit is contained in:
mateuszb
2008-09-03 10:52:07 +00:00
parent 01105ddc41
commit 6633fb86ef
3 changed files with 36 additions and 38 deletions

View File

@@ -176,7 +176,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
}
}
shadedHexesGraphic = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen);
}
CBattleInterface::~CBattleInterface()
@@ -186,7 +186,7 @@ CBattleInterface::~CBattleInterface()
SDL_FreeSurface(amountBasic);
SDL_FreeSurface(amountNormal);
SDL_FreeSurface(cellBorders);
SDL_FreeSurface(shadedHexesGraphic);
SDL_FreeSurface(backgroundWithHexes);
delete bOptions;
delete bSurrender;
delete bFlee;
@@ -253,12 +253,20 @@ void CBattleInterface::show(SDL_Surface * to)
++animCount;
if(!to) //"evaluating" to
to = screen;
//showing background
blitAt(background, 0, 0, to);
if(printCellBorders)
//printing background and hexes
if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
{
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
blitAt(backgroundWithHexes, 0, 0, to);
}
else
{
//showing background
blitAt(background, 0, 0, to);
if(printCellBorders)
{
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
}
}
//printing hovered cell
for(int b=0; b<187; ++b)
@@ -270,11 +278,7 @@ void CBattleInterface::show(SDL_Surface * to)
CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
}
}
//showing selected unit's range
if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //don't show if unit is moving
{
showRange(to, activeStack);
}
//showing menu background and console
blitAt(menu, 0, 556, to);
@@ -494,24 +498,18 @@ void CBattleInterface::stackActivated(int 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;
//preparating background graphic with hexes and shaded hexes
blitAt(background, 0, 0, backgroundWithHexes);
if(printCellBorders)
CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
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);
}
}
CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
}
}
@@ -872,7 +870,7 @@ void CBattleInterface::showRange(SDL_Surface * to, int ID)
{
CSDL_Ext::blit8bppAlphaTo24bpp(CBattleInterface::cellShade, NULL, to, &bfield[shadedHexes[i]].pos);
}*/
CSDL_Ext::blit8bppAlphaTo24bpp(shadedHexesGraphic, NULL, to, NULL);
//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, * cellBorders, *shadedHexesGraphic;
SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, * backgroundWithHexes;
AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
CBattleConsole * console;

View File

@@ -627,14 +627,14 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
case 255:
break;
case 0:
p[0] = (Uint32)tbc.r;
p[1] = (Uint32)tbc.g;
p[2] = (Uint32)tbc.b;
p[0] = tbc.r;
p[1] = tbc.g;
p[2] = tbc.b;
break;
case 128: // optimized
p[0] = ((Uint32)tbc.r + (Uint32)p[0]) >> 1;
p[1] = ((Uint32)tbc.g + (Uint32)p[1]) >> 1;
p[2] = ((Uint32)tbc.b + (Uint32)p[2]) >> 1;
p[0] = ((Uint16)tbc.r + (Uint16)p[0]) >> 1;
p[1] = ((Uint16)tbc.g + (Uint16)p[1]) >> 1;
p[2] = ((Uint16)tbc.b + (Uint16)p[2]) >> 1;
break;
default:
p[0] = ((((Uint32)p[0]-(Uint32)tbc.r)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.r) & 0xFF;
@@ -662,14 +662,14 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
case 255:
break;
case 0:
p[2] = (Uint32)tbc.r;
p[1] = (Uint32)tbc.g;
p[0] = (Uint32)tbc.b;
p[2] = tbc.r;
p[1] = tbc.g;
p[0] = tbc.b;
break;
case 128: // optimized
p[2] = ((Uint32)tbc.r + (Uint32)p[2]) >> 1;
p[1] = ((Uint32)tbc.g + (Uint32)p[1]) >> 1;
p[0] = ((Uint32)tbc.b + (Uint32)p[0]) >> 1;
p[2] = ((Uint16)tbc.r + (Uint16)p[2]) >> 1;
p[1] = ((Uint16)tbc.g + (Uint16)p[1]) >> 1;
p[0] = ((Uint16)tbc.b + (Uint16)p[0]) >> 1;
break;
default:
p[2] = ((((Uint32)p[2]-(Uint32)tbc.r)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.r) & 0xFF;