From 356ca81361c0f626096127c1f6b4417c0d3925de Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:38:35 +0100 Subject: [PATCH 1/7] FlxBunnyMark: modify _bunnies.members directly to avoid lag with many bunnies --- Performance/FlxBunnyMark/source/PlayState.hx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index 28180eee6..8f32c503b 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -183,13 +183,21 @@ class PlayState extends FlxState #end // It's much slower to recycle objects, but keeps runtime costs of garbage collection low - _bunnies.add(new Bunny().init(offScreen, useShaders, shader)); + var bunny = new Bunny().init(offScreen, useShaders, shader); + + // Modify the members array directly to avoid lag with many bunnies due to searching for duplicates + _bunnies.members.push(bunny); + _bunnies.length++; } else { var bunny:Bunny = _bunnies.getFirstAlive(); if (bunny != null) - _bunnies.remove(bunny); + { + // Modify the members array directly to avoid lag with many bunnies due to searching for duplicates + _bunnies.members.remove(bunny); + _bunnies.length--; + } } } From 9e8a65205fef34b898688873ce3b636e95ff83eb Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:51:26 +0100 Subject: [PATCH 2/7] FlxBunnyMark: add a button to toggle the background --- Performance/FlxBunnyMark/source/PlayState.hx | 28 ++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index 8f32c503b..c9f1a43bd 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -30,12 +30,14 @@ class PlayState extends FlxState var _times:Array; var _collisions:Bool = false; + var _background:FlxSprite; var _bunnies:FlxTypedGroup; var _uiOverlay:FlxSpriteGroup; var _complexityButton:FlxButton; var _collisionButton:FlxButton; var _timestepButton:FlxButton; var _offScreenButton:FlxButton; + var _backgroundButton:FlxButton; var _bunnyCounter:FlxText; var _fpsCounter:FlxText; @@ -60,12 +62,13 @@ class PlayState extends FlxState if (useAnimatedBackground) { - add(new Background()); + _background = new Background(); + add(_background); } else { - var bg = new FlxTileblock(0, 0, bgWidth, bgHeight); - add(bg.loadTiles("assets/grass.png")); + _background = new FlxTileblock(0, 0, bgWidth, bgHeight).loadTiles("assets/grass.png"); + add(_background); } var initialAmount = _changeAmount; @@ -107,26 +110,29 @@ class PlayState extends FlxState // Column2 1 var rightButtonX:Float = FlxG.width - 100; - _complexityButton = new FlxButton(rightButtonX, 10, "Simple", onComplexityToggle); + _complexityButton = new FlxButton(rightButtonX, 5, "Simple", onComplexityToggle); overlay.add(_complexityButton); - _collisionButton = new FlxButton(rightButtonX, 35, "Collisons: Off", onCollisionToggle); + _collisionButton = new FlxButton(rightButtonX, 30, "Collisons: Off", onCollisionToggle); overlay.add(_collisionButton); // Column2 rightButtonX -= 100; - _timestepButton = new FlxButton(rightButtonX, 10, "Step: Fixed", onTimestepToggle); + _timestepButton = new FlxButton(rightButtonX, 5, "Step: Fixed", onTimestepToggle); overlay.add(_timestepButton); - _offScreenButton = new FlxButton(rightButtonX, 35, "On-Screen", onOffScreenToggle); + _offScreenButton = new FlxButton(rightButtonX, 30, "On-Screen", onOffScreenToggle); overlay.add(_offScreenButton); #if shaders_supported - _shaderButton = new FlxButton(rightButtonX, 60, "Shaders: Off", onShaderToggle); + _shaderButton = new FlxButton(rightButtonX, 55, "Shaders: Off", onShaderToggle); overlay.add(_shaderButton); #end + _backgroundButton = new FlxButton(rightButtonX, 80, "BG: On", onBackgroundToggle); + overlay.add(_backgroundButton); + // The texts _bunnyCounter = new FlxText(0, 10, FlxG.width, "Bunnies: " + _bunnies.length); _bunnyCounter.setFormat(null, 22, FlxColor.BLACK, CENTER); @@ -254,6 +260,12 @@ class PlayState extends FlxState } #end + function onBackgroundToggle():Void + { + _background.exists = !_background.exists; + toggleLabel(_backgroundButton, "BG: Off", "BG: On"); + } + function toggleLabel(button:FlxButton, text1:String, text2:String):Void { button.label.text = if (button.label.text == text1) text2 else text1; From 971a66e63f6bad4b145b9b565eac68a2368af626 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 3 Feb 2026 14:01:43 +0100 Subject: [PATCH 3/7] FlxBunnyMark: add a button to toggle rotation --- Performance/FlxBunnyMark/source/Bunny.hx | 23 +++++++++++++++++--- Performance/FlxBunnyMark/source/PlayState.hx | 19 ++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Performance/FlxBunnyMark/source/Bunny.hx b/Performance/FlxBunnyMark/source/Bunny.hx index a85dbaaf7..256cb9742 100644 --- a/Performance/FlxBunnyMark/source/Bunny.hx +++ b/Performance/FlxBunnyMark/source/Bunny.hx @@ -13,6 +13,8 @@ class Bunny extends FlxSprite public var useShader(default, set):Bool = false; + public var allowRotation(default, set):Bool = true; + var _shader:FlxShader; public function new() @@ -25,7 +27,7 @@ class Bunny extends FlxSprite loadGraphic("assets/wabbit_alpha.png"); } - public function init(offscreen:Bool = false, useShader:Bool = false, ?shader:FlxShader):Bunny + public function init(offscreen:Bool = false, useShader:Bool = false, ?shader:FlxShader, allowRotation:Bool):Bunny { var speedMultiplier:Int = 50; @@ -40,9 +42,8 @@ class Bunny extends FlxSprite velocity.x = speedMultiplier * FlxG.random.float(-5, 5); velocity.y = speedMultiplier * FlxG.random.float(-7.5, 2.5); acceleration.y = 5; - angle = FlxG.random.float(-15, 15); - angularVelocity = 30 * FlxG.random.float(-5, 5); complex = PlayState.complex; + this.allowRotation = allowRotation; elasticity = 1; return this; @@ -107,4 +108,20 @@ class Bunny extends FlxSprite shader = if (value) _shader else null; return useShader = value; } + + function set_allowRotation(value:Bool):Bool + { + if (value) + { + angle = FlxG.random.float(-15, 15); + angularVelocity = 30 * FlxG.random.float(-5, 5); + } + else + { + angle = 0; + angularVelocity = 0; + } + + return allowRotation = value; + } } diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index c9f1a43bd..3214288a1 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -25,6 +25,7 @@ class PlayState extends FlxState public static var complex:Bool = false; public static var offScreen:Bool = false; public static var useShaders:Bool = false; + public static var allowRotation:Bool = true; var _changeAmount:Int = 1000; var _times:Array; @@ -38,6 +39,7 @@ class PlayState extends FlxState var _timestepButton:FlxButton; var _offScreenButton:FlxButton; var _backgroundButton:FlxButton; + var _rotationButton:FlxButton; var _bunnyCounter:FlxText; var _fpsCounter:FlxText; @@ -116,6 +118,9 @@ class PlayState extends FlxState _collisionButton = new FlxButton(rightButtonX, 30, "Collisons: Off", onCollisionToggle); overlay.add(_collisionButton); + _rotationButton = new FlxButton(rightButtonX, 55, "Rotation: On", onRotationToggle); + overlay.add(_rotationButton); + // Column2 rightButtonX -= 100; @@ -189,7 +194,7 @@ class PlayState extends FlxState #end // It's much slower to recycle objects, but keeps runtime costs of garbage collection low - var bunny = new Bunny().init(offScreen, useShaders, shader); + var bunny = new Bunny().init(offScreen, useShaders, shader, allowRotation); // Modify the members array directly to avoid lag with many bunnies due to searching for duplicates _bunnies.members.push(bunny); @@ -245,7 +250,7 @@ class PlayState extends FlxState for (bunny in _bunnies) if (bunny != null) - bunny.init(offScreen, useShaders); + bunny.init(offScreen, useShaders, null, allowRotation); } #if shaders_supported @@ -266,6 +271,16 @@ class PlayState extends FlxState toggleLabel(_backgroundButton, "BG: Off", "BG: On"); } + function onRotationToggle():Void + { + allowRotation = !allowRotation; + toggleLabel(_rotationButton, "Rotation: Off", "Rotation: On"); + + for (bunny in _bunnies) + if (bunny != null) + bunny.allowRotation = allowRotation; + } + function toggleLabel(button:FlxButton, text1:String, text2:String):Void { button.label.text = if (button.label.text == text1) text2 else text1; From 240219e0406a8e4f70622e7771fffdcad527b64a Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:09:58 +0100 Subject: [PATCH 4/7] FlxBunnyMark: slightly increase bg height --- Performance/FlxBunnyMark/source/PlayState.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index 3214288a1..45a75be04 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -95,7 +95,7 @@ class PlayState extends FlxState var overlay = new FlxSpriteGroup(); var uiBackground = new FlxSprite(); - uiBackground.makeGraphic(FlxG.width, 100, FlxColor.WHITE); + uiBackground.makeGraphic(FlxG.width, 105, FlxColor.WHITE); uiBackground.alpha = 0.7; overlay.add(uiBackground); From f46bad4f40eb07582d49c07d9617554c095a1322 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:11:38 +0100 Subject: [PATCH 5/7] FlxBunnyMark: update shaders only when used --- Performance/FlxBunnyMark/source/PlayState.hx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index 45a75be04..b6a84a513 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -157,12 +157,15 @@ class PlayState extends FlxState var time = FlxG.game.ticks; #if shaders_supported - var floodFillY = 0.5 * (1.0 + Math.sin(time / 1000)); - #if (openfl >= "8.0.0") - floodFill.uFloodFillY.value = [floodFillY]; - #else - floodFill.uFloodFillY = floodFillY; - #end + if (useShaders) + { + var floodFillY = 0.5 * (1.0 + Math.sin(time / 1000)); + #if (openfl >= "8.0.0") + floodFill.uFloodFillY.value = [floodFillY]; + #else + floodFill.uFloodFillY = floodFillY; + #end + } #end if (_collisions) From 5ad0c555428e692c1aae6a8e38cf006884535d2c Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:31:44 +0100 Subject: [PATCH 6/7] FlxBunnyMark: add a FPS counter only mode --- Performance/FlxBunnyMark/source/PlayState.hx | 39 +++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index b6a84a513..ab347bdb9 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -1,5 +1,6 @@ package; +import flixel.math.FlxMath; import flash.Lib; import flixel.addons.ui.FlxSlider; import flixel.FlxG; @@ -30,6 +31,7 @@ class PlayState extends FlxState var _changeAmount:Int = 1000; var _times:Array; var _collisions:Bool = false; + var _uiState:UIState = VISIBLE; var _background:FlxSprite; var _bunnies:FlxTypedGroup; @@ -181,7 +183,7 @@ class PlayState extends FlxState #if FLX_KEYBOARD if (FlxG.keys.justPressed.SPACE) - _uiOverlay.visible = !_uiOverlay.visible; + updateUIState(); #end } @@ -224,6 +226,34 @@ class PlayState extends FlxState } } + function updateUIState():Void + { + _uiState = FlxMath.wrap(_uiState + 1, VISIBLE, HIDDEN); + + switch (_uiState) + { + case VISIBLE: + _uiOverlay.exists = true; + _fpsCounter.y = _bunnyCounter.y + _bunnyCounter.height + 20; + _fpsCounter.setBorderStyle(NONE); + + case FPS_ONLY: + for (ui in _uiOverlay) + { + if (ui == _fpsCounter) + continue; + + ui.exists = false; + } + + _fpsCounter.setBorderStyle(OUTLINE, FlxColor.WHITE, 2); + _fpsCounter.y = 10; + + case HIDDEN: + _uiOverlay.exists = false; + } + } + function onComplexityToggle():Void { complex = !complex; @@ -289,3 +319,10 @@ class PlayState extends FlxState button.label.text = if (button.label.text == text1) text2 else text1; } } + +enum abstract UIState(Int) from Int to Int +{ + var VISIBLE = 0; + var FPS_ONLY = 1; + var HIDDEN = 2; +} From 34bbd9ccaf617c60370163a79de5acd23c5b5f3b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:08:52 +0100 Subject: [PATCH 7/7] Remove references to outdated OpenFL versions --- Performance/FlxBunnyMark/source/PlayState.hx | 13 +------- .../FlxBunnyMark/source/openfl3/FloodFill.hx | 31 ------------------- .../FlxBunnyMark/source/openfl3/Invert.hx | 18 ----------- .../source/{openfl8 => shaders}/FloodFill.hx | 2 +- .../source/{openfl8 => shaders}/Invert.hx | 2 +- 5 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 Performance/FlxBunnyMark/source/openfl3/FloodFill.hx delete mode 100644 Performance/FlxBunnyMark/source/openfl3/Invert.hx rename Performance/FlxBunnyMark/source/{openfl8 => shaders}/FloodFill.hx (96%) rename Performance/FlxBunnyMark/source/{openfl8 => shaders}/Invert.hx (95%) diff --git a/Performance/FlxBunnyMark/source/PlayState.hx b/Performance/FlxBunnyMark/source/PlayState.hx index ab347bdb9..e7334f979 100644 --- a/Performance/FlxBunnyMark/source/PlayState.hx +++ b/Performance/FlxBunnyMark/source/PlayState.hx @@ -12,11 +12,7 @@ import flixel.text.FlxText; import flixel.tile.FlxTileblock; import flixel.ui.FlxButton; import flixel.util.FlxColor; -#if (openfl >= "8.0.0") -import openfl8.*; -#else -import openfl3.*; -#end +import shaders.*; /** * @author Zaphod @@ -60,9 +56,6 @@ class PlayState extends FlxState var bgHeight:Int = Math.ceil(FlxG.height / bgSize) * bgSize; var useAnimatedBackground = !FlxG.renderBlit; - #if (!openfl_legacy && openfl <= "4.0.0") - useAnimatedBackground = false; - #end if (useAnimatedBackground) { @@ -162,11 +155,7 @@ class PlayState extends FlxState if (useShaders) { var floodFillY = 0.5 * (1.0 + Math.sin(time / 1000)); - #if (openfl >= "8.0.0") floodFill.uFloodFillY.value = [floodFillY]; - #else - floodFill.uFloodFillY = floodFillY; - #end } #end diff --git a/Performance/FlxBunnyMark/source/openfl3/FloodFill.hx b/Performance/FlxBunnyMark/source/openfl3/FloodFill.hx deleted file mode 100644 index 9b77eb48e..000000000 --- a/Performance/FlxBunnyMark/source/openfl3/FloodFill.hx +++ /dev/null @@ -1,31 +0,0 @@ -package openfl3; - -import openfl.display.Shader; - -class FloodFill extends Shader -{ - @fragment var code = ' - uniform float uFloodFillY; - - void main() - { - vec2 border = vec2(${Shader.vTexCoord}.x, uFloodFillY); - vec4 color; - - if (${Shader.vTexCoord}.y > uFloodFillY) - { - color = texture2D(${Shader.uSampler}, border); - } - else - { - color = texture2D(${Shader.uSampler}, ${Shader.vTexCoord}); - } - - gl_FragColor = color; - }'; - - public function new() - { - super(); - } -} diff --git a/Performance/FlxBunnyMark/source/openfl3/Invert.hx b/Performance/FlxBunnyMark/source/openfl3/Invert.hx deleted file mode 100644 index 1ea938dae..000000000 --- a/Performance/FlxBunnyMark/source/openfl3/Invert.hx +++ /dev/null @@ -1,18 +0,0 @@ -package openfl3; - -import openfl.display.Shader; - -class Invert extends Shader -{ - @fragment var fragment = ' - void main() - { - vec4 color = texture2D(${Shader.uSampler}, ${Shader.vTexCoord}); - gl_FragColor = vec4((1.0 - color.r) * color.a, (1.0 - color.g) * color.a, (1.0 - color.b) * color.a, color.a); - }'; - - public function new() - { - super(); - } -} diff --git a/Performance/FlxBunnyMark/source/openfl8/FloodFill.hx b/Performance/FlxBunnyMark/source/shaders/FloodFill.hx similarity index 96% rename from Performance/FlxBunnyMark/source/openfl8/FloodFill.hx rename to Performance/FlxBunnyMark/source/shaders/FloodFill.hx index b70eb8a6f..233071401 100644 --- a/Performance/FlxBunnyMark/source/openfl8/FloodFill.hx +++ b/Performance/FlxBunnyMark/source/shaders/FloodFill.hx @@ -1,4 +1,4 @@ -package openfl8; +package shaders; import flixel.system.FlxAssets.FlxShader; diff --git a/Performance/FlxBunnyMark/source/openfl8/Invert.hx b/Performance/FlxBunnyMark/source/shaders/Invert.hx similarity index 95% rename from Performance/FlxBunnyMark/source/openfl8/Invert.hx rename to Performance/FlxBunnyMark/source/shaders/Invert.hx index 112dc9eff..ab8226347 100644 --- a/Performance/FlxBunnyMark/source/openfl8/Invert.hx +++ b/Performance/FlxBunnyMark/source/shaders/Invert.hx @@ -1,4 +1,4 @@ -package openfl8; +package shaders; import flixel.system.FlxAssets.FlxShader;