Remove a bunch of unnecessary nil checks. FreeTexture does its own nil check.
authornemo
Mon, 14 Nov 2011 18:08:36 -0500
changeset 6380 1ff5ad1d771b
parent 6379 ef4288298e57
child 6381 5f3412f6809e
Remove a bunch of unnecessary nil checks. FreeTexture does its own nil check.
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
hedgewars/uLandTexture.pas
hedgewars/uScript.pas
hedgewars/uStore.pas
hedgewars/uTextures.pas
hedgewars/uVisualGears.pas
hedgewars/uWorld.pas
--- a/hedgewars/GSHandlers.inc	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/GSHandlers.inc	Mon Nov 14 18:08:36 2011 -0500
@@ -3641,7 +3641,7 @@
         begin
         Gear^.Damage:= i;
         //AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
-        if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+        FreeTexture(Gear^.Tex);
         Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                      '%', cWhiteColor, fntSmall)
         end;
@@ -4685,7 +4685,7 @@
         if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
             begin
             Gear^.Damage:= i;
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                          '%', cWhiteColor, fntSmall)
             end
@@ -4757,7 +4757,7 @@
         if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
             begin
             Gear^.Damage:= i;
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                          '%', cWhiteColor, fntSmall)
             end
--- a/hedgewars/uGears.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uGears.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -591,11 +591,8 @@
 
 DeleteCI(Gear);
 
-if Gear^.Tex <> nil then
-    begin
-    FreeTexture(Gear^.Tex);
-    Gear^.Tex:= nil
-    end;
+FreeTexture(Gear^.Tex);
+Gear^.Tex:= nil;
 
 // make sure that portals have their link removed before deletion
 if (Gear^.Kind = gtPortal) then
@@ -660,7 +657,7 @@
             with CurrentHedgehog^ do 
                 begin
                 inc(Team^.stats.AIKills);
-                if Team^.AIKillsTex <> nil then FreeTexture(Team^.AIKillsTex);
+                FreeTexture(Team^.AIKillsTex);
                 Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
                 end
         end;
@@ -803,7 +800,7 @@
         begin
         if Gear^.RenderTimer and (Gear^.Timer > 500) and ((Gear^.Timer mod 1000) = 0) then
             begin
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex:= RenderStringTex(inttostr(Gear^.Timer div 1000), cWhiteColor, fntSmall);
             end;
         Gear^.doStep(Gear);
@@ -1684,7 +1681,7 @@
         with CurrentHedgehog^ do 
             begin
             inc(Team^.stats.AIKills);
-            if Team^.AIKillsTex <> nil then FreeTexture(Team^.AIKillsTex);
+            FreeTexture(Team^.AIKillsTex);
             Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
             end;
     tempTeam := gear^.Hedgehog^.Team;
--- a/hedgewars/uLandTexture.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uLandTexture.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -143,7 +143,7 @@
         for y:= 0 to LANDTEXARH - 1 do
             with LandTextures[x, y] do
                 begin
-                if tex <> nil then FreeTexture(tex);
+                FreeTexture(tex);
                 tex:= nil;
                 end;
 end;
--- a/hedgewars/uScript.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uScript.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -725,7 +725,7 @@
             gear^.Hedgehog^.Name:= hogName;
 
 	    FreeTexture(gear^.Hedgehog^.NameTagTex);
-            gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
+        gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
 
         end;
     lc_sethogname:= 0;
--- a/hedgewars/uStore.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uStore.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -110,7 +110,7 @@
     if SDL_MustLock(texsurf) then
         SDL_UnlockSurface(texsurf);
 
-    if CrosshairTex <> nil then FreeTexture(CrosshairTex);
+    FreeTexture(CrosshairTex);
     CrosshairTex:= Surface2Tex(texsurf, false);
     SDL_FreeSurface(texsurf)
     end;
@@ -376,24 +376,22 @@
 // name of weapons in ammo menu
 for ai:= Low(TAmmoType) to High(TAmmoType) do
     with Ammoz[ai] do
-    begin
+        begin
         TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
         tmpsurf:= doSurfaceConversion(tmpsurf);
-        if (NameTex <> nil) then
-            FreeTexture(NameTex);
+        FreeTexture(NameTex);
         NameTex:= Surface2Tex(tmpsurf, false);
         SDL_FreeSurface(tmpsurf)
-    end;
+        end;
 
 // number of weapons in ammo menu
 for i:= Low(CountTexz) to High(CountTexz) do
 begin
     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
     tmpsurf:= doSurfaceConversion(tmpsurf);
-    if (CountTexz[i] <> nil) then
-        FreeTexture(CountTexz[i]);
+    FreeTexture(CountTexz[i]);
     CountTexz[i]:= Surface2Tex(tmpsurf, false);
     SDL_FreeSurface(tmpsurf)
 end;
