Render FPS value to its own surface one time a second
authorunc0rr
Sun, 10 Dec 2006 19:30:16 +0000
changeset 298 112e61bd2cc2
parent 297 279e10ec31b4
child 299 098c722e13e1
Render FPS value to its own surface one time a second
hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Sun Dec 10 18:57:05 2006 +0000
+++ b/hedgewars/uWorld.pas	Sun Dec 10 19:30:16 2006 +0000
@@ -53,6 +53,7 @@
 var cWaterSprCount: integer;
     Captions: array[TCapGroup] of TCaptionStr;
     AMxLeft, AMxCurr, SlotsNum: integer;
+    fpsSurface: PSDL_Surface;
 
 procedure InitWorld;
 begin
@@ -338,14 +339,22 @@
 if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseSurface, Surface);
 
 inc(Frames);
-inc(CountTicks, Lag);
-if CountTicks >= 1000 then
+if cShowFPS then
    begin
-   FPS:= Frames;
-   Frames:= 0;
-   CountTicks:= 0;
+   inc(CountTicks, Lag);
+   if CountTicks >= 1000 then
+      begin
+      FPS:= Frames;
+      Frames:= 0;
+      CountTicks:= 0;
+      s:= inttostr(FPS) + ' fps';
+      if fpsSurface <> nil then SDL_FreeSurface(fpsSurface);
+      fpsSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, PChar(String(s)), $FFFFFF);
+      end;
+   r.x:= cScreenWidth - 50;
+   r.y:= 10;
+   SDL_UpperBlit(fpsSurface, nil, Surface, @r)
    end;
-if cShowFPS then DXOutText(cScreenWidth - 50, 10, fnt16, inttostr(FPS) + ' fps', Surface);
 
 inc(SoundTimerTicks, Lag);
 if SoundTimerTicks >= 50 then