finishing the gtHealthTag -> vgtHealthTag, no segfaults and hogzombies no more, hopefully
authorsheepluva
Fri, 07 May 2010 06:29:46 +0000
changeset 3443 14d12df0d363
parent 3442 69898c6ede14
child 3444 9d501dc22f71
finishing the gtHealthTag -> vgtHealthTag, no segfaults and hogzombies no more, hopefully
hedgewars/VGSHandlers.inc
hedgewars/uGears.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/VGSHandlers.inc	Fri May 07 04:52:46 2010 +0000
+++ b/hedgewars/VGSHandlers.inc	Fri May 07 06:29:46 2010 +0000
@@ -429,13 +429,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepHealthTagWork(Gear: PVisualGear; Steps: Longword);
 begin
-//if Gear^.Kind = gtHealthTag then
-//    AllInactive:= false;
-
 if Steps > Gear^.Timer then
     begin
-//    if (Gear^.Kind = vgtHealthTag) and (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
-//        PHedgehog(Gear^.Hedgehog)^.Gear^.Active:= true; // to let current hh die
     DeleteVisualGear(Gear);
     end
 else
@@ -447,8 +442,6 @@
 
 procedure doStepHealthTagWorkUnderWater(Gear: PVisualGear; Steps: Longword);
 begin
-//AllInactive:= false;
-
 if hwRound(Gear^.Y) < cWaterLine + 10 then
     DeleteVisualGear(Gear)
 else
@@ -459,14 +452,14 @@
 procedure doStepHealthTag(Gear: PVisualGear; Steps: Longword);
 var s: shortstring;
 begin
-//AllInactive:= false;
-
 s:= '';
 
 Gear^.dY:= -_0_08;
 
 str(Gear^.State, s);
 Gear^.Tex:= RenderStringTex(s, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color, fnt16);
+// if you segfault here you probably added this healthtag directly
+// maybe you should call spawnHealthTagForHH() in uGears.pas instead
 
 if hwRound(Gear^.Y) < cWaterLine then
     Gear^.doStep:= @doStepHealthTagWork
--- a/hedgewars/uGears.pas	Fri May 07 04:52:46 2010 +0000
+++ b/hedgewars/uGears.pas	Fri May 07 06:29:46 2010 +0000
@@ -219,6 +219,17 @@
     GearsList:= Gear^.NextGear
 end;
 
+procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
+var tag: PVisualGear;
+begin
+tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg);
+tag^.Hedgehog:= PHedgehog(HHGear^.Hedgehog); // the tag needs the tag to determine the text color
+tag^.doStep(tag,1); // do this now because the Gear could already be deleted on next step call
+tag^.Hedgehog:= nil;
+AllInactive:= false;
+HHGear^.Active:= true;
+end;
+
 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
 const Counter: Longword = 0;
 var gear: PGear;
@@ -515,7 +526,7 @@
             t:= max(Gear^.Damage, Gear^.Health);
             Gear^.Damage:= t;
             if (cWaterOpacity < $FF) and (hwRound(Gear^.Y) < cWaterLine + 256) then
-                AddVisualGear(hwRound(Gear^.X), min(hwRound(Gear^.Y),cWaterLine+cVisibleWater+32), vgtHealthTag, t)^.Hedgehog:= Gear^.Hedgehog;
+                spawnHealthTagForHH(Gear, t);
             uStats.HedgehogDamaged(Gear)
             end;
 
@@ -576,8 +587,7 @@
                 not SuddenDeathDmg then
                 Gear^.State:= Gear^.State or gstLoser;
 
-            AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12,
-                    vgtHealthTag, dmg)^.Hedgehog:= Gear^.Hedgehog;
+            spawnHealthTagForHH(Gear, dmg);
 
             RenderHealth(PHedgehog(Gear^.Hedgehog)^);
             RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team);
@@ -897,9 +907,7 @@
            not CurrentHedgehog^.Gear^.Invulnerable then
            begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
-           AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X),
-                   hwRound(CurrentHedgehog^.Gear^.Y),
-                   vgtHealthTag, tmpDmg)^.Hedgehog:= CurrentHedgehog;
+           spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
            end;
         end;
     end;
--- a/hedgewars/uVisualGears.pas	Fri May 07 04:52:46 2010 +0000
+++ b/hedgewars/uVisualGears.pas	Fri May 07 06:29:46 2010 +0000
@@ -381,6 +381,9 @@
                     else
                         DrawRotatedF(sprFlake, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
             vgtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame);
+            
+            vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);
+            vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);
             end;
         Gear:= Gear^.NextGear
         end;
@@ -398,21 +401,19 @@
                             if Gear^.FrameTicks < 255 then
                                 Tint($FF, $FF, $FF, $FF);
                             end;
-                end;
-            case Gear^.Kind of
-                vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);
-                vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);                
-                vgtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) - 32 + WorldDx, hwRound(Gear^.Y) - 32 + WorldDy, Gear^.State);
-                vgtBigExplosion: begin
-                                 Tint($FF, $FF, $FF, floor($FF * (1 - power(Gear^.Timer / 250, 4))));
-                                 DrawRotatedTextureF(SpritesData[sprBigExplosion].Texture, 0.85 * (-power(2, -10 * Int(Gear^.Timer)/250) + 1) + 0.4, 0, 0, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, 1, 385, 385, Gear^.Angle);
-                                 Tint($FF, $FF, $FF, $FF);
-                                 end;
-            end;
+                 end;
         Gear:= Gear^.NextGear
         end;
     2: while Gear <> nil do
         begin
+        case Gear^.Kind of
+            vgtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) - 32 + WorldDx, hwRound(Gear^.Y) - 32 + WorldDy, Gear^.State);
+            vgtBigExplosion: begin
+                             Tint($FF, $FF, $FF, floor($FF * (1 - power(Gear^.Timer / 250, 4))));
+                             DrawRotatedTextureF(SpritesData[sprBigExplosion].Texture, 0.85 * (-power(2, -10 * Int(Gear^.Timer)/250) + 1) + 0.4, 0, 0, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, 1, 385, 385, Gear^.Angle);
+                             Tint($FF, $FF, $FF, $FF);
+                             end;
+            end;
         if not cReducedQuality then
             case Gear^.Kind of
                 vgtExplPart: DrawSprite(sprExplPart, hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 7 - Gear^.Frame);