@@ -444,9 +442,9 @@
 
     // free all team and hedgehog textures
     for t:= 0 to Pred(TeamsCount) do
-    begin
+        begin
         if TeamsArray[t] <> nil then
-        begin
+            begin
             FreeTexture(TeamsArray[t]^.NameTagTex);
             TeamsArray[t]^.NameTagTex:= nil;
             FreeTexture(TeamsArray[t]^.CrosshairTex);
@@ -460,26 +458,26 @@
             FreeTexture(TeamsArray[t]^.FlagTex);
             TeamsArray[t]^.FlagTex:= nil;
             for i:= 0 to cMaxHHIndex do
-            begin
+                begin
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].NameTagTex);
                 TeamsArray[t]^.Hedgehogs[i].NameTagTex:= nil;
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HealthTagTex);
                 TeamsArray[t]^.Hedgehogs[i].HealthTagTex:= nil;
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HatTex);
                 TeamsArray[t]^.Hedgehogs[i].HatTex:= nil;
+                end;
             end;
         end;
-    end;
 {$IFNDEF S3D_DISABLED}
     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
-    begin
+        begin
         glDeleteTextures(1, @texl);
         glDeleteRenderbuffersEXT(1, @depthl);
         glDeleteFramebuffersEXT(1, @framel);
         glDeleteTextures(1, @texr);
         glDeleteRenderbuffersEXT(1, @depthr);
         glDeleteFramebuffersEXT(1, @framer)
-    end
+        end
 {$ENDIF}
 end;
 
@@ -488,8 +486,7 @@
 var s: shortstring;
 begin
     str(Hedgehog.Gear^.Health, s);
-    if Hedgehog.HealthTagTex <> nil then
-        FreeTexture(Hedgehog.HealthTagTex);
+    FreeTexture(Hedgehog.HealthTagTex);
     Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
@@ -938,8 +935,6 @@
 procedure FreeWeaponTooltip;
 begin
 // free the existing texture (if there is any)
-if WeaponTooltipTex = nil then
-    exit;
 FreeTexture(WeaponTooltipTex);
 WeaponTooltipTex:= nil
 end;
--- a/hedgewars/uTextures.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uTextures.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -207,7 +207,7 @@
 procedure FreeTexture(tex: PTexture);
 begin
     if tex <> nil then
-    begin
+        begin
         if tex^.NextTexture <> nil then
             tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
         if tex^.PrevTexture <> nil then
@@ -216,7 +216,7 @@
             TextureList:= tex^.NextTexture;
         glDeleteTextures(1, @tex^.id);
         Dispose(tex);
-    end
+        end
 end;
 
 procedure initModule;
--- a/hedgewars/uVisualGears.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uVisualGears.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -401,8 +401,7 @@
 
 procedure DeleteVisualGear(Gear: PVisualGear);
 begin
-    if Gear^.Tex <> nil then
-        FreeTexture(Gear^.Tex);
+    FreeTexture(Gear^.Tex);
     Gear^.Tex:= nil;
 
     if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
--- a/hedgewars/uWorld.pas	Mon Nov 14 17:56:44 2011 -0500
+++ b/hedgewars/uWorld.pas	Mon Nov 14 18:08:36 2011 -0500
@@ -1087,12 +1087,10 @@
         if t < 10 then s:= '0' + s;
         s:= inttostr(i div 60) + ':' + s;
    
-        if timeTexture <> nil then
-            FreeTexture(timeTexture);
-        timeTexture:= nil;
     
         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
         tmpSurface:= doSurfaceConversion(tmpSurface);
+        FreeTexture(timeTexture);
         timeTexture:= Surface2Tex(tmpSurface, false);
         SDL_FreeSurface(tmpSurface)
     end;
@@ -1108,11 +1106,9 @@
             Frames:= 0;
             CountTicks:= 0;
             s:= inttostr(FPS) + ' fps';
-            if fpsTexture <> nil then
-                FreeTexture(fpsTexture);
-            fpsTexture:= nil;
             tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
             tmpSurface:= doSurfaceConversion(tmpSurface);
+            FreeTexture(fpsTexture);
             fpsTexture:= Surface2Tex(tmpSurface, false);
             SDL_FreeSurface(tmpSurface)
         end;
@@ -1316,9 +1312,7 @@
 
 if time = 0 then time:= 5000;
 missionTimer:= time;
-if missionTex <> nil then
-    FreeTexture(missionTex);
-missionTex:= nil;
+FreeTexture(missionTex);
 
 if icon > -1 then
     begin
@@ -1384,8 +1378,11 @@
 begin
     stereoDepth:= stereoDepth; // avoid hint
     FreeTexture(fpsTexture);
+    fpsTexture:= nil;
     FreeTexture(timeTexture);
+    timeTexture:= nil;
     FreeTexture(missionTex);
+    missionTex:= nil
 end;
 
 end.