Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2febbd2
feat(math): Add cross-platform deterministic math via GameMath (fdlibm)
Okladnoj Apr 28, 2026
2730383
fix(math): Route BaseType.h sqrt() through deterministic Sqrt() wrapper
Okladnoj Apr 30, 2026
94cea68
fix(math): Enforce USE_DETERMINISTIC_MATH and complete deterministic …
Okladnoj May 1, 2026
6341acd
fix(math): Restore original formatting and complete deterministic cov…
Okladnoj May 1, 2026
bb13d8b
test(math): Implement diagnostic benchmark for deterministic math parity
Okladnoj May 3, 2026
0af2f0e
fix(math): Resolve VC6 loop scoping error C2374 in benchmark
Okladnoj May 3, 2026
51e719f
TheSuperHackers @fix Disable FMA contraction for cross-platform deter…
Okladnoj May 3, 2026
9bd9edb
refactor(math): Address xezon review feedback on PR #2670
Okladnoj May 5, 2026
fde33e1
style(math): Fix indentation of if statements in benchmark
Okladnoj May 8, 2026
5932f19
Remove duplicate math constants in visualc.h
xezon May 23, 2026
ea61303
Rename new wwmath functions
xezon May 23, 2026
f218797
Remove unused code in Trig.cpp
xezon May 23, 2026
0e5d8d6
Move Trig function impl from wwmath.h to Trig.cpp and correct Sqrt(Real)
xezon May 23, 2026
52908ec
Remove indentation in wwmath.h
xezon May 23, 2026
4142bdc
Call the double gmmath functions
xezon May 23, 2026
f80248f
Fix indentation in wwmath.h
xezon May 23, 2026
cc47aba
Rename Atan, Atan2 to Atan_Legacy, Atan2_Legacy
xezon May 23, 2026
2142089
Rename Atan_Origin, Atan2_Origin, Atanf_Origin, Atan2fOrigin to Atan,…
xezon May 23, 2026
afd03b9
Remove duplicate trig declarations in wwmath.h
xezon May 23, 2026
b1bc06e
Rename Sqrt to Sqrt_Legacy
xezon May 23, 2026
3294fe7
Rename Sqrt_Origin, Sqrtf_Origin to Sqrt, Sqrtf
xezon May 23, 2026
7ceefd5
Rename Asin, Acos to Asin_Legacy, Acos_Legacy
xezon May 23, 2026
5ff0b61
Rename Asin_Origin, Acos_Origin, Asinf_Origin, Acosf_Origin to Asin, …
xezon May 23, 2026
1528b10
Remove redundant scopes in wwmath.h
xezon May 23, 2026
3483838
Rename Inv_Sqrt to Inv_Sqrt_Legacy
xezon May 23, 2026
a2af980
Rename Tan_Origin, Tanf_Origin to Tan, Tanf
xezon May 23, 2026
04dee27
Remove Ceil
xezon May 23, 2026
8a5ca63
Explicitly call double version in Legacy functions
xezon May 23, 2026
7c8bf81
Add deterministic version for Floor, Floorf
xezon May 23, 2026
1e7bc9e
Add deterministic version for Round, Roundf
xezon May 23, 2026
7ec2489
Rename Ceil_Origin, Ceilf_Origin to Ceil, Ceilf
xezon May 23, 2026
f576004
Rename Pow_Origin, Powf_Origin to Pow, Powf
xezon May 23, 2026
1eedfcb
Rename Fabs to Fabsf and make it deterministic/defined behavior
xezon May 23, 2026
c8e590f
Rename Fabsf_Origin to Fabsf_Legacy
xezon May 23, 2026
af74213
Rename Fabs_Origin to Fabs
xezon May 23, 2026
c1af7ea
Remove unused Sign
xezon May 23, 2026
f65e59b
Rename Expf_Origin, Log10f_Origin, Logf_Origin, Sinhf_Origin, Coshf_O…
xezon May 23, 2026
6cc0660
Float_To_Int_Chop, Float_To_Int_Floor pass float by value
xezon May 23, 2026
378b6d2
Add double versions for Exp, Log10, Log, Sinh, Cosh, Tanh
xezon May 23, 2026
1c17a02
Simplify math function definitions
xezon May 23, 2026
faeeae7
Rename Cos, Sin to Cosf, Sinf
xezon May 23, 2026
bf00447
Fix x,y args of Atan2
xezon May 23, 2026
d9205b8
Add double variant for Cos, Sin
xezon May 23, 2026
5e301e5
Separate function definitions from declarations
xezon May 23, 2026
222b6ec
Add determinism to Sin, Cos Fast Tables
xezon May 24, 2026
5215df4
Move Fabsf together with Fabs
xezon May 24, 2026
7f4cc52
Move Sin, Cos together with Tan
xezon May 24, 2026
5ad672d
Add Inv_Sqrt, Inv_Sqrtf
xezon May 24, 2026
3e8ab7a
Move Inv_Sqrt_Legacy together with Inv_Sqrt
xezon May 24, 2026
acec821
Move Sqrt_Legacy together with Sqrt
xezon May 24, 2026
2aec165
Move Float_To_ functions together
xezon May 24, 2026
c8af290
Move float cast functions together
xezon May 24, 2026
9d799ba
Move Acos_Legacy, Asin_Legacy together with Acos, Asin
xezon May 24, 2026
a62c59b
Add some spacings around function declaration blocks
xezon May 24, 2026
781874f
Move Round together with Ceil, Floor
xezon May 24, 2026
1f4d390
Move Pow together with Sqrt
xezon May 24, 2026
7f34668
Move Sinh & Co closer to Sin & Co
xezon May 24, 2026
ebf7547
Reorder trig functions to cos, sin, tan conistently
xezon May 24, 2026
e9e012b
Move Fast_ trig functions closer to regular trig functions
xezon May 24, 2026
80ac812
Move misc function definitions to where they belong
xezon May 24, 2026
a5aa2fd
Move Sqrt_Legacy to correct location
xezon May 24, 2026
eb49bdf
Improve setup for USE_DETERMINISTIC_MATH
xezon May 24, 2026
dfad198
Add coverage for cos/sin/tan
xezon May 25, 2026
fa510df
Rename Cosf, Sinf to Cosf_Legacy, Sinf_Legacy
xezon May 25, 2026
89fe91d
Add coverage for cosf/sinf/tanf
xezon May 25, 2026
7c21cd7
Simplify Trig.cpp
xezon May 25, 2026
4df7386
Add coverage for sqrt
xezon May 25, 2026
420a5ff
Uncomment RETAIL_COMPATIBLE_CRC in BaseType.h
xezon May 25, 2026
c35ce76
Rename Fabsf_Legacy to Fabsf and Fabsf to Fabsf_Legacy
xezon May 25, 2026
ee2c66a
Add coverage for fabsf
xezon May 25, 2026
ec55507
Add a comment for the Legacy functions
xezon May 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ endif()

