From 635946385051a5cd1e6c79d623b535fe5068a35e Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 25 Aug 2024 15:40:03 +0200 Subject: [PATCH] Small optimization --- .../editors/charter/CharterBackdropGroup.hx | 43 ++++++++++++++++--- source/funkin/editors/ui/UIState.hx | 6 +-- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/source/funkin/editors/charter/CharterBackdropGroup.hx b/source/funkin/editors/charter/CharterBackdropGroup.hx index cd11c80c..8aaa21e7 100644 --- a/source/funkin/editors/charter/CharterBackdropGroup.hx +++ b/source/funkin/editors/charter/CharterBackdropGroup.hx @@ -5,6 +5,37 @@ import flixel.graphics.FlxGraphic; import funkin.backend.system.Conductor; import openfl.geom.Rectangle; +class FlxFastTypedGroup extends FlxTypedGroup { + public function new(?maxSize:Int = 0) { + super(maxSize); + } + + override public function add(Object:T):T + { + if (Object == null) + { + FlxG.log.warn("Cannot add a `null` object to a FlxGroup."); + return null; + } + + // removed the check for multiple + // removed the check for null reuse + + // If the group is full, return the Object + if (maxSize > 0 && length >= maxSize) + return Object; + + // If we made it this far, we need to add the object to the group. + members.push(Object); + length++; + + if (_memberAdded != null) + _memberAdded.dispatch(Object); + + return Object; + } +} + class CharterBackdropGroup extends FlxTypedGroup { public var strumLineGroup:CharterStrumLineGroup; public var notesGroup:CharterNoteGroup; @@ -68,9 +99,11 @@ class CharterBackdropGroup extends FlxTypedGroup { grid.notesGroup.clear(); notesGroup.forEach((n) -> { - var onStr:Bool = (n.snappedToStrumline ? n.strumLineID : CoolUtil.boundInt(Std.int((n.x+n.width)/(40*4)), 0, strumLineGroup.members.length-1)) == i; - if(n.exists && n.visible && onStr) - grid.notesGroup.add(n); + if(n.exists && n.visible) { + var onStr:Bool = (n.snappedToStrumline ? n.strumLineID : CoolUtil.boundInt(Std.int((n.x+n.width)/(40*4)), 0, strumLineGroup.members.length-1)) == i; + if(onStr) + grid.notesGroup.add(n); + } }); grid.active = grid.visible = true; @@ -109,7 +142,7 @@ class CharterBackdropGroup extends FlxTypedGroup { } } -class CharterBackdrop extends FlxTypedGroup { +class CharterBackdrop extends FlxTypedGroup { public var gridBackDrop:FlxBackdrop; public var topLimit:FlxSprite; public var topSeparator:FlxSprite; @@ -122,7 +155,7 @@ class CharterBackdrop extends FlxTypedGroup { public var beatSeparator:FlxBackdrop; public var sectionSeparator:FlxBackdrop; - public var notesGroup:FlxTypedGroup = new FlxTypedGroup(); + public var notesGroup:FlxFastTypedGroup = new FlxFastTypedGroup(); public var strumLine:CharterStrumline; public function new(gridGraphic:FlxGraphic) { diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index e2e580af..47324848 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -28,6 +28,8 @@ class UIState extends MusicBeatState { private var __rect:FlxRect; private var __mousePos:FlxPoint; + static var __point:FlxPoint = new FlxPoint(); + private inline static function get_state() return FlxG.state is UIState ? cast FlxG.state : null; @@ -70,17 +72,15 @@ class UIState extends MusicBeatState { public function isOverlapping(spr:UISprite, rect:FlxRect) { for(camera in spr.__lastDrawCameras) { - var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get()); + var pos = FlxG.mouse.getScreenPosition(camera, __point); __rect.copyFrom(rect); __rect.x -= camera.scroll.x * spr.scrollFactor.x; __rect.y -= camera.scroll.y * spr.scrollFactor.y; if (((pos.x > __rect.x) && (pos.x < __rect.x + __rect.width)) && ((pos.y > __rect.y) && (pos.y < __rect.y + __rect.height))) { - pos.put(); return true; } - pos.put(); } return false; }