From 5c2e96bec018046dfd91862642ac5eacaa02a55a Mon Sep 17 00:00:00 2001 From: UngVince <62026087+ungvince@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:42:23 +0100 Subject: [PATCH 1/3] build: use SSE floating point math on Linux With -m32, gcc does float math on the x87 by default, so the results depend on the gcc version and optimization level, and that can change how tas scripts play. SSE rounds every float operation the same way. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e3ef6a93..d9eb05b6 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ VERSION=$(shell git describe --tags) DEPS=$(OBJS:%.o=%.d) WARNINGS=-Wall -Wno-parentheses -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor -Wno-overloaded-virtual -CXXFLAGS=-std=c++17 -m32 $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -Ilib/ffmpeg/include -Ilib/SFML/include -Ilib/curl/include -Ilib/discord-rpc/include -DSFML_STATIC -DCURL_STATICLIB +CXXFLAGS=-std=c++17 -m32 -msse2 -mfpmath=sse $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -Ilib/ffmpeg/include -Ilib/SFML/include -Ilib/curl/include -Ilib/discord-rpc/include -DSFML_STATIC -DCURL_STATICLIB LDFLAGS=-m32 -shared -lstdc++fs -Llib/ffmpeg/lib/linux -lavformat -lavcodec -lavutil -lswscale -lswresample -lx264 -lx265 -lvorbis -lvorbisenc -lvorbisfile -logg -lopus -lvpx -Llib/SFML/lib/linux -lsfml -Llib/curl/lib/linux -lcurl -lssl -lcrypto -lnghttp2 -Llib/discord-rpc/lib/linux -ldiscord-rpc # Import config.mk, which can be used for optional config From 14744abf1defdae2d4e6106f21872378eae218a1 Mon Sep 17 00:00:00 2001 From: UngVince <62026087+ungvince@users.noreply.github.com> Date: Mon, 9 Nov 2026 00:46:00 +0100 Subject: [PATCH 2/3] fix: (tas v10) same tas tool results on Linux as on Windows glibc's sinf and cosf sometimes return a slightly different value than MSVC's, which computes them in double. That was enough for some tool-heavy scripts to play out differently on Linux (a cube ended up 356 units away in one). Compute them in double everywhere. This changes how existing scripts play on Linux, so it only applies from version 10. --- docs/p2tas.md | 6 ++- src/Features/Tas/TasParser.hpp | 2 +- src/Features/Tas/TasTool.hpp | 19 +++++-- .../Tas/TasTools/AbsoluteMoveTool.cpp | 4 +- src/Features/Tas/TasTools/AngleToolsUtils.cpp | 16 +++--- src/Features/Tas/TasTools/AngleToolsUtils.hpp | 4 +- src/Features/Tas/TasTools/AutoAimTool.cpp | 1 + src/Features/Tas/TasTools/DecelTool.cpp | 4 +- src/Features/Tas/TasTools/MoveTool.cpp | 32 +++++++++--- src/Features/Tas/TasTools/MoveTool.hpp | 13 +++++ src/Features/Tas/TasTools/SetAngleTool.cpp | 1 + src/Features/Tas/TasTools/StrafeTool.cpp | 52 +++++++++---------- src/Features/Tas/TasTools/TasUtils.cpp | 5 +- src/Utils/Math.hpp | 28 ++++++++++ 14 files changed, 133 insertions(+), 54 deletions(-) diff --git a/docs/p2tas.md b/docs/p2tas.md index f74cfbed..053b4eb8 100644 --- a/docs/p2tas.md +++ b/docs/p2tas.md @@ -64,7 +64,7 @@ The parser is case-sensitive. All keywords are lowercase. The file should begin with a set of properties, defined in this exact order: -- `version ` - required, defines a version of the script file, which affects how the script is processed and executed. Currently, the newest version is 7. For more details, see [Version History](#version-history). +- `version ` - required, defines a version of the script file, which affects how the script is processed and executed. Currently, the newest version is 10. For more details, see [Version History](#version-history). - `start {next} {save/next/cm/now} ` - required, defines a starting point for the script file playback: - `next` - when used, playback doesn't start immediately after the given starting operation, but after the next game load. Usually used in full-game runs to run scripts right after level transition. - `save` - starts from a save with a given `name`. @@ -429,5 +429,7 @@ Stops all tools that were activated in the past tickbulks. Optionally, it accept - Fix `decel` tool not respecting jump-based tools. - Version 9: - Fix `use` tool by processing some tools during input fetching. +- Version 10: + - Fix tools giving slightly different results on Linux than on Windows by computing `sinf`, `cosf` etc. in double on both. -Last updated during version 9 release. +Last updated during version 10 release. diff --git a/src/Features/Tas/TasParser.hpp b/src/Features/Tas/TasParser.hpp index b3d2992f..7465c757 100644 --- a/src/Features/Tas/TasParser.hpp +++ b/src/Features/Tas/TasParser.hpp @@ -1,7 +1,7 @@ #pragma once #include "TasScript.hpp" -#define MAX_SCRIPT_VERSION 9 +#define MAX_SCRIPT_VERSION 10 #include #include diff --git a/src/Features/Tas/TasTool.hpp b/src/Features/Tas/TasTool.hpp index 85e6c823..79471ac9 100644 --- a/src/Features/Tas/TasTool.hpp +++ b/src/Features/Tas/TasTool.hpp @@ -5,15 +5,26 @@ #include #include +// glibc's sinf etc. sometimes return a slightly different value than +// MSVC's, which computes them in double. Since version 10 the tools use +// Math::Sin etc. (float in/out, computed in double) on every platform. +// Older scripts keep the platform's own functions +#define tasSinf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Sin(x) : sinf(x)) +#define tasCosf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Cos(x) : cosf(x)) +#define tasAtan2f(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Atan2(x, y) : atan2f(x, y)) +#define tasAcosf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Acos(x) : acosf(x)) +#define tasAsinf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Asin(x) : asinf(x)) +#define tasPowf(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Pow(x, y) : powf(x, y)) + // A bunch of stuff accidentally used sin/cos directly, which led to // inconsistent scripts between Windows and Linux since Windows has // overloads for some functions. These helper macros dispatch to // sinf/cosf on newer script versions for platform consistency #define absOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(3) ? fabsf(x) : abs(x)) // we noticed this one sooner lol -#define sinOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? sinf(x) : sin(x)) -#define cosOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? cosf(x) : cos(x)) -#define atan2Old(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? atan2f(x, y) : atan2(x, y)) -#define powOld(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? powf(x, y) : pow(x, y)) +#define sinOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasSinf(x) : sin(x)) +#define cosOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasCosf(x) : cos(x)) +#define atan2Old(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasAtan2f(x, y) : atan2(x, y)) +#define powOld(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasPowf(x, y) : pow(x, y)) struct TasToolParams { bool enabled = false; diff --git a/src/Features/Tas/TasTools/AbsoluteMoveTool.cpp b/src/Features/Tas/TasTools/AbsoluteMoveTool.cpp index 2d939389..fcf87fe3 100644 --- a/src/Features/Tas/TasTools/AbsoluteMoveTool.cpp +++ b/src/Features/Tas/TasTools/AbsoluteMoveTool.cpp @@ -29,8 +29,8 @@ void AbsoluteMoveTool::Apply(TasFramebulk &fb, const TasPlayerInfo &playerInfo) float desired = params.direction; float rad = DEG2RAD(desired - angles.y); - float x = -sinf(rad); - float y = cosf(rad) / forward_coef; + float x = -tasSinf(rad); + float y = tasCosf(rad) / forward_coef; x *= params.strength; y *= params.strength; diff --git a/src/Features/Tas/TasTools/AngleToolsUtils.cpp b/src/Features/Tas/TasTools/AngleToolsUtils.cpp index 510cf9a3..f8d69599 100644 --- a/src/Features/Tas/TasTools/AngleToolsUtils.cpp +++ b/src/Features/Tas/TasTools/AngleToolsUtils.cpp @@ -1,16 +1,18 @@ #include "AngleToolsUtils.hpp" +#include "Features/Tas/TasPlayer.hpp" + namespace AngleToolsUtils { - float Ease(float t, EasingType easingType) { + float Ease(int slot, float t, EasingType easingType) { if (t == 0.0f || t == 1.0f) return t; switch (easingType) { case Sine: - return (cosf(M_PI * t) - 1.0f) / -2.0f; + return (tasCosf(M_PI * t) - 1.0f) / -2.0f; case Cubic: - return t < 0.5f ? 4.0f * t * t * t : 1.0f - powf(-2.0f * t + 2.0f, 3.0f) / 2.0f; + return t < 0.5f ? 4.0f * t * t * t : 1.0f - tasPowf(-2.0f * t + 2.0f, 3.0f) / 2.0f; case Exponential: - return t < 0.5f ? powf(2.0f, 20.0f * t - 10.0f) / 2 : (2 - powf(2.0f, -20.0f * t + 10.0f)) / 2.0f; + return t < 0.5f ? tasPowf(2.0f, 20.0f * t - 10.0f) / 2 : (2 - tasPowf(2.0f, -20.0f * t + 10.0f)) / 2.0f; default: return t; } @@ -30,7 +32,7 @@ namespace AngleToolsUtils { } } - Vector GetInterpolatedViewAnalog(Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType) { + Vector GetInterpolatedViewAnalog(int slot, Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType) { Vector requiredDelta = currentAngles - targetAngles; while (requiredDelta.y < 0.0f) requiredDelta.y += 360.0f; @@ -46,8 +48,8 @@ namespace AngleToolsUtils { } else { float realFactorNow = elapsedTicks / (float)easingTicks; float realFactorNext = (elapsedTicks + 1) / (float)easingTicks; - float easeFactorNow = Ease(realFactorNow, easingType); - float easeFactorNext = Ease(realFactorNext, easingType); + float easeFactorNow = Ease(slot, realFactorNow, easingType); + float easeFactorNext = Ease(slot, realFactorNext, easingType); // how much of the remaining angle distance we should move float partFactor = (easeFactorNext - easeFactorNow) / (1.0f - easeFactorNow); diff --git a/src/Features/Tas/TasTools/AngleToolsUtils.hpp b/src/Features/Tas/TasTools/AngleToolsUtils.hpp index d010a0f8..1462699b 100644 --- a/src/Features/Tas/TasTools/AngleToolsUtils.hpp +++ b/src/Features/Tas/TasTools/AngleToolsUtils.hpp @@ -9,7 +9,7 @@ namespace AngleToolsUtils { Exponential, }; - float Ease(float t, EasingType easingType); + float Ease(int slot, float t, EasingType easingType); EasingType ParseEasingType(std::string typeStr); - Vector GetInterpolatedViewAnalog(Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType); + Vector GetInterpolatedViewAnalog(int slot, Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType); } diff --git a/src/Features/Tas/TasTools/AutoAimTool.cpp b/src/Features/Tas/TasTools/AutoAimTool.cpp index c0d87bd6..56efa0fe 100644 --- a/src/Features/Tas/TasTools/AutoAimTool.cpp +++ b/src/Features/Tas/TasTools/AutoAimTool.cpp @@ -113,6 +113,7 @@ void AutoAimTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) { yaw *= 180.0f / M_PI; bulk.viewAnalog = AngleToolsUtils::GetInterpolatedViewAnalog( + slot, QAngleToVector(playerInfo.angles), Vector{pitch, yaw}, params.easingTicks, diff --git a/src/Features/Tas/TasTools/DecelTool.cpp b/src/Features/Tas/TasTools/DecelTool.cpp index 3fd3eb5a..0bb01124 100644 --- a/src/Features/Tas/TasTools/DecelTool.cpp +++ b/src/Features/Tas/TasTools/DecelTool.cpp @@ -25,8 +25,8 @@ void DecelTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) { // move the opposite side of your current velocity float moveAngle = DEG2RAD(TasUtils::GetVelocityAngles(&playerInfo).x + 180 - playerInfo.angles.y + bulk.viewAnalog.x); - bulk.moveAnalog.x = -sinf(moveAngle); - bulk.moveAnalog.y = cosf(moveAngle); + bulk.moveAnalog.x = -tasSinf(moveAngle); + bulk.moveAnalog.y = tasCosf(moveAngle); // make sure to move only the necessary amount float maxAccel = autoStrafeTool[this->slot].GetMaxAccel(playerInfo, autoStrafeTool[this->slot].CreateWishDir(playerInfo,bulk.moveAnalog.y, bulk.moveAnalog.x)); diff --git a/src/Features/Tas/TasTools/MoveTool.cpp b/src/Features/Tas/TasTools/MoveTool.cpp index 6ea31173..7ad84b23 100644 --- a/src/Features/Tas/TasTools/MoveTool.cpp +++ b/src/Features/Tas/TasTools/MoveTool.cpp @@ -26,11 +26,28 @@ void MoveTool::Apply(TasFramebulk &fb, const TasPlayerInfo &playerInfo) { tasAbsoluteMoveTool[slot].Reset(); } - fb.moveAnalog.x = params.sideMove; - fb.moveAnalog.y = params.forwardMove; + float forwardMove = params.forwardMove; + float sideMove = params.sideMove; + + if (params.movingByDegrees) { + forwardMove = tasCosf(params.degrees); + sideMove = tasSinf(params.degrees); + + if (params.scaleAssigned) { + auto length = sqrtf((forwardMove * forwardMove) + (sideMove * sideMove)); + forwardMove /= length; + sideMove /= length; + } + + forwardMove *= params.scale; + sideMove *= params.scale; + } + + fb.moveAnalog.x = sideMove; + fb.moveAnalog.y = forwardMove; if (sar_tas_debug.GetBool()) { - console->Print("move %.3f %.3f\n", params.forwardMove, params.sideMove); + console->Print("move %.3f %.3f\n", forwardMove, sideMove); } } @@ -41,6 +58,7 @@ std::shared_ptr MoveTool::ParseParams(std::vector vp float forwardMove = 0.0f; float sideMove = 0.0f; + float degrees = 0.0f; float scale = 1.0f; int numberCount = 0; @@ -58,9 +76,7 @@ std::shared_ptr MoveTool::ParseParams(std::vector vp throw TasParserException(Utils::ssprintf("Repeated degrees parameter for tool %s: %s", this->GetName(), param.c_str())); } movingByDegrees = true; - float degrees = TasParser::toFloat(param.substr(0, param.size() - 3)); - forwardMove = cosf(degrees); - sideMove = sinf(degrees); + degrees = TasParser::toFloat(param.substr(0, param.size() - 3)); } else if (param == "forward") { @@ -104,6 +120,10 @@ std::shared_ptr MoveTool::ParseParams(std::vector vp throw TasParserException(Utils::ssprintf("Too many direction identifiers for tool %s", this->GetName())); } + if (movingByDegrees) { + return std::make_shared(degrees, scale, scaleAssigned); + } + if (directionsCount > 0 || scaleAssigned) { auto length = sqrtf((forwardMove * forwardMove) + (sideMove * sideMove)); forwardMove /= length; diff --git a/src/Features/Tas/TasTools/MoveTool.hpp b/src/Features/Tas/TasTools/MoveTool.hpp index ae36f1fc..3fbe5f55 100644 --- a/src/Features/Tas/TasTools/MoveTool.hpp +++ b/src/Features/Tas/TasTools/MoveTool.hpp @@ -5,6 +5,11 @@ struct MoveToolParams : public TasToolParams { float forwardMove = 0; float sideMove = 0; + // `deg`: the direction is computed in Apply, where the script version is known + bool movingByDegrees = false; + float degrees = 0; + float scale = 1; + bool scaleAssigned = false; MoveToolParams() : TasToolParams() { } @@ -14,6 +19,14 @@ struct MoveToolParams : public TasToolParams { , forwardMove(forwardMove) , sideMove(sideMove) { } + + MoveToolParams(float degrees, float scale, bool scaleAssigned) + : TasToolParams(true) + , movingByDegrees(true) + , degrees(degrees) + , scale(scale) + , scaleAssigned(scaleAssigned) { + } }; class MoveTool : public TasToolWithParams { diff --git a/src/Features/Tas/TasTools/SetAngleTool.cpp b/src/Features/Tas/TasTools/SetAngleTool.cpp index d7a5e262..d64f9354 100644 --- a/src/Features/Tas/TasTools/SetAngleTool.cpp +++ b/src/Features/Tas/TasTools/SetAngleTool.cpp @@ -30,6 +30,7 @@ void SetAngleTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) { } bulk.viewAnalog = bulk.viewAnalog + AngleToolsUtils::GetInterpolatedViewAnalog( + slot, QAngleToVector(playerInfo.angles), target, params.easingTicks, diff --git a/src/Features/Tas/TasTools/StrafeTool.cpp b/src/Features/Tas/TasTools/StrafeTool.cpp index ec2d0a7b..c20f47d9 100644 --- a/src/Features/Tas/TasTools/StrafeTool.cpp +++ b/src/Features/Tas/TasTools/StrafeTool.cpp @@ -111,7 +111,7 @@ bool AutoStrafeTool::TryReachTargetValues(TasFramebulk &bulk, const TasPlayerInf velocity.z = 0; float targetAngleRad = DEG2RAD(params.strafeDir.angle); - Vector targetVel = Vector{cosf(targetAngleRad), sinf(targetAngleRad), 0} * params.strafeSpeed.speed; + Vector targetVel = Vector{tasCosf(targetAngleRad), tasSinf(targetAngleRad), 0} * params.strafeSpeed.speed; Vector targetVelDelta = targetVel - velocity; if (targetVelDelta == Vector(0, 0, 0)) { @@ -129,12 +129,12 @@ bool AutoStrafeTool::TryReachTargetValues(TasFramebulk &bulk, const TasPlayerInf } Vector absoluteWishDir = targetVelDelta.Normalize(); - float absoluteWishDirAngleRad = atan2f(absoluteWishDir.y, absoluteWishDir.x); + float absoluteWishDirAngleRad = tasAtan2f(absoluteWishDir.y, absoluteWishDir.x); float playerYawRad = DEG2RAD(pInfo.angles.y); float wishDirAngleRad = absoluteWishDirAngleRad - playerYawRad; - float forwardMove = cosf(wishDirAngleRad) * params.force; - float sideMove = -sinf(wishDirAngleRad) * params.force; + float forwardMove = tasCosf(wishDirAngleRad) * params.force; + float sideMove = -tasSinf(wishDirAngleRad) * params.force; Vector velocityAfterMove = GetVelocityAfterMove(pInfo, forwardMove, sideMove); Vector afterMoveDelta = velocityAfterMove - velocity; @@ -149,8 +149,8 @@ bool AutoStrafeTool::TryReachTargetValues(TasFramebulk &bulk, const TasPlayerInf wishDirAngleRad -= DEG2RAD(angleDelta); - forwardMove = cosf(wishDirAngleRad); - sideMove = -sinf(wishDirAngleRad); + forwardMove = tasCosf(wishDirAngleRad); + sideMove = -tasSinf(wishDirAngleRad); } float inputScale = targetVelDeltaLength / afterMoveDeltaLength; @@ -177,7 +177,7 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) { FOR_TAS_SCRIPT_VERSIONS_SINCE(8) { // Deal with airlock: we're strafing, so always try to maximize how much // we can turn while also "trying" to meet speed criteria. - Vector absoluteMoveDirection{cosf(DEG2RAD(angle)), sinf(DEG2RAD(angle)), 0}; + Vector absoluteMoveDirection{tasCosf(DEG2RAD(angle)), tasSinf(DEG2RAD(angle)), 0}; Vector airLockFactor = GetAirLockFactorVector(pInfo); bool isDecelerating = pInfo.velocity.Length2D() > params.strafeSpeed.speed; @@ -193,14 +193,14 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) { } } - angle = RAD2DEG(atan2f(absoluteMoveDirection.y, absoluteMoveDirection.x)); + angle = RAD2DEG(tasAtan2f(absoluteMoveDirection.y, absoluteMoveDirection.x)); } // applying the calculated angle depending on the type of strafing if (params.strafeType == AutoStrafeType::VECTORIAL) { float moveAngle = DEG2RAD(angle - pInfo.angles.y); - fb.moveAnalog.x = -sinf(moveAngle); - fb.moveAnalog.y = cosf(moveAngle); + fb.moveAnalog.x = -tasSinf(moveAngle); + fb.moveAnalog.y = tasCosf(moveAngle); if (pInfo.onSpeedPaint) fb.moveAnalog.x *= 2; } else if (params.strafeType == AutoStrafeType::VECTORIAL_CAM) { float lookAngle = this->shouldFollowLine ? params.strafeDir.angle : velAngle; @@ -209,8 +209,8 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) { fb.viewAnalog.x = -(lookAngle - pInfo.angles.y); } float moveAngle = DEG2RAD(angle - lookAngle); - fb.moveAnalog.x = -sinf(moveAngle); - fb.moveAnalog.y = cosf(moveAngle); + fb.moveAnalog.x = -tasSinf(moveAngle); + fb.moveAnalog.y = tasCosf(moveAngle); if (pInfo.onSpeedPaint) fb.moveAnalog.x *= 2; } else if (params.strafeType == AutoStrafeType::ANGULAR) { // making sure moveAnalog is always at maximum value. @@ -220,7 +220,7 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) { fb.moveAnalog = fb.moveAnalog.Normalize(); } - float lookAngle = RAD2DEG(atan2f(fb.moveAnalog.x, fb.moveAnalog.y)); + float lookAngle = RAD2DEG(tasAtan2f(fb.moveAnalog.x, fb.moveAnalog.y)); QAngle newAngle = {0, angle + lookAngle, 0}; fb.viewAnalog.x -= newAngle.y - pInfo.angles.y; @@ -376,7 +376,7 @@ float AutoStrafeTool::GetFastestStrafeAngle(const TasPlayerInfo &player) { // formula shamelessly taken from https://www.jwchong.com/hl/movement.html float cosAng = (maxSpeed - maxAccel) / velocity.Length2D(); - return acosf(fminf(fmaxf(cosAng,0.0f),1.0f)); + return tasAcosf(fminf(fmaxf(cosAng,0.0f),1.0f)); } // get horizontal angle of wishdir that would achieve given velocity @@ -392,24 +392,24 @@ float AutoStrafeTool::GetTargetStrafeAngle(const TasPlayerInfo &player, float ta // Assuming that it is possible to achieve a velocity of a given length, // I'm using a law of cosines to get the right angle for acceleration. - float targetAngle = acosf(-(powOld(currentSpeed, 2) + powOld(maxAccel, 2) - powOld(targetSpeed, 2)) / (2.0f * currentSpeed * maxAccel)) * turningDir; + float targetAngle = tasAcosf(-(powOld(currentSpeed, 2) + powOld(maxAccel, 2) - powOld(targetSpeed, 2)) / (2.0f * currentSpeed * maxAccel)) * turningDir; FOR_TAS_SCRIPT_VERSIONS_SINCE(8) { // When we're affected by pitch, we should recalculate the angle a couple of times to ensure we can reach it. if (params.noPitchLock && IsMovementAffectedByPitch(player)) { float velAngle = TasUtils::GetVelocityAngles(&player).x; float velToLocalAngleDeltaRad = DEG2RAD(player.angles.y) - DEG2RAD(velAngle); - float cosPitch = cosf(DEG2RAD(player.angles.x)); + float cosPitch = tasCosf(DEG2RAD(player.angles.x)); const int maxIterations = 50; for (int i = 0; i < maxIterations; i++) { float correctAng = targetAngle - velToLocalAngleDeltaRad; - float forwardmove = cosf(correctAng) / cosPitch; - float sidemove = -sinf(correctAng); + float forwardmove = tasCosf(correctAng) / cosPitch; + float sidemove = -tasSinf(correctAng); float scaledAccel = maxAccel / sqrtf(forwardmove * forwardmove + sidemove * sidemove); float previousTargetAngle = targetAngle; - targetAngle = acosf(-(powf(currentSpeed, 2) + powf(scaledAccel, 2) - powf(targetSpeed, 2)) / (2.0f * currentSpeed * scaledAccel)) * turningDir; + targetAngle = tasAcosf(-(tasPowf(currentSpeed, 2) + tasPowf(scaledAccel, 2) - tasPowf(targetSpeed, 2)) / (2.0f * currentSpeed * scaledAccel)) * turningDir; if (fabsf(previousTargetAngle - targetAngle) < 0.00001f) { break; @@ -439,7 +439,7 @@ float AutoStrafeTool::GetTurningStrafeAngle(const TasPlayerInfo &player) { float cosAng = -maxAccel / velocity.Length2D(); if (cosAng < -1) cosAng = 0; - return acosf(cosAng); + return tasAcosf(cosAng); } // get horizontal angle of wishdir that would give the biggest turning angle while understrafing @@ -455,7 +455,7 @@ float AutoStrafeTool::GetMaxUnderstrafeAngle(const TasPlayerInfo &player) { float cosAng = maxSpeed / velocity.Length2D(); if (cosAng > 1) cosAng = 1; - return acosf(cosAng); + return tasAcosf(cosAng); } @@ -491,8 +491,8 @@ float AutoStrafeTool::GetStrafeAngle(const TasPlayerInfo &player, AutoStrafePara } float correctAng = (DEG2RAD(velAngle) + ang) - DEG2RAD(player.angles.y); - float forwardmove = cosf(correctAng); - float sidemove = -sinf(correctAng); + float forwardmove = tasCosf(correctAng); + float sidemove = -tasSinf(correctAng); FOR_TAS_SCRIPT_VERSIONS_UNTIL(2) { forwardmove = cosOld(ang); @@ -546,7 +546,7 @@ int AutoStrafeTool::GetTurningDirection(const TasPlayerInfo &pInfo, float desAng // line following is too "wobbly" Vector velocity = GetGroundFrictionVelocity(pInfo); float maxAccel = GetMaxAccel(pInfo, Vector(0, 1) * params.force); - float maxRotAng = RAD2DEG(asinf(maxAccel / velocity.Length2D())); + float maxRotAng = RAD2DEG(tasAsinf(maxAccel / velocity.Length2D())); // scale maxRotAng by surfaceFriction and make it slightly bigger, as the range // is often surpassed by slowfly and some other shit I wasn't able to isolate @@ -616,8 +616,8 @@ int AutoStrafeTool::GetTurningDirection(const TasPlayerInfo &pInfo, float desAng // we're on a speedcapped bumpy road, so we're making sure to detour into speedy highway if (fabsf(pInfo.velocity.x) > speedCappedVel && fabsf(pInfo.velocity.y) > speedCappedVel) { - float velAngle = atan2f(pInfo.velocity.y, pInfo.velocity.x); - float cardinalDir = -sinf(velAngle * 4); + float velAngle = tasAtan2f(pInfo.velocity.y, pInfo.velocity.x); + float cardinalDir = -tasSinf(velAngle * 4); cardinalDir = (cardinalDir == 0) ? turnDir : (cardinalDir / fabsf(cardinalDir)); turnDir = cardinalDir; speedLockAvoided = true; diff --git a/src/Features/Tas/TasTools/TasUtils.cpp b/src/Features/Tas/TasTools/TasUtils.cpp index f824af9d..c5217c4e 100644 --- a/src/Features/Tas/TasTools/TasUtils.cpp +++ b/src/Features/Tas/TasTools/TasUtils.cpp @@ -8,8 +8,9 @@ Vector TasUtils::GetVelocityAngles(const TasPlayerInfo *pi) { Math::VectorNormalize(velocityAngles); - float yaw = atan2f(velocityAngles.y, velocityAngles.x); - float pitch = atan2f(velocityAngles.z, sqrtf(velocityAngles.y * velocityAngles.y + velocityAngles.x * velocityAngles.x)); + int slot = pi->slot; + float yaw = tasAtan2f(velocityAngles.y, velocityAngles.x); + float pitch = tasAtan2f(velocityAngles.z, sqrtf(velocityAngles.y * velocityAngles.y + velocityAngles.x * velocityAngles.x)); return {RAD2DEG(yaw), RAD2DEG(pitch), 0}; } diff --git a/src/Utils/Math.hpp b/src/Utils/Math.hpp index 1caff0ab..638af63d 100644 --- a/src/Utils/Math.hpp +++ b/src/Utils/Math.hpp @@ -1,6 +1,7 @@ #pragma once #include "SDK.hpp" +#include #include #define M_PI 3.14159265358979323846 @@ -14,6 +15,12 @@ class Matrix; namespace Math { void SinCos(float radians, float *sine, float *cosine); + float Sin(float x); + float Cos(float x); + float Atan2(float y, float x); + float Acos(float x); + float Asin(float x); + float Pow(float x, float y); float AngleNormalize(float angle); float VectorNormalize(Vector &vec); void VectorAdd(const Vector &a, const Vector &b, Vector &c); @@ -33,6 +40,27 @@ namespace Math { void LerpAngles(const QAngle &oldAng, const QAngle &newAng, float time, QAngle &outPut); } // namespace Math +// TAS tool math goes through double, as MSVC's x86 CRT does for sinf etc.; +// glibc's float versions give other results on some inputs. The round trip +// must not be optimized away (no -ffast-math) +inline float Math::Sin(float x) { + return (float)std::sin((double)x); +} +inline float Math::Cos(float x) { + return (float)std::cos((double)x); +} +inline float Math::Atan2(float y, float x) { + return (float)std::atan2((double)y, (double)x); +} +inline float Math::Acos(float x) { + return (float)std::acos((double)x); +} +inline float Math::Asin(float x) { + return (float)std::asin((double)x); +} +inline float Math::Pow(float x, float y) { + return (float)std::pow((double)x, (double)y); +} inline void Math::SinCos(float radians, float *sine, float *cosine) { #ifdef _WIN32 _asm { From 751995fc5906f1d99d28cbd1863abecf53cb1466 Mon Sep 17 00:00:00 2001 From: UngVince <62026087+ungvince@users.noreply.github.com> Date: Mon, 9 Nov 2026 00:46:49 +0100 Subject: [PATCH 3/3] fix: (tas v10) same tas tool results with MSVC as with gcc and clang MSVC keeps some float math at higher precision, so the movement and view angle tools give slightly different results on Windows than on Linux. Round to float precision while those tools run. This changes how existing scripts play on Windows, so it only applies from version 10. --- docs/p2tas.md | 1 + src/Features/Tas/TasPlayer.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/p2tas.md b/docs/p2tas.md index 053b4eb8..dffd971c 100644 --- a/docs/p2tas.md +++ b/docs/p2tas.md @@ -431,5 +431,6 @@ Stops all tools that were activated in the past tickbulks. Optionally, it accept - Fix `use` tool by processing some tools during input fetching. - Version 10: - Fix tools giving slightly different results on Linux than on Windows by computing `sinf`, `cosf` etc. in double on both. + - Fix movement and view angle tools giving slightly different results on Windows than on Linux. Last updated during version 10 release. diff --git a/src/Features/Tas/TasPlayer.cpp b/src/Features/Tas/TasPlayer.cpp index b417795d..4a2a1c11 100644 --- a/src/Features/Tas/TasPlayer.cpp +++ b/src/Features/Tas/TasPlayer.cpp @@ -15,6 +15,7 @@ #include "Event.hpp" #include "Variable.hpp" +#include #include #include #include "TasTools/JumpTool.hpp" @@ -844,7 +845,18 @@ void TasPlayer::ApplyTools(TasFramebulk &fb, const TasPlayerInfo &pInfo, TasTool for (std::string toolName : TasTool::priorityList) { auto tool = TasTool::GetInstanceByName(slot, toolName); if (!CanProcessTool(tool, processType)) continue; +#ifdef _M_IX86 + // MSVC keeps some float intermediates on the x87, which rounds them to double; round them to + // float as with gcc and clang. Only the movement and view angle tools do float math; the others keep + // the game's setting. + bool pin = TAS_SCRIPT_VERSION_AT_LEAST(10) && (tool->GetBulkType() & (MOVEMENT | VIEWANGLES)); + unsigned int oldControl = pin ? _controlfp(0, 0) : 0; + if (pin) _controlfp(_PC_24, _MCW_PC); +#endif tool->Apply(fb, pInfo); +#ifdef _M_IX86 + if (pin) _controlfp(oldControl, _MCW_PC); +#endif } }