Some tiny optimizations
authorunc0rr
Fri, 02 Dec 2011 15:03:27 +0400
changeset 6498 5678806aafca
parent 6497 2359798a8dce
child 6499 33180b479efa
Some tiny optimizations
hedgewars/GSHandlers.inc
hedgewars/uFloat.pas
hedgewars/uGearsUtils.pas
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/GameMode.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Grave.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Map.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Scheme.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Team.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Weapon.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/UserInput/TouchInterface.java
share/hedgewars/Data/Scripts/plist/Racer.plist
--- a/hedgewars/GSHandlers.inc	Sun Dec 04 15:21:50 2011 -0500
+++ b/hedgewars/GSHandlers.inc	Fri Dec 02 15:03:27 2011 +0400
@@ -197,7 +197,7 @@
         if land <> 0 then
             begin
             collV := -1;
-            if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10)
+            if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
             else Gear^.dX := Gear^.dX * Gear^.Friction;
 
             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
@@ -206,14 +206,16 @@
         else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1;
         end
     else 
-        begin
+        begin // Gear^.dY.isNegative is false
         land:= TestCollisionYwithGear(Gear, 1);
         if land <> 0 then
             begin
             collV := 1;
             isFalling := false;
-            if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10)
-            else Gear^.dX := Gear^.dX * Gear^.Friction;
+            if land and lfIce <> 0 then 
+                Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
+            else 
+                Gear^.dX := Gear^.dX * Gear^.Friction;
 
             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
             Gear^.State := Gear^.State or gstCollision
@@ -221,7 +223,7 @@
         else
             begin
             isFalling := true;
-            if (Gear^.AdvBounce=1) and (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
+            if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, -1) <> 0) then
                 collV := -1
             end
         end;
@@ -261,8 +263,7 @@
     if Gear^.Kind <> gtBee then
         CheckGearDrowning(Gear);
     //if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
-    if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) and
-       (not isFalling) then
+    if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then
         Gear^.State := Gear^.State and (not gstMoving)
     else
         Gear^.State := Gear^.State or      gstMoving;
@@ -376,23 +377,23 @@
         end;
     DeleteGear(Gear);
     exit
-end;
-
-CalcRotationDirAngle(Gear);
-
-if Gear^.Kind = gtHellishBomb then
-begin
-
-    if Gear^.Timer = 3000 then
+    end;
+
+    CalcRotationDirAngle(Gear);
+
+    if Gear^.Kind = gtHellishBomb then
     begin
-        Gear^.nImpactSounds := 0;
-        PlaySound(sndHellish);
+
+        if Gear^.Timer = 3000 then
+        begin
+            Gear^.nImpactSounds := 0;
+            PlaySound(sndHellish);
+        end;
+
+        if (GameTicks and $3F) = 0 then
+            if (Gear^.State and gstCollision) = 0 then
+                AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace);
     end;
-
-    if (GameTicks and $3F) = 0 then
-        if (Gear^.State and gstCollision) = 0 then
-            AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace);
-end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1363,7 +1364,7 @@
     if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
 
     if (Gear^.Message and gmAttack) <> 0 then
-    begin
+        begin
         Gear^.X := HHGear^.X;
         Gear^.Y := HHGear^.Y;
 
@@ -1371,11 +1372,11 @@
 
         Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
         Gear^.dY := -AngleCos(HHGear^.Angle);
-        Gear^.Friction := _450 * _0_01 * cRopePercent;
+        Gear^.Friction := _4_5 * cRopePercent;
         Gear^.Elasticity := _0;
         Gear^.State := Gear^.State and (not gsttmpflag);
         Gear^.doStep := @doStepRope;
-    end
+        end
 end;
 
 procedure RopeDeleteMe(Gear, HHGear: PGear);
@@ -1786,7 +1787,7 @@
             else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then
                  inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
         
-        if (Gear^.Damage > random(30)) and ((GameTicks and $FF) = 0) then
+        if ((GameTicks and $FF) = 0) and (Gear^.Damage > random(30)) then
             begin
             vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
             if vg <> nil then vg^.Scale:= 0.5
@@ -1841,7 +1842,10 @@
 procedure doStepSMine(Gear: PGear);
 begin
     // TODO: do real calculation?
-    if TestCollisionXwithGear(Gear, 2) or (TestCollisionYwithGear(Gear, -2) <> 0) or TestCollisionXwithGear(Gear, -2) or (TestCollisionYwithGear(Gear, 2) <> 0) then
+    if TestCollisionXwithGear(Gear, 2) 
+        or (TestCollisionYwithGear(Gear, -2) <> 0) 
+        or TestCollisionXwithGear(Gear, -2) 
+        or (TestCollisionYwithGear(Gear, 2) <> 0) then
     begin
         if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then
         begin
@@ -1870,13 +1874,14 @@
         else // gstAttacking <> 0
         begin
             AllInactive := false;
-            if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
             if Gear^.Timer = 0 then
             begin
                 doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
                 DeleteGear(Gear);
                 exit
-            end;
+            end else
+                if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
+
             dec(Gear^.Timer);
         end
     end
--- a/hedgewars/uFloat.pas	Sun Dec 04 15:21:50 2011 -0500
+++ b/hedgewars/uFloat.pas	Fri Dec 02 15:03:27 2011 +0400
@@ -148,6 +148,7 @@
               _2: hwFloat = (isNegative: false; QWordValue:  4294967296 * 2);
               _3: hwFloat = (isNegative: false; QWordValue:  4294967296 * 3);
               _4: hwFloat = (isNegative: false; QWordValue:  4294967296 * 4);
+            _4_5: hwFloat = (isNegative: false; QWordValue:  4294967296 * 9 div 2);
               _5: hwFloat = (isNegative: false; QWordValue:  4294967296 * 5);
               _6: hwFloat = (isNegative: false; QWordValue:  4294967296 * 6);
              _10: hwFloat = (isNegative: false; QWordValue:  4294967296 * 10);
--- a/hedgewars/uGearsUtils.pas	Sun Dec 04 15:21:50 2011 -0500
+++ b/hedgewars/uGearsUtils.pas	Fri Dec 02 15:03:27 2011 +0400
@@ -321,11 +321,11 @@
     particle: PVisualGear;
     isSubmersible: boolean;
 begin
-    isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
     // probably needs tweaking. might need to be in a case statement based upon gear type
     Y:= hwRound(Gear^.Y);
     if cWaterLine < Y + Gear^.Radius then
         begin
+        isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
         skipSpeed := _0_25;
         skipAngle := _1_9;
         skipDecay := _0_87;