Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
authornemo
Mon, 11 May 2009 18:56:55 +0000
changeset 2042 905c554d62e6
parent 2041 9e0b5a6bcecf
child 2043 1f2b91b5e7ef
Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
hedgewars/CCHandlers.inc
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uConsole.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uTeams.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/CCHandlers.inc	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/CCHandlers.inc	Mon May 11 18:56:55 2009 +0000
@@ -391,7 +391,7 @@
 end;
 
 procedure chHogSay(var s: shortstring);
-var Gear: PGear;
+var Gear: PVisualGear;
     text: shortstring;
 begin
 text:= copy(s, 2, Length(s)-1);
@@ -402,21 +402,20 @@
     end;
 
 if not CurrentTeam^.ExtDriven then SendIPC('h' + s);
+
 if byte(s[1]) < 4 then
     begin
-    Gear:= AddGear(0, 0, gtSpeechBubble, 0, _0, _0, 0);
+    Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
+    Gear^.Hedgehog:= CurrentHedgehog;
     Gear^.Text:= text;
-    Gear^.Hedgehog:= CurrentHedgehog;
-    Gear^.State:= byte(s[1]);
+    Gear^.FrameTicks:= byte(s[1])
     end
 else
     begin
-    // If I knew how to add a gear without it becoming immediately active, I'd
-    // just create/attach the hedgehog SpeechGear here, then activate it where
-    // SpeechType/SpeechText are activated
     SpeechType:= byte(s[1])-3;
     SpeechText:= text
     end;
+
 end;
 
 procedure chNewGrave;
--- a/hedgewars/GSHandlers.inc	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Mon May 11 18:56:55 2009 +0000
@@ -287,44 +287,6 @@
 Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Tex^.h)
 end;
 
-procedure doStepSpeechBubbleWork(Gear: PGear);
-begin
-dec(Gear^.Timer);
-
-if (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
-    begin
-    Gear^.X:= PHedgehog(Gear^.Hedgehog)^.Gear^.X+int2hwFloat(Gear^.Tex^.w div 2  - Gear^.State);
-    Gear^.Y:= PHedgehog(Gear^.Hedgehog)^.Gear^.Y-int2hwFloat(16+Gear^.Tex^.h);
-    end;
-
-if Gear^.Timer = 0 then
-    begin
-    CurrentHedgehog^.SpeechGear:= nil;
-	DeleteGear(Gear)
-    end;
-end;
-
-procedure doStepSpeechBubble(Gear: PGear);
-begin
-if (CurrentHedgehog^.SpeechGear <> nil) then DeleteGear(CurrentHedgehog^.SpeechGear);
-CurrentHedgehog^.SpeechGear:= Gear;
-
-Gear^.Timer:= max(Length(Gear^.Text)*150,3000);
-
-Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.State, fnt16);
-
-// Arbitrary offsets added to the widths based on shape of current tails
-case Gear^.State of
-    1: Gear^.State:= SpritesData[sprSpeechTail].Width-28;
-    2: Gear^.State:= SpritesData[sprThoughtTail].Width-20;
-    3: Gear^.State:= SpritesData[sprShoutTail].Width-10;
-    end;
-
-Gear^.doStep:= @doStepSpeechBubbleWork;
-
-Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Tex^.h)
-end;
-
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepGrave(Gear: PGear);
 begin
--- a/hedgewars/HHHandlers.inc	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/HHHandlers.inc	Mon May 11 18:56:55 2009 +0000
@@ -100,7 +100,7 @@
 
 procedure Attack(Gear: PGear);
 var xx, yy: hwFloat;
-    tmpGear: PGear;
+    tmpGear: PVisualGear;
 begin
 with Gear^,
      PHedgehog(Gear^.Hedgehog)^ do
@@ -196,10 +196,10 @@
 
         if not (SpeechText = '') then
             begin