include(cmake/config.cmake)
include(cmake/gamespy.cmake)
if (NOT IS_VS6_BUILD)
include(cmake/gamemath.cmake)
endif()
include(cmake/lzhl.cmake)

if (IS_VS6_BUILD)
Expand Down
1 change: 1 addition & 0 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_include_directories(corei_libraries_source_wwvegas_wwlib INTERFACE "Libra
target_include_directories(corei_main INTERFACE "Main")

target_sources(corei_libraries_include PRIVATE
Libraries/Include/Lib/BaseDefines.h
Libraries/Include/Lib/BaseType.h
Libraries/Include/Lib/BaseTypeCore.h
Libraries/Include/Lib/trig.h
Expand Down
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#pragma once

// Flags for diagnostic math benchmarks
#define RUN_MATH_BENCHMARK_REPLAY400_FLAG (0)

class SimulationMathCrc
{
public:
static UnsignedInt calculate();
static void runBenchmark(int iterations = 10000);
};
4 changes: 1 addition & 3 deletions Core/GameEngine/Include/Common/GameDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@
#define PRESERVE_RETAIL_SCRIPTED_CAMERA (1) // Retain scripted camera behavior present in retail Generals 1.08 and Zero Hour 1.04
#endif

#ifndef RETAIL_COMPATIBLE_CRC
#define RETAIL_COMPATIBLE_CRC (1) // Game is expected to be CRC compatible with retail Generals 1.08, Zero Hour 1.04
#endif
// RETAIL_COMPATIBLE_CRC is default defined in BaseDefines.h

#ifndef RETAIL_COMPATIBLE_XFER_SAVE
#define RETAIL_COMPATIBLE_XFER_SAVE (1) // Game is expected to be Xfer Save compatible with retail Generals 1.08, Zero Hour 1.04
Expand Down
105 changes: 91 additions & 14 deletions Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include "GameLogic/FPUControl.h"

#include <math.h>
#include <stdio.h>
#include <time.h>

static void appendSimulationMathCrc(XferCRC &xfer)
static void appendSimulationMathCrc_Deterministic(XferCRC &xfer)
{
Matrix3D matrix;
Matrix3D factorsMatrix;
Expand All @@ -37,18 +39,48 @@ static void appendSimulationMathCrc(XferCRC &xfer)
0.9f, 1.0f, 2.1f, 1.2f);

factorsMatrix.Set(
WWMath::Sin(0.7f) * log10f(2.3f),
WWMath::Cos(1.1f) * powf(1.1f, 2.0f),
tanf(0.3f),
asinf(0.967302263f),
acosf(0.967302263f),
atanf(0.967302263f) * powf(1.1f, 2.0f),
atan2f(0.4f, 1.3f),
sinhf(0.2f),
coshf(0.4f) * tanhf(0.5f),
sqrtf(55788.84375f),
expf(0.1f) * log10f(2.3f),
logf(1.4f));
WWMath::Sinf(0.7f) * WWMath::Log10f(2.3f),
WWMath::Cosf(1.1f) * WWMath::Powf(1.1f, 2.0f),
WWMath::Tanf(0.3f),
WWMath::Asinf(0.967302263f),
WWMath::Acosf(0.967302263f),
WWMath::Atanf(0.967302263f) * WWMath::Powf(1.1f, 2.0f),
WWMath::Atan2f(0.4f, 1.3f),
WWMath::Sinhf(0.2f),
WWMath::Coshf(0.4f) * WWMath::Tanhf(0.5f),
WWMath::Sqrtf(55788.84375f),
WWMath::Expf(0.1f) * WWMath::Log10f(2.3f),
WWMath::Logf(1.4f));

Matrix3D::Multiply(matrix, factorsMatrix, &matrix);
matrix.Get_Inverse(matrix);

xfer.xferMatrix3D(&matrix);
}

