From 751d7607726ec2affc0da930a659a4a858325569 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Tue, 22 Jul 2014 23:26:54 -0700 Subject: [PATCH] Use standard (f)abs functions --- Sources/Plasma/CoreLib/HeadSpin.h | 1 - Sources/Plasma/CoreLib/hsQuat.cpp | 2 +- .../FeatureLib/pfCamera/plCameraBrain.cpp | 10 ++--- .../FeatureLib/pfCamera/plCameraModifier.cpp | 2 +- .../FeatureLib/pfCamera/plVirtualCamNeu.cpp | 2 +- .../pnNetCommon/plSynchedObject.cpp | 2 +- .../NucleusLib/pnNetCommon/plSynchedValue.h | 2 +- .../PubUtilLib/plAvatar/plAvTaskSeek.cpp | 2 +- .../plAvatar/plPhysicalControllerCore.cpp | 8 ++-- .../plInputCore/plAvatarInputInterface.cpp | 16 ++++---- .../plInputCore/plDebugInputInterface.cpp | 16 ++++---- .../plInputCore/plSceneInputInterface.cpp | 2 +- Sources/Plasma/PubUtilLib/plInterp/hsKeys.cpp | 40 +++++++++---------- .../PubUtilLib/plSDL/plStateVariable.cpp | 17 +++++++- 14 files changed, 68 insertions(+), 54 deletions(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 9a883e09..ab9c72af 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -133,7 +133,6 @@ typedef uint32_t hsGSeedValue; #define hsLongAlign(n) (((n) + 3) & ~3L) -#define hsABS(x) ((x) < 0 ? -(x) : (x)) #define hsSGN(x) (((x) < 0) ? -1 : ( ((x) > 0) ? 1 : 0 )) #define hsBitTst2Bool(value, mask) (((value) & (mask)) != 0) diff --git a/Sources/Plasma/CoreLib/hsQuat.cpp b/Sources/Plasma/CoreLib/hsQuat.cpp index 1acf0982..7741d020 100644 --- a/Sources/Plasma/CoreLib/hsQuat.cpp +++ b/Sources/Plasma/CoreLib/hsQuat.cpp @@ -81,7 +81,7 @@ hsPoint3 hsQuat::Rotate(const hsScalarTriple* v) const hsQuat qVec(v->fX, v->fY, v->fZ, 0); hsQuat t = qInv * qVec; hsQuat res = (t * (*this)); - //hsAssert(hsABS(res.fW)<1e-5, "Error rotating vector"); + //hsAssert(fabs(res.fW)<1e-5, "Error rotating vector"); return hsPoint3(res.fX, res.fY, res.fZ); } diff --git a/Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp b/Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp index d5caf08a..4297f284 100644 --- a/Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp +++ b/Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp @@ -301,7 +301,7 @@ void plCameraBrain1::IMoveTowardGoal(double elapsedTime) if (distToGoal <= 5.0f && distToGoal > 0.1f) { float mult = (distToGoal - 5.0f)*0.1f; - adjMaxVel = fVelocity - hsABS(fVelocity*mult); + adjMaxVel = fVelocity - fabs(fVelocity*mult); } @@ -380,7 +380,7 @@ void plCameraBrain1::IPointTowardGoal(double elapsedTime) if (distToGoal <= 5.0f && distToGoal > 0.1f) { float mult = (distToGoal - 5.0f)*0.1f; - adjMaxVel = fPOAVelocity - hsABS(fPOAVelocity*mult); + adjMaxVel = fPOAVelocity - fabs(fPOAVelocity*mult); } @@ -483,7 +483,7 @@ bool plCameraBrain1::IShouldDecelerate(float decelSpeed, float curSpeed, float d float avgSpeed = curSpeed * .5f; float stopDist = avgSpeed * stopTime; - return (hsABS(distToGoal) <= hsABS(stopDist)); // stopDist+avgSpeed? + return (fabs(distToGoal) <= fabs(stopDist)); // stopDist+avgSpeed? } // @@ -560,7 +560,7 @@ float plCameraBrain1::IMakeFOVwZoom(float fovH) const { float num = tan(hsDegreesToRadians(fovH / 2)) * tan(hsDegreesToRadians(fCamera->GetFOVw() / 2)); float denom = tan(hsDegreesToRadians(fCamera->GetFOVh() / 2)); - return 2 * hsABS(hsRadiansToDegrees(atan(num / denom))); + return 2 * fabs(hsRadiansToDegrees(atan(num / denom))); } bool plCameraBrain1::MsgReceive(plMessage* msg) @@ -1689,7 +1689,7 @@ hsPoint3 plCameraBrain1_Circle::MoveTowardsFromGoal(const hsPoint3* fromGoal, do if (fCurRad != fGoalRad) { - float dist = hsABS(fGoalRad-fCurRad); + float dist = fabs(fGoalRad-fCurRad); hsAssert(dist>=0 && dist<=kTwoPI, "illegal radian diff"); bool mustWrap = (dist > M_PI); // go opposite direction for shortcut and wrap diff --git a/Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.cpp b/Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.cpp index 6723f0bf..a6f2a0e4 100644 --- a/Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.cpp +++ b/Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.cpp @@ -198,7 +198,7 @@ bool plCameraModifier1::MsgReceive(plMessage* msg) { double time = (double)fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fAccel; double time2 = (double)pEventMsg->fEventTime; - time = hsABS(time - time2); + time = fabs(time - time2); float h = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVh; float w = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVw; if (GetBrain()) diff --git a/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp b/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp index 2e1237d3..5a92a0f8 100644 --- a/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp +++ b/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp @@ -1949,7 +1949,7 @@ void plVirtualCam1::StartTransition(CamTrans* transition) pBrain->SetCamera(fTransitionCamera); // deal with FOV - - float diffH = hsABS(pCam->GetFOVh() - fPrevCam->GetFOVh()); + float diffH = fabs(pCam->GetFOVh() - fPrevCam->GetFOVh()); if ( diffH ) { double time = 0; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp index e11123a5..e1483f8c 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp @@ -134,7 +134,7 @@ void plSynchedObject::IAppendSynchedValueFriend(plSynchedValueBase* v) uint8_t plSynchedObject::RegisterSynchedValue(plSynchedValueBase* v) { int32_t addrOff = ((int32_t)v - (int32_t)this)>>2; - hsAssert(hsABS(addrOff) < (uint32_t)(1<<(sizeof(AddrOffsetType)<<3)), "address offset overflow"); + hsAssert(abs(addrOff) < (uint32_t)(1<<(sizeof(AddrOffsetType)<<3)), "address offset overflow"); IAppendSynchedValueAddrOffset((AddrOffsetType)addrOff); int32_t idx = fNumSynchedValues-1; hsAssert(idx<256, "index too big"); diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h index 079c5800..77a0b60e 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h @@ -87,7 +87,7 @@ protected: // is set to his address so we can automatically get at it during construction. fFlags=0; int32_t off = (int32_t)plSynchedObject::GetStaticSynchedObject() - (int32_t)this; - if ( hsABS(off) < (1<<(sizeof(fSynchedObjectAddrOffset)<<3)) ) + if ( abs(off) < (1<<(sizeof(fSynchedObjectAddrOffset)<<3)) ) fSynchedObjectAddrOffset = (int16_t)off; else fSynchedObjectAddrOffset=-1; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp index 3f80b997..57501f05 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp @@ -622,7 +622,7 @@ float QuatAngleDiff(const hsQuat &a, const hsQuat &b) // Calling acos on 1.0 is returning an undefined value. Need to check for it. float epsilon = 0.00001; - if (hsABS(cos_t - 1.f) < epsilon) + if (fabs(cos_t - 1.f) < epsilon) return 0; theta = acos(cos_t); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp index 8a4a5903..b6c5451a 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp @@ -284,7 +284,7 @@ void plAnimatedMovementStrategy::RecalcVelocity(double timeNow, float elapsed, b // Update controller rotation float zRot = fAnimAngularVel + fTurnStr; - if (hsABS(zRot) > 0.0001f) + if (fabs(zRot) > 0.0001f) fController->IncrementAngle(zRot * elapsed); // Update controller velocity @@ -396,7 +396,7 @@ void plWalkingStrategy::Apply(float delSecs) hsVector3 achievedVelocity = fController->GetAchievedLinearVelocity(); // Add in gravity if the avatar's z velocity isn't being set explicitly - if (hsABS(velocity.fZ) < 0.001f) + if (fabs(velocity.fZ) < 0.001f) { // Get our previous z velocity. If we're on the ground, clamp it to zero at // the largest, so we won't launch into the air if we're running uphill. @@ -625,7 +625,7 @@ void plSwimStrategy::Apply(float delSecs) hsVector3 linCurrent(0.0f, 0.0f, 0.0f); fCurrentRegion->GetCurrent(fController, linCurrent, angCurrent, delSecs); - if (hsABS(angCurrent) > 0.0001f) + if (fabs(angCurrent) > 0.0001f) fController->IncrementAngle(angCurrent * delSecs); velocity += linCurrent; @@ -710,7 +710,7 @@ void plDynamicWalkingStrategy::Apply(float delSecs) hsVector3 achievedVelocity = fController->GetAchievedLinearVelocity(); // Add in gravity if the avatar's z velocity isn't being set explicitly - if (hsABS(velocity.fZ) < 0.001f) + if (fabs(velocity.fZ) < 0.001f) { // Get our previous z velocity. If we're on the ground, clamp it to zero at // the largest, so we won't launch into the air if we're running uphill. diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp index ca7ef87e..a6a1744e 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp @@ -849,17 +849,17 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg ) if (mouseMap->fMap[i]->fControlFlags & kControlFlagRangePos) { if (mouseMap->fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((mouseMap->fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); + pct = fabs((mouseMap->fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); else - pct = hsABS((mouseMap->fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); + pct = fabs((mouseMap->fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); } else if (mouseMap->fMap[i]->fControlFlags & kControlFlagRangeNeg) { if (mouseMap->fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((mouseMap->fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); + pct = fabs((mouseMap->fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); else - pct = hsABS((mouseMap->fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); + pct = fabs((mouseMap->fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); } pCmd->fPct = pct; if (pct == 1.0f || pct == -1.0f) @@ -960,17 +960,17 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg ) if (mouseMap->fMap[i]->fControlFlags & kControlFlagRangePos) { if (mouseMap->fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((mouseMap->fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); + pct = fabs((mouseMap->fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); else - pct = hsABS((mouseMap->fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); + pct = fabs((mouseMap->fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); } else if (mouseMap->fMap[i]->fControlFlags & kControlFlagRangeNeg) { if (mouseMap->fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((mouseMap->fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); + pct = fabs((mouseMap->fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (mouseMap->fMap[i]->fBox.fY - mouseMap->fMap[i]->fBox.fX)); else - pct = hsABS((mouseMap->fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); + pct = fabs((mouseMap->fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (mouseMap->fMap[i]->fBox.fW - mouseMap->fMap[i]->fBox.fZ)); } pCmd->fPct = pct; if (pct == 1.0f || pct == -1.0f) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plDebugInputInterface.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plDebugInputInterface.cpp index ddec7617..86104386 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plDebugInputInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plDebugInputInterface.cpp @@ -245,17 +245,17 @@ bool plDebugInputInterface::InterpretInputEvent( plInputEventMsg *pMsg ) if (fMouseMap.fMap[i]->fControlFlags & kControlFlagRangePos) { if (fMouseMap.fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((fMouseMap.fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); + pct = fabs((fMouseMap.fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); else - pct = hsABS((fMouseMap.fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); + pct = fabs((fMouseMap.fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); } else if (fMouseMap.fMap[i]->fControlFlags & kControlFlagRangeNeg) { if (fMouseMap.fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((fMouseMap.fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); + pct = fabs((fMouseMap.fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); else - pct = hsABS((fMouseMap.fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); + pct = fabs((fMouseMap.fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); } pCmd->fPct = pct; if (pct == 1.0f || pct == -1.0f) @@ -320,17 +320,17 @@ bool plDebugInputInterface::InterpretInputEvent( plInputEventMsg *pMsg ) if (fMouseMap.fMap[i]->fControlFlags & kControlFlagRangePos) { if (fMouseMap.fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((fMouseMap.fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); + pct = fabs((fMouseMap.fMap[i]->fBox.fX - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); else - pct = hsABS((fMouseMap.fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); + pct = fabs((fMouseMap.fMap[i]->fBox.fZ - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); } else if (fMouseMap.fMap[i]->fControlFlags & kControlFlagRangeNeg) { if (fMouseMap.fMap[i]->fControlFlags & kControlFlagXAxisEvent) - pct = hsABS((fMouseMap.fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); + pct = fabs((fMouseMap.fMap[i]->fBox.fY - pMouseMsg->GetXPos()) / (fMouseMap.fMap[i]->fBox.fY - fMouseMap.fMap[i]->fBox.fX)); else - pct = hsABS((fMouseMap.fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); + pct = fabs((fMouseMap.fMap[i]->fBox.fW - pMouseMsg->GetYPos()) / (fMouseMap.fMap[i]->fBox.fW - fMouseMap.fMap[i]->fBox.fZ)); } pCmd->fPct = pct; if (pct == 1.0f || pct == -1.0f) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp index 8ae64159..efc773c6 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp @@ -413,7 +413,7 @@ bool plSceneInputInterface::MsgReceive( plMessage *msg ) return true; } - if (hsABS(avPt.fZ - objPt.fZ) > 1.0f) // you need to also be in the same plane (some books are on top of rocks you need to jump onto) + if (fabs(avPt.fZ - objPt.fZ) > 1.0f) // you need to also be in the same plane (some books are on top of rocks you need to jump onto) { ResetClickableState(); return true; diff --git a/Sources/Plasma/PubUtilLib/plInterp/hsKeys.cpp b/Sources/Plasma/PubUtilLib/plInterp/hsKeys.cpp index 054b48fa..1f722233 100644 --- a/Sources/Plasma/PubUtilLib/plInterp/hsKeys.cpp +++ b/Sources/Plasma/PubUtilLib/plInterp/hsKeys.cpp @@ -61,9 +61,9 @@ void hsPoint3Key::Write(hsStream *stream) bool hsPoint3Key::CompareValue(hsPoint3Key *key) { - return hsABS(fValue.fX - key->fValue.fX) < .01 && - hsABS(fValue.fY - key->fValue.fY) < .01 && - hsABS(fValue.fZ - key->fValue.fZ) < .01; + return fabs(fValue.fX - key->fValue.fX) < .01 && + fabs(fValue.fY - key->fValue.fY) < .01 && + fabs(fValue.fZ - key->fValue.fZ) < .01; } void hsBezPoint3Key::Read(hsStream *stream) @@ -84,9 +84,9 @@ void hsBezPoint3Key::Write(hsStream *stream) bool hsBezPoint3Key::CompareValue(hsBezPoint3Key *key) { - return hsABS(fValue.fX - key->fValue.fX) < .01 && - hsABS(fValue.fY - key->fValue.fY) < .01 && - hsABS(fValue.fZ - key->fValue.fZ) < .01; + return fabs(fValue.fX - key->fValue.fX) < .01 && + fabs(fValue.fY - key->fValue.fY) < .01 && + fabs(fValue.fZ - key->fValue.fZ) < .01; } ///////////////////////////////////////// @@ -179,21 +179,21 @@ void hsCompressedQuatKey32::SetQuat(hsQuat &q) { q.Normalize(); uint32_t maxElement = kCompQuatNukeX; - float maxVal = hsABS(q.fX); - if (hsABS(q.fY) > maxVal) + float maxVal = fabs(q.fX); + if (fabs(q.fY) > maxVal) { maxElement = kCompQuatNukeY; - maxVal = hsABS(q.fY); + maxVal = fabs(q.fY); } - if (hsABS(q.fZ) > maxVal) + if (fabs(q.fZ) > maxVal) { maxElement = kCompQuatNukeZ; - maxVal = hsABS(q.fZ); + maxVal = fabs(q.fZ); } - if (hsABS(q.fW) > maxVal) + if (fabs(q.fW) > maxVal) { maxElement = kCompQuatNukeW; - maxVal = hsABS(q.fW); + maxVal = fabs(q.fW); } switch (maxElement) { @@ -322,21 +322,21 @@ void hsCompressedQuatKey64::SetQuat(hsQuat &q) { q.Normalize(); uint32_t maxElement = kCompQuatNukeX; - float maxVal = hsABS(q.fX); - if (hsABS(q.fY) > maxVal) + float maxVal = fabs(q.fX); + if (fabs(q.fY) > maxVal) { maxElement = kCompQuatNukeY; - maxVal = hsABS(q.fY); + maxVal = fabs(q.fY); } - if (hsABS(q.fZ) > maxVal) + if (fabs(q.fZ) > maxVal) { maxElement = kCompQuatNukeZ; - maxVal = hsABS(q.fZ); + maxVal = fabs(q.fZ); } - if (hsABS(q.fW) > maxVal) + if (fabs(q.fW) > maxVal) { maxElement = kCompQuatNukeW; - maxVal = hsABS(q.fW); + maxVal = fabs(q.fW); } switch (maxElement) { diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp index ef01995f..c514555a 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp @@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include +#include #include "hsStream.h" #include "hsTimer.h" #include "plSDL.h" @@ -2110,10 +2111,24 @@ void plSimpleStateVariable::CopyData(const plSimpleStateVariable* other, uint32_ // send notification msg if necessary, called internally // +template +typename std::enable_if::value, _T>::type +_generic_abs(_T value) +{ + return fabs(value); +} + +template +typename std::enable_if::value, _T>::type +_generic_abs(_T value) +{ + return abs(value); +} + #define NOTIFY_CHECK(type, var) \ case type: \ for(i=0;ivar[i])>d) \ + if (_generic_abs(var[i] - other->var[i]) > d) \ { \ notify=true; \ break; \