1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +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() CBattleInterface::~CBattleInterface()
@@ -186,7 +186,7 @@ CBattleInterface::~CBattleInterface()
SDL_FreeSurface(amountBasic); SDL_FreeSurface(amountBasic);
SDL_FreeSurface(amountNormal); SDL_FreeSurface(amountNormal);
SDL_FreeSurface(cellBorders); SDL_FreeSurface(cellBorders);
SDL_FreeSurface(shadedHexesGraphic); SDL_FreeSurface(backgroundWithHexes);
delete bOptions; delete bOptions;
delete bSurrender; delete bSurrender;
delete bFlee; delete bFlee;
@@ -254,11 +254,19 @@ void CBattleInterface::show(SDL_Surface * to)
if(!to) //"evaluating" to if(!to) //"evaluating" to
to = screen; to = screen;
//showing background //printing background and hexes
blitAt(background, 0, 0, to); if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
if(printCellBorders)
{ {
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 //printing hovered cell
for(int b=0; b<187; ++b) 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)); 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 //showing menu background and console
blitAt(menu, 0, 556, to); blitAt(menu, 0, 556, to);
@@ -494,24 +498,18 @@ void CBattleInterface::stackActivated(int number)
shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number); shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number);
myTurn = true; myTurn = true;
//preparating graphic with shaded hexes //preparating background graphic with hexes and shaded hexes
//prepairing graphic with cell borders blitAt(background, 0, 0, backgroundWithHexes);
shadedHexesGraphic = CSDL_Ext::newSurface(background->w, background->h, cellShade); if(printCellBorders)
*shadedHexesGraphic->format->palette = *cellShade->format->palette; CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
for(int m=0; m<shadedHexes.size(); ++m) //rows for(int m=0; m<shadedHexes.size(); ++m) //rows
{ {
int i = shadedHexes[m]/17; //row int i = shadedHexes[m]/17; //row
int j = shadedHexes[m]%17-1; //column int j = shadedHexes[m]%17-1; //column
int x = 58 + (i%2==0 ? 22 : 0) + 44*j; int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
int y = 86 + 42 * i; int y = 86 + 42 * i;
for(int cellX = 0; cellX < cellShade->w; ++cellX) CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
{
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);
}
}
} }
} }
@@ -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(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 class CBattleInterface : public CMainInterface
{ {
private: private:
SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, *shadedHexesGraphic; SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, * backgroundWithHexes;
AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell, AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
* bWait, * bDefence, * bConsoleUp, * bConsoleDown; * bWait, * bDefence, * bConsoleUp, * bConsoleDown;
CBattleConsole * console; CBattleConsole * console;

View File

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