static void appendSimulationMathCrc_Native(XferCRC &xfer)
{
Matrix3D matrix;
Matrix3D factorsMatrix;

matrix.Set(
4.1f, 1.2f, 0.3f, 0.4f,
0.5f, 3.6f, 0.7f, 0.8f,
0.9f, 1.0f, 2.1f, 1.2f);

factorsMatrix.Set(
(float)(::sin(0.7) * ::log10(2.3)),
(float)(::cos(1.1) * ::pow(1.1, 2.0)),
(float)::tan(0.3),
(float)::asin(0.967302263),
(float)::acos(0.967302263),
(float)(::atan(0.967302263) * ::pow(1.1, 2.0)),
(float)::atan2(0.4, 1.3),
(float)::sinh(0.2),
(float)(::cosh(0.4) * ::tanh(0.5)),
(float)::sqrt(55788.84375),
(float)(::exp(0.1) * ::log10(2.3)),
(float)::log(1.4));

Matrix3D::Multiply(matrix, factorsMatrix, &matrix);
matrix.Get_Inverse(matrix);
Expand All @@ -63,11 +95,56 @@ UnsignedInt SimulationMathCrc::calculate()

setFPMode();

appendSimulationMathCrc(xfer);
appendSimulationMathCrc_Deterministic(xfer);

_fpreset();

xfer.close();

return xfer.getCRC();
}

