From c72b21936bff05b3a9e12ac8fbf12c37f9259254 Mon Sep 17 00:00:00 2001 From: Eric Myllyoja Date: Fri, 2 Dec 2022 12:15:12 -0500 Subject: [PATCH 01/10] Enable GLSL 3.00 migration --- flixel/graphics/tile/FlxGraphicsShader.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index 02f0a9f157..2151b9c7c1 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -24,7 +24,7 @@ class FlxGraphicsShader extends GraphicsShader openfl_ColorOffsetv = colorOffset / 255.0; openfl_ColorMultiplierv = colorMultiplier; } - }") + }", true) @:glFragmentHeader(" uniform bool hasTransform; uniform bool hasColorTransform; @@ -63,7 +63,7 @@ class FlxGraphicsShader extends GraphicsShader } return vec4(0.0, 0.0, 0.0, 0.0); } - ") + ", true) @:glFragmentSource(" #pragma header From f2959a62cc32f2f311d1466d68248bba8680280a Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 2 Nov 2023 21:31:44 -0400 Subject: [PATCH 02/10] Fix issue causing his to be null on HTML5 --- flixel/FlxG.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index a5ec5395f1..3c1c281267 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -373,11 +373,11 @@ class FlxG * Attempts to switch from the current game state to `nextState`. * The state switch is successful if `switchTo()` of the current `state` returns `true`. */ - public static inline function switchState(nextState:FlxState):Void + public static function switchState(nextState:FlxState):Void { final stateOnCall = FlxG.state; // Use reflection to avoid deprecation warning on switchTo - if (Reflect.field(state, 'switchTo')(nextState)) + if (Reflect.callMethod(state, Reflect.field(state, 'switchTo'), [nextState])) { state.startOutro(function() { From a83738673e7edbf8acba3a1426af284dfe6719fe Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 20 Dec 2023 15:12:59 -0500 Subject: [PATCH 03/10] Readd wasDestroyed warnings to camera draw functions. --- flixel/FlxCamera.hx | 88 ++++++++++++------------ flixel/graphics/tile/FlxDrawQuadsItem.hx | 5 +- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 416767d3ce..2e47e3270b 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -52,7 +52,7 @@ class FlxCamera extends FlxBasic /** * Used behind-the-scenes during the draw phase so that members use the same default * cameras as their parent. - * + * * Prior to 4.9.0 it was useful to change this value, but that feature is deprecated. * Instead use the `defaultDrawTarget` argument in `FlxG.cameras.add `. * or`FlxG.cameras.setDefaultDrawTarget` . @@ -60,11 +60,11 @@ class FlxCamera extends FlxBasic */ @:deprecated("`FlxCamera.defaultCameras` is deprecated, use `FlxG.cameras.setDefaultDrawTarget` instead") public static var defaultCameras(get, set):Array; - + /** * Used behind-the-scenes during the draw phase so that members use the same default * cameras as their parent. - * + * * This is the non-deprecated list that the public `defaultCameras` proxies. Allows flixel classes * to use it without warning. */ @@ -221,7 +221,7 @@ class FlxCamera extends FlxBasic * WARNING: setting this to `false` on blitting targets is very expensive. */ public var pixelPerfectRender:Bool; - + /** * If true, screen shake will be rounded to game pixels. If null, pixelPerfectRender is used. * @since 5.4.0 @@ -635,6 +635,8 @@ class FlxCamera extends FlxBasic itemToReturn = new FlxDrawItem(); } + if (graphic.isDestroyed) throw 'Attempted to queue an invalid FlxDrawItem, did you destroy a cached sprite?'; + itemToReturn.graphics = graphic; itemToReturn.antialiasing = smooth; itemToReturn.colored = colored; @@ -1168,11 +1170,11 @@ class FlxCamera extends FlxBasic // Make sure we didn't go outside the camera's bounds bindScrollPos(scroll); } - + /** * Takes the desired scroll position and restricts it to the camera's min/max scroll properties. * This modifies the given point. - * + * * @param scrollPos The scroll position * @return The same point passed in, moved within the scroll bounds * @since 5.4.0 @@ -1229,7 +1231,7 @@ class FlxCamera extends FlxBasic { _scrollTarget.y -= viewHeight; } - + // without this we see weird behavior when switching to SCREEN_BY_SCREEN at arbitrary scroll positions bindScrollPos(_scrollTarget); } @@ -1348,16 +1350,16 @@ class FlxCamera extends FlxBasic var shakePixels = FlxG.random.float(-1, 1) * _fxShakeIntensity * width; if (pixelPerfect) shakePixels = Math.round(shakePixels); - + flashSprite.x += shakePixels * zoom * FlxG.scaleMode.scale.x; } - + if (_fxShakeAxes.y) { var shakePixels = FlxG.random.float(-1, 1) * _fxShakeIntensity * height; if (pixelPerfect) shakePixels = Math.round(shakePixels); - + flashSprite.y += shakePixels * zoom * FlxG.scaleMode.scale.y; } } @@ -1868,11 +1870,11 @@ class FlxCamera extends FlxBasic updateFlashOffset(); setScale(scaleX, scaleY); } - + /** * The size and position of this camera's margins, via `viewMarginLeft`, `viewMarginTop`, `viewWidth` * and `viewHeight`. - * + * * Notes: Deprecated, in 4.11.0 this was made public, but the wording is confusing. * In flixel 6.0.0 this will be changed to use `viewX`, `viewY`, `viewWidth` and `viewHeight`, * meaning, this will return the world coordinates of the camera. @@ -1883,10 +1885,10 @@ class FlxCamera extends FlxBasic { if (rect == null) rect = FlxRect.get(); - + return rect.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); } - + /** * The size and position of this camera's margins, via `viewMarginLeft`, `viewMarginTop`, `viewWidth` * and `viewHeight`. @@ -1896,10 +1898,10 @@ class FlxCamera extends FlxBasic { if (rect == null) rect = FlxRect.get(); - + return rect.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); } - + /** * Checks whether this camera contains a given point or rectangle, in * screen coordinates. @@ -1912,7 +1914,7 @@ class FlxCamera extends FlxBasic point.putWeak(); return contained; } - + /** * Checks whether this camera contains a given rectangle, in screen coordinates. * @since 4.11.0 @@ -2060,7 +2062,7 @@ class FlxCamera extends FlxBasic @:deprecated("Use calcMarginY") inline function calcOffsetY():Void calcMarginY(); - + inline function calcMarginX():Void { viewMarginX = 0.5 * width * (scaleX - initialZoom) / scaleX; @@ -2070,104 +2072,104 @@ class FlxCamera extends FlxBasic { viewMarginY = 0.5 * height * (scaleY - initialZoom) / scaleY; } - + static inline function get_defaultCameras():Array { return _defaultCameras; } - + static inline function set_defaultCameras(value:Array):Array { return _defaultCameras = value; } - + inline function get_viewMarginLeft():Float { return viewMarginX; } - + inline function get_viewMarginTop():Float { return viewMarginY; } - + inline function get_viewMarginRight():Float { return width - viewMarginX; } - + inline function get_viewMarginBottom():Float { return height - viewMarginY; } - + inline function get_viewWidth():Float { return width - viewMarginX * 2; } - + inline function get_viewHeight():Float { return height - viewMarginY * 2; } - + inline function get_viewX():Float { return scroll.x + viewMarginX; } - + inline function get_viewY():Float { return scroll.y + viewMarginY; } - + inline function get_viewLeft():Float { return viewX; } - + inline function get_viewTop():Float { return viewY; } - + inline function get_viewRight():Float { return scroll.x + viewMarginRight; } - + inline function get_viewBottom():Float { return scroll.y + viewMarginBottom; } - + // deprecated vars inline function get_viewOffsetX():Float { return viewMarginX; } - + inline function set_viewOffsetX(value:Float):Float { return viewMarginX = value; } - + inline function get_viewOffsetY():Float { return viewMarginY; } - + inline function set_viewOffsetY(value:Float):Float { return viewMarginY = value; } - + inline function get_viewOffsetWidth():Float { return viewMarginRight; } - + inline function get_viewOffsetHeight():Float { return viewMarginBottom; @@ -2182,7 +2184,7 @@ class FlxCamera extends FlxBasic { return filters = Value; } - + /** * Do not use the following fields! They only exists because FlxCamera extends FlxBasic, * we're hiding them because they've only caused confusion. @@ -2190,19 +2192,19 @@ class FlxCamera extends FlxBasic @:deprecated("don't reference camera.camera") @:noCompletion override function get_camera():FlxCamera throw "don't reference camera.camera"; - + @:deprecated("don't reference camera.camera") @:noCompletion override function set_camera(value:FlxCamera):FlxCamera throw "don't reference camera.camera"; - + @:deprecated("don't reference camera.cameras") @:noCompletion override function get_cameras():Array throw "don't reference camera.cameras"; - + @:deprecated("don't reference camera.cameras") @:noCompletion override function set_cameras(value:Array):Array throw "don't reference camera.cameras"; - + } enum FlxCameraFollowStyle diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index cccf2aa6e0..077cd8d2fe 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -115,6 +115,9 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem return; var shader = shader != null ? shader : graphics.shader; + + if (shader == null) throw 'Attempted to render an invalid FlxDrawItem, did you destroy a cached sprite?'; + shader.bitmap.input = graphics.bitmap; shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST; shader.alpha.value = alphas; @@ -143,4 +146,4 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem parameter.value[0] = value; } #end -} \ No newline at end of file +} From 6af9faffe2d366d9b1076a85509fd75eb4317f11 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 16 Jan 2024 22:27:27 -0500 Subject: [PATCH 04/10] Update BitmapFrontEnd.hx --- flixel/system/frontEnds/BitmapFrontEnd.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/frontEnds/BitmapFrontEnd.hx b/flixel/system/frontEnds/BitmapFrontEnd.hx index d9e1d16966..e4f18d3d60 100644 --- a/flixel/system/frontEnds/BitmapFrontEnd.hx +++ b/flixel/system/frontEnds/BitmapFrontEnd.hx @@ -294,7 +294,7 @@ class BitmapFrontEnd if (graphic != null) { removeKey(graphic.key); - graphic.destroy(); + if (!graphic.isDestroyed) graphic.destroy(); } } From 8c030ad6e421d4ef8f00a96c6b8c59cc12060047 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 16 Jan 2024 22:34:43 -0500 Subject: [PATCH 05/10] Update FlxGraphic.hx --- flixel/graphics/FlxGraphic.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flixel/graphics/FlxGraphic.hx b/flixel/graphics/FlxGraphic.hx index b3140b93e2..2fdf93e752 100644 --- a/flixel/graphics/FlxGraphic.hx +++ b/flixel/graphics/FlxGraphic.hx @@ -511,6 +511,8 @@ class FlxGraphic implements IFlxDestroyable */ public inline function getFramesCollections(type:FlxFrameCollectionType):Array { + if (isDestroyed) return []; + var collections:Array = frameCollections.get(type); if (collections == null) { From b2d23633355f52522b4d1c266adaf1571f79e89c Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 17 Jan 2024 00:57:28 -0500 Subject: [PATCH 06/10] Prevent readding collections. --- flixel/graphics/FlxGraphic.hx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flixel/graphics/FlxGraphic.hx b/flixel/graphics/FlxGraphic.hx index b3140b93e2..9cb613fc9b 100644 --- a/flixel/graphics/FlxGraphic.hx +++ b/flixel/graphics/FlxGraphic.hx @@ -499,7 +499,8 @@ class FlxGraphic implements IFlxDestroyable if (collection.type != null) { var collections:Array = getFramesCollections(collection.type); - collections.push(collection); + if (collections.indexOf(collection) == -1) + collections.push(collection); } } From edfaf85f38ad6ed140960c2d34d6053b240e3f3a Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Tue, 12 Mar 2024 23:23:25 -0400 Subject: [PATCH 07/10] Fix a crash when flickering in onComplete --- flixel/effects/FlxFlicker.hx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flixel/effects/FlxFlicker.hx b/flixel/effects/FlxFlicker.hx index 754d2aa2af..2baf758d52 100644 --- a/flixel/effects/FlxFlicker.hx +++ b/flixel/effects/FlxFlicker.hx @@ -182,7 +182,12 @@ class FlxFlicker implements IFlxDestroyable { completionCallback(this); } - release(); + + // NOTE: Calling `flicker` in the completion callback will call release() on this object before reinstantiating it. + // If that happens, we don't want to call release() again! So we check if the flicker is still done before releasing. + if (this.timer == Timer) { + release(); + } } } From 44f2961a446f4c79f4efbfdd63294cd6009d8813 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Tue, 12 Mar 2024 23:24:52 -0400 Subject: [PATCH 08/10] Include the text in the bitmap key. --- flixel/text/FlxText.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index e010d537b3..52b17b9e9c 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -891,7 +891,7 @@ class FlxText extends FlxSprite if (oldWidth != newWidth || oldHeight != newHeight) { // Need to generate a new buffer to store the text graphic - var key:String = FlxG.bitmap.getUniqueKey("text"); + var key:String = FlxG.bitmap.getUniqueKey('text(${this.text})'); makeGraphic(newWidth, newHeight, FlxColor.TRANSPARENT, false, key); if (_hasBorderAlpha) From 5823c46b4e7410372d58b99f8d5c52fc18b3cb3d Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 13 Mar 2024 11:42:56 -0400 Subject: [PATCH 09/10] Add convenience functions to FlxFlicker. --- flixel/effects/FlxFlicker.hx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flixel/effects/FlxFlicker.hx b/flixel/effects/FlxFlicker.hx index 2baf758d52..2513f2ca3d 100644 --- a/flixel/effects/FlxFlicker.hx +++ b/flixel/effects/FlxFlicker.hx @@ -129,6 +129,16 @@ class FlxFlicker implements IFlxDestroyable progressCallback = null; } + public function pause():Void { + if (timer == null) return; + timer.active = false; + } + + public function resume():Void { + if (timer == null) return; + timer.active = true; + } + /** * Starts flickering behavior. */ From a7d8e3bad89a0a3506a4714121f73d8e34522c49 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 27 Apr 2024 00:45:44 -0400 Subject: [PATCH 10/10] debug pointer accounts for flxsprite opacity --- .../system/debug/interaction/Interaction.hx | 68 +++++++++++-------- .../system/debug/interaction/tools/Pointer.hx | 14 ++-- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index 7f5de15140..698df15476 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -6,6 +6,7 @@ import openfl.display.Sprite; import openfl.display.DisplayObject; import openfl.events.KeyboardEvent; import flixel.FlxObject; +import flixel.FlxSprite; import openfl.events.MouseEvent; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.input.FlxPointer; @@ -36,7 +37,7 @@ class Interaction extends Window static inline var BUTTONS_PER_LINE = 2; static inline var SPACING = 25; static inline var PADDING = 10; - + public var activeTool(default, null):Tool; public var selectedItems(default, null):FlxTypedGroup = new FlxTypedGroup(); @@ -51,7 +52,7 @@ class Interaction extends Window * selection marks, for instance. */ public var shouldDrawItemsSelection:Bool = true; - + /** * Whether or not the user is using a mac keyboard, determines whether to use command or ctrl */ @@ -63,7 +64,7 @@ class Interaction extends Window #else false; #end - + var _container:Sprite; var _customCursor:Sprite; var _tools:Array = []; @@ -240,11 +241,11 @@ class Interaction extends Window addChild(button); resizeByTotal(buttons); } - + /** * Removes the tool, if possible. If the tool has a button, all other buttons will be moved and * the containing window will be resized, if needed. - * + * * @param tool The tool to be removed * @since 5.4.0 */ @@ -252,22 +253,22 @@ class Interaction extends Window { if (!_tools.contains(tool)) return; - + // If there's no button just remove it if (tool.button == null) { _tools.remove(tool); return; } - + // if there is a button move all the following buttons var index = _tools.indexOf(tool); var prevX = tool.button.x; var prevY = tool.button.y; - + _tools.remove(tool); removeChild(tool.button); - + while (index < _tools.length) { final tool = _tools[index]; @@ -285,15 +286,15 @@ class Interaction extends Window } index++; } - + autoResize(); } - + inline function autoResize() { resizeByTotal(countToolsWithUIButton()); } - + inline function resizeByTotal(total:Int) { final spacing = 25; @@ -606,7 +607,7 @@ class Interaction extends Window /** * Returns a list all items in the state and substate that are within the given area - * + * * @param state The state to search * @param area The rectangular area to search * @since 5.6.0 @@ -614,24 +615,24 @@ class Interaction extends Window public function getItemsWithinState(state:FlxState, area:FlxRect):Array { final items = new Array(); - + addItemsWithinArea(items, state.members, area); if (state.subState != null) addItemsWithinState(items, state.subState, area); - + return items; } - + @:deprecated("findItemsWithinState is deprecated, use getItemsWithinState or addItemsWithinState") public inline function findItemsWithinState(items:Array, state:FlxState, area:FlxRect):Void { addItemsWithinState(cast items, state, area); } - + /** * finds all items in the state and substate that are within the given area and * adds them to the given list. - * + * * @param items The list to add the items * @param state The state to search * @param area The rectangular area to search @@ -643,10 +644,10 @@ class Interaction extends Window if (state.subState != null) addItemsWithinState(items, state.subState, area); } - + /** * Finds and returns top-most item in the state and substate within the given area - * + * * @param state The state to search * @param area The rectangular area to search * @since 5.6.0 @@ -655,7 +656,7 @@ class Interaction extends Window { if (state.subState != null) return getTopItemWithinState(state.subState, area); - + return getTopItemWithinArea(state.members, area); } @@ -674,7 +675,7 @@ class Interaction extends Window { addItemsWithinArea(cast items, members, area); } - + /** * Find all items within an area. In order to improve performance and reduce temporary allocations, * the method has no return, you must pass an array where items will be placed. The method decides @@ -696,10 +697,16 @@ class Interaction extends Window // Ignore invisible or non-existent entities if (member == null || !member.visible || !member.exists) continue; - + final group = FlxTypedGroup.resolveSelectionGroup(member); if (group != null) addItemsWithinArea(items, group.members, area); + else if (member is FlxSprite) + { + final object:FlxSprite = cast member; + if (object.pixelsOverlapPoint(flixelPointer, 0xEE)) + items.push(object); + } else if (member is FlxObject) { final object:FlxObject = cast member; @@ -708,10 +715,10 @@ class Interaction extends Window } } } - + /** * Searches the members for the top-most object inside the given rectangle - * + * * @param members The list of FlxObjects or FlxGroups * @param area The rectangular area to search * @return The top-most item @@ -728,11 +735,18 @@ class Interaction extends Window // Ignore invisible or non-existent entities if (member == null || !member.visible || !member.exists) continue; - + final group = FlxTypedGroup.resolveGroup(member); if (group != null) return getTopItemWithinArea(group.members, area); - + + if (member is FlxSprite) + { + final object:FlxSprite = cast member; + if (object.pixelsOverlapPoint(flixelPointer, 0xEE)) + return object; + } + if (member is FlxObject) { final object:FlxObject = cast member; diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index 76487a7621..7d94397019 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -60,7 +60,7 @@ class Pointer extends Tool // If we had a selection happening, it's time to end it. if (!_selectionHappening) return; - + final selectedItems = stopSelectionAndFindItems(); final drewRect = _selectionArea.width != 0 || _selectionArea.height != 0; // If we have items in the selection area, handle them @@ -109,7 +109,7 @@ class Pointer extends Tool _selectionHappening = false; _selectionArea.set(0, 0, 0, 0); } - + /** * Stop any selection activity that is happening. */ @@ -133,12 +133,12 @@ class Pointer extends Tool if (topItem != null) items = [topItem]; } - + updateConsoleSelection(items); // Clear everything stopSelection(); - + return items; } @@ -160,15 +160,15 @@ class Pointer extends Tool // We add things to the selection list if the user is pressing the "add-new-item" key final adding = _brain.keyPressed(Keyboard.SHIFT); final removing = _brain.keyPressed(Keyboard.ALTERNATE) && !adding; - + // If we are not selectively adding items, just clear // the brain's list of selected items. if (!adding && !removing) _brain.clearSelection(); - + if (items == null || items.length == 0) return; - + final prevSelectedItems = _brain.selectedItems; if (adding && !drewRect && items.length == 1) {