See $(SUBJECT), now please add your $(ARG) over $(PERFECT_SOLUTION). ;-)
- Per
Index: src/move.c
===================================================================
--- src/move.c (revision 1391)
+++ src/move.c (working copy)
@@ -892,38 +892,30 @@
/* Calculate the change in direction given a target angle and turn rate */
-static void moveCalcTurn(float *pCurr, float target, UDWORD rate)
+static float moveCalcTurn(float pCurr, float target, UDWORD rate)
{
- float diff, change;
-#ifdef DEBUG //Ugh. If your gonna ONLY use this variable in "DEBUG", then
- SDWORD path=0; //make sure you wrap the function that uses it also!
-#define SET_PATH(x) path=x
-#else
-#define SET_PATH(x)
-#endif
+ float diff, change, retval;
ASSERT( target < 360.0 && target >= 0.0,
"moveCalcTurn: target out of range %f", target );
- ASSERT( *pCurr < 360.0 && *pCurr >= 0.0,
- "moveCalcTurn: cur ang out of range %f", *pCurr );
+ ASSERT( pCurr < 360.0 && pCurr >= 0.0,
+ "moveCalcTurn: cur ang out of range %f", pCurr );
+ retval = pCurr;
// calculate the difference in the angles
- diff = target - *pCurr;
+ diff = target - retval;
// calculate the change in direction
-
-
change = (baseTurn * rate); // constant rate so we can use a normal multiplication
if ((diff >= 0 && diff < change) ||
(diff < 0 && diff > -change))
{
// got to the target direction
- *pCurr = target;
- SET_PATH(0);
+ retval = target;
}
else if (diff > 0)
{
@@ -931,14 +923,12 @@
if (diff < TRIG_DEGREES / 2)
{
// Simple case - just increase towards target
- *pCurr += change;
- SET_PATH(1);
+ retval += change;
}
else
{
// decrease to target, but could go over 0 boundary */
- *pCurr -= change;
- SET_PATH(2);
+ retval -= change;
}
}
else
@@ -946,33 +936,27 @@
if (diff > -(TRIG_DEGREES/2))
{
// Simple case - just decrease towards target
- *pCurr -= change;
- SET_PATH(3);
+ retval -= change;
}
else
{
// increase to target, but could go over 0 boundary
- *pCurr += change;
- SET_PATH(4);
+ retval += change;
}
}
- if (*pCurr < 0.0f)
+ if (retval < 0.0f)
{
- *pCurr += 360.0f;
+ retval += 360.0f;
}
- else if (*pCurr >= 360.0f)
+ if (retval >= 360.0f)
{
- *pCurr -= 360.0f;
+ retval -= (360.0f - 0.001f); /* minus an epsilon to make up for possible floating point fuzziness */
}
+ ASSERT(retval < 360.0f && retval >= 0, "moveCalcTurn: bad angle! current %f, target %f, angle %f", pCurr, target, retval);
-#ifdef DEBUG //Don't forget that if you don't define the variable, then we error out.
-
- ASSERT( (*pCurr) < 360 && (*pCurr) >= 0,
- "moveCalcTurn: angle out of range - path %d\n"
- " NOTE - ANYONE WHO SEES THIS PLEASE REMEMBER: path %d", path, path );
-#endif
+ return retval;
}
@@ -2314,7 +2298,6 @@
float *pfSpeed ) // direction is target-direction
{
float adiff;
- float temp;
*pfSpeed = MKF(*pSpeed);
*pDroidDir = psDroid->direction;
@@ -2325,7 +2308,6 @@
return;
}
- temp = *pDroidDir;
adiff = fabsf(direction - *pDroidDir);
if (adiff > TRIG_DEGREES/2)
{
@@ -2334,18 +2316,14 @@
if (adiff > iSpinAngle)
{
// large change in direction, spin on the spot
-// debug( LOG_NEVER, "Spin ");
- moveCalcTurn(&temp, MKF(direction), iSpinSpeed);
*pSpeed = 0;
+ *pDroidDir = moveCalcTurn(*pDroidDir, MKF(direction), iSpinSpeed);
}
else
{
// small change in direction, turn while moving
-// debug( LOG_NEVER, "Curve ");
- moveCalcTurn(&temp, MKF(direction), iTurnSpeed);
+ *pDroidDir = moveCalcTurn(*pDroidDir, MKF(direction), iTurnSpeed);
}
-
- *pDroidDir = temp;
}
_______________________________________________
Warzone-dev mailing list
[email protected]
https://mail.gna.org/listinfo/warzone-dev