Use textSurfaces instead of calling drawString() in doInfo().

This increases efficiency significantly. Before, callgrind estimated that 58%
of the CPU time was spent in doInfo(), taking roughly 1.6 kcycles on average
per call. After, only 0.13 kcycles on average per call are used (12x speedup),
and only 14% of the CPU time is spent in doInfo().
This commit is contained in:
Guus Sliepen 2011-08-25 13:48:36 +02:00
parent 9e4ae7e3bd
commit 70d0b13ea2
1 changed files with 10 additions and 5 deletions

View File

@ -158,19 +158,22 @@ void doInfo()
fontColor = FONT_WHITE; fontColor = FONT_WHITE;
graphics.blitText(10); // time remaining graphics.blitText(10); // time remaining
sprintf(text, "%.2d:%.2d", engine.minutes, engine.seconds); sprintf(text, "%.2d:%.2d", engine.minutes, engine.seconds);
graphics.drawString(text, 410, 21, fontColor); graphics.textSurface(30, text, 410, 21, fontColor);
graphics.blitText(30);
} }
if (currentGame.area != MAX_MISSIONS - 1) if (currentGame.area != MAX_MISSIONS - 1)
{ {
graphics.blitText(9); // mission objectives graphics.blitText(9); // mission objectives
sprintf(text, "%d", (currentMission.remainingObjectives1 + currentMission.remainingObjectives2)); sprintf(text, "%d", (currentMission.remainingObjectives1 + currentMission.remainingObjectives2));
graphics.drawString(text, 745, 21, FONT_WHITE); graphics.textSurface(39, text, 745, 21, FONT_WHITE);
graphics.blitText(39);
} }
graphics.blitText(8); // cash graphics.blitText(8); // cash
sprintf(text, "%.6d", currentGame.cash); sprintf(text, "%.6d", currentGame.cash);
graphics.drawString(text, 90, 21, FONT_WHITE); graphics.textSurface(38, text, 90, 21, FONT_WHITE);
graphics.blitText(38);
doTargetArrow(); doTargetArrow();
@ -182,7 +185,8 @@ void doInfo()
} }
graphics.blitText(5); // plasma ammo graphics.blitText(5); // plasma ammo
sprintf(text, "%.3d", player.ammo[0]); sprintf(text, "%.3d", player.ammo[0]);
graphics.drawString(text, 320, 551, fontColor); graphics.textSurface(35, text, 320, 551, fontColor);
graphics.blitText(35);
graphics.blitText(6); graphics.blitText(6);
@ -193,7 +197,8 @@ void doInfo()
else else
fontColor = FONT_WHITE; fontColor = FONT_WHITE;
sprintf(text, "%.3d", player.ammo[1]); // rocket ammo sprintf(text, "%.3d", player.ammo[1]); // rocket ammo
graphics.drawString(text, 465, 551, fontColor); graphics.textSurface(36, text, 465, 551, fontColor);
graphics.blitText(36);
} }
if (((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER)) && (player.ammo[1] > 0)) if (((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER)) && (player.ammo[1] > 0))