Update of /cvsroot/netrek/client/netrekxp/src
In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11382

Modified Files:
	input.c util.c 
Log Message:
Autophaser, optimize code to reduce math operations.

Index: input.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/input.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- input.c	23 May 2009 15:21:20 -0000	1.52
+++ input.c	24 May 2009 01:38:55 -0000	1.53
@@ -1920,9 +1920,8 @@
 phaseraction (W_Event * data)
 {
     unsigned char course;
-    int x, y;
+    int x, y, dx, dy;
     int distance;
-    register struct player *j;
     struct obtype *gettarget (W_Window ww,
                               int x,
                               int y,
@@ -1939,47 +1938,31 @@
             sendPhaserReq (course);
             return;
         }
-        if (target->o_type == PLAYERTYPE)
-        {
-            j = &players[target->o_num];
-            if (data->Window == mapw)
-            {
-                x = j->p_x * GWINSIDE / GWIDTH;
-                y = j->p_y * GWINSIDE / GWIDTH;
-            }
-            else if (data->Window == w)
-            {
-                x = (j->p_x - me->p_x) / scaleFactor + TWINSIDE / 2;
-                y = (j->p_y - me->p_y) / scaleFactor + TWINSIDE / 2;
-            }
-        }
-        else if (target->o_type == PLASMATYPE)
-        {
-            x = target->o_dist_x;
-            y = target->o_dist_y;
-        }
+        dx = target->o_dist_x - me->p_x;
+        dy = target->o_dist_y - me->p_y;
   
-        /* Sanity check on distance.  Negative x or y indicates phaser is in local
-           window but target is outside viewable range. */
-        if (x < 0 || y < 0)
+        /* Sanity check on distance.  */
+        /* Check ship max phaser range for phasers.  Sometimes phasers are fired to "point". */
+
+        distance = (int) sqrt((double) dx*dx + (double) dy*dy);
+        if (distance > (PHASEDIST * me->p_ship.s_phaserdamage / 100))
         { 
             course = (unsigned char) (getcourse (data->Window, data->x, data->y));
             sendPhaserReq (course);
             return;
         }
-        /* Check ship max phaser range for local window phasers.  Sometimes phasers
-           are fired to "point".  Not checking galaxy map phasers. */
+
+        /* Everything checks out.  Scale to window coordinates. */
         if (data->Window == w)
         {
-            distance = (int) sqrt((x- TWINSIDE / 2)*(x - TWINSIDE / 2) + (y - TWINSIDE / 2)*(y - TWINSIDE /2));
-            if (distance > (PHASEDIST * j->p_ship.s_phaserdamage / 100 / scaleFactor))
-            { 
-                course = (unsigned char) (getcourse (data->Window, data->x, data->y));
-                sendPhaserReq (course);
-                return;
-            }
+            x = dx / scaleFactor + TWINSIDE / 2;
+            y = dy / scaleFactor + TWINSIDE / 2;
+        }
+        else
+        {
+            x = target->o_dist_x * GWINSIDE / GWIDTH;
+            y = target->o_dist_y * GWINSIDE / GWIDTH;
         }
-        /* Everything checks out */
         course = (unsigned char) (getcourse (data->Window, x, y));
     }
     else

Index: util.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/util.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- util.c	23 May 2009 15:21:20 -0000	1.9
+++ util.c	24 May 2009 01:38:55 -0000	1.10
@@ -123,8 +123,8 @@
             {
                 _target.o_type = PLANETTYPE;
                 _target.o_num = i;
-                _target.o_dist_x = -1;
-                _target.o_dist_y = -1;
+                _target.o_dist_x = k->pl_x;
+                _target.o_dist_y = k->pl_y;
                 closedist = dist;
             }
 
@@ -152,8 +152,8 @@
             {
                 _target.o_type = PLAYERTYPE;
                 _target.o_num = i;
-                _target.o_dist_x = -1;
-                _target.o_dist_y = -1;
+                _target.o_dist_x = j->p_x;
+                _target.o_dist_y = j->p_y;
                 closedist = dist;
             }
         }
@@ -172,8 +172,8 @@
             {
                 _target.o_type = PLASMATYPE;
                 _target.o_num = -1;
-                _target.o_dist_x = (int) ((x - pt->pt_x) / scaleFactor + TWINSIDE / 2);
-                _target.o_dist_y = (int) ((y - pt->pt_y) / scaleFactor + TWINSIDE / 2);
+                _target.o_dist_x = pt->pt_x;
+                _target.o_dist_y = pt->pt_y;
                 closedist = dist;
             }
         }