-            tmpGear:= AddGear(0, 0, gtSpeechBubble, 0, _0, _0, 0);
+            tmpGear:= AddVisualGear(0, 0, vgtSpeechBubble);
             tmpGear^.Text:= SpeechText;
             tmpGear^.Hedgehog:= CurrentHedgehog;
-            tmpGear^.State:= SpeechType;
+            tmpGear^.FrameTicks:= SpeechType;
             SpeechText:= ''
             end;
 
--- a/hedgewars/uConsole.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uConsole.pas	Mon May 11 18:56:55 2009 +0000
@@ -36,7 +36,7 @@
 implementation
 {$J+}
 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand,
-     uRandom, uAmmos, uTriggers, uStats, uGame, uChat, SDLh, uSound;
+     uRandom, uAmmos, uTriggers, uStats, uGame, uChat, SDLh, uSound, uVisualGears;
 
 const cLineWidth: LongInt = 0;
       cLinesCount = 256;
--- a/hedgewars/uConsts.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uConsts.pas	Mon May 11 18:56:55 2009 +0000
@@ -73,10 +73,10 @@
 			gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder, // 27
 			gtTeleport, gtSwitcher, gtTarget, gtMortar, // 31
 			gtWhip, gtKamikaze, gtCake, gtSeduction, gtWatermelon, gtMelonPiece, // 37
-			gtHellishBomb, gtEvilTrace, gtWaterUp, gtDrill, gtBallGun, gtBall,gtRCPlane, gtSpeechBubble, gtSniperRifleShot);
+			gtHellishBomb, gtEvilTrace, gtWaterUp, gtDrill, gtBallGun, gtBall,gtRCPlane, gtSniperRifleShot);
 
 	TVisualGearType = (vgtFlake, vgtCloud, vgtExplPart, vgtExplPart2, vgtFire,
-			vgtSmallDamageTag, vgtTeamHealthSorter);
+			vgtSmallDamageTag, vgtTeamHealthSorter, vgtSpeechBubble);
 
 	TGearsType = set of TGearType;
 
--- a/hedgewars/uGears.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uGears.pas	Mon May 11 18:56:55 2009 +0000
@@ -53,8 +53,7 @@
 			Z: Longword;
 			IntersectGear: PGear;
 			TriggerId: Longword;
-			uid: Longword;
-            Text: shortstring;
+			uid: Longword
 			end;
 
 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
@@ -163,7 +162,6 @@
 			@doStepBallgun,
 			@doStepBomb,
 			@doStepRCPlane,
-			@doStepSpeechBubble,
 			@doStepSniperRifleShot
 			);
 
@@ -257,9 +255,6 @@
                 Result^.Timer:= 1500;
                 Result^.Z:= 2002;
                 end;
-   gtSpeechBubble: begin
-                Result^.Z:= 2003;
-                end;
        gtGrave: begin
                 Result^.Radius:= 10;
                 Result^.Elasticity:= _0_6;
@@ -654,7 +649,7 @@
           for i:= 0 to cMaxHHIndex do
               with Hedgehogs[i] do
                   begin
-                  if (SpeechGear <> nil) then DeleteGear(SpeechGear);  // remove to restore persisting beyond end of turn. Tiy says was too much of a gameplay issue
+                  if (SpeechGear <> nil) then DeleteVisualGear(SpeechGear);  // remove to restore persisting beyond end of turn. Tiy says was too much of a gameplay issue
                   if (Gear <> nil) then
                      if (GameFlags and gfInvulnerable) = 0 then
                         Gear^.Invulnerable:= false;
@@ -1295,8 +1290,6 @@
        
        gtHealthTag: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
 
-       gtSpeechBubble: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
-           
            gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex);
              
              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4);
--- a/hedgewars/uTeams.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uTeams.pas	Mon May 11 18:56:55 2009 +0000
@@ -18,7 +18,7 @@
 
 unit uTeams;
 interface
-uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats, 
+uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats, uVisualGears, 
 {$IFDEF IPHONE}
 	gles11,
 {$ELSE}
@@ -37,7 +37,7 @@
 	THedgehog = record
 			Name: string[MAXNAMELEN];
 			Gear: PGear;
-			SpeechGear: PGear;
+			SpeechGear: PVisualGear;
 			NameTagTex,
 			HealthTagTex,
 			HatTex: PTexture;
@@ -107,7 +107,7 @@
 procedure TeamGoneEffect(var Team: TTeam);
 
 implementation
-uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat, uVisualGears;
+uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat;
 const MaxTeamHealth: LongInt = 0;
 
 procedure FreeTeamsList; forward;
--- a/hedgewars/uVisualGears.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Mon May 11 18:56:55 2009 +0000
@@ -44,6 +44,8 @@
 		Kind: TVisualGearType;
 		doStep: TVGearStepProcedure;
 		Tex: PTexture;
+        Hedgehog: pointer;
+        Text: shortstring
 		end;
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
@@ -240,6 +242,47 @@
 //doStepTeamHealthSorterWork(Gear, Steps)
 end;
 
+procedure doStepSpeechBubbleWork(Gear: PVisualGear; Steps: Longword);
+var t: LongWord;
+begin
+for t:= 1 to Steps do
+    begin
+    dec(Gear^.Timer);
+
+    if (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
+        begin
+        Gear^.X:= PHedgehog(Gear^.Hedgehog)^.Gear^.X+int2hwFloat(Gear^.Tex^.w div 2  - Gear^.FrameTicks);
+        Gear^.Y:= PHedgehog(Gear^.Hedgehog)^.Gear^.Y-int2hwFloat(16+Gear^.Tex^.h);
+        end;
+
+    if Gear^.Timer = 0 then
+        begin
+        CurrentHedgehog^.SpeechGear:= nil;
+        DeleteVisualGear(Gear)
+        end;
+    end
+end;
+
+procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);
+begin
+if (CurrentHedgehog^.SpeechGear <> nil) then DeleteVisualGear(CurrentHedgehog^.SpeechGear);
+CurrentHedgehog^.SpeechGear:= Gear;
+
+Gear^.Timer:= max(Length(Gear^.Text)*150,3000);
+
+Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);
+
+case Gear^.FrameTicks of
+    1: Gear^.FrameTicks:= SpritesData[sprSpeechTail].Width-28;
+    2: Gear^.FrameTicks:= SpritesData[sprThoughtTail].Width-20;
+    3: Gear^.FrameTicks:= SpritesData[sprShoutTail].Width-10;
+    end;
+
+Gear^.doStep:= @doStepSpeechBubbleWork;
+
+Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Tex^.h)
+end;
+
 // ==================================================================
 const doStepHandlers: array[TVisualGearType] of TVGearStepProcedure =
 		(
@@ -249,7 +292,8 @@
 			@doStepExpl,
 			@doStepFire,
 			@doStepSmallDamage,
-			@doStepTeamHealthSorter
+			@doStepTeamHealthSorter,
+			@doStepSpeechBubble
 		);
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
@@ -264,7 +308,7 @@
 		exit
 		end;
 
-if cReducedQuality and (Kind <> vgtTeamHealthSorter) then
+if cReducedQuality and (Kind <> vgtTeamHealthSorter) and (Kind <> vgtSpeechBubble) then
 	begin
 	AddVisualGear:= nil;
 	exit
@@ -382,6 +426,7 @@
 			vgtExplPart2: DrawSprite(sprExplPart2, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 7 - Gear^.Frame);
 			vgtFire: DrawSprite(sprFlame, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (RealTicks div 64 + Gear^.Frame) mod 8);
 			vgtSmallDamageTag: DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
+            vgtSpeechBubble: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
 			end;
 		Gear:= Gear^.NextGear
 		end