Make clouds/flakes change direction smoothly
authornemo
Sun, 22 Apr 2012 13:58:53 -0400
changeset 6913 73984ea24ff5
parent 6912 831416764d2d
child 6914 e6094d329108
Make clouds/flakes change direction smoothly
hedgewars/VGSHandlers.inc
hedgewars/uTeams.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/VGSHandlers.inc	Sun Apr 22 21:23:32 2012 +0400
+++ b/hedgewars/VGSHandlers.inc	Sun Apr 22 13:58:53 2012 -0400
@@ -728,16 +728,26 @@
 begin
 inc(Gear^.Timer, Steps);
     
-    while Gear^.Timer >= 10 do
-        begin
-        dec(Gear^.Timer, 10);
-        if WindBarWidth < Gear^.Tag then
-            inc(WindBarWidth)
-        else if WindBarWidth > Gear^.Tag then
-            dec(WindBarWidth);
-        end;
+while Gear^.Timer >= 10 do
+    begin
+    dec(Gear^.Timer, 10);
+    if WindBarWidth < Gear^.Tag then
+        inc(WindBarWidth)
+    else if WindBarWidth > Gear^.Tag then
+        dec(WindBarWidth);
+    end;
+if cWindspeedf > Gear^.dAngle then
+    begin
+    cWindspeedf := cWindspeedf - Gear^.Angle*Steps;
+    if cWindspeedf < Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
+    end
+else if cWindspeedf < Gear^.dAngle then
+    begin
+    cWindspeedf := cWindspeedf + Gear^.Angle*Steps;
+    if cWindspeedf > Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
+    end;
         
-if WindBarWidth = Gear^.Tag then 
+if (WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)  then 
     DeleteVisualGear(Gear)
 end;
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/uTeams.pas	Sun Apr 22 21:23:32 2012 +0400
+++ b/hedgewars/uTeams.pas	Sun Apr 22 13:58:53 2012 -0400
@@ -205,6 +205,8 @@
 procedure AfterSwitchHedgehog;
 var i, t: LongInt;
     CurWeapon: PAmmo;
+    w: real;
+    vg: PVisualGear;
 
 begin
 if PlacingHogs then
@@ -249,12 +251,9 @@
 if (GameFlags and gfDisableWind) = 0 then
     begin
     cWindSpeed:= rndSign(GetRandom * 2 * cMaxWindSpeed);
-    // cWindSpeedf:= cWindSpeed.QWordValue / _1.QWordValue throws 'Internal error 200502052' on Darwin
-    // see http://mantis.freepascal.org/view.php?id=17714
-    cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
-    if cWindSpeed.isNegative then
-        CWindSpeedf := -cWindSpeedf;
-    AddVisualGear(0, 0, vgtSmoothWindBar);
+    w:= hwFloat2Float(cWindSpeed);
+    vg:= AddVisualGear(0, 0, vgtSmoothWindBar);
+    if vg <> nil then vg^.dAngle:= w;
     AddFileLog('Wind = '+FloatToStr(cWindSpeed));
     end;
 
--- a/hedgewars/uVisualGears.pas	Sun Apr 22 21:23:32 2012 +0400
+++ b/hedgewars/uVisualGears.pas	Sun Apr 22 13:58:53 2012 -0400
@@ -365,7 +365,11 @@
                 Frame:= 7;
                 Angle:= 0;
                 end;
-vgtSmoothWindBar: Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
+vgtSmoothWindBar: 
+                begin
+                Angle:= hwFloat2Float(cMaxWindSpeed)*2 / 1440; // seems rate below is supposed to change wind bar at 1px per 10ms. Max time, 1440ms. This tries to match the rate of change
+                Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
+                end;
  vgtStraightShot:
                 begin
                 Angle:= 0;