bee:
authorsheepluva
Tue, 29 Jun 2010 23:25:42 +0200
changeset 3591 c447d5218f6f
parent 3590 66e1bc1ea3a9
child 3592 0bcad5c38c9e
bee: * make be correct its course only 62.5 times per second (instead of 1000) * cache values (e.g. that one for speed)
hedgewars/GSHandlers.inc
hedgewars/uFloat.pas
--- a/hedgewars/GSHandlers.inc	Tue Jun 29 22:16:26 2010 +0200
+++ b/hedgewars/GSHandlers.inc	Tue Jun 29 23:25:42 2010 +0200
@@ -538,7 +538,7 @@
     AllInactive := false;
     gX := hwRound(Gear^.X);
     gY := hwRound(Gear^.Y);
-    nuw := (cWaterLine < hwRound(Gear^.Y) + Gear^.Radius);
+    nuw := (cWaterLine < gy + Gear^.Radius);
     if nuw and not uw then
     begin
         AddVisualGear(gX, cWaterLine, vgtSplash);
@@ -559,21 +559,21 @@
         end;
 
 
-    t := Distance(Gear^.dX, Gear^.dY);
-    Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000004 * (TargetPoint.X - gX));
-    Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000004 * (TargetPoint.Y - gY));
-
-    t := t / Distance(Gear^.dX, Gear^.dY);
-    Gear^.dX := Gear^.dX * t;
-    Gear^.dY := Gear^.dY * t;
+    if (GameTicks and $F) = 0 then
+    begin
+        if (GameTicks and $30) = 0 then
+            AddVisualGear(gX, gY, vgtBeeTrace);
+        Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (TargetPoint.X - gX));
+        Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (TargetPoint.Y - gY));
+        // make sure new speed isn't higher than original one (which we stored in Friction variable)
+        t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
+        Gear^.dX := Gear^.dX * t;
+        Gear^.dY := Gear^.dY * t;
+    end;
+
     Gear^.X := Gear^.X + Gear^.dX;
     Gear^.Y := Gear^.Y + Gear^.dY;
 
-    if (GameTicks and $3F) = 0 then
-    begin
-        AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBeeTrace);
-    end;
-
     CheckCollision(Gear);
     dec(Gear^.Timer);
     if ((Gear^.State and gstCollision) <> 0) or (Gear^.Timer = 0) then
@@ -602,6 +602,8 @@
     begin
         Gear^.SoundChannel := LoopSound(sndBee);
         Gear^.Timer := 5000;
+        // save initial speed in otherwise unused Friction variable
+        Gear^.Friction := Distance(Gear^.dX, Gear^.dY);
         Gear^.doStep := @doStepBeeWork
     end;
 end;
--- a/hedgewars/uFloat.pas	Tue Jun 29 22:16:26 2010 +0200
+++ b/hedgewars/uFloat.pas	Tue Jun 29 23:25:42 2010 +0200
@@ -74,6 +74,7 @@
           _1div3: hwFloat = (isNegative: false; QWordValue:  1431655766);
             hwPi: hwFloat = (isNegative: false; QWordValue: 13493037704);
        _0_000004: hwFloat = (isNegative: false; QWordValue:       17179);
+       _0_000064: hwFloat = (isNegative: false; QWordValue:      274878);
          _0_0002: hwFloat = (isNegative: false; QWordValue:      858993);
          _0_0005: hwFloat = (isNegative: false; QWordValue:     2147484);
           _0_001: hwFloat = (isNegative: false; QWordValue:     4294967);