if at all possible, don't regenerate arbitrary number of health textures each tick
authoralfadur
Wed, 15 May 2019 14:12:15 +0300
changeset 14955 088c1d319612
parent 14954 f59b7f5cf6e8
child 14956 225839af5272
child 14957 947a4a4d2131
if at all possible, don't regenerate arbitrary number of health textures each tick
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsRender.pas
--- a/hedgewars/uGearsHandlersMess.pas	Wed May 15 09:08:39 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Wed May 15 14:12:15 2019 +0300
@@ -2394,13 +2394,19 @@
             AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke)
     else
         AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
-    // health texture
-    FreeAndNilTexture(Gear^.Tex);
-    Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
+
     dec(Gear^.Health, Gear^.Damage);
     Gear^.Damage := 0;
     if Gear^.Health <= 0 then
-        doStepCase(Gear);
+        doStepCase(Gear)
+    else
+        // health texture (FlightTime = health when the last texture was generated)
+        if Gear^.Health <> Gear^.FlightTime then
+            begin
+            Gear^.FlightTime:= Gear^.Health;
+            FreeAndNilTexture(Gear^.Tex);
+            Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
+            end;
 end;
 
 procedure doStepCase(Gear: PGear);
@@ -2469,18 +2475,22 @@
                 AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke)
             else
                 AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
+
         dec(Gear^.Health, Gear^.Damage);
         Gear^.Damage := 0;
-        // health texture
-        FreeAndNilTexture(Gear^.Tex);
-        Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
+        // health texture (FlightTime = health when the last texture was generated)
+        if Gear^.Health <> Gear^.FlightTime then
+            begin
+            Gear^.FlightTime:= Gear^.Health;
+            FreeAndNilTexture(Gear^.Tex);
+            Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
+            end;
         end
     else
         begin
         // health texture for health crate
-        if (k = gtCase) and ((Gear^.Pos and $02) <> 0) then
-            begin
-            FreeAndNilTexture(Gear^.Tex);
+        if (k = gtCase) and ((Gear^.Pos and posCaseHealth) <> 0) then
+            begin
             if ((Gear^.State and gstFrozen) = 0) then
                 begin
                 // Karma=2: Always hide health
@@ -2496,9 +2506,23 @@
                 else
                     i:= 1;
                 if i = 1 then
-                    Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff80ff80, fnt16)
+                    begin
+                    if Gear^.Health <> Gear^.FlightTime then
+                        begin
+                        Gear^.FlightTime:= Gear^.Health;
+                        FreeAndNilTexture(Gear^.Tex);
+                        Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff80ff80, fnt16)
+                        end
+                    end
                 else
-                    Gear^.Tex := RenderStringTex(trmsg[sidUnknownGearValue], $ff80ff80, fnt16)
+                    begin
+                    if Gear^.FlightTime <> $ffffffff then
+                        begin
+                        Gear^.FlightTime:= $ffffffff;
+                        FreeAndNilTexture(Gear^.Tex);
+                        Gear^.Tex := RenderStringTex(trmsg[sidUnknownGearValue], $ff80ff80, fnt16)
+                        end
+                    end
                 end;
             end;
         if Gear^.Timer = 500 then
--- a/hedgewars/uGearsRender.pas	Wed May 15 09:08:39 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Wed May 15 14:12:15 2019 +0300
@@ -1656,7 +1656,7 @@
 begin
 if isShowGearInfo and (Gear^.RenderHealth) and (Gear^.Tex <> nil) then
     begin
-    if (Gear^.Kind = gtCase) and ((Gear^.Pos and $02) <> 0) then
+    if (Gear^.Kind = gtCase) and ((Gear^.Pos and posCaseHealth) <> 0) then
         DrawTextureCentered(x, y - 38, Gear^.Tex);
     if (Gear^.Kind = gtExplosives) then
         DrawTextureCentered(x, y - 38, Gear^.Tex);