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 e5418de3c7c96da7cf2dcddf78d96e3bb8b942af Mon Sep 17 00:00:00 2001 From: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com> Date: Sun, 22 Feb 2026 12:39:13 +0800 Subject: [PATCH 3/3] Update FlxAction.hx --- flixel/input/actions/FlxAction.hx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/flixel/input/actions/FlxAction.hx b/flixel/input/actions/FlxAction.hx index 07b9250d92..7fed39918a 100644 --- a/flixel/input/actions/FlxAction.hx +++ b/flixel/input/actions/FlxAction.hx @@ -341,7 +341,7 @@ class FlxAction implements IFlxDestroyable var _x:Null = null; var _y:Null = null; - var _timestamp:Int = 0; + var _check:Bool = false; var _checked(get, set):Bool; inline function get__checked():Bool @@ -441,13 +441,14 @@ class FlxAction implements IFlxDestroyable */ public function check():Bool { - if (_timestamp == FlxG.game.ticks) + if (_check) return triggered; // run no more than once per frame _x = null; _y = null; - _timestamp = FlxG.game.ticks; + _check = false; + triggered = false; var i = inputs != null ? inputs.length : 0; @@ -476,6 +477,7 @@ class FlxAction implements IFlxDestroyable */ public function update():Void { + _check = true; check(); }