From c5a1b3f4d8d0cacdfe93edce2a897270debfc0cc Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:42:59 +0800 Subject: [PATCH 1/3] FlxMath::fastSinCos (#18) --- flixel/math/FlxMath.hx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/flixel/math/FlxMath.hx b/flixel/math/FlxMath.hx index b0c579e4d9..6243a4bdad 100644 --- a/flixel/math/FlxMath.hx +++ b/flixel/math/FlxMath.hx @@ -548,6 +548,26 @@ class FlxMath return fastSin(n + 1.570796327); // sin and cos are the same, offset by pi/2 } + /** + * ~1.3x faster than calling fastSin() + fastCos() separately. + */ + public static inline function fastSinCos(angle:Float):{sin:Float, cos:Float} + { + var n = angle * 0.3183098862; + + if (n > 1.0 || n < -1.0) + { + n -= Math.ffloor(n * 0.5 + 0.5) * 2.0; + } + + final n2 = n * n; + + final sin = n * (3.1 + n2 * (0.5 + n2 * (-7.2 + n2 * 3.6))); + final cos = 1.0 - 0.5 * n2 + 0.0417 * n2 * n2 - 0.00139 * n2 * n2 * n2; + + return {sin: sin, cos: cos}; + } + /** * Hyperbolic sine. */ From 5e1d3c35f2c48faa75a820e7db79c27271457a5b Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Tue, 10 Feb 2026 08:53:55 +0800 Subject: [PATCH 2/3] Update FlxMath.hx (#19) --- flixel/math/FlxMath.hx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/flixel/math/FlxMath.hx b/flixel/math/FlxMath.hx index 6243a4bdad..5ed9cf553d 100644 --- a/flixel/math/FlxMath.hx +++ b/flixel/math/FlxMath.hx @@ -555,15 +555,32 @@ class FlxMath { var n = angle * 0.3183098862; - if (n > 1.0 || n < -1.0) + if (n > 1) + { + n -= (Math.ceil(n) >> 1) << 1; + } + else if (n < -1) { - n -= Math.ffloor(n * 0.5 + 0.5) * 2.0; + n += (Math.ceil(-n) >> 1) << 1; } - final n2 = n * n; + var sin:Float; + if (n > 0) + { + sin = n * (3.1 + n * (0.5 + n * (-7.2 + n * 3.6))); + } + else + { + sin = n * (3.1 - n * (0.5 + n * (7.2 + n * 3.6))); + } - final sin = n * (3.1 + n2 * (0.5 + n2 * (-7.2 + n2 * 3.6))); - final cos = 1.0 - 0.5 * n2 + 0.0417 * n2 * n2 - 0.00139 * n2 * n2 * n2; + var cos = Math.sqrt(1 - sin * sin); + + var originalN = n * Math.PI; + if (originalN < -Math.PI * 0.5 || originalN > Math.PI * 0.5) + { + cos = -cos; + } return {sin: sin, cos: cos}; } From ed899429f0a84fbb1736bcc93642a80e3eda2d04 Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:36:45 +0800 Subject: [PATCH 3/3] Animation improvement --- flixel/animation/FlxAnimation.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/animation/FlxAnimation.hx b/flixel/animation/FlxAnimation.hx index a49c91f94c..006234d78f 100644 --- a/flixel/animation/FlxAnimation.hx +++ b/flixel/animation/FlxAnimation.hx @@ -177,7 +177,7 @@ class FlxAnimation extends FlxBaseAnimation reversed = Reversed; paused = false; - _frameTimer = 0; + _frameTimer = -FlxG.elapsed / 2; finished = frameDuration == 0; var maxFrameIndex:Int = numFrames - 1;