rope: optimization, should save up to ~3 million hwFloat multiplications per second
authorsheepluva
Tue, 29 Jun 2010 07:09:55 +0200
changeset 3585 39570d86de57
parent 3584 7c05f2e0a8b5
child 3586 64ab042084a2
rope: optimization, should save up to ~3 million hwFloat multiplications per second
hedgewars/GSHandlers.inc
--- a/hedgewars/GSHandlers.inc	Tue Jun 29 06:27:59 2010 +0200
+++ b/hedgewars/GSHandlers.inc	Tue Jun 29 07:09:55 2010 +0200
@@ -1155,21 +1155,22 @@
     // check whether rope needs dividing
 
     len := Gear^.Elasticity - _5;
+    nx := Gear^.X + mdX * len;
+    ny := Gear^.Y + mdY * len;
+    tx := mdX * _0_3; // should be the same as increase step
+    ty := mdY * _0_3;
+
     while len > _3 do
     begin
-        lx := hwRound(Gear^.X + mdX * len);
-        ly := hwRound(Gear^.Y + mdY * len);
+        lx := hwRound(nx);
+        ly := hwRound(ny);
         if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and (Land[ly, lx] <> 0
            ) then
         begin
-            // calculate those the first time we have to divide the rope
-            if not haveDivided then
-            begin
             ny := _1 / Distance(ropeDx, ropeDy);
             // old rope pos
             nx := ropeDx * ny;
             ny := ropeDy * ny;
-            end;
 
             with RopePoints.ar[RopePoints.Count] do
             begin
@@ -1194,6 +1195,8 @@
             haveDivided := true;
             break
         end;
+        nx := nx - tx;
+        ny := ny - ty;
         len := len - _0_3 // should be the same as increase step
     end;