void SimulationMathCrc::runBenchmark(int iterations)
{
int i;
clock_t startDet = clock();
UnsignedInt crcDet = 0;

setFPMode();

for (i = 0; i < iterations; ++i)
{
XferCRC xfer;
xfer.open("SimMathDet");
appendSimulationMathCrc_Deterministic(xfer);
xfer.close();
if (i == 0)
crcDet = xfer.getCRC();
}
_fpreset();
clock_t endDet = clock();
double timeDetMs = (double)(endDet - startDet) / CLOCKS_PER_SEC * 1000.0;

clock_t startNat = clock();
UnsignedInt crcNat = 0;

setFPMode();

for (i = 0; i < iterations; ++i)
{
XferCRC xfer;
xfer.open("SimMathNat");
appendSimulationMathCrc_Native(xfer);
xfer.close();
if (i == 0)
crcNat = xfer.getCRC();
}
_fpreset();
clock_t endNat = clock();
double timeNatMs = (double)(endNat - startNat) / CLOCKS_PER_SEC * 1000.0;

printf("\n================ MATH BENCHMARK (%d iterations) ================\n", iterations);
printf("Deterministic (WWMath): CRC = %08X, Time = %.2f ms\n", crcDet, timeDetMs);
printf("Native (system math): CRC = %08X, Time = %.2f ms\n", crcNat, timeNatMs);
printf("===========================================================\n\n");
}
4 changes: 2 additions & 2 deletions Core/GameEngine/Source/Common/INI/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,15 +1789,15 @@ void INI::parseDurationReal( INI *ini, void * /*instance*/, void *store, const v
void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ )
{
UnsignedInt val = scanUnsignedInt(ini->getNextToken());
*(UnsignedInt *)store = (UnsignedInt)ceilf(ConvertDurationFromMsecsToFrames((Real)val));
*(UnsignedInt *)store = (UnsignedInt)WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)val));
}

// ------------------------------------------------------------------------------------------------
// parse a duration in msec and convert to duration in integral number of frames, (unsignedshort) rounding UP
void INI::parseDurationUnsignedShort( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ )
{
UnsignedInt val = scanUnsignedInt(ini->getNextToken());
*(UnsignedShort *)store = (UnsignedShort)ceilf(ConvertDurationFromMsecsToFrames((Real)val));
*(UnsignedShort *)store = (UnsignedShort)WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)val));
}

//-------------------------------------------------------------------------------------------------
Expand Down
32 changes: 16 additions & 16 deletions Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,9 @@ inline Bool isReallyClose(const Coord3D& a, const Coord3D& b)
{
const Real CLOSE_ENOUGH = 0.1f;
return
fabs(a.x-b.x) <= CLOSE_ENOUGH &&
fabs(a.y-b.y) <= CLOSE_ENOUGH &&
fabs(a.z-b.z) <= CLOSE_ENOUGH;
WWMath::Fabs(a.x-b.x) <= CLOSE_ENOUGH &&
WWMath::Fabs(a.y-b.y) <= CLOSE_ENOUGH &&
WWMath::Fabs(a.z-b.z) <= CLOSE_ENOUGH;
}

