SDL_Surface *text = TTF_RenderUTF8_Shaded(font[fontSize], in, fontForeground, fontBackground);
if (!text)
- {
text = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
- }
+
+ if (!text)
+ return;
+
+ setTransparent(text);
if (alignment == TXT_RIGHT) x -= text->w;
if (alignment == TXT_CENTERED) center = true;
- setTransparent(text);
blit(text, x, y, dest, center);
SDL_FreeSurface(text);
}
+void Graphics::drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest, SurfaceCache &cache)
+{
+ bool center = false;
+
+ if(!cache.text || strcmp(in, cache.text)) {
+ if(cache.surface)
+ SDL_FreeSurface(cache.surface);
+
+ if(cache.text)
+ ::free(cache.text);
+
+ cache.text = strdup(in);
+
+ cache.surface = TTF_RenderUTF8_Shaded(font[fontSize], in, fontForeground, fontBackground);
+
+ if (!cache.surface)
+ cache.surface = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
+
+ if(!cache.surface)
+ return;
+
+ setTransparent(cache.surface);
+ }
+
+ if (alignment == TXT_RIGHT) x -= cache.surface->w;
+ if (alignment == TXT_CENTERED) center = true;
+
+ blit(cache.surface, x, y, dest, center);
+}
+
void Graphics::clearChatString()
{
chatString[0] = 0;
SDL_Surface *infoMessage;
public:
+ struct SurfaceCache {
+ char *text;
+ SDL_Surface *surface;
+ SurfaceCache(): text(NULL), surface(NULL) {}
+ };
bool takeRandomScreenShots;
void setFontSize(int size);
SDL_Surface *getString(const char *in, bool transparent);
void drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest);
+ void drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest, SurfaceCache &cache);
void clearChatString();
void createChatString(const char *in);
void showMedalMessage(int type, const char *in);
frameLimit = SDL_GetTicks() + 64;
#if DEBUG
- graphics.drawString(fps, 600, 30, true, graphics.screen);
+ static Graphics::SurfaceCache fpsCache;
+ graphics.drawString(fps, 600, 30, true, graphics.screen, fpsCache);
if (SDL_GetTicks() > frameCounter + 500)
{
if (validStage)
{
+ static Graphics::SurfaceCache cache;
graphics.drawRect(10, 400, 620, 20, graphics.black, graphics.white, graphics.screen);
snprintf(string, sizeof string, "%s : %s", _("Selected Destination"), _(game.stageName));
- graphics.drawString(string, 320, 409, true, graphics.screen);
+ graphics.drawString(string, 320, 409, true, graphics.screen, cache);
}
graphics.drawRect(10, 430, 620, 40, graphics.black, graphics.white, graphics.screen);
#if DEBUG
+ static Graphics::SurfaceCache posCache;
snprintf(pos, sizeof pos, "%.3d:%.3d", engine.getMouseX(), engine.getMouseY());
- graphics.drawString(pos, 320, 15, true, graphics.screen);
+ graphics.drawString(pos, 320, 15, true, graphics.screen, posCache);
#endif
engine.getInput();
void doStatusBar()
{
+ static Graphics::SurfaceCache healthCache;
+ static Graphics::SurfaceCache oxygenCache;
+ static Graphics::SurfaceCache jetpackCache;
+
graphics.setFontSize(0);
graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
graphics.blit(graphics.infoBar, 0, 0, graphics.screen, false);
- graphics.drawString(_("Health"), 50, 5, TXT_RIGHT, graphics.screen);
+ graphics.drawString(_("Health"), 50, 5, TXT_RIGHT, graphics.screen, healthCache);
for (int i = 0 ; i < MAX_HEALTH ; i++)
{
if ((!game.hasAquaLung) && (!engine.cheatExtras))
{
- graphics.drawString(_("Oxygen"), 305, 5, TXT_RIGHT, graphics.screen);
+ graphics.drawString(_("Oxygen"), 305, 5, TXT_RIGHT, graphics.screen, oxygenCache);
for (int i = 0 ; i < 7 ; i++)
{
}
else if ((game.hasJetPack) || (engine.cheatExtras))
{
- graphics.drawString(_("Jetpack"), 305, 5, TXT_RIGHT, graphics.screen);
+ graphics.drawString(_("Jetpack"), 305, 5, TXT_RIGHT, graphics.screen, jetpackCache);
for (int i = 0 ; i < 7 ; i++)
{
break;
}
+ static Graphics::SurfaceCache cache;
graphics.blit(graphics.infoBar, 0, 455, graphics.screen, false);
- graphics.drawString(_(engine.message), 320, 466, true, graphics.screen);
+ graphics.drawString(_(engine.message), 320, 466, true, graphics.screen, cache);
engine.messageTime--;
if (engine.messageTime == -1)
{
graphics.blit(graphics.infoBar, 0, 455, graphics.screen, false);
- graphics.drawString(_(map.mainBossPart->name), 255, 460, TXT_RIGHT, graphics.screen);
+ static Graphics::SurfaceCache cache;
+ graphics.drawString(_(map.mainBossPart->name), 255, 460, TXT_RIGHT, graphics.screen, cache);
graphics.drawRect(265 - 1, 463 - 1, 200 + 2, 10 + 2, graphics.white, graphics.screen);
graphics.drawRect(265, 463, 200, 10, graphics.black, graphics.screen);
}
}
+ static Graphics::SurfaceCache weaponCache;
snprintf(string, sizeof string, "%s %s", _("Weapon:"), _(player.currentWeapon->name));
- graphics.drawString(string, 630, 5, TXT_RIGHT, graphics.screen);
+ graphics.drawString(string, 630, 5, TXT_RIGHT, graphics.screen, weaponCache);
if (game.skill == 3)
{
}
}
}
- graphics.drawString(string, 320, 35, TXT_CENTERED, graphics.screen);
+ static Graphics::SurfaceCache cache;
+ graphics.drawString(string, 320, 35, TXT_CENTERED, graphics.screen, cache);
}
else
{
+ static Graphics::SurfaceCache cache;
graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
graphics.setFontSize(3);
- graphics.drawString(_("Mission Failed! Time Up!"), 320, 220, TXT_CENTERED, graphics.screen);
+ graphics.drawString(_("Mission Failed! Time Up!"), 320, 220, TXT_CENTERED, graphics.screen, cache);
graphics.setFontSize(0);
game.canContinue = 0;
}
if ((mia->value != 100) && (!(mia->flags & ENT_DYING)))
{
+ static Graphics::SurfaceCache cache;
graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
- graphics.drawString(_((char*)mia_scared[mia->value]), x + 10, y - 10, true, graphics.screen);
+ graphics.drawString(_((char*)mia_scared[mia->value]), x + 10, y - 10, true, graphics.screen, cache);
}
graphics.blit(mia->getFaceImage(), x, y, graphics.screen, false);
}
}
+ static Graphics::SurfaceCache cache;
snprintf(message, sizeof message, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
- graphics.drawString(message, 320, 420, true, graphics.screen);
+ graphics.drawString(message, 320, 420, true, graphics.screen, cache);
engine.delay(frameLimit);
frameLimit = SDL_GetTicks() + 16;