/**
Expand Down Expand Up @@ -921,7 +921,7 @@ void Path::computePointOnPath(
// compute distance of point from this path segment
Real toDistSqr = sqr(toPos.x) + sqr(toPos.y);
Real offsetDistSq = toDistSqr - sqr(alongPathDist);
Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : sqrt(offsetDistSq);
Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : WWMath::Sqrt(offsetDistSq);

// If we are basically on the path, return the next path node as the movement goal.
// However, the farther off the path we get, the movement goal becomes closer to our
Expand Down Expand Up @@ -1011,8 +1011,8 @@ void Path::computePointOnPath(
out.posOnPath.x = closeNodePos->x + alongPathDist * segmentDirNorm.x;
out.posOnPath.y = closeNodePos->y + alongPathDist * segmentDirNorm.y;
out.posOnPath.z = closeNodePos->z;
Real dx = fabs(pos.x - out.posOnPath.x);
Real dy = fabs(pos.y - out.posOnPath.y);
Real dx = WWMath::Fabs(pos.x - out.posOnPath.x);
Real dy = WWMath::Fabs(pos.y - out.posOnPath.y);
if (dx<1 && dy<1 && closeNode->getNextOptimized() && closeNode->getNextOptimized()->getNextOptimized()) {
out.posOnPath = *closeNode->getNextOptimized()->getNextOptimized()->getPosition();
}
Expand Down Expand Up @@ -2070,7 +2070,7 @@ UnsignedInt PathfindCell::costToGoal( PathfindCell *goal )
Int dy = m_info->m_pos.y - goal->getYIndex();
#define NO_REAL_DIST
#ifdef REAL_DIST
Int cost = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy);
Int cost = COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy);
#else
if (dx<0) dx = -dx;
if (dy<0) dy = -dy;
Expand All @@ -2096,7 +2096,7 @@ UnsignedInt PathfindCell::costToHierGoal( PathfindCell *goal )
}
Int dx = m_info->m_pos.x - goal->getXIndex();
Int dy = m_info->m_pos.y - goal->getYIndex();
Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*sqrt(dx*dx + dy*dy) + 0.5f);
Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy) + 0.5f);
return cost;
}

Expand Down Expand Up @@ -3963,8 +3963,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo
Real pty = pt->y - obj->getPosition()->y;

// inverse-rotate it to the right coord system
Real ptx_new = (Real)fabs(ptx*c - pty*s);
Real pty_new = (Real)fabs(ptx*s + pty*c);
Real ptx_new = (Real)WWMath::Fabs(ptx*c - pty*s);
Real pty_new = (Real)WWMath::Fabs(ptx*s + pty*c);

if (ptx_new <= major && pty_new <= minor)
{
Expand Down Expand Up @@ -6415,7 +6415,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ;
toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y);

if ( fabs(fromPos.z - toPos.z)<PATHFIND_CELL_SIZE_F) {
if ( WWMath::Fabs(fromPos.z - toPos.z)<PATHFIND_CELL_SIZE_F) {
newCostSoFar += 7*COST_DIAGONAL;
}
} else if (newCell->getPinched()) {
Expand All @@ -6440,7 +6440,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
} else {
dx = newCellCoord.x - goalCell->getXIndex();
dy = newCellCoord.y - goalCell->getYIndex();
costRemaining = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy);
costRemaining = COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy);
costRemaining -= attackDistance/2;
if (costRemaining<0)
costRemaining=0;
Expand Down Expand Up @@ -6764,7 +6764,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
dx = from->x - to->x;
dy = from->y - to->y;

Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
if (count<2) count = 2;
Int i;
color.green = 0;
Expand Down Expand Up @@ -7455,7 +7455,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
dx = from->x - to->x;
dy = from->y - to->y;

Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
if (count<2) count = 2;
Int i;
color.green = 0;
Expand Down Expand Up @@ -8159,7 +8159,7 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
dx = from->x - to->x;
dy = from->y - to->y;

Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
if (count<2) count = 2;
Int i;
color.green = 0;
Expand Down Expand Up @@ -11216,7 +11216,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
farthestDistanceSqr = distSqr;
if (cellCount > MAX_CELLS) {
#ifdef INTENSE_DEBUG
DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", sqrt(farthestDistanceSqr), repulsorRadius));
DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", WWMath::Sqrt(farthestDistanceSqr), repulsorRadius));
#endif
ok = true; // Already a big search, just take this one.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ void BaseHeightMapRenderObjClass::updateViewImpassableAreas(Bool partial, Int mi
}

// save calculating the tangent over and over again.
Real tanImpassableRad = tan(m_curImpassableSlope / 360.f * 2 * PI);
Real tanImpassableRad = WWMath::Tan(m_curImpassableSlope / 360.f * 2 * PI);
for (Int j = minY; j < maxY; ++j) {
for (Int i = minX; i < maxX; ++i) {
m_showAsVisibleCliff[i + j * xSize] = evaluateAsVisibleCliff(i, j, tanImpassableRad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ void CameraShakeSystemClass::CameraShakerClass::Compute_Rotations(const Vector3
** omega(t) = start_omega + (end_omega - start_omega) * t
** phi = random(0..start_omega)
*/
float intensity = Intensity * (1.0f - WWMath::Sqrt(len2) / Radius) * (1.0f - ElapsedTime / Duration);
float intensity = Intensity * (1.0f - WWMath::Sqrt_Legacy(len2) / Radius) * (1.0f - ElapsedTime / Duration);
for (int i=0; i<3; i++) {
float omega = Omega[i] + (END_OMEGA - Omega[i]) * ElapsedTime;
(*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sin(omega * ElapsedTime + Phi[i]);
(*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sinf_Legacy(omega * ElapsedTime + Phi[i]);

//WST 11/14/2002. Add in additional random fudge. There seems to be a too mathematical pattern of shake with the above
Vector3 secondary_angles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void W3DTankDraw::updateTreadPositions(Real uvDelta)
}

// ensure coordinates of offset are in [0, 1] range:
offset_u = offset_u - WWMath::Floor(offset_u);
offset_u = offset_u - WWMath::Floorf(offset_u);
pTread->m_materialSettings.customUVOffset.Set(offset_u,0);
pTread++;
}
Expand Down Expand Up @@ -398,7 +398,7 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)
{
offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed;
// ensure coordinates of offset are in [0, 1] range:
offset_u = offset_u - WWMath::Floor(offset_u);
offset_u = offset_u - WWMath::Floorf(offset_u);
pTread->m_materialSettings.customUVOffset.Set(offset_u,0);
pTread++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void W3DTankTruckDraw::updateTreadPositions(Real uvDelta)
}

// ensure coordinates of offset are in [0, 1] range:
offset_u = offset_u - WWMath::Floor(offset_u);
offset_u = offset_u - WWMath::Floorf(offset_u);
pTread->m_materialSettings.customUVOffset.Set(offset_u,0);
pTread++;
}
Expand Down Expand Up @@ -720,7 +720,7 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
{
offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed;
// ensure coordinates of offset are in [0, 1] range:
offset_u = offset_u - WWMath::Floor(offset_u);
offset_u = offset_u - WWMath::Floorf(offset_u);
pTread->m_materialSettings.customUVOffset.Set(offset_u,0);
pTread++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1786,8 +1786,8 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera, const Vector3 *c
shiftPivot.X = viewDir.X * magicEdgeLenScale;
shiftPivot.Y = viewDir.Y * magicEdgeLenScale;

newOrgX = WWMath::Round((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline();
newOrgY = WWMath::Round((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline();
newOrgX = WWMath::Roundf((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline();
newOrgY = WWMath::Roundf((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline();
}

WorldHeightMap::DrawArea newDrawArea = m_map->createDrawArea(newOrgX, newOrgY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void W3DMouse::draw()
offset = TheInGameUI->getScrollAmount();
offset.normalize();
Real theta = atan2(-offset.y, offset.x);
theta -= (Real)M_PI/2;
theta -= (Real)WWMATH_HALF_PI;
tm.Rotate_Z(theta);
}
cursorModels[m_currentW3DCursor]->Set_Transform(tm);
Expand Down Expand Up @@ -672,12 +672,12 @@ void W3DMouse::setCursorDirection(MouseCursor cursor)
{
offset.normalize();
Real theta = atan2(offset.y, offset.x);
theta = fmod(theta+M_PI*2,M_PI*2);
theta = fmod(theta+WWMATH_TWO_PI,WWMATH_TWO_PI);
Int numDirections=m_cursorInfo[m_currentCursor].numDirections;
//Figure out which of our predrawn cursor orientations best matches the
//actual cursor direction. Frame 0 is assumed to point right and continue
//clockwise.
m_directionFrame=(Int)(theta/(2.0f*M_PI/(Real)numDirections)+0.5f);
m_directionFrame=(Int)(theta/(WWMATH_TWO_PI/(Real)numDirections)+0.5f);
if (m_directionFrame >= numDirections)
m_directionFrame = 0;
}
Expand Down
Loading