From d390790c224826335bbebf62b5163c7a7c31e3c4 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 23 Dec 2025 13:04:03 +0100 Subject: [PATCH 01/72] Implement FlxCameraView & port blit/quad renderer --- flixel/FlxCamera.hx | 851 +++++-------------- flixel/FlxObject.hx | 10 +- flixel/graphics/tile/FlxDrawQuadsItem.hx | 8 +- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 10 +- flixel/system/frontEnds/CameraFrontEnd.hx | 58 +- flixel/system/render/FlxCameraView.hx | 378 ++++++++ flixel/system/render/blit/FlxBlitView.hx | 490 +++++++++++ flixel/system/render/quad/FlxQuadView.hx | 497 +++++++++++ 8 files changed, 1623 insertions(+), 679 deletions(-) create mode 100644 flixel/system/render/FlxCameraView.hx create mode 100644 flixel/system/render/blit/FlxBlitView.hx create mode 100644 flixel/system/render/quad/FlxQuadView.hx diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 94d7973df8..f1546839ba 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1,5 +1,9 @@ package flixel; +import flixel.system.render.FlxCameraView; +import flixel.system.render.quad.FlxQuadView; +import flixel.system.render.blit.FlxBlitView; + import openfl.display.Bitmap; import openfl.display.BitmapData; import openfl.display.DisplayObject; @@ -98,6 +102,26 @@ class FlxCamera extends FlxBasic */ public var totalScaleY(default, null):Float; + /** + * Render view for this camera. + * All rendering related commands (like draw rectangle or fill camera view with specified color) are handled by this object. + */ + public var view(default, null):FlxCameraView; + + /** + * This camera's `view`, but typed as a `FlxQuadView`. + * + * **NOTE**: May be null depending on the render implementation used. + */ + public var viewQuad(default, null):Null; + + /** + * This camera's `view`, but typed as a `FlxBlitView`. + * + * **NOTE**: May be null depending on the render implementation used. + */ + public var viewBlit(default, null):Null; + /** * Tells the camera to use this following style. */ @@ -161,7 +185,8 @@ class FlxCamera extends FlxBasic * The actual `BitmapData` of the camera display itself. * Used in blit render mode, where you can manipulate its pixels for achieving some visual effects. */ - public var buffer:BitmapData; + @:deprecated("buffer is deprecated, avoid referencing it directly and use the methods from camera.view instead") + public var buffer(get, set):BitmapData; /** * The natural background color of the camera, in `AARRGGBB` format. Defaults to `FlxG.cameras.bgColor`. @@ -176,7 +201,8 @@ class FlxCamera extends FlxBasic * * **NOTE:** This field is only used in blit render mode. */ - public var screen:FlxSprite; + @:deprecated("screen is deprecated, avoid referencing it directly and use the methods from camera.view instead") + public var screen(get, set):FlxSprite; /** * Whether to use alpha blending for the camera's background fill or not. @@ -197,7 +223,8 @@ class FlxCamera extends FlxBasic * * Its position is modified by `updateFlashSpritePosition()` which is called every frame. */ - public var flashSprite:Sprite = new Sprite(); + @:deprecated("flashSprite is deprecated, avoid referencing it directly and use the methods from camera.view instead") + public var flashSprite(get, set):Sprite; /** * Whether the positions of the objects rendered on this camera are rounded. @@ -322,11 +349,13 @@ class FlxCamera extends FlxBasic * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom * (it is applied to all objects rendered on the camera at such circumstances). */ + @:deprecated("depblit") var _blitMatrix:FlxMatrix = new FlxMatrix(); /** * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. */ + @:deprecated("depblit") var _useBlitMatrix:Bool = false; /** @@ -366,6 +395,7 @@ class FlxCamera extends FlxBasic * (the area of camera's buffer which should be filled with `bgColor`). * Do not modify it unless you know what are you doing. */ + @:deprecated("depblit") var _flashRect:Rectangle; /** @@ -373,6 +403,7 @@ class FlxCamera extends FlxBasic * Its coordinates are always `(0,0)`, where camera's buffer filling should start. * Do not modify it unless you know what are you doing. */ + @:deprecated("depblit") var _flashPoint:Point = new Point(); /** @@ -480,6 +511,7 @@ class FlxCamera extends FlxBasic * Internal helper variable for doing better wipes/fills between renders. * Used it blit render mode only (in `fill()` method). */ + @:deprecated("depblit") var _fill:BitmapData; /** @@ -488,6 +520,7 @@ class FlxCamera extends FlxBasic * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. * It is a child of the `_scrollRect` `Sprite`. */ + @:deprecated("depblit") var _flashBitmap:Bitmap; /** @@ -495,11 +528,13 @@ class FlxCamera extends FlxBasic * It is a child of `flashSprite`. * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ - var _scrollRect:Sprite = new Sprite(); + @:deprecated("depshared") + var _scrollRect:Sprite; /** * Helper rect for `drawTriangles()` visibility checks */ + @:deprecated("depblit") var _bounds:FlxRect = FlxRect.get(); /** @@ -508,7 +543,8 @@ class FlxCamera extends FlxBasic * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. */ - public var canvas:Sprite; + @:deprecated("canvas is deprecated, avoid referencing it directly and use the methods from camera.view instead") + public var canvas(get, set):Sprite; #if FLX_DEBUG /** @@ -517,407 +553,162 @@ class FlxCamera extends FlxBasic * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. */ - public var debugLayer:Sprite; + @:deprecated("debugLayer is deprecated, avoid referencing it directly and use the methods from camera.view instead") + public var debugLayer(get, set):Sprite; #end + @:deprecated("depshared") var _helperMatrix:FlxMatrix = new FlxMatrix(); + @:deprecated("depblit") var _helperPoint:Point = new Point(); /** * Currently used draw stack item */ + @:deprecated("depquad") var _currentDrawItem:FlxDrawBaseItem; /** * Pointer to head of stack with draw items */ + @:deprecated("depquad") var _headOfDrawStack:FlxDrawBaseItem; /** * Last draw tiles item */ + @:deprecated("depquad") var _headTiles:FlxDrawItem; /** * Last draw triangles item */ + @:deprecated("depquad") var _headTriangles:FlxDrawTrianglesItem; /** * Draw tiles stack items that can be reused */ + @:deprecated("depquad") static var _storageTilesHead:FlxDrawItem; /** * Draw triangles stack items that can be reused */ + @:deprecated("depquad") static var _storageTrianglesHead:FlxDrawTrianglesItem; /** * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. */ + @:deprecated("depblit") static var drawVertices:Vector = new Vector(); /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ + @:deprecated("depblit") static var trianglesSprite:Sprite = new Sprite(); /** * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. * Added for less garbage creation. */ + @:deprecated("depblit") static var renderPoint:FlxPoint = FlxPoint.get(); + @:deprecated("depblit") static var renderRect:FlxRect = FlxRect.get(); @:noCompletion public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) { - #if FLX_RENDER_TRIANGLE - return startTrianglesBatch(graphic, smooth, colored, blend); - #else - var itemToReturn = null; - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); - - if (_currentDrawItem != null - && _currentDrawItem.type == FlxDrawItemType.TILES - && _headTiles.graphics == graphic - && _headTiles.colored == colored - && _headTiles.hasColorOffsets == hasColorOffsets - && _headTiles.blending == blendInt - && _headTiles.blend == blend - && _headTiles.antialiasing == smooth - && _headTiles.shader == shader) - { - return _headTiles; - } - - if (_storageTilesHead != null) - { - itemToReturn = _storageTilesHead; - var newHead = _storageTilesHead.nextTyped; - itemToReturn.reset(); - _storageTilesHead = newHead; - } - else - { - itemToReturn = new FlxDrawItem(); - } - - // TODO: catch this error when the dev actually messes up, not in the draw phase - if (graphic.isDestroyed) - throw 'Cannot queue ${graphic.key}. This sprite was destroyed.'; - - itemToReturn.graphics = graphic; - itemToReturn.antialiasing = smooth; - itemToReturn.colored = colored; - itemToReturn.hasColorOffsets = hasColorOffsets; - itemToReturn.blending = blendInt; - itemToReturn.blend = blend; - itemToReturn.shader = shader; - - itemToReturn.nextTyped = _headTiles; - _headTiles = itemToReturn; - - if (_headOfDrawStack == null) - { - _headOfDrawStack = itemToReturn; - } - - if (_currentDrawItem != null) - { - _currentDrawItem.next = itemToReturn; - } - - _currentDrawItem = itemToReturn; - - return itemToReturn; - #end + return viewQuad.startQuadBatch(graphic, colored, hasColorOffsets, blend, smooth, shader); } @:noCompletion public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); - - if (_currentDrawItem != null - && _currentDrawItem.type == FlxDrawItemType.TRIANGLES - && _headTriangles.graphics == graphic - && _headTriangles.antialiasing == smoothing - && _headTriangles.colored == isColored - && _headTriangles.blending == blendInt - && _headTriangles.blend == blend - #if !flash - && _headTriangles.hasColorOffsets == hasColorOffsets - && _headTriangles.shader == shader - #end - ) - { - return _headTriangles; - } - - return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + return viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } @:noCompletion public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { - var itemToReturn:FlxDrawTrianglesItem = null; - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); - - if (_storageTrianglesHead != null) - { - itemToReturn = _storageTrianglesHead; - var newHead:FlxDrawTrianglesItem = _storageTrianglesHead.nextTyped; - itemToReturn.reset(); - _storageTrianglesHead = newHead; - } - else - { - itemToReturn = new FlxDrawTrianglesItem(); - } - - itemToReturn.graphics = graphic; - itemToReturn.antialiasing = smoothing; - itemToReturn.colored = isColored; - itemToReturn.blending = blendInt; - itemToReturn.blend = blend; - #if !flash - itemToReturn.hasColorOffsets = hasColorOffsets; - itemToReturn.shader = shader; - #end - - itemToReturn.nextTyped = _headTriangles; - _headTriangles = itemToReturn; - - if (_headOfDrawStack == null) - { - _headOfDrawStack = itemToReturn; - } + return viewQuad.getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + } - if (_currentDrawItem != null) - { - _currentDrawItem.next = itemToReturn; - } + @:allow(flixel.system.frontEnds.CameraFrontEnd) + function clearDrawStack():Void + { + viewQuad.clearDrawStack(); + } - _currentDrawItem = itemToReturn; + @:allow(flixel.system.frontEnds.CameraFrontEnd) + inline function lock(?useBufferLocking:Bool):Void + { + view.lock(useBufferLocking); + } - return itemToReturn; + @:allow(flixel.system.frontEnds.CameraFrontEnd) + function render():Void + { + view.render(); } @:allow(flixel.system.frontEnds.CameraFrontEnd) - function clearDrawStack():Void + inline function unlock(?useBufferLocking:Bool):Void { - var currTiles = _headTiles; - var newTilesHead; + view.unlock(useBufferLocking); + } - while (currTiles != null) - { - newTilesHead = currTiles.nextTyped; - currTiles.reset(); - currTiles.nextTyped = _storageTilesHead; - _storageTilesHead = currTiles; - currTiles = newTilesHead; - } + public function beginDrawDebug():Void + { + view.beginDrawDebug(); + } - var currTriangles:FlxDrawTrianglesItem = _headTriangles; - var newTrianglesHead:FlxDrawTrianglesItem; + public function endDrawDebug(?matrix:FlxMatrix):Void + { + view.endDrawDebug(matrix); + } - while (currTriangles != null) - { - newTrianglesHead = currTriangles.nextTyped; - currTriangles.reset(); - currTriangles.nextTyped = _storageTrianglesHead; - _storageTrianglesHead = currTriangles; - currTriangles = newTrianglesHead; - } + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + view.drawDebugRect(x, y, width, height, color, thickness); + } - _currentDrawItem = null; - _headOfDrawStack = null; - _headTiles = null; - _headTriangles = null; + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + view.drawDebugFilledRect(x, y, width, height, color); } - @:allow(flixel.system.frontEnds.CameraFrontEnd) - function render():Void + public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { - var currItem:FlxDrawBaseItem = _headOfDrawStack; - while (currItem != null) - { - currItem.render(this); - currItem = currItem.next; - } + view.drawDebugCircle(x, y, radius, color); + } + + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + view.drawDebugLine(x1, y1, x2, y2, color, thickness); } public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - if (FlxG.renderBlit) - { - _helperMatrix.copyFrom(matrix); - - if (_useBlitMatrix) - { - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); - buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); - } - } - else - { - var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if FLX_RENDER_TRIANGLE - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend); - #else - var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #end - drawItem.addQuad(frame, matrix, transform); - } + view.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); } public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - if (FlxG.renderBlit) - { - if (pixels != null) - { - if (_useBlitMatrix) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperPoint.x = destPoint.x - Std.int(viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(viewMarginTop); - buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); - } - } - else if (frame != null) - { - // TODO: fix this case for zoom less than initial zoom... - frame.paint(buffer, destPoint, true); - } - } - else - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); - - var isColored = (transform != null && transform.hasRGBMultipliers()); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if !FLX_RENDER_TRIANGLE - var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #else - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend); - #end - drawItem.addQuad(frame, _helperMatrix, transform); - } + view.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); } public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void { - if (FlxG.renderBlit) - { - if (position == null) - position = renderPoint.set(); - - _bounds.set(0, 0, width, height); - - var verticesLength:Int = vertices.length; - var currentVertexPosition:Int = 0; - - var tempX:Float, tempY:Float; - var i:Int = 0; - var bounds = renderRect.set(); - drawVertices.splice(0, drawVertices.length); - - while (i < verticesLength) - { - tempX = position.x + vertices[i]; - tempY = position.y + vertices[i + 1]; - - drawVertices[currentVertexPosition++] = tempX; - drawVertices[currentVertexPosition++] = tempY; - - if (i == 0) - { - bounds.set(tempX, tempY, 0, 0); - } - else - { - FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); - } - - i += 2; - } - - position.putWeak(); - - if (!_bounds.overlaps(bounds)) - { - drawVertices.splice(drawVertices.length - verticesLength, verticesLength); - } - else - { - trianglesSprite.graphics.clear(); - trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); - trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); - trianglesSprite.graphics.endFill(); - - // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... - if (_useBlitMatrix) - _helperMatrix.copyFrom(_blitMatrix); - else - { - _helperMatrix.identity(); - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); - } - - buffer.draw(trianglesSprite, _helperMatrix); - #if FLX_DEBUG - if (FlxG.debugger.drawDebug) - { - var gfx:Graphics = FlxSpriteUtil.flashGfx; - gfx.clear(); - gfx.lineStyle(1, FlxColor.BLUE, 0.5); - gfx.drawTriangles(drawVertices, indices); - buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); - } - #end - // End of TODO... - } - - bounds.put(); - } - else - { - _bounds.set(0, 0, width, height); - var isColored:Bool = (colors != null && colors.length != 0); - - #if !flash - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - isColored = isColored || (transform != null && transform.hasRGBMultipliers()); - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds, transform); - #else - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds); - #end - } + view.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); } /** @@ -925,22 +716,9 @@ class FlxCamera extends FlxBasic * @param rect rectangle to prepare for rendering * @return transformed rectangle with respect to camera's zoom factor */ - function transformRect(rect:FlxRect):FlxRect + inline function transformRect(rect:FlxRect):FlxRect { - if (FlxG.renderBlit) - { - rect.offset(-viewMarginLeft, -viewMarginTop); - - if (_useBlitMatrix) - { - rect.x *= zoom; - rect.y *= zoom; - rect.width *= zoom; - rect.height *= zoom; - } - } - - return rect; + return view.transformRect(rect); } /** @@ -948,17 +726,9 @@ class FlxCamera extends FlxBasic * @param point point to prepare for rendering * @return transformed point with respect to camera's zoom factor */ - function transformPoint(point:FlxPoint):FlxPoint + inline function transformPoint(point:FlxPoint):FlxPoint { - if (FlxG.renderBlit) - { - point.subtract(viewMarginLeft, viewMarginTop); - - if (_useBlitMatrix) - point.scale(zoom); - } - - return point; + return view.transformPoint(point); } /** @@ -968,10 +738,7 @@ class FlxCamera extends FlxBasic */ inline function transformVector(vector:FlxPoint):FlxPoint { - if (FlxG.renderBlit && _useBlitMatrix) - vector.scale(zoom); - - return vector; + return view.transformVector(vector); } /** @@ -981,18 +748,9 @@ class FlxCamera extends FlxBasic * @param object display object to apply transformations to. * @return transformed object. */ - function transformObject(object:DisplayObject):DisplayObject + inline function transformObject(object:DisplayObject):DisplayObject { - object.scaleX *= totalScaleX; - object.scaleY *= totalScaleY; - - object.x -= scroll.x * totalScaleX; - object.y -= scroll.y * totalScaleY; - - object.x -= 0.5 * width * (scaleX - initialZoom) * FlxG.scaleMode.scale.x; - object.y -= 0.5 * height * (scaleY - initialZoom) * FlxG.scaleMode.scale.y; - - return object; + return view.transformObject(object); } /** @@ -1023,34 +781,15 @@ class FlxCamera extends FlxBasic this.width = width; this.height = height; - _flashRect = new Rectangle(0, 0, width, height); - flashSprite.addChild(_scrollRect); - _scrollRect.scrollRect = new Rectangle(); + view = FlxCameraView.create(this); + if (view is FlxQuadView) + viewQuad = cast view; + else if (view is FlxBlitView) + viewBlit = cast view; pixelPerfectRender = FlxG.renderBlit; - if (FlxG.renderBlit) - { - screen = new FlxSprite(); - buffer = new BitmapData(width, height, true, 0); - screen.pixels = buffer; - screen.origin.set(); - _flashBitmap = new Bitmap(buffer); - _scrollRect.addChild(_flashBitmap); - _fill = new BitmapData(width, height, true, FlxColor.TRANSPARENT); - } - else - { - canvas = new Sprite(); - _scrollRect.addChild(canvas); - - #if FLX_DEBUG - debugLayer = new Sprite(); - _scrollRect.addChild(debugLayer); - #end - } - set_color(FlxColor.WHITE); // sets the scale of flash sprite, which in turn loads flashOffset values @@ -1069,42 +808,7 @@ class FlxCamera extends FlxBasic */ override public function destroy():Void { - FlxDestroyUtil.removeChild(flashSprite, _scrollRect); - - if (FlxG.renderBlit) - { - FlxDestroyUtil.removeChild(_scrollRect, _flashBitmap); - screen = FlxDestroyUtil.destroy(screen); - buffer = null; - _flashBitmap = null; - _fill = FlxDestroyUtil.dispose(_fill); - } - else - { - #if FLX_DEBUG - FlxDestroyUtil.removeChild(_scrollRect, debugLayer); - debugLayer = null; - #end - - FlxDestroyUtil.removeChild(_scrollRect, canvas); - if (canvas != null) - { - for (i in 0...canvas.numChildren) - { - canvas.removeChildAt(0); - } - canvas = null; - } - - if (_headOfDrawStack != null) - { - clearDrawStack(); - } - - _blitMatrix = null; - _helperMatrix = null; - _helperPoint = null; - } + view.destroy(); _bounds = null; scroll = FlxDestroyUtil.put(scroll); @@ -1112,10 +816,6 @@ class FlxCamera extends FlxBasic deadzone = FlxDestroyUtil.put(deadzone); target = null; - flashSprite = null; - _scrollRect = null; - _flashRect = null; - _flashPoint = null; _fxFlashComplete = null; _fxFadeComplete = null; _fxShakeComplete = null; @@ -1334,6 +1034,9 @@ class FlxCamera extends FlxBasic } else { + var offsetX:Float = 0; + var offsetY:Float = 0; + final pixelPerfect = pixelPerfectShake == null ? pixelPerfectRender : pixelPerfectShake; if (_fxShakeAxes.x) { @@ -1341,7 +1044,7 @@ class FlxCamera extends FlxBasic if (pixelPerfect) shakePixels = Math.round(shakePixels); - flashSprite.x += shakePixels * zoom * FlxG.scaleMode.scale.x; + offsetX = shakePixels * zoom * FlxG.scaleMode.scale.x; } if (_fxShakeAxes.y) @@ -1350,8 +1053,10 @@ class FlxCamera extends FlxBasic if (pixelPerfect) shakePixels = Math.round(shakePixels); - flashSprite.y += shakePixels * zoom * FlxG.scaleMode.scale.y; + offsetY = shakePixels * zoom * FlxG.scaleMode.scale.y; } + + view.offsetView(offsetX, offsetY); } } } @@ -1362,11 +1067,8 @@ class FlxCamera extends FlxBasic */ function updateFlashSpritePosition():Void { - if (flashSprite != null) - { - flashSprite.x = x * FlxG.scaleMode.scale.x + _flashOffset.x; - flashSprite.y = y * FlxG.scaleMode.scale.y + _flashOffset.y; - } + if (view != null) + view.updatePosition(); } /** @@ -1375,8 +1077,8 @@ class FlxCamera extends FlxBasic */ function updateFlashOffset():Void { - _flashOffset.x = width * 0.5 * FlxG.scaleMode.scale.x * initialZoom; - _flashOffset.y = height * 0.5 * FlxG.scaleMode.scale.y * initialZoom; + if (view != null) + view.updateOffset(); } /** @@ -1389,20 +1091,8 @@ class FlxCamera extends FlxBasic */ function updateScrollRect():Void { - var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; - - if (rect != null) - { - rect.x = rect.y = 0; - - rect.width = width * initialZoom * FlxG.scaleMode.scale.x; - rect.height = height * initialZoom * FlxG.scaleMode.scale.y; - - _scrollRect.scrollRect = rect; - - _scrollRect.x = -0.5 * rect.width; - _scrollRect.y = -0.5 * rect.height; - } + if (view != null) + view.updateScrollRect(); } /** @@ -1413,36 +1103,8 @@ class FlxCamera extends FlxBasic */ function updateInternalSpritePositions():Void { - if (FlxG.renderBlit) - { - if (_flashBitmap != null) - { - _flashBitmap.x = 0; - _flashBitmap.y = 0; - } - } - else - { - if (canvas != null) - { - canvas.x = -0.5 * width * (scaleX - initialZoom) * FlxG.scaleMode.scale.x; - canvas.y = -0.5 * height * (scaleY - initialZoom) * FlxG.scaleMode.scale.y; - - canvas.scaleX = totalScaleX; - canvas.scaleY = totalScaleY; - - #if FLX_DEBUG - if (debugLayer != null) - { - debugLayer.x = canvas.x; - debugLayer.y = canvas.y; - - debugLayer.scaleX = totalScaleX; - debugLayer.scaleY = totalScaleY; - } - #end - } - } + if (view != null) + view.updateInternals(); } /** @@ -1657,101 +1319,57 @@ class FlxCamera extends FlxBasic /** * Fill the camera with the specified color. * - * @param Color The color to fill with in `0xAARRGGBB` hex format. - * @param BlendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. + * @param color The color to fill with in `0xAARRGGBB` hex format. + * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. */ - public function fill(Color:FlxColor, BlendAlpha:Bool = true, FxAlpha:Float = 1.0, ?graphics:Graphics):Void + @:deprecated("The 4-arg fill(color, blendAlpha, fxAlpha, ?graphics) is deprecated, use the 2-arg fill(color, blendAlpha) instead.") + overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void { - if (FlxG.renderBlit) - { - if (BlendAlpha) - { - _fill.fillRect(_flashRect, Color); - buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, BlendAlpha); - } - else - { - buffer.fillRect(_flashRect, Color); - } - } - else - { - if (FxAlpha == 0) - return; - - final targetGraphics = (graphics == null) ? canvas.graphics : graphics; + color.alphaFloat = fxAlpha; + view.fill(color, blendAlpha); + } - targetGraphics.overrideBlendMode(null); - targetGraphics.beginFill(Color, FxAlpha); - // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, - // which could appear while cameras fading - targetGraphics.drawRect(viewMarginLeft - 1, viewMarginTop - 1, viewWidth + 2, viewHeight + 2); - targetGraphics.endFill(); - } + /** + * Fill the camera with the specified color. + * + * @param color The color to fill with in `0xAARRGGBB` hex format. + * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. + */ + overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true):Void + { + view.fill(color, blendAlpha); } /** * Internal helper function, handles the actual drawing of all the special effects. */ - @:allow(flixel.system.frontEnds.CameraFrontEnd) + @:allow(flixel.system.render.FlxCameraView) function drawFX():Void { // Draw the "flash" special effect onto the buffer if (_fxFlashAlpha > 0.0) { - if (FlxG.renderBlit) - { - var color = _fxFlashColor; - color.alphaFloat *= _fxFlashAlpha; - fill(color); - } - else - { - final alpha = _fxFlashColor.alphaFloat * _fxFlashAlpha; - fill(_fxFlashColor.rgb, true, alpha, canvas.graphics); - } + var color = _fxFlashColor; + color.alphaFloat *= _fxFlashAlpha; + view.fill(color); } // Draw the "fade" special effect onto the buffer if (_fxFadeAlpha > 0.0) { - if (FlxG.renderBlit) - { - var color = _fxFadeColor; - color.alphaFloat *= _fxFadeAlpha; - fill(color); - } - else - { - final alpha = _fxFadeColor.alphaFloat * _fxFadeAlpha; - fill(_fxFadeColor.rgb, true, alpha, canvas.graphics); - } + var color = _fxFadeColor; + color.alphaFloat *= _fxFadeAlpha; + view.fill(color); } } @:allow(flixel.system.frontEnds.CameraFrontEnd) function checkResize():Void { - if (FlxG.renderBlit) - { - if (width != buffer.width || height != buffer.height) - { - var oldBuffer:FlxGraphic = screen.graphic; - buffer = new BitmapData(width, height, true, 0); - screen.pixels = buffer; - screen.origin.set(); - _flashBitmap.bitmapData = buffer; - _flashRect.width = width; - _flashRect.height = height; - _fill = FlxDestroyUtil.dispose(_fill); - _fill = new BitmapData(width, height, true, FlxColor.TRANSPARENT); - FlxG.bitmap.removeIfNoUse(oldBuffer); - } - - updateBlitMatrix(); - } + view.checkResize(); } + @:deprecated("depblit") inline function updateBlitMatrix():Void { _blitMatrix.identity(); @@ -1838,24 +1456,7 @@ class FlxCamera extends FlxBasic totalScaleX = scaleX * FlxG.scaleMode.scale.x; totalScaleY = scaleY * FlxG.scaleMode.scale.y; - if (FlxG.renderBlit) - { - updateBlitMatrix(); - - if (_useBlitMatrix) - { - _flashBitmap.scaleX = initialZoom * FlxG.scaleMode.scale.x; - _flashBitmap.scaleY = initialZoom * FlxG.scaleMode.scale.y; - } - else - { - _flashBitmap.scaleX = totalScaleX; - _flashBitmap.scaleY = totalScaleY; - } - } - - calcMarginX(); - calcMarginY(); + view.updateScale(); updateScrollRect(); updateInternalSpritePositions(); @@ -1916,7 +1517,9 @@ class FlxCamera extends FlxBasic if (width != Value && Value > 0) { width = Value; - calcMarginX(); + + if (view != null) + view.calcMarginX(); updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); @@ -1931,7 +1534,9 @@ class FlxCamera extends FlxBasic if (height != Value && Value > 0) { height = Value; - calcMarginY(); + + if (view != null) + view.calcMarginY(); updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); @@ -1948,69 +1553,32 @@ class FlxCamera extends FlxBasic return zoom; } - function set_alpha(Alpha:Float):Float + function set_alpha(alpha:Float):Float { - alpha = FlxMath.bound(Alpha, 0, 1); - if (FlxG.renderBlit) - { - _flashBitmap.alpha = Alpha; - } - else - { - canvas.alpha = Alpha; - } - return Alpha; + this.alpha = FlxMath.bound(alpha, 0, 1); + view.alpha = alpha; + return alpha; } - function set_angle(Angle:Float):Float + function set_angle(angle:Float):Float { - angle = Angle; - flashSprite.rotation = Angle; - return Angle; + this.angle = angle; + view.angle = angle; + return angle; } - function set_color(Color:FlxColor):FlxColor + function set_color(color:FlxColor):FlxColor { - color = Color; - var colorTransform:ColorTransform; - - if (FlxG.renderBlit) - { - if (_flashBitmap == null) - { - return Color; - } - colorTransform = _flashBitmap.transform.colorTransform; - } - else - { - colorTransform = canvas.transform.colorTransform; - } - - colorTransform.redMultiplier = color.redFloat; - colorTransform.greenMultiplier = color.greenFloat; - colorTransform.blueMultiplier = color.blueFloat; - - if (FlxG.renderBlit) - { - _flashBitmap.transform.colorTransform = colorTransform; - } - else - { - canvas.transform.colorTransform = colorTransform; - } - - return Color; + this.color = color; + view.color = color; + return color; } - function set_antialiasing(Antialiasing:Bool):Bool + function set_antialiasing(antialiasing:Bool):Bool { - antialiasing = Antialiasing; - if (FlxG.renderBlit) - { - _flashBitmap.smoothing = Antialiasing; - } - return Antialiasing; + this.antialiasing = antialiasing; + view.antialiasing = antialiasing; + return antialiasing; } function set_x(x:Float):Float @@ -2029,21 +1597,20 @@ class FlxCamera extends FlxBasic override function set_visible(visible:Bool):Bool { - if (flashSprite != null) - { - flashSprite.visible = visible; - } + view.visible = visible; return this.visible = visible; } + @:deprecated("depshared") inline function calcMarginX():Void { - viewMarginX = 0.5 * width * (scaleX - initialZoom) / scaleX; + view.calcMarginX(); } + @:deprecated("depshared") inline function calcMarginY():Void { - viewMarginY = 0.5 * height * (scaleY - initialZoom) / scaleY; + view.calcMarginY(); } static inline function get_defaultCameras():Array @@ -2115,6 +1682,59 @@ class FlxCamera extends FlxBasic { return scroll.y + viewMarginBottom; } + + inline function set_flashSprite(value:Sprite):Sprite + { + var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; + return sprite = value; + } + + inline function get_flashSprite():Sprite + { + return FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; + } + + inline function set_screen(value:FlxSprite):FlxSprite + { + return viewBlit.screen = value; + } + + inline function get_screen():FlxSprite + { + return viewBlit.screen; + } + + inline function set_buffer(value:BitmapData):BitmapData + { + return viewBlit.buffer = value; + } + + inline function get_buffer():BitmapData + { + return viewBlit.buffer; + } + + inline function set_canvas(value:Sprite):Sprite + { + return viewQuad.canvas = value; + } + + inline function get_canvas():Sprite + { + return viewQuad.canvas; + } + + #if FLX_DEBUG + inline function set_debugLayer(value:Sprite):Sprite + { + return viewQuad.debugLayer; + } + + inline function get_debugLayer():Sprite + { + return viewQuad.debugLayer; + } + #end /** * Do not use the following fields! They only exists because FlxCamera extends FlxBasic, @@ -2135,7 +1755,6 @@ class FlxCamera extends FlxBasic @: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/FlxObject.hx b/flixel/FlxObject.hx index 756d23a498..f91fc082af 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1289,23 +1289,25 @@ class FlxObject extends FlxBasic gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } + @:deprecated("use object.beginDrawDebug(camera) is deprecated, camera.beginDrawDebug() instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { + camera.beginDrawDebug(); + if (FlxG.renderBlit) { - FlxSpriteUtil.flashGfx.clear(); return FlxSpriteUtil.flashGfx; } else { - return camera.debugLayer.graphics; + return camera.viewQuad.debugLayer.graphics; } } + @:deprecated("use object.endDrawDebug(camera) is deprecated, camera.endDrawDebug() instead") inline function endDrawDebug(camera:FlxCamera) { - if (FlxG.renderBlit) - camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); + camera.endDrawDebug(); } #end diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index 9b513a8106..93e1ced9ff 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -133,9 +133,9 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - camera.canvas.graphics.overrideBlendMode(blend); - camera.canvas.graphics.beginShaderFill(shader); - camera.canvas.graphics.drawQuads(rects, null, transforms); + camera.viewQuad.canvas.graphics.overrideBlendMode(blend); + camera.viewQuad.canvas.graphics.beginShaderFill(shader); + camera.viewQuad.canvas.graphics.drawQuads(rects, null, transforms); super.render(camera); } @@ -146,4 +146,4 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem parameter.value[0] = value; } #end -} \ No newline at end of file +} diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index b2f71ce51e..2367b4c1d2 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -79,15 +79,15 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - camera.canvas.graphics.overrideBlendMode(blend); + camera.viewQuad.canvas.graphics.overrideBlendMode(blend); - camera.canvas.graphics.beginShaderFill(shader); + camera.viewQuad.canvas.graphics.beginShaderFill(shader); #else - camera.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); + camera.viewQuad.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); #end - camera.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); - camera.canvas.graphics.endFill(); + camera.viewQuad.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); + camera.viewQuad.canvas.graphics.endFill(); #if FLX_DEBUG if (FlxG.debugger.drawDebug) diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 965d0eff3d..c334b6b849 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -64,7 +64,7 @@ class CameraFrontEnd */ public function add(NewCamera:T, DefaultDrawTarget:Bool = true):T { - FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game._inputContainer)); + FlxG.game.addChildAt(NewCamera.view.display, FlxG.game.getChildIndex(FlxG.game._inputContainer)); list.push(NewCamera); if (DefaultDrawTarget) @@ -97,8 +97,8 @@ class CameraFrontEnd if (position >= list.length) return add(newCamera); - final childIndex = FlxG.game.getChildIndex(list[position].flashSprite); - FlxG.game.addChildAt(newCamera.flashSprite, childIndex); + final childIndex = FlxG.game.getChildIndex(list[position].view.display); + FlxG.game.addChildAt(newCamera.view.display, childIndex); list.insert(position, newCamera); if (defaultDrawTarget) @@ -122,7 +122,7 @@ class CameraFrontEnd var index:Int = list.indexOf(Camera); if (Camera != null && index != -1) { - FlxG.game.removeChild(Camera.flashSprite); + FlxG.game.removeChild(Camera.view.display); list.splice(index, 1); defaults.remove(Camera); } @@ -257,39 +257,9 @@ class CameraFrontEnd { for (camera in list) { - if (camera == null || !camera.exists || !camera.visible) + if ((camera != null) && camera.exists && camera.visible) { - continue; - } - - if (FlxG.renderBlit) - { - camera.checkResize(); - - if (useBufferLocking) - { - camera.buffer.lock(); - } - } - - if (FlxG.renderTile) - { - camera.clearDrawStack(); - camera.canvas.graphics.clear(); - // Clearing camera's debug sprite - #if FLX_DEBUG - camera.debugLayer.graphics.clear(); - #end - } - - if (FlxG.renderBlit) - { - camera.fill(camera.bgColor, camera.useBgAlphaBlending); - camera.screen.dirty = true; - } - else - { - camera.fill(camera.bgColor.rgb, camera.useBgAlphaBlending, camera.bgColor.alphaFloat); + camera.lock(useBufferLocking); } } } @@ -317,21 +287,9 @@ class CameraFrontEnd { for (camera in list) { - if ((camera == null) || !camera.exists || !camera.visible) - { - continue; - } - - camera.drawFX(); - - if (FlxG.renderBlit) + if ((camera != null) && camera.exists && camera.visible) { - if (useBufferLocking) - { - camera.buffer.unlock(); - } - - camera.screen.dirty = true; + camera.unlock(useBufferLocking); } } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx new file mode 100644 index 0000000000..6115ecc27f --- /dev/null +++ b/flixel/system/render/FlxCameraView.hx @@ -0,0 +1,378 @@ +package flixel.system.render; + +import flixel.math.FlxRect; +import openfl.display.DisplayObjectContainer; +import flixel.FlxG; +import flixel.FlxCamera; +import flixel.util.FlxDestroyUtil; +import flixel.graphics.FlxGraphic; +import flixel.system.FlxAssets.FlxShader; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxPoint; +import flixel.math.FlxMatrix; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.util.FlxColor; +import openfl.filters.BitmapFilter; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; +import openfl.display.BlendMode; +import openfl.display.DisplayObject; +import openfl.display.BitmapData; + +/** + * A `FlxCameraView` is the base class for all rendering functionality. + * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. + */ +@:allow(flixel.FlxCamera) +class FlxCameraView implements IFlxDestroyable +{ + /** + * The number of total draw calls in a frame. + */ + public static var totalDrawCalls:Int = 0; + + /** + * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. + * @param camera The camera to create the view for + */ + public static inline function create(camera:FlxCamera):FlxCameraView + { + if (FlxG.renderTile) + { + return cast new flixel.system.render.quad.FlxQuadView(camera); + } + else + { + return cast new flixel.system.render.blit.FlxBlitView(camera); + } + } + + /** + * Display object which is used as a container for all of the camera's graphics. + * This object is added to the display tree. + */ + public var display(get, never):DisplayObjectContainer; + + /** + * The parent camera for this view. + */ + public var camera(default, null):FlxCamera; + + /** + * The margin cut off on the left and right by the camera zooming in (or out), in world space. + */ + public var viewMarginX(default, null):Float; + + /** + * The margin cut off on the top and bottom by the camera zooming in (or out), in world space. + */ + public var viewMarginY(default, null):Float; + + /** + * The margin cut off on the left by the camera zooming in (or out), in world space. + */ + public var viewMarginLeft(get, never):Float; + + /** + * The margin cut off on the top by the camera zooming in (or out), in world space + */ + public var viewMarginTop(get, never):Float; + + /** + * The margin cut off on the right by the camera zooming in (or out), in world space + */ + public var viewMarginRight(get, never):Float; + + /** + * The margin cut off on the bottom by the camera zooming in (or out), in world space + */ + public var viewMarginBottom(get, never):Float; + + /** + * The size of the camera's view, in world space. + */ + public var viewWidth(get, never):Float; + + /** + * The size of the camera's view, in world space. + */ + public var viewHeight(get, never):Float; + + /** + * The left of the camera's view, in world space. + */ + public var viewX(get, never):Float; + + /** + * The top of the camera's view, in world space. + */ + public var viewY(get, never):Float; + + /** + * The left of the camera's view, in world space. + */ + public var viewLeft(get, never):Float; + + /** + * The top of the camera's view, in world space. + */ + public var viewTop(get, never):Float; + + /** + * The right side of the camera's view, in world space. + */ + public var viewRight(get, never):Float; + + /** + * The bottom side of the camera's view, in world space. + */ + public var viewBottom(get, never):Float; + + public var antialiasing(get, set):Bool; + public var angle(get, set):Float; + public var alpha(get, set):Float; + public var color(get, set):FlxColor; + public var visible(get, set):Bool; + public var filters:Array = []; + + var _flashOffset:FlxPoint = FlxPoint.get(); + + function new(camera:FlxCamera) + { + this.camera = camera; + } + + public function destroy():Void + { + _flashOffset = FlxDestroyUtil.put(_flashOffset); + } + + public function lock(?useBufferLocking:Bool):Void {} + + public function render():Void {} + + public function unlock(?useBufferLocking:Bool):Void {} + + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader):Void {} + + public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader):Void {} + + public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} + + public function beginDrawDebug():Void {} + + public function endDrawDebug(?matrix:FlxMatrix):Void {} + + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} + + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} + + public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} + + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} + + public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} + + function drawFX():Void {} + + function updateScale():Void + { + calcMarginX(); + calcMarginY(); + } + + function updatePosition():Void {} + function updateInternals():Void {} + + function updateOffset():Void + { + _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; + _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; + } + + public function offsetView(x:Float, y:Float):Void {} + + function updateScrollRect():Void {} + + /** + * Helper method preparing debug rectangle for rendering in blit render mode + * @param rect rectangle to prepare for rendering + * @return transformed rectangle with respect to camera's zoom factor + */ + function transformRect(rect:FlxRect):FlxRect + { + return rect; + } + + /** + * Helper method preparing debug point for rendering in blit render mode (for debug path rendering, for example) + * @param point point to prepare for rendering + * @return transformed point with respect to camera's zoom factor + */ + function transformPoint(point:FlxPoint):FlxPoint + { + return point; + } + + /** + * Helper method preparing debug vectors (relative positions) for rendering in blit render mode + * @param vector relative position to prepare for rendering + * @return transformed vector with respect to camera's zoom factor + */ + function transformVector(vector:FlxPoint):FlxPoint + { + return vector; + } + + /** + * Helper method for applying transformations (scaling and offsets) + * to specified display objects which has been added to the camera display list. + * For example, debug sprite for nape debug rendering. + * @param object display object to apply transformations to. + * @return transformed object. + */ + function transformObject(object:DisplayObject):DisplayObject + { + object.scaleX *= camera.totalScaleX; + object.scaleY *= camera.totalScaleY; + + object.x -= camera.scroll.x * camera.totalScaleX; + object.y -= camera.scroll.y * camera.totalScaleY; + + object.x -= 0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; + object.y -= 0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; + + return object; + } + + function checkResize():Void {} + + public inline function calcMarginX():Void + { + viewMarginX = 0.5 * camera.width * (camera.scaleX - camera.initialZoom) / camera.scaleX; + } + + public inline function calcMarginY():Void + { + viewMarginY = 0.5 * camera.height * (camera.scaleY - camera.initialZoom) / camera.scaleY; + } + + inline function get_viewMarginLeft():Float + { + return viewMarginX; + } + + inline function get_viewMarginTop():Float + { + return viewMarginY; + } + + inline function get_viewMarginRight():Float + { + return camera.width - viewMarginX; + } + + inline function get_viewMarginBottom():Float + { + return camera.height - viewMarginY; + } + + inline function get_viewWidth():Float + { + return camera.width - viewMarginX * 2; + } + + inline function get_viewHeight():Float + { + return camera.height - viewMarginY * 2; + } + + inline function get_viewX():Float + { + return camera.scroll.x + viewMarginX; + } + + inline function get_viewY():Float + { + return camera.scroll.y + viewMarginY; + } + + inline function get_viewLeft():Float + { + return viewX; + } + + inline function get_viewTop():Float + { + return viewY; + } + + inline function get_viewRight():Float + { + return camera.scroll.x + viewMarginRight; + } + + inline function get_viewBottom():Float + { + return camera.scroll.y + viewMarginBottom; + } + + function get_display():DisplayObjectContainer + { + return null; + } + + function get_color():FlxColor + { + return camera.color; + } + + function set_color(color:FlxColor):FlxColor + { + return color; + } + + function get_antialiasing():Bool + { + return camera.antialiasing; + } + + function set_antialiasing(antialiasing:Bool):Bool + { + return antialiasing; + } + + function get_angle():Float + { + return camera.angle; + } + + function set_angle(angle:Float):Float + { + return angle; + } + + function get_visible():Bool + { + return camera.visible; + } + + function set_visible(visible:Bool):Bool + { + return visible; + } + + function get_alpha():Float + { + return camera.alpha; + } + + function set_alpha(alpha:Float):Float + { + return alpha; + } +} diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx new file mode 100644 index 0000000000..a60834688a --- /dev/null +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -0,0 +1,490 @@ +package flixel.system.render.blit; + +import flixel.math.FlxRect; +import openfl.display.Bitmap; +import openfl.display.DisplayObjectContainer; +import flixel.system.render.FlxCameraView; +import flixel.FlxG; +import flixel.FlxCamera; +import flixel.util.FlxDestroyUtil; +import flixel.graphics.FlxGraphic; +import flixel.system.FlxAssets.FlxShader; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxPoint; +import flixel.math.FlxMatrix; +import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.util.FlxColor; +import openfl.filters.BitmapFilter; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; +import openfl.display.BlendMode; +import openfl.display.DisplayObject; +import openfl.display.BitmapData; +import openfl.display.Sprite; +import openfl.Vector; +import openfl.display.Graphics; +import flixel.util.FlxSpriteUtil; + +class FlxBlitView extends FlxCameraView +{ + /** + * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. + */ + static var trianglesSprite:Sprite = new Sprite(); + + /** + * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. + * Added for less garbage creation. + */ + static var renderPoint:FlxPoint = FlxPoint.get(); + + static var renderRect:FlxRect = FlxRect.get(); + + /** + * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. + */ + static var drawVertices:Vector = new Vector(); + + /** + * Used to render buffer to screen space. + * NOTE: We don't recommend modifying this directly unless you are fairly experienced. + * Uses include 3D projection, advanced display list modification, and more. + * This is container for everything else that is used by camera and rendered to the camera. + * + * Its position is modified by `updateFlashSpritePosition()` which is called every frame. + */ + public var flashSprite:Sprite = new Sprite(); + + /** + * Sometimes it's easier to just work with a `FlxSprite`, than it is to work directly with the `BitmapData` buffer. + * This sprite reference will allow you to do exactly that. + * Basically, this sprite's `pixels` property is the camera's `BitmapData` buffer. + * + * **NOTE:** This field is only used in blit render mode. + */ + public var screen:FlxSprite; + + /** + * The actual `BitmapData` of the camera display itself. + * Used in blit render mode, where you can manipulate its pixels for achieving some visual effects. + */ + public var buffer:BitmapData; + + /** + * Internal sprite, used for correct trimming of camera viewport. + * It is a child of `flashSprite`. + * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. + */ + var _scrollRect:Sprite = new Sprite(); + + /** + * Internal, used in blit render mode in camera's `fill()` method for less garbage creation. + * It represents the size of buffer `BitmapData` + * (the area of camera's buffer which should be filled with `bgColor`). + * Do not modify it unless you know what are you doing. + */ + var _flashRect:Rectangle; + + /** + * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: + * Its coordinates are always `(0,0)`, where camera's buffer filling should start. + * Do not modify it unless you know what are you doing. + */ + var _flashPoint:Point = new Point(); + + /** + * Internal, used to render buffer to screen space. Used it blit render mode only. + * This Bitmap used for rendering camera's buffer (`_flashBitmap.bitmapData = buffer;`) + * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. + * It is a child of the `_scrollRect` `Sprite`. + */ + var _flashBitmap:Bitmap; + + /** + * Internal helper variable for doing better wipes/fills between renders. + * Used it blit render mode only (in `fill()` method). + */ + var _fill:BitmapData; + + /** + * Helper rect for `drawTriangles()` visibility checks + */ + var _bounds:FlxRect = FlxRect.get(); + + /** + * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. + */ + var _useBlitMatrix:Bool = false; + + /** + * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom + * (it is applied to all objects rendered on the camera at such circumstances). + */ + var _blitMatrix:FlxMatrix = new FlxMatrix(); + + var _helperMatrix:FlxMatrix = new FlxMatrix(); + var _helperPoint:Point = new Point(); + + @:allow(flixel.system.render.FlxCameraView) + function new(camera:FlxCamera) + { + super(camera); + + flashSprite.addChild(_scrollRect); + _scrollRect.scrollRect = new Rectangle(); + + _flashRect = new Rectangle(0, 0, camera.width, camera.height); + + screen = new FlxSprite(); + buffer = new BitmapData(camera.width, camera.height, true, 0); + screen.pixels = buffer; + screen.origin.set(); + _flashBitmap = new Bitmap(buffer); + _scrollRect.addChild(_flashBitmap); + _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); + } + + override function destroy():Void + { + super.destroy(); + + FlxDestroyUtil.removeChild(flashSprite, _scrollRect); + FlxDestroyUtil.removeChild(_scrollRect, _flashBitmap); + screen = FlxDestroyUtil.destroy(screen); + buffer = null; + _flashBitmap = null; + _fill = FlxDestroyUtil.dispose(_fill); + flashSprite = null; + _scrollRect = null; + _flashRect = null; + _flashPoint = null; + } + + override function lock(?useBufferLocking:Bool) + { + checkResize(); + + if (useBufferLocking) + { + buffer.lock(); + } + + fill(camera.bgColor, camera.useBgAlphaBlending); + screen.dirty = true; + } + + override function unlock(?useBufferLocking:Bool):Void + { + camera.drawFX(); + + if (useBufferLocking) + { + buffer.unlock(); + } + + screen.dirty = true; + } + + override function beginDrawDebug():Void + { + FlxSpriteUtil.flashGfx.clear(); + } + + override function endDrawDebug(?matrix:FlxMatrix):Void + { + buffer.draw(FlxSpriteUtil.flashGfxSprite); + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void + { + _helperMatrix.copyFrom(matrix); + + if (_useBlitMatrix) + { + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); + } + } + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + { + if (pixels != null) + { + if (_useBlitMatrix) + { + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x, destPoint.y); + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperPoint.x = destPoint.x - Std.int(viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(viewMarginTop); + buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); + } + } + else if (frame != null) + { + // TODO: fix this case for zoom less than initial zoom... + frame.paint(buffer, destPoint, true); + } + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + if (position == null) + position = renderPoint.set(); + + _bounds.set(0, 0, camera.width, camera.height); + + var verticesLength:Int = vertices.length; + var currentVertexPosition:Int = 0; + + var tempX:Float, tempY:Float; + var i:Int = 0; + var bounds = renderRect.set(); + drawVertices.splice(0, drawVertices.length); + + while (i < verticesLength) + { + tempX = position.x + vertices[i]; + tempY = position.y + vertices[i + 1]; + + drawVertices[currentVertexPosition++] = tempX; + drawVertices[currentVertexPosition++] = tempY; + + if (i == 0) + { + bounds.set(tempX, tempY, 0, 0); + } + else + { + FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); + } + + i += 2; + } + + position.putWeak(); + + if (!_bounds.overlaps(bounds)) + { + drawVertices.splice(drawVertices.length - verticesLength, verticesLength); + } + else + { + trianglesSprite.graphics.clear(); + trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); + trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); + trianglesSprite.graphics.endFill(); + + // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... + if (_useBlitMatrix) + _helperMatrix.copyFrom(_blitMatrix); + else + { + _helperMatrix.identity(); + _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + } + + buffer.draw(trianglesSprite, _helperMatrix); + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + { + var gfx:Graphics = FlxSpriteUtil.flashGfx; + gfx.clear(); + gfx.lineStyle(1, FlxColor.BLUE, 0.5); + gfx.drawTriangles(drawVertices, indices); + buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); + } + #end + // End of TODO... + } + + bounds.put(); + } + + override function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) + { + _fill.fillRect(_flashRect, color); + buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); + } + else + { + buffer.fillRect(_flashRect, color); + } + } + + override function offsetView(x:Float, y:Float):Void + { + flashSprite.x += x; + flashSprite.y += y; + } + + override function updatePosition():Void + { + if (flashSprite != null) + { + flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; + flashSprite.y = camera.y * FlxG.scaleMode.scale.y + _flashOffset.y; + } + } + + override function updateScrollRect():Void + { + var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + + if (rect != null) + { + rect.x = rect.y = 0; + + rect.width = camera.width * camera.initialZoom * FlxG.scaleMode.scale.x; + rect.height = camera.height * camera.initialZoom * FlxG.scaleMode.scale.y; + + _scrollRect.scrollRect = rect; + + _scrollRect.x = -0.5 * rect.width; + _scrollRect.y = -0.5 * rect.height; + } + } + + override function updateScale():Void + { + updateBlitMatrix(); + + if (_useBlitMatrix) + { + _flashBitmap.scaleX = camera.initialZoom * FlxG.scaleMode.scale.x; + _flashBitmap.scaleY = camera.initialZoom * FlxG.scaleMode.scale.y; + } + else + { + _flashBitmap.scaleX = camera.totalScaleX; + _flashBitmap.scaleY = camera.totalScaleY; + } + + super.updateScale(); + } + + override function updateInternals():Void + { + if (_flashBitmap != null) + { + _flashBitmap.x = 0; + _flashBitmap.y = 0; + } + } + + override function checkResize() + { + if (camera.width != buffer.width || camera.height != buffer.height) + { + var oldBuffer:FlxGraphic = screen.graphic; + buffer = new BitmapData(camera.width, camera.height, true, 0); + screen.pixels = buffer; + screen.origin.set(); + _flashBitmap.bitmapData = buffer; + _flashRect.width = camera.width; + _flashRect.height = camera.height; + _fill = FlxDestroyUtil.dispose(_fill); + _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); + FlxG.bitmap.removeIfNoUse(oldBuffer); + } + + updateBlitMatrix(); + } + + inline function updateBlitMatrix():Void + { + _blitMatrix.identity(); + _blitMatrix.translate(-viewMarginLeft, -viewMarginTop); + _blitMatrix.scale(camera.scaleX, camera.scaleY); + + _useBlitMatrix = (camera.scaleX < camera.initialZoom) || (camera.scaleY < camera.initialZoom); + } + + override function transformRect(rect:FlxRect):FlxRect + { + rect.offset(-viewMarginLeft, -viewMarginTop); + + if (_useBlitMatrix) + { + rect.x *= camera.zoom; + rect.y *= camera.zoom; + rect.width *= camera.zoom; + rect.height *= camera.zoom; + } + + return rect; + } + + override function transformPoint(point:FlxPoint):FlxPoint + { + point.subtract(viewMarginLeft, viewMarginTop); + + if (_useBlitMatrix) + point.scale(camera.zoom); + + return point; + } + + override function transformVector(vector:FlxPoint):FlxPoint + { + if (_useBlitMatrix) + vector.scale(camera.zoom); + + return vector; + } + + override function get_display():DisplayObjectContainer + { + return flashSprite; + } + + override function set_color(color:FlxColor):FlxColor + { + if (_flashBitmap != null) + { + final colorTransform:ColorTransform = _flashBitmap.transform.colorTransform; + + colorTransform.redMultiplier = color.redFloat; + colorTransform.greenMultiplier = color.greenFloat; + colorTransform.blueMultiplier = color.blueFloat; + + _flashBitmap.transform.colorTransform = colorTransform; + } + + return color; + } + + override function set_antialiasing(antialiasing:Bool):Bool + { + return _flashBitmap.smoothing = antialiasing; + } + + override function set_alpha(alpha:Float):Float + { + return _flashBitmap.alpha = alpha; + } + + override function set_angle(angle:Float):Float + { + return flashSprite.rotation = angle; + } + + override function set_visible(visible:Bool):Bool + { + flashSprite.visible = visible; + return visible; + } +} diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx new file mode 100644 index 0000000000..78d580cbf8 --- /dev/null +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -0,0 +1,497 @@ +package flixel.system.render.quad; + +import flixel.math.FlxRect; +import openfl.display.DisplayObjectContainer; +import flixel.system.render.FlxCameraView; +import flixel.FlxG; +import flixel.FlxCamera; +import flixel.util.FlxDestroyUtil; +import flixel.graphics.FlxGraphic; +import flixel.system.FlxAssets.FlxShader; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxPoint; +import flixel.math.FlxMatrix; +import flixel.graphics.tile.FlxDrawBaseItem; +import flixel.graphics.tile.FlxDrawQuadsItem; +import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.util.FlxColor; +import openfl.filters.BitmapFilter; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; +import openfl.display.BlendMode; +import openfl.display.DisplayObject; +import openfl.display.BitmapData; +import openfl.display.Sprite; + +using flixel.util.FlxColorTransformUtil; + +private typedef FlxDrawItem = flixel.graphics.tile.FlxDrawQuadsItem; + +class FlxQuadView extends FlxCameraView +{ + /** + * Sprite used for actual rendering in tile render mode (instead of `_flashBitmap` for blitting). + * Its graphics is used as a drawing surface for `drawTriangles()` and `drawTiles()` methods. + * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). + * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. + */ + public var canvas:Sprite; + + #if FLX_DEBUG + /** + * Sprite for visual effects (flash and fade) and drawDebug information + * (bounding boxes are drawn on it) for tile render mode. + * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). + * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. + */ + public var debugLayer:Sprite; + #end + + /** + * Used to render buffer to screen space. + * NOTE: We don't recommend modifying this directly unless you are fairly experienced. + * Uses include 3D projection, advanced display list modification, and more. + * This is container for everything else that is used by camera and rendered to the camera. + * + * Its position is modified by `updateFlashSpritePosition()` which is called every frame. + */ + public var flashSprite:Sprite = new Sprite(); + + /** + * Internal sprite, used for correct trimming of camera viewport. + * It is a child of `flashSprite`. + * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. + */ + var _scrollRect:Sprite = new Sprite(); + + /** + * Helper rect for `drawTriangles()` visibility checks + */ + var _bounds:FlxRect = FlxRect.get(); + + var _helperMatrix:FlxMatrix = new FlxMatrix(); + + @:allow(flixel.system.render.FlxCameraView) + function new(camera:FlxCamera) + { + super(camera); + + flashSprite.addChild(_scrollRect); + _scrollRect.scrollRect = new Rectangle(); + + canvas = new Sprite(); + _scrollRect.addChild(canvas); + + #if FLX_DEBUG + debugLayer = new Sprite(); + _scrollRect.addChild(debugLayer); + #end + } + + override function destroy():Void + { + super.destroy(); + + FlxDestroyUtil.removeChild(flashSprite, _scrollRect); + #if FLX_DEBUG + FlxDestroyUtil.removeChild(_scrollRect, debugLayer); + debugLayer = null; + #end + + FlxDestroyUtil.removeChild(_scrollRect, canvas); + if (canvas != null) + { + for (i in 0...canvas.numChildren) + { + canvas.removeChildAt(0); + } + canvas = null; + } + + if (_headOfDrawStack != null) + { + clearDrawStack(); + } + + flashSprite = null; + _scrollRect = null; + _helperMatrix = null; + } + + override function lock(?useBufferLocking:Bool):Void + { + clearDrawStack(); + + canvas.graphics.clear(); + // Clearing camera's debug sprite + #if FLX_DEBUG + debugLayer.graphics.clear(); + #end + + fill(camera.bgColor, camera.useBgAlphaBlending); + } + + override function render():Void + { + flashSprite.filters = camera.filtersEnabled ? filters : null; + + var currItem:FlxDrawBaseItem = _headOfDrawStack; + while (currItem != null) + { + currItem.render(camera); + currItem = currItem.next; + } + } + + override function unlock(?useBufferLocking:Bool):Void + { + camera.drawFX(); + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + { + var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + #else + final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #end + drawItem.addQuad(frame, matrix, transform); + } + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + { + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); + + var isColored = (transform != null && transform.hasRGBMultipliers()); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if !FLX_RENDER_TRIANGLE + var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #else + var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend); + #end + drawItem.addQuad(frame, _helperMatrix, transform); + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + _bounds.set(0, 0, camera.width, camera.height); + var isColored:Bool = (colors != null && colors.length != 0); + + #if !flash + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + isColored = isColored || (transform != null && transform.hasRGBMultipliers()); + var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds, transform); + #else + var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend); + drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds); + #end + } + + override function fill(color:FlxColor, blendAlpha:Bool = true):Void + { + if (color.alpha == 0) + return; + + canvas.graphics.overrideBlendMode(null); + canvas.graphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + canvas.graphics.drawRect(viewMarginLeft - 1, viewMarginTop - 1, viewWidth + 2, viewHeight + 2); + canvas.graphics.endFill(); + } + + override function offsetView(x:Float, y:Float):Void + { + flashSprite.x += x; + flashSprite.y += y; + } + + override function updatePosition():Void + { + if (flashSprite != null) + { + flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; + flashSprite.y = camera.y * FlxG.scaleMode.scale.y + _flashOffset.y; + } + } + + override function updateScrollRect():Void + { + var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + + if (rect != null) + { + rect.x = rect.y = 0; + + rect.width = camera.width * camera.initialZoom * FlxG.scaleMode.scale.x; + rect.height = camera.height * camera.initialZoom * FlxG.scaleMode.scale.y; + + _scrollRect.scrollRect = rect; + + _scrollRect.x = -0.5 * rect.width; + _scrollRect.y = -0.5 * rect.height; + } + } + + override function updateInternals():Void + { + if (canvas != null) + { + canvas.x = -0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; + canvas.y = -0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; + + canvas.scaleX = camera.totalScaleX; + canvas.scaleY = camera.totalScaleY; + + #if FLX_DEBUG + if (debugLayer != null) + { + debugLayer.x = canvas.x; + debugLayer.y = canvas.y; + + debugLayer.scaleX = camera.totalScaleX; + debugLayer.scaleY = camera.totalScaleY; + } + #end + } + } + + override function set_color(color:FlxColor):FlxColor + { + final colorTransform:ColorTransform = canvas.transform.colorTransform; + + colorTransform.redMultiplier = color.redFloat; + colorTransform.greenMultiplier = color.greenFloat; + colorTransform.blueMultiplier = color.blueFloat; + + canvas.transform.colorTransform = colorTransform; + + return color; + } + + override function set_alpha(alpha:Float):Float + { + return canvas.alpha = alpha; + } + + override function set_angle(angle:Float):Float + { + return flashSprite.rotation = angle; + } + + override function set_visible(visible:Bool):Bool + { + flashSprite.visible = visible; + return visible; + } + + override function get_display():DisplayObjectContainer + { + return flashSprite; + } + + /** + * Currently used draw stack item + */ + var _currentDrawItem:FlxDrawBaseItem; + + /** + * Pointer to head of stack with draw items + */ + var _headOfDrawStack:FlxDrawBaseItem; + + /** + * Last draw tiles item + */ + var _headTiles:FlxDrawItem; + + /** + * Last draw triangles item + */ + var _headTriangles:FlxDrawTrianglesItem; + + /** + * Draw tiles stack items that can be reused + */ + static var _storageTilesHead:FlxDrawItem; + + /** + * Draw triangles stack items that can be reused + */ + static var _storageTrianglesHead:FlxDrawTrianglesItem; + + @:noCompletion + public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) + { + #if FLX_RENDER_TRIANGLE + return startTrianglesBatch(graphic, smooth, colored, blend); + #else + var itemToReturn = null; + var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); + + if (_currentDrawItem != null + && _currentDrawItem.type == FlxDrawItemType.TILES + && _headTiles.graphics == graphic + && _headTiles.colored == colored + && _headTiles.hasColorOffsets == hasColorOffsets + && _headTiles.blending == blendInt + && _headTiles.blend == blend + && _headTiles.antialiasing == smooth + && _headTiles.shader == shader) + { + return _headTiles; + } + + if (_storageTilesHead != null) + { + itemToReturn = _storageTilesHead; + var newHead = _storageTilesHead.nextTyped; + itemToReturn.reset(); + _storageTilesHead = newHead; + } + else + { + itemToReturn = new FlxDrawItem(); + } + + // TODO: catch this error when the dev actually messes up, not in the draw phase + if (graphic.isDestroyed) + throw 'Cannot queue ${graphic.key}. This sprite was destroyed.'; + + itemToReturn.graphics = graphic; + itemToReturn.antialiasing = smooth; + itemToReturn.colored = colored; + itemToReturn.hasColorOffsets = hasColorOffsets; + itemToReturn.blending = blendInt; + itemToReturn.blend = blend; + itemToReturn.shader = shader; + + itemToReturn.nextTyped = _headTiles; + _headTiles = itemToReturn; + + if (_headOfDrawStack == null) + { + _headOfDrawStack = itemToReturn; + } + + if (_currentDrawItem != null) + { + _currentDrawItem.next = itemToReturn; + } + + _currentDrawItem = itemToReturn; + + return itemToReturn; + #end + } + + @:noCompletion + public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + { + var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); + + if (_currentDrawItem != null + && _currentDrawItem.type == FlxDrawItemType.TRIANGLES + && _headTriangles.graphics == graphic + && _headTriangles.antialiasing == smoothing + && _headTriangles.colored == isColored + && _headTriangles.blending == blendInt + && _headTriangles.blend == blend + #if !flash + && _headTriangles.hasColorOffsets == hasColorOffsets + && _headTriangles.shader == shader + #end + ) + { + return _headTriangles; + } + + return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + } + + @:noCompletion + public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + { + var itemToReturn:FlxDrawTrianglesItem = null; + var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); + + if (_storageTrianglesHead != null) + { + itemToReturn = _storageTrianglesHead; + var newHead:FlxDrawTrianglesItem = _storageTrianglesHead.nextTyped; + itemToReturn.reset(); + _storageTrianglesHead = newHead; + } + else + { + itemToReturn = new FlxDrawTrianglesItem(); + } + + itemToReturn.graphics = graphic; + itemToReturn.antialiasing = smoothing; + itemToReturn.colored = isColored; + itemToReturn.blending = blendInt; + itemToReturn.blend = blend; + #if !flash + itemToReturn.hasColorOffsets = hasColorOffsets; + itemToReturn.shader = shader; + #end + + itemToReturn.nextTyped = _headTriangles; + _headTriangles = itemToReturn; + + if (_headOfDrawStack == null) + { + _headOfDrawStack = itemToReturn; + } + + if (_currentDrawItem != null) + { + _currentDrawItem.next = itemToReturn; + } + + _currentDrawItem = itemToReturn; + + return itemToReturn; + } + + @:noCompletion + public function clearDrawStack():Void + { + var currTiles = _headTiles; + var newTilesHead; + + while (currTiles != null) + { + newTilesHead = currTiles.nextTyped; + currTiles.reset(); + currTiles.nextTyped = _storageTilesHead; + _storageTilesHead = currTiles; + currTiles = newTilesHead; + } + + var currTriangles:FlxDrawTrianglesItem = _headTriangles; + var newTrianglesHead:FlxDrawTrianglesItem; + + while (currTriangles != null) + { + newTrianglesHead = currTriangles.nextTyped; + currTriangles.reset(); + currTriangles.nextTyped = _storageTrianglesHead; + _storageTrianglesHead = currTriangles; + currTriangles = newTrianglesHead; + } + + _currentDrawItem = null; + _headOfDrawStack = null; + _headTiles = null; + _headTriangles = null; + } +} From 1b1a5a06967b52bc5cd2d509654ec76fe5d5e1e5 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 23 Dec 2025 13:18:29 +0100 Subject: [PATCH 02/72] merge some fixes from upstream cus im dumb and on an old branch!! --- flixel/system/render/blit/FlxBlitView.hx | 14 ++++--- flixel/system/render/quad/FlxQuadView.hx | 50 +++++++----------------- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index a60834688a..1988abc9e5 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -139,7 +139,7 @@ class FlxBlitView extends FlxCameraView screen = new FlxSprite(); buffer = new BitmapData(camera.width, camera.height, true, 0); screen.pixels = buffer; - screen.origin.set(); + screen.origin.zero(); _flashBitmap = new Bitmap(buffer); _scrollRect.addChild(_flashBitmap); _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); @@ -159,6 +159,7 @@ class FlxBlitView extends FlxCameraView _scrollRect = null; _flashRect = null; _flashPoint = null; + _bounds = FlxDestroyUtil.put(_bounds); } override function lock(?useBufferLocking:Bool) @@ -240,11 +241,11 @@ class FlxBlitView extends FlxCameraView override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { + final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); + if (position == null) position = renderPoint.set(); - _bounds.set(0, 0, camera.width, camera.height); - var verticesLength:Int = vertices.length; var currentVertexPosition:Int = 0; @@ -275,7 +276,7 @@ class FlxBlitView extends FlxCameraView position.putWeak(); - if (!_bounds.overlaps(bounds)) + if (!cameraBounds.overlaps(bounds)) { drawVertices.splice(drawVertices.length - verticesLength, verticesLength); } @@ -295,7 +296,8 @@ class FlxBlitView extends FlxCameraView _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); } - buffer.draw(trianglesSprite, _helperMatrix); + buffer.draw(trianglesSprite, _helperMatrix, transform); + #if FLX_DEBUG if (FlxG.debugger.drawDebug) { @@ -392,7 +394,7 @@ class FlxBlitView extends FlxCameraView var oldBuffer:FlxGraphic = screen.graphic; buffer = new BitmapData(camera.width, camera.height, true, 0); screen.pixels = buffer; - screen.origin.set(); + screen.origin.zero(); _flashBitmap.bitmapData = buffer; _flashRect.width = camera.width; _flashRect.height = camera.height; diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 78d580cbf8..35df206c18 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -26,8 +26,6 @@ import openfl.display.Sprite; using flixel.util.FlxColorTransformUtil; -private typedef FlxDrawItem = flixel.graphics.tile.FlxDrawQuadsItem; - class FlxQuadView extends FlxCameraView { /** @@ -117,6 +115,7 @@ class FlxQuadView extends FlxCameraView flashSprite = null; _scrollRect = null; _helperMatrix = null; + _bounds = FlxDestroyUtil.put(_bounds); } override function lock(?useBufferLocking:Bool):Void @@ -170,35 +169,27 @@ class FlxQuadView extends FlxCameraView var isColored = (transform != null && transform.hasRGBMultipliers()); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - #if !FLX_RENDER_TRIANGLE - var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend); + final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); #end drawItem.addQuad(frame, _helperMatrix, transform); } override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { - _bounds.set(0, 0, camera.width, camera.height); - var isColored:Bool = (colors != null && colors.length != 0); + final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); - #if !flash - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - isColored = isColored || (transform != null && transform.hasRGBMultipliers()); - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds, transform); - #else - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds); - #end + final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); + final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); + + final drawItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); } override function fill(color:FlxColor, blendAlpha:Bool = true):Void { - if (color.alpha == 0) - return; - canvas.graphics.overrideBlendMode(null); canvas.graphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, @@ -310,7 +301,7 @@ class FlxQuadView extends FlxCameraView /** * Last draw tiles item */ - var _headTiles:FlxDrawItem; + var _headTiles:FlxDrawQuadsItem; /** * Last draw triangles item @@ -320,7 +311,7 @@ class FlxQuadView extends FlxCameraView /** * Draw tiles stack items that can be reused */ - static var _storageTilesHead:FlxDrawItem; + static var _storageTilesHead:FlxDrawQuadsItem; /** * Draw triangles stack items that can be reused @@ -334,14 +325,12 @@ class FlxQuadView extends FlxCameraView return startTrianglesBatch(graphic, smooth, colored, blend); #else var itemToReturn = null; - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); if (_currentDrawItem != null && _currentDrawItem.type == FlxDrawItemType.TILES && _headTiles.graphics == graphic && _headTiles.colored == colored && _headTiles.hasColorOffsets == hasColorOffsets - && _headTiles.blending == blendInt && _headTiles.blend == blend && _headTiles.antialiasing == smooth && _headTiles.shader == shader) @@ -358,7 +347,7 @@ class FlxQuadView extends FlxCameraView } else { - itemToReturn = new FlxDrawItem(); + itemToReturn = new FlxDrawQuadsItem(); } // TODO: catch this error when the dev actually messes up, not in the draw phase @@ -369,7 +358,6 @@ class FlxQuadView extends FlxCameraView itemToReturn.antialiasing = smooth; itemToReturn.colored = colored; itemToReturn.hasColorOffsets = hasColorOffsets; - itemToReturn.blending = blendInt; itemToReturn.blend = blend; itemToReturn.shader = shader; @@ -395,20 +383,14 @@ class FlxQuadView extends FlxCameraView @:noCompletion public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); - if (_currentDrawItem != null && _currentDrawItem.type == FlxDrawItemType.TRIANGLES && _headTriangles.graphics == graphic && _headTriangles.antialiasing == smoothing && _headTriangles.colored == isColored - && _headTriangles.blending == blendInt && _headTriangles.blend == blend - #if !flash && _headTriangles.hasColorOffsets == hasColorOffsets - && _headTriangles.shader == shader - #end - ) + && _headTriangles.shader == shader) { return _headTriangles; } @@ -420,7 +402,6 @@ class FlxQuadView extends FlxCameraView public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { var itemToReturn:FlxDrawTrianglesItem = null; - var blendInt:Int = FlxDrawBaseItem.blendToInt(blend); if (_storageTrianglesHead != null) { @@ -437,12 +418,9 @@ class FlxQuadView extends FlxCameraView itemToReturn.graphics = graphic; itemToReturn.antialiasing = smoothing; itemToReturn.colored = isColored; - itemToReturn.blending = blendInt; itemToReturn.blend = blend; - #if !flash itemToReturn.hasColorOffsets = hasColorOffsets; itemToReturn.shader = shader; - #end itemToReturn.nextTyped = _headTriangles; _headTriangles = itemToReturn; From 66c64bdc0909fbcac297490922d3e3b1ee907481 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 23 Dec 2025 13:18:48 +0100 Subject: [PATCH 03/72] formatting --- flixel/system/render/FlxCameraView.hx | 259 +++++---- flixel/system/render/blit/FlxBlitView.hx | 712 ++++++++++++----------- flixel/system/render/quad/FlxQuadView.hx | 363 ++++++------ 3 files changed, 671 insertions(+), 663 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 6115ecc27f..e70383fbd5 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -27,178 +27,179 @@ import openfl.display.BitmapData; @:allow(flixel.FlxCamera) class FlxCameraView implements IFlxDestroyable { - /** - * The number of total draw calls in a frame. - */ - public static var totalDrawCalls:Int = 0; - - /** - * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. - * @param camera The camera to create the view for - */ - public static inline function create(camera:FlxCamera):FlxCameraView - { - if (FlxG.renderTile) - { - return cast new flixel.system.render.quad.FlxQuadView(camera); - } - else - { - return cast new flixel.system.render.blit.FlxBlitView(camera); - } - } - - /** + /** + * The number of total draw calls in a frame. + */ + public static var totalDrawCalls:Int = 0; + + /** + * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. + * @param camera The camera to create the view for + */ + public static inline function create(camera:FlxCamera):FlxCameraView + { + if (FlxG.renderTile) + { + return cast new flixel.system.render.quad.FlxQuadView(camera); + } + else + { + return cast new flixel.system.render.blit.FlxBlitView(camera); + } + } + + /** * Display object which is used as a container for all of the camera's graphics. * This object is added to the display tree. */ - public var display(get, never):DisplayObjectContainer; - - /** - * The parent camera for this view. - */ - public var camera(default, null):FlxCamera; - - /** + public var display(get, never):DisplayObjectContainer; + + /** + * The parent camera for this view. + */ + public var camera(default, null):FlxCamera; + + /** * The margin cut off on the left and right by the camera zooming in (or out), in world space. */ public var viewMarginX(default, null):Float; - + /** * The margin cut off on the top and bottom by the camera zooming in (or out), in world space. */ public var viewMarginY(default, null):Float; - + /** * The margin cut off on the left by the camera zooming in (or out), in world space. */ public var viewMarginLeft(get, never):Float; - + /** * The margin cut off on the top by the camera zooming in (or out), in world space */ public var viewMarginTop(get, never):Float; - + /** * The margin cut off on the right by the camera zooming in (or out), in world space */ public var viewMarginRight(get, never):Float; - + /** * The margin cut off on the bottom by the camera zooming in (or out), in world space */ public var viewMarginBottom(get, never):Float; - + /** * The size of the camera's view, in world space. */ public var viewWidth(get, never):Float; - + /** * The size of the camera's view, in world space. */ public var viewHeight(get, never):Float; - + /** * The left of the camera's view, in world space. */ public var viewX(get, never):Float; - + /** * The top of the camera's view, in world space. */ public var viewY(get, never):Float; - + /** * The left of the camera's view, in world space. */ public var viewLeft(get, never):Float; - + /** * The top of the camera's view, in world space. */ public var viewTop(get, never):Float; - + /** * The right side of the camera's view, in world space. */ public var viewRight(get, never):Float; - + /** * The bottom side of the camera's view, in world space. */ public var viewBottom(get, never):Float; - - public var antialiasing(get, set):Bool; + + public var antialiasing(get, set):Bool; public var angle(get, set):Float; public var alpha(get, set):Float; public var color(get, set):FlxColor; public var visible(get, set):Bool; public var filters:Array = []; - - var _flashOffset:FlxPoint = FlxPoint.get(); - - function new(camera:FlxCamera) - { - this.camera = camera; - } - - public function destroy():Void - { - _flashOffset = FlxDestroyUtil.put(_flashOffset); - } - - public function lock(?useBufferLocking:Bool):Void {} - + + var _flashOffset:FlxPoint = FlxPoint.get(); + + function new(camera:FlxCamera) + { + this.camera = camera; + } + + public function destroy():Void + { + _flashOffset = FlxDestroyUtil.put(_flashOffset); + } + + public function lock(?useBufferLocking:Bool):Void {} + public function render():Void {} - - public function unlock(?useBufferLocking:Bool):Void {} - + + public function unlock(?useBufferLocking:Bool):Void {} + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void {} - + ?shader:FlxShader):Void {} + public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader):Void {} - + smoothing:Bool = false, ?shader:FlxShader):Void {} + public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} - + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} + public function beginDrawDebug():Void {} - + public function endDrawDebug(?matrix:FlxMatrix):Void {} - + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} - + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} - + public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} - + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} - - public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} - + + public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} + function drawFX():Void {} - - function updateScale():Void + + function updateScale():Void { calcMarginX(); calcMarginY(); } - + function updatePosition():Void {} + function updateInternals():Void {} - - function updateOffset():Void + + function updateOffset():Void { _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; } - + public function offsetView(x:Float, y:Float):Void {} - + function updateScrollRect():Void {} - - /** + + /** * Helper method preparing debug rectangle for rendering in blit render mode * @param rect rectangle to prepare for rendering * @return transformed rectangle with respect to camera's zoom factor @@ -207,7 +208,7 @@ class FlxCameraView implements IFlxDestroyable { return rect; } - + /** * Helper method preparing debug point for rendering in blit render mode (for debug path rendering, for example) * @param point point to prepare for rendering @@ -217,7 +218,7 @@ class FlxCameraView implements IFlxDestroyable { return point; } - + /** * Helper method preparing debug vectors (relative positions) for rendering in blit render mode * @param vector relative position to prepare for rendering @@ -227,7 +228,7 @@ class FlxCameraView implements IFlxDestroyable { return vector; } - + /** * Helper method for applying transformations (scaling and offsets) * to specified display objects which has been added to the camera display list. @@ -239,28 +240,28 @@ class FlxCameraView implements IFlxDestroyable { object.scaleX *= camera.totalScaleX; object.scaleY *= camera.totalScaleY; - + object.x -= camera.scroll.x * camera.totalScaleX; object.y -= camera.scroll.y * camera.totalScaleY; - + object.x -= 0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; object.y -= 0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; - + return object; } - - function checkResize():Void {} - - public inline function calcMarginX():Void + + function checkResize():Void {} + + public inline function calcMarginX():Void { viewMarginX = 0.5 * camera.width * (camera.scaleX - camera.initialZoom) / camera.scaleX; } - + public inline function calcMarginY():Void { viewMarginY = 0.5 * camera.height * (camera.scaleY - camera.initialZoom) / camera.scaleY; } - + inline function get_viewMarginLeft():Float { return viewMarginX; @@ -320,33 +321,33 @@ class FlxCameraView implements IFlxDestroyable { return camera.scroll.y + viewMarginBottom; } - - function get_display():DisplayObjectContainer - { - return null; - } - - function get_color():FlxColor - { - return camera.color; - } - - function set_color(color:FlxColor):FlxColor - { - return color; - } - - function get_antialiasing():Bool - { - return camera.antialiasing; - } - - function set_antialiasing(antialiasing:Bool):Bool - { - return antialiasing; - } - - function get_angle():Float + + function get_display():DisplayObjectContainer + { + return null; + } + + function get_color():FlxColor + { + return camera.color; + } + + function set_color(color:FlxColor):FlxColor + { + return color; + } + + function get_antialiasing():Bool + { + return camera.antialiasing; + } + + function set_antialiasing(antialiasing:Bool):Bool + { + return antialiasing; + } + + function get_angle():Float { return camera.angle; } @@ -355,8 +356,8 @@ class FlxCameraView implements IFlxDestroyable { return angle; } - - function get_visible():Bool + + function get_visible():Bool { return camera.visible; } @@ -365,8 +366,8 @@ class FlxCameraView implements IFlxDestroyable { return visible; } - - function get_alpha():Float + + function get_alpha():Float { return camera.alpha; } diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 1988abc9e5..c1d5b15e43 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -28,25 +28,25 @@ import flixel.util.FlxSpriteUtil; class FlxBlitView extends FlxCameraView { - /** + /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ static var trianglesSprite:Sprite = new Sprite(); - - /** + + /** * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. * Added for less garbage creation. */ static var renderPoint:FlxPoint = FlxPoint.get(); - + static var renderRect:FlxRect = FlxRect.get(); - - /** + + /** * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. */ static var drawVertices:Vector = new Vector(); - - /** + + /** * Used to render buffer to screen space. * NOTE: We don't recommend modifying this directly unless you are fairly experienced. * Uses include 3D projection, advanced display list modification, and more. @@ -55,8 +55,8 @@ class FlxBlitView extends FlxCameraView * Its position is modified by `updateFlashSpritePosition()` which is called every frame. */ public var flashSprite:Sprite = new Sprite(); - - /** + + /** * Sometimes it's easier to just work with a `FlxSprite`, than it is to work directly with the `BitmapData` buffer. * This sprite reference will allow you to do exactly that. * Basically, this sprite's `pixels` property is the camera's `BitmapData` buffer. @@ -64,429 +64,431 @@ class FlxBlitView extends FlxCameraView * **NOTE:** This field is only used in blit render mode. */ public var screen:FlxSprite; - - /** + + /** * The actual `BitmapData` of the camera display itself. * Used in blit render mode, where you can manipulate its pixels for achieving some visual effects. */ public var buffer:BitmapData; - - /** + + /** * Internal sprite, used for correct trimming of camera viewport. * It is a child of `flashSprite`. * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ var _scrollRect:Sprite = new Sprite(); - - /** + + /** * Internal, used in blit render mode in camera's `fill()` method for less garbage creation. * It represents the size of buffer `BitmapData` * (the area of camera's buffer which should be filled with `bgColor`). * Do not modify it unless you know what are you doing. */ var _flashRect:Rectangle; - + /** * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: * Its coordinates are always `(0,0)`, where camera's buffer filling should start. * Do not modify it unless you know what are you doing. */ var _flashPoint:Point = new Point(); - - /** + + /** * Internal, used to render buffer to screen space. Used it blit render mode only. * This Bitmap used for rendering camera's buffer (`_flashBitmap.bitmapData = buffer;`) * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. * It is a child of the `_scrollRect` `Sprite`. */ var _flashBitmap:Bitmap; - - /** + + /** * Internal helper variable for doing better wipes/fills between renders. * Used it blit render mode only (in `fill()` method). */ var _fill:BitmapData; - - /** + + /** * Helper rect for `drawTriangles()` visibility checks */ var _bounds:FlxRect = FlxRect.get(); - - /** + + /** * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. */ - var _useBlitMatrix:Bool = false; - - /** + var _useBlitMatrix:Bool = false; + + /** * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom * (it is applied to all objects rendered on the camera at such circumstances). */ var _blitMatrix:FlxMatrix = new FlxMatrix(); - - var _helperMatrix:FlxMatrix = new FlxMatrix(); + + var _helperMatrix:FlxMatrix = new FlxMatrix(); var _helperPoint:Point = new Point(); - - @:allow(flixel.system.render.FlxCameraView) - function new(camera:FlxCamera) - { - super(camera); - - flashSprite.addChild(_scrollRect); - _scrollRect.scrollRect = new Rectangle(); - - _flashRect = new Rectangle(0, 0, camera.width, camera.height); - - screen = new FlxSprite(); - buffer = new BitmapData(camera.width, camera.height, true, 0); - screen.pixels = buffer; - screen.origin.zero(); - _flashBitmap = new Bitmap(buffer); - _scrollRect.addChild(_flashBitmap); - _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); - } - - override function destroy():Void - { - super.destroy(); - - FlxDestroyUtil.removeChild(flashSprite, _scrollRect); - FlxDestroyUtil.removeChild(_scrollRect, _flashBitmap); - screen = FlxDestroyUtil.destroy(screen); - buffer = null; - _flashBitmap = null; - _fill = FlxDestroyUtil.dispose(_fill); - flashSprite = null; + + @:allow(flixel.system.render.FlxCameraView) + function new(camera:FlxCamera) + { + super(camera); + + flashSprite.addChild(_scrollRect); + _scrollRect.scrollRect = new Rectangle(); + + _flashRect = new Rectangle(0, 0, camera.width, camera.height); + + screen = new FlxSprite(); + buffer = new BitmapData(camera.width, camera.height, true, 0); + screen.pixels = buffer; + screen.origin.zero(); + _flashBitmap = new Bitmap(buffer); + _scrollRect.addChild(_flashBitmap); + _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); + } + + override function destroy():Void + { + super.destroy(); + + FlxDestroyUtil.removeChild(flashSprite, _scrollRect); + FlxDestroyUtil.removeChild(_scrollRect, _flashBitmap); + screen = FlxDestroyUtil.destroy(screen); + buffer = null; + _flashBitmap = null; + _fill = FlxDestroyUtil.dispose(_fill); + flashSprite = null; _scrollRect = null; _flashRect = null; _flashPoint = null; - _bounds = FlxDestroyUtil.put(_bounds); - } - - override function lock(?useBufferLocking:Bool) - { - checkResize(); - - if (useBufferLocking) - { - buffer.lock(); - } - - fill(camera.bgColor, camera.useBgAlphaBlending); - screen.dirty = true; - } - - override function unlock(?useBufferLocking:Bool):Void - { - camera.drawFX(); - - if (useBufferLocking) - { - buffer.unlock(); - } - - screen.dirty = true; - } - - override function beginDrawDebug():Void - { - FlxSpriteUtil.flashGfx.clear(); - } - - override function endDrawDebug(?matrix:FlxMatrix):Void - { - buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void - { - _helperMatrix.copyFrom(matrix); - - if (_useBlitMatrix) - { - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); - buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); - } - } - - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) - { - if (pixels != null) - { - if (_useBlitMatrix) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperPoint.x = destPoint.x - Std.int(viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(viewMarginTop); - buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); - } - } - else if (frame != null) - { - // TODO: fix this case for zoom less than initial zoom... - frame.paint(buffer, destPoint, true); - } - } - - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) - { - final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); - - if (position == null) - position = renderPoint.set(); - - var verticesLength:Int = vertices.length; - var currentVertexPosition:Int = 0; - - var tempX:Float, tempY:Float; - var i:Int = 0; - var bounds = renderRect.set(); - drawVertices.splice(0, drawVertices.length); - - while (i < verticesLength) - { - tempX = position.x + vertices[i]; - tempY = position.y + vertices[i + 1]; - - drawVertices[currentVertexPosition++] = tempX; - drawVertices[currentVertexPosition++] = tempY; - - if (i == 0) - { - bounds.set(tempX, tempY, 0, 0); - } - else - { - FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); - } - - i += 2; - } - - position.putWeak(); - - if (!cameraBounds.overlaps(bounds)) - { - drawVertices.splice(drawVertices.length - verticesLength, verticesLength); - } - else - { - trianglesSprite.graphics.clear(); - trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); - trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); - trianglesSprite.graphics.endFill(); - - // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... - if (_useBlitMatrix) - _helperMatrix.copyFrom(_blitMatrix); - else - { - _helperMatrix.identity(); - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); - } - - buffer.draw(trianglesSprite, _helperMatrix, transform); - - #if FLX_DEBUG - if (FlxG.debugger.drawDebug) - { - var gfx:Graphics = FlxSpriteUtil.flashGfx; - gfx.clear(); - gfx.lineStyle(1, FlxColor.BLUE, 0.5); - gfx.drawTriangles(drawVertices, indices); - buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); - } - #end - // End of TODO... - } - - bounds.put(); - } - - override function fill(color:FlxColor, blendAlpha:Bool = true) - { - if (blendAlpha) - { - _fill.fillRect(_flashRect, color); - buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); - } - else - { - buffer.fillRect(_flashRect, color); - } - } - - override function offsetView(x:Float, y:Float):Void + _bounds = FlxDestroyUtil.put(_bounds); + } + + override function lock(?useBufferLocking:Bool) + { + checkResize(); + + if (useBufferLocking) + { + buffer.lock(); + } + + fill(camera.bgColor, camera.useBgAlphaBlending); + screen.dirty = true; + } + + override function unlock(?useBufferLocking:Bool):Void + { + camera.drawFX(); + + if (useBufferLocking) + { + buffer.unlock(); + } + + screen.dirty = true; + } + + override function beginDrawDebug():Void + { + FlxSpriteUtil.flashGfx.clear(); + } + + override function endDrawDebug(?matrix:FlxMatrix):Void + { + buffer.draw(FlxSpriteUtil.flashGfxSprite); + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader):Void + { + _helperMatrix.copyFrom(matrix); + + if (_useBlitMatrix) + { + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); + } + } + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) + { + if (pixels != null) + { + if (_useBlitMatrix) + { + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x, destPoint.y); + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperPoint.x = destPoint.x - Std.int(viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(viewMarginTop); + buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); + } + } + else if (frame != null) + { + // TODO: fix this case for zoom less than initial zoom... + frame.paint(buffer, destPoint, true); + } + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); + + if (position == null) + position = renderPoint.set(); + + var verticesLength:Int = vertices.length; + var currentVertexPosition:Int = 0; + + var tempX:Float, tempY:Float; + var i:Int = 0; + var bounds = renderRect.set(); + drawVertices.splice(0, drawVertices.length); + + while (i < verticesLength) + { + tempX = position.x + vertices[i]; + tempY = position.y + vertices[i + 1]; + + drawVertices[currentVertexPosition++] = tempX; + drawVertices[currentVertexPosition++] = tempY; + + if (i == 0) + { + bounds.set(tempX, tempY, 0, 0); + } + else + { + FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); + } + + i += 2; + } + + position.putWeak(); + + if (!cameraBounds.overlaps(bounds)) + { + drawVertices.splice(drawVertices.length - verticesLength, verticesLength); + } + else + { + trianglesSprite.graphics.clear(); + trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); + trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); + trianglesSprite.graphics.endFill(); + + // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... + if (_useBlitMatrix) + _helperMatrix.copyFrom(_blitMatrix); + else + { + _helperMatrix.identity(); + _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + } + + buffer.draw(trianglesSprite, _helperMatrix, transform); + + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + { + var gfx:Graphics = FlxSpriteUtil.flashGfx; + gfx.clear(); + gfx.lineStyle(1, FlxColor.BLUE, 0.5); + gfx.drawTriangles(drawVertices, indices); + buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); + } + #end + // End of TODO... + } + + bounds.put(); + } + + override function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) + { + _fill.fillRect(_flashRect, color); + buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); + } + else + { + buffer.fillRect(_flashRect, color); + } + } + + override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; flashSprite.y += y; } - - override function updatePosition():Void - { - if (flashSprite != null) + + override function updatePosition():Void + { + if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; flashSprite.y = camera.y * FlxG.scaleMode.scale.y + _flashOffset.y; } - } - - override function updateScrollRect():Void - { - var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; - + } + + override function updateScrollRect():Void + { + var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + if (rect != null) { rect.x = rect.y = 0; - + rect.width = camera.width * camera.initialZoom * FlxG.scaleMode.scale.x; rect.height = camera.height * camera.initialZoom * FlxG.scaleMode.scale.y; - + _scrollRect.scrollRect = rect; - + _scrollRect.x = -0.5 * rect.width; _scrollRect.y = -0.5 * rect.height; } - } - - override function updateScale():Void - { - updateBlitMatrix(); - - if (_useBlitMatrix) - { - _flashBitmap.scaleX = camera.initialZoom * FlxG.scaleMode.scale.x; - _flashBitmap.scaleY = camera.initialZoom * FlxG.scaleMode.scale.y; - } - else - { - _flashBitmap.scaleX = camera.totalScaleX; - _flashBitmap.scaleY = camera.totalScaleY; - } - - super.updateScale(); - } - - override function updateInternals():Void - { - if (_flashBitmap != null) - { - _flashBitmap.x = 0; - _flashBitmap.y = 0; - } - } - - override function checkResize() - { - if (camera.width != buffer.width || camera.height != buffer.height) - { - var oldBuffer:FlxGraphic = screen.graphic; - buffer = new BitmapData(camera.width, camera.height, true, 0); - screen.pixels = buffer; - screen.origin.zero(); - _flashBitmap.bitmapData = buffer; - _flashRect.width = camera.width; - _flashRect.height = camera.height; - _fill = FlxDestroyUtil.dispose(_fill); - _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); - FlxG.bitmap.removeIfNoUse(oldBuffer); - } - - updateBlitMatrix(); - } - - inline function updateBlitMatrix():Void + } + + override function updateScale():Void + { + updateBlitMatrix(); + + if (_useBlitMatrix) + { + _flashBitmap.scaleX = camera.initialZoom * FlxG.scaleMode.scale.x; + _flashBitmap.scaleY = camera.initialZoom * FlxG.scaleMode.scale.y; + } + else + { + _flashBitmap.scaleX = camera.totalScaleX; + _flashBitmap.scaleY = camera.totalScaleY; + } + + super.updateScale(); + } + + override function updateInternals():Void + { + if (_flashBitmap != null) + { + _flashBitmap.x = 0; + _flashBitmap.y = 0; + } + } + + override function checkResize() + { + if (camera.width != buffer.width || camera.height != buffer.height) + { + var oldBuffer:FlxGraphic = screen.graphic; + buffer = new BitmapData(camera.width, camera.height, true, 0); + screen.pixels = buffer; + screen.origin.zero(); + _flashBitmap.bitmapData = buffer; + _flashRect.width = camera.width; + _flashRect.height = camera.height; + _fill = FlxDestroyUtil.dispose(_fill); + _fill = new BitmapData(camera.width, camera.height, true, FlxColor.TRANSPARENT); + FlxG.bitmap.removeIfNoUse(oldBuffer); + } + + updateBlitMatrix(); + } + + inline function updateBlitMatrix():Void { _blitMatrix.identity(); _blitMatrix.translate(-viewMarginLeft, -viewMarginTop); _blitMatrix.scale(camera.scaleX, camera.scaleY); - + _useBlitMatrix = (camera.scaleX < camera.initialZoom) || (camera.scaleY < camera.initialZoom); } - - override function transformRect(rect:FlxRect):FlxRect + + override function transformRect(rect:FlxRect):FlxRect { - rect.offset(-viewMarginLeft, -viewMarginTop); - - if (_useBlitMatrix) - { - rect.x *= camera.zoom; - rect.y *= camera.zoom; - rect.width *= camera.zoom; - rect.height *= camera.zoom; - } - + rect.offset(-viewMarginLeft, -viewMarginTop); + + if (_useBlitMatrix) + { + rect.x *= camera.zoom; + rect.y *= camera.zoom; + rect.width *= camera.zoom; + rect.height *= camera.zoom; + } + return rect; } - - override function transformPoint(point:FlxPoint):FlxPoint + + override function transformPoint(point:FlxPoint):FlxPoint { - point.subtract(viewMarginLeft, viewMarginTop); - - if (_useBlitMatrix) - point.scale(camera.zoom); - + point.subtract(viewMarginLeft, viewMarginTop); + + if (_useBlitMatrix) + point.scale(camera.zoom); + return point; } - - override function transformVector(vector:FlxPoint):FlxPoint + + override function transformVector(vector:FlxPoint):FlxPoint { if (_useBlitMatrix) vector.scale(camera.zoom); - + return vector; } - - override function get_display():DisplayObjectContainer - { - return flashSprite; - } - - override function set_color(color:FlxColor):FlxColor - { - if (_flashBitmap != null) - { - final colorTransform:ColorTransform = _flashBitmap.transform.colorTransform; - - colorTransform.redMultiplier = color.redFloat; - colorTransform.greenMultiplier = color.greenFloat; - colorTransform.blueMultiplier = color.blueFloat; - - _flashBitmap.transform.colorTransform = colorTransform; - } - - return color; - } - - override function set_antialiasing(antialiasing:Bool):Bool - { + + override function get_display():DisplayObjectContainer + { + return flashSprite; + } + + override function set_color(color:FlxColor):FlxColor + { + if (_flashBitmap != null) + { + final colorTransform:ColorTransform = _flashBitmap.transform.colorTransform; + + colorTransform.redMultiplier = color.redFloat; + colorTransform.greenMultiplier = color.greenFloat; + colorTransform.blueMultiplier = color.blueFloat; + + _flashBitmap.transform.colorTransform = colorTransform; + } + + return color; + } + + override function set_antialiasing(antialiasing:Bool):Bool + { return _flashBitmap.smoothing = antialiasing; - } - - override function set_alpha(alpha:Float):Float - { - return _flashBitmap.alpha = alpha; - } - - override function set_angle(angle:Float):Float - { - return flashSprite.rotation = angle; - } - - override function set_visible(visible:Bool):Bool - { + } + + override function set_alpha(alpha:Float):Float + { + return _flashBitmap.alpha = alpha; + } + + override function set_angle(angle:Float):Float + { + return flashSprite.rotation = angle; + } + + override function set_visible(visible:Bool):Bool + { flashSprite.visible = visible; - return visible; - } + return visible; + } } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 35df206c18..093e2fedf2 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -28,14 +28,14 @@ using flixel.util.FlxColorTransformUtil; class FlxQuadView extends FlxCameraView { - /** + /** * Sprite used for actual rendering in tile render mode (instead of `_flashBitmap` for blitting). * Its graphics is used as a drawing surface for `drawTriangles()` and `drawTiles()` methods. * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. */ public var canvas:Sprite; - + #if FLX_DEBUG /** * Sprite for visual effects (flash and fade) and drawDebug information @@ -45,8 +45,8 @@ class FlxQuadView extends FlxCameraView */ public var debugLayer:Sprite; #end - - /** + + /** * Used to render buffer to screen space. * NOTE: We don't recommend modifying this directly unless you are fairly experienced. * Uses include 3D projection, advanced display list modification, and more. @@ -55,104 +55,105 @@ class FlxQuadView extends FlxCameraView * Its position is modified by `updateFlashSpritePosition()` which is called every frame. */ public var flashSprite:Sprite = new Sprite(); - - /** + + /** * Internal sprite, used for correct trimming of camera viewport. * It is a child of `flashSprite`. * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ var _scrollRect:Sprite = new Sprite(); - + /** * Helper rect for `drawTriangles()` visibility checks */ var _bounds:FlxRect = FlxRect.get(); - + var _helperMatrix:FlxMatrix = new FlxMatrix(); - - @:allow(flixel.system.render.FlxCameraView) - function new(camera:FlxCamera) - { - super(camera); - + + @:allow(flixel.system.render.FlxCameraView) + function new(camera:FlxCamera) + { + super(camera); + flashSprite.addChild(_scrollRect); - _scrollRect.scrollRect = new Rectangle(); - - canvas = new Sprite(); - _scrollRect.addChild(canvas); - - #if FLX_DEBUG - debugLayer = new Sprite(); - _scrollRect.addChild(debugLayer); - #end - } - - override function destroy():Void - { - super.destroy(); - - FlxDestroyUtil.removeChild(flashSprite, _scrollRect); - #if FLX_DEBUG - FlxDestroyUtil.removeChild(_scrollRect, debugLayer); - debugLayer = null; - #end - - FlxDestroyUtil.removeChild(_scrollRect, canvas); - if (canvas != null) - { - for (i in 0...canvas.numChildren) - { - canvas.removeChildAt(0); - } - canvas = null; - } - - if (_headOfDrawStack != null) - { - clearDrawStack(); - } - - flashSprite = null; + _scrollRect.scrollRect = new Rectangle(); + + canvas = new Sprite(); + _scrollRect.addChild(canvas); + + #if FLX_DEBUG + debugLayer = new Sprite(); + _scrollRect.addChild(debugLayer); + #end + } + + override function destroy():Void + { + super.destroy(); + + FlxDestroyUtil.removeChild(flashSprite, _scrollRect); + #if FLX_DEBUG + FlxDestroyUtil.removeChild(_scrollRect, debugLayer); + debugLayer = null; + #end + + FlxDestroyUtil.removeChild(_scrollRect, canvas); + if (canvas != null) + { + for (i in 0...canvas.numChildren) + { + canvas.removeChildAt(0); + } + canvas = null; + } + + if (_headOfDrawStack != null) + { + clearDrawStack(); + } + + flashSprite = null; _scrollRect = null; _helperMatrix = null; _bounds = FlxDestroyUtil.put(_bounds); - } - - override function lock(?useBufferLocking:Bool):Void - { - clearDrawStack(); - - canvas.graphics.clear(); - // Clearing camera's debug sprite - #if FLX_DEBUG - debugLayer.graphics.clear(); - #end - - fill(camera.bgColor, camera.useBgAlphaBlending); - } - - override function render():Void - { + } + + override function lock(?useBufferLocking:Bool):Void + { + clearDrawStack(); + + canvas.graphics.clear(); + // Clearing camera's debug sprite + #if FLX_DEBUG + debugLayer.graphics.clear(); + #end + + fill(camera.bgColor, camera.useBgAlphaBlending); + } + + override function render():Void + { flashSprite.filters = camera.filtersEnabled ? filters : null; - - var currItem:FlxDrawBaseItem = _headOfDrawStack; + + var currItem:FlxDrawBaseItem = _headOfDrawStack; while (currItem != null) { currItem.render(camera); currItem = currItem.next; } - } - - override function unlock(?useBufferLocking:Bool):Void - { - camera.drawFX(); - } - - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + } + + override function unlock(?useBufferLocking:Bool):Void + { + camera.drawFX(); + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader) { var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - + #if FLX_RENDER_TRIANGLE final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else @@ -160,15 +161,16 @@ class FlxQuadView extends FlxCameraView #end drawItem.addQuad(frame, matrix, transform); } - - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) { _helperMatrix.identity(); _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); - + var isColored = (transform != null && transform.hasRGBMultipliers()); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - + #if FLX_RENDER_TRIANGLE final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else @@ -176,18 +178,19 @@ class FlxQuadView extends FlxCameraView #end drawItem.addQuad(frame, _helperMatrix, transform); } - - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); - + final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); - + final drawItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); } - + override function fill(color:FlxColor, blendAlpha:Bool = true):Void { canvas.graphics.overrideBlendMode(null); @@ -197,135 +200,135 @@ class FlxQuadView extends FlxCameraView canvas.graphics.drawRect(viewMarginLeft - 1, viewMarginTop - 1, viewWidth + 2, viewHeight + 2); canvas.graphics.endFill(); } - + override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; flashSprite.y += y; } - - override function updatePosition():Void - { - if (flashSprite != null) + + override function updatePosition():Void + { + if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; flashSprite.y = camera.y * FlxG.scaleMode.scale.y + _flashOffset.y; } - } - + } + override function updateScrollRect():Void - { - var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; - + { + var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + if (rect != null) { rect.x = rect.y = 0; - + rect.width = camera.width * camera.initialZoom * FlxG.scaleMode.scale.x; rect.height = camera.height * camera.initialZoom * FlxG.scaleMode.scale.y; - + _scrollRect.scrollRect = rect; - + _scrollRect.x = -0.5 * rect.width; _scrollRect.y = -0.5 * rect.height; } - } - - override function updateInternals():Void - { - if (canvas != null) - { - canvas.x = -0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; - canvas.y = -0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; - - canvas.scaleX = camera.totalScaleX; - canvas.scaleY = camera.totalScaleY; - - #if FLX_DEBUG - if (debugLayer != null) - { - debugLayer.x = canvas.x; - debugLayer.y = canvas.y; - - debugLayer.scaleX = camera.totalScaleX; - debugLayer.scaleY = camera.totalScaleY; - } - #end - } - } - - override function set_color(color:FlxColor):FlxColor + } + + override function updateInternals():Void + { + if (canvas != null) + { + canvas.x = -0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; + canvas.y = -0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; + + canvas.scaleX = camera.totalScaleX; + canvas.scaleY = camera.totalScaleY; + + #if FLX_DEBUG + if (debugLayer != null) + { + debugLayer.x = canvas.x; + debugLayer.y = canvas.y; + + debugLayer.scaleX = camera.totalScaleX; + debugLayer.scaleY = camera.totalScaleY; + } + #end + } + } + + override function set_color(color:FlxColor):FlxColor { final colorTransform:ColorTransform = canvas.transform.colorTransform; - + colorTransform.redMultiplier = color.redFloat; colorTransform.greenMultiplier = color.greenFloat; colorTransform.blueMultiplier = color.blueFloat; canvas.transform.colorTransform = colorTransform; - + return color; } - + override function set_alpha(alpha:Float):Float { return canvas.alpha = alpha; } - - override function set_angle(angle:Float):Float - { - return flashSprite.rotation = angle; - } - - override function set_visible(visible:Bool):Bool - { + + override function set_angle(angle:Float):Float + { + return flashSprite.rotation = angle; + } + + override function set_visible(visible:Bool):Bool + { flashSprite.visible = visible; - return visible; - } - - override function get_display():DisplayObjectContainer - { - return flashSprite; - } - - /** + return visible; + } + + override function get_display():DisplayObjectContainer + { + return flashSprite; + } + + /** * Currently used draw stack item */ var _currentDrawItem:FlxDrawBaseItem; - + /** * Pointer to head of stack with draw items */ var _headOfDrawStack:FlxDrawBaseItem; - + /** * Last draw tiles item */ var _headTiles:FlxDrawQuadsItem; - + /** * Last draw triangles item */ var _headTriangles:FlxDrawTrianglesItem; - + /** * Draw tiles stack items that can be reused */ static var _storageTilesHead:FlxDrawQuadsItem; - + /** * Draw triangles stack items that can be reused */ static var _storageTrianglesHead:FlxDrawTrianglesItem; - - @:noCompletion + + @:noCompletion public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) { #if FLX_RENDER_TRIANGLE return startTrianglesBatch(graphic, smooth, colored, blend); #else var itemToReturn = null; - + if (_currentDrawItem != null && _currentDrawItem.type == FlxDrawItemType.TILES && _headTiles.graphics == graphic @@ -337,7 +340,7 @@ class FlxQuadView extends FlxCameraView { return _headTiles; } - + if (_storageTilesHead != null) { itemToReturn = _storageTilesHead; @@ -353,35 +356,36 @@ class FlxQuadView extends FlxCameraView // TODO: catch this error when the dev actually messes up, not in the draw phase if (graphic.isDestroyed) throw 'Cannot queue ${graphic.key}. This sprite was destroyed.'; - + itemToReturn.graphics = graphic; itemToReturn.antialiasing = smooth; itemToReturn.colored = colored; itemToReturn.hasColorOffsets = hasColorOffsets; itemToReturn.blend = blend; itemToReturn.shader = shader; - + itemToReturn.nextTyped = _headTiles; _headTiles = itemToReturn; - + if (_headOfDrawStack == null) { _headOfDrawStack = itemToReturn; } - + if (_currentDrawItem != null) { _currentDrawItem.next = itemToReturn; } - + _currentDrawItem = itemToReturn; - + return itemToReturn; #end } - + @:noCompletion - public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + ?shader:FlxShader):FlxDrawTrianglesItem { if (_currentDrawItem != null && _currentDrawItem.type == FlxDrawItemType.TRIANGLES @@ -394,15 +398,16 @@ class FlxQuadView extends FlxCameraView { return _headTriangles; } - + return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } - + @:noCompletion - public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + ?shader:FlxShader):FlxDrawTrianglesItem { var itemToReturn:FlxDrawTrianglesItem = null; - + if (_storageTrianglesHead != null) { itemToReturn = _storageTrianglesHead; @@ -414,38 +419,38 @@ class FlxQuadView extends FlxCameraView { itemToReturn = new FlxDrawTrianglesItem(); } - + itemToReturn.graphics = graphic; itemToReturn.antialiasing = smoothing; itemToReturn.colored = isColored; itemToReturn.blend = blend; itemToReturn.hasColorOffsets = hasColorOffsets; itemToReturn.shader = shader; - + itemToReturn.nextTyped = _headTriangles; _headTriangles = itemToReturn; - + if (_headOfDrawStack == null) { _headOfDrawStack = itemToReturn; } - + if (_currentDrawItem != null) { _currentDrawItem.next = itemToReturn; } - + _currentDrawItem = itemToReturn; - + return itemToReturn; } - + @:noCompletion public function clearDrawStack():Void { var currTiles = _headTiles; var newTilesHead; - + while (currTiles != null) { newTilesHead = currTiles.nextTyped; @@ -454,10 +459,10 @@ class FlxQuadView extends FlxCameraView _storageTilesHead = currTiles; currTiles = newTilesHead; } - + var currTriangles:FlxDrawTrianglesItem = _headTriangles; var newTrianglesHead:FlxDrawTrianglesItem; - + while (currTriangles != null) { newTrianglesHead = currTriangles.nextTyped; @@ -466,7 +471,7 @@ class FlxQuadView extends FlxCameraView _storageTrianglesHead = currTriangles; currTriangles = newTrianglesHead; } - + _currentDrawItem = null; _headOfDrawStack = null; _headTiles = null; From a0861e9f261b72e722858e0c53f5347d2e480c96 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:08:42 +0100 Subject: [PATCH 04/72] Add debug drawing methods to `FlxCamera` and `FlxCameraView` --- flixel/FlxCamera.hx | 28 +++++++----- flixel/FlxObject.hx | 25 ++++++++--- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 2 +- flixel/path/FlxBasePath.hx | 44 ++++++++---------- .../system/debug/interaction/Interaction.hx | 26 +++++------ .../system/debug/interaction/tools/Pointer.hx | 16 +++---- .../debug/interaction/tools/Transform.hx | 45 +++++++++---------- flixel/system/render/blit/FlxBlitView.hx | 32 +++++++++++++ flixel/system/render/quad/FlxQuadView.hx | 32 +++++++++++++ .../system/scaleModes/StageSizeScaleMode.hx | 4 +- flixel/tile/FlxTilemap.hx | 2 +- 11 files changed, 166 insertions(+), 90 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 99b030bf96..05c5cff0de 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1,10 +1,5 @@ package flixel; -<<<<<<< HEAD -import flixel.system.render.FlxCameraView; -import flixel.system.render.quad.FlxQuadView; -import flixel.system.render.blit.FlxBlitView; - import openfl.display.Bitmap; import openfl.display.BitmapData; import openfl.display.DisplayObject; @@ -13,8 +8,6 @@ import openfl.display.Sprite; import openfl.geom.ColorTransform; import openfl.geom.Point; import openfl.geom.Rectangle; -======= ->>>>>>> upstream/dev import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; import flixel.graphics.tile.FlxDrawBaseItem; @@ -25,6 +18,9 @@ import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; +import flixel.system.render.FlxCameraView; +import flixel.system.render.quad.FlxQuadView; +import flixel.system.render.blit.FlxBlitView; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -36,6 +32,7 @@ import openfl.display.BlendMode; import openfl.display.DisplayObject; import openfl.display.Graphics; import openfl.display.Sprite; +import openfl.display.DisplayObjectContainer; import openfl.filters.BitmapFilter; import openfl.geom.ColorTransform; import openfl.geom.Point; @@ -355,6 +352,11 @@ class FlxCamera extends FlxBasic */ public var viewBottom(get, never):Float; + /** + * Reference to camera's `view.display`. + */ + public var display(get, never):DisplayObjectContainer; + /** * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom * (it is applied to all objects rendered on the camera at such circumstances). @@ -545,7 +547,7 @@ class FlxCamera extends FlxBasic * Helper rect for `drawTriangles()` visibility checks */ @:deprecated("depblit") - var _bounds:FlxRect = FlxRect.get(); + var _bounds:FlxRect; /** * Sprite used for actual rendering in tile render mode (instead of `_flashBitmap` for blitting). @@ -589,7 +591,7 @@ class FlxCamera extends FlxBasic * Last draw tiles item */ @:deprecated("depquad") - var _headTiles:FlxDrawItem; + var _headTiles:FlxDrawQuadsItem; /** * Last draw triangles item @@ -601,7 +603,7 @@ class FlxCamera extends FlxBasic * Draw tiles stack items that can be reused */ @:deprecated("depquad") - static var _storageTilesHead:FlxDrawItem; + static var _storageTilesHead:FlxDrawQuadsItem; /** * Draw triangles stack items that can be reused @@ -820,7 +822,6 @@ class FlxCamera extends FlxBasic { view.destroy(); - _bounds = FlxDestroyUtil.put(_bounds); scroll = FlxDestroyUtil.put(scroll); targetOffset = FlxDestroyUtil.put(targetOffset); deadzone = FlxDestroyUtil.put(deadzone); @@ -2017,6 +2018,11 @@ class FlxCamera extends FlxBasic return scroll.y + viewMarginBottom; } + inline function get_display():DisplayObjectContainer + { + return view.display; + } + inline function set_flashSprite(value:Sprite):Sprite { var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 080d4edca1..4647ac5cf8 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1318,18 +1318,27 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - final gfx = beginDrawDebug(camera); - drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); - endDrawDebug(camera); + camera.beginDrawDebug(); + drawDebugBoundingBox(camera, rect, allowCollisions); + camera.endDrawDebug(); } } - function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) + @:deprecated("drawDebugBoundingBox(gfx, rect, allowCollisions, partial) is deprecated. Use drawDebugBoundingBox(camera, rect, allowCollisions) instead.") + overload extern inline function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) { // Find the color to use final color = getDebugBoundingBoxColor(allowCollisions); drawDebugBoundingBoxColor(gfx, rect, color); } + + overload extern inline function drawDebugBoundingBox(camera:FlxCamera, rect:FlxRect, allowCollisions:FlxDirectionFlags) + { + // Find the color to use + var color = getDebugBoundingBoxColor(allowCollisions); + color.alphaFloat = 0.75; + drawDebugBoundingBoxColor(camera, rect, color); + } function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) { @@ -1346,13 +1355,19 @@ class FlxObject extends FlxBasic } - function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) + @:deprecated("drawDebugBoundingBoxColor(gfx, rect, color) is deprecated, use drawDebugBoundingBoxColor(camera, rect, color) instead") + overload extern inline function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { // fill static graphics object with square shape gfx.lineStyle(1, color, 0.75, false, null, null, MITER, 255); gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } + overload extern inline function drawDebugBoundingBoxColor(camera:FlxCamera, rect:FlxRect, color:FlxColor) + { + camera.drawDebugRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color); + } + @:deprecated("use object.beginDrawDebug(camera) is deprecated, camera.beginDrawDebug() instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index 66e6c192ab..e3ac8acb43 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -88,7 +88,7 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem #if FLX_DEBUG if (FlxG.debugger.drawDebug) { - var gfx:Graphics = camera.debugLayer.graphics; + var gfx:Graphics = camera.viewQuad.debugLayer.graphics; gfx.lineStyle(1, FlxColor.BLUE, 0.5); gfx.drawTriangles(vertices, indices, uvtData); } diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 3fa14e379a..b993c338f3 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -318,18 +318,8 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy */ public function drawDebugOnCamera(camera:FlxCamera):Void { - // Set up our global flash graphics object to draw out the path - var gfx:Graphics = null; - if (FlxG.renderBlit) - { - gfx = FlxSpriteUtil.flashGfx; - gfx.clear(); - } - else - { - gfx = camera.debugLayer.graphics; - } - + camera.beginDrawDebug(); + final length = nodes.length; // Then fill up the object with node and path graphics for (i=>node in nodes) @@ -355,24 +345,20 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy } // draw a box for the node - drawNode(gfx, prevNodeScreen, nodeSize, nodeColor); + drawNode(camera, prevNodeScreen, nodeSize, nodeColor); if (i + 1 < length || loopType == LOOP) { // draw a line to the next node, if LOOP, get connect the tail and head final nextNode = nodes[(i + 1) % length]; final nextNodeScreen = copyWorldToScreenPos(nextNode, camera); - drawLine(gfx, prevNodeScreen, nextNodeScreen); + drawLine(camera, prevNodeScreen, nextNodeScreen); nextNodeScreen.put(); } prevNodeScreen.put(); } - if (FlxG.renderBlit) - { - // then stamp the path down onto the game buffer - camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } + camera.endDrawDebug(); } @:access(flixel.FlxCamera) @@ -396,16 +382,14 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - inline function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) + inline function drawNode(camera:FlxCamera, node:FlxPoint, size:Int, color:FlxColor) { - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.lineStyle(); final offset = Math.floor(size * 0.5); - gfx.drawRect(node.x - offset, node.y - offset, size, size); - gfx.endFill(); + camera.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); } - function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) + @:deprecated("drawLine(gfx, node1, node2) is deprecated. Use drawLine(camera, node1, node2) instead.") + overload extern inline function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) { // then draw a line to the next node final color = debugDrawData.lineColor; @@ -416,6 +400,16 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy gfx.moveTo(node1.x + lineOffset, node1.y + lineOffset); gfx.lineTo(node2.x + lineOffset, node2.y + lineOffset); } + + overload extern inline function drawLine(camera:FlxCamera, node1:FlxPoint, node2:FlxPoint) + { + // then draw a line to the next node + final color = debugDrawData.lineColor; + final size = debugDrawData.lineSize; + final lineOffset = debugDrawData.lineSize / 2; + + camera.drawDebugLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, color, size); + } #end } diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index 799201e498..9c68f03c05 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -16,6 +16,7 @@ import flixel.system.debug.interaction.tools.TrackObject; import flixel.system.debug.interaction.tools.Transform; import flixel.util.FlxDestroyUtil; import flixel.util.FlxSpriteUtil; +import flixel.util.FlxColor; import openfl.display.BitmapData; import openfl.display.DisplayObject; import openfl.display.Graphics; @@ -377,6 +378,7 @@ class Interaction extends Window drawItemsSelection(); } + @:deprecated("getDebugGraphics() is deprecated. Use the debug draw functions from FlxCamera instead.") public function getDebugGraphics():Graphics { if (FlxG.renderBlit) @@ -394,25 +396,23 @@ class Interaction extends Window function drawItemsSelection():Void { - var gfx:Graphics = getDebugGraphics(); - if (gfx == null) - return; + final camera = FlxG.camera; + camera.beginDrawDebug(); for (member in selectedItems) { if (member != null && member.scrollFactor != null && member.isOnScreen()) { final margin = 0.5; - final scroll = FlxG.camera.scroll; + final scroll = camera.scroll; // Render a white rectangle centered at the selected item - gfx.lineStyle(1.0, 0xFFFFFF, 0.75); - gfx.drawRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2); + + final color:FlxColor = FlxColor.fromRGBFloat(1, 1, 1, 0.75); + camera.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); } } - // Draw the debug info to the main camera buffer. - if (FlxG.renderBlit) - FlxG.camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); + camera.endDrawDebug(); } /** @@ -791,18 +791,18 @@ class Interaction extends Window public function toDebugX(worldX:Float, camera:FlxCamera) { if (FlxG.renderTile) - return camera.canvas.localToGlobal(new Point(worldX, 0)).x; + return camera.viewQuad.canvas.localToGlobal(new Point(worldX, 0)).x; else @:privateAccess - return camera._flashBitmap.localToGlobal(new Point(worldX, 0)).x; + return camera.viewBlit._flashBitmap.localToGlobal(new Point(worldX, 0)).x; } public function toDebugY(worldY:Float, camera:FlxCamera) { if (FlxG.renderTile) - return camera.canvas.localToGlobal(new Point(0, worldY)).y; + return camera.viewQuad.canvas.localToGlobal(new Point(0, worldY)).y; else @:privateAccess - return camera._flashBitmap.localToGlobal(new Point(0, worldY)).y; + return camera.viewBlit._flashBitmap.localToGlobal(new Point(0, worldY)).y; } } diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index ecc4d354a4..e11a070126 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -9,6 +9,7 @@ import flixel.math.FlxRect; import flixel.system.debug.Icon; import flixel.system.debug.interaction.Interaction; import flixel.util.FlxSpriteUtil; +import flixel.util.FlxColor; using flixel.util.FlxArrayUtil; @@ -133,9 +134,7 @@ class Pointer extends Tool override public function draw():Void { - var gfx:Graphics = _brain.getDebugGraphics(); - if (gfx == null) - return; + FlxG.camera.beginDrawDebug(); switch state { @@ -144,14 +143,13 @@ class Pointer extends Tool final rect = FlxRect.get(); setAbsRect(rect, startX, startY, _brain.flixelPointer.x, _brain.flixelPointer.y); // Render the selection rectangle - gfx.lineStyle(0.9, 0xbb0000); - gfx.drawRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height); + var color:FlxColor = 0xbb0000; + color.alphaFloat = 0.9; + FlxG.camera.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); rect.put(); } - // Render everything into the camera buffer - if (FlxG.renderBlit) - FlxG.camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); + FlxG.camera.endDrawDebug(); } static function setAbsRect(rect:FlxRect, x1:Float, y1:Float, x2:Float, y2:Float) @@ -174,4 +172,4 @@ private enum Selection { TOP(obj:Null); ALL(objs:Array); -} \ No newline at end of file +} diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index 428fa4b505..c26d428700 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -232,34 +232,35 @@ class Transform extends Tool case TRANSFORM(target, _, _, _): target; } + + FlxG.camera.beginDrawDebug(); - final gfx = _brain.getDebugGraphics(); - if (gfx == null) - return; - - drawSelection(gfx, target.getDefaultCamera()); - Marker.draw(target.x + target.origin.x, target.y + target.origin.y, false, gfx); + final camera = target.getDefaultCamera(); + drawSelection(camera); + Marker.draw(target.x + target.origin.x, target.y + target.origin.y, false, camera); - // Draw the debug info to the main camera buffer. - if (FlxG.renderBlit) - FlxG.camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); + FlxG.camera.endDrawDebug(); } - - function drawSelection(gfx:Graphics, camera:FlxCamera) + + function drawSelection(camera:FlxCamera) { - gfx.lineStyle(1.0, FlxColor.MAGENTA, 1.0, false, LineScaleMode.NORMAL, CapsStyle.SQUARE); - // draw lines - gfx.moveTo(markers[3].x, markers[3].y); + var prevX = markers[3].x; + var prevY = markers[3].y; for (marker in markers) - gfx.lineTo(marker.x, marker.y); + { + camera.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); + + prevX = marker.x; + prevY = marker.y; + } // draw markers for (marker in markers) { final x = marker.x; final y = marker.y; - Marker.draw(x, y, marker.type == ROTATE, gfx); + Marker.draw(x, y, marker.type == ROTATE, camera); } } } @@ -297,15 +298,13 @@ private class Marker y = target.y + target.origin.y + rot.y; rot.put(); } - - public static function draw(screenX:Float, screenY:Float, circle:Bool, gfx:Graphics) + + public static function draw(screenX:Float, screenY:Float, circle:Bool, camera:FlxCamera) { - gfx.beginFill(FlxColor.MAGENTA); if (circle) - gfx.drawCircle(screenX, screenY, CIRCLE_RADIUS); + camera.drawDebugCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); else - gfx.drawRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE); - gfx.endFill(); + camera.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); } } @@ -353,4 +352,4 @@ private enum TransformAction SET_SCALE_X(start:Float); SET_SCALE_Y(start:Float); SET_SCALE_XY(startX:Float, startY:Float); -} \ No newline at end of file +} diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index c1d5b15e43..fd7c069e7b 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -196,6 +196,38 @@ class FlxBlitView extends FlxCameraView { buffer.draw(FlxSpriteUtil.flashGfxSprite); } + + override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + override public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, x2); + gfx.lineTo(x2, y2); + } override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 093e2fedf2..d615efce10 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -148,6 +148,38 @@ class FlxQuadView extends FlxCameraView camera.drawFX(); } + override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + override public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, x2); + gfx.lineTo(x2, y2); + } + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { diff --git a/flixel/system/scaleModes/StageSizeScaleMode.hx b/flixel/system/scaleModes/StageSizeScaleMode.hx index e6cecff086..15c041ff63 100644 --- a/flixel/system/scaleModes/StageSizeScaleMode.hx +++ b/flixel/system/scaleModes/StageSizeScaleMode.hx @@ -32,8 +32,8 @@ class StageSizeScaleMode extends BaseScaleMode var newH = Math.ceil(Height / FlxG.camera.zoom); FlxG.camera.setSize(newW, newH); - FlxG.camera.flashSprite.x += (newW - oldW) / 2; - FlxG.camera.flashSprite.y += (newH - oldH) / 2; + FlxG.camera.display.x += (newW - oldW) / 2; + FlxG.camera.display.y += (newH - oldH) / 2; } } } diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 85d3478b32..bca2cc2548 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -595,7 +595,7 @@ class FlxTypedTilemap extends FlxBaseTilemap if (color != null) { final colStr = color.toHexString(); - drawDebugBoundingBoxColor(camera.debugLayer.graphics, rect, color); + drawDebugBoundingBoxColor(camera, rect, color); } } } From 2d4eacb790c3da3595b2eb7187819ae67aaa8bf1 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:47:53 +0100 Subject: [PATCH 05/72] FlxQuadView: wrap debug draw methods in FLX_DEBUG --- flixel/system/render/quad/FlxQuadView.hx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index d615efce10..aaab60857c 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -148,14 +148,15 @@ class FlxQuadView extends FlxCameraView camera.drawFX(); } - override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + #if FLX_DEBUG + override function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void { final gfx = debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); gfx.drawRect(x, y, width, height); } - override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + override function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void { final gfx = debugLayer.graphics; gfx.lineStyle(); @@ -164,7 +165,7 @@ class FlxQuadView extends FlxCameraView gfx.endFill(); } - override public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + override function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { final gfx = debugLayer.graphics; gfx.beginFill(color.rgb, color.alphaFloat); @@ -172,13 +173,14 @@ class FlxQuadView extends FlxCameraView gfx.endFill(); } - override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + override function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void { final gfx = debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); gfx.moveTo(x1, x2); gfx.lineTo(x2, y2); } + #end override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) From 07215116adae7eb5bcabb1322a928459099638f6 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 12:41:15 +0100 Subject: [PATCH 06/72] use FlxCameraView to count draw calls --- flixel/FlxGame.hx | 7 +++---- flixel/graphics/tile/FlxDrawBaseItem.hx | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 6f9eb08b3b..8337763b5b 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -1,6 +1,6 @@ package flixel; -import flixel.graphics.tile.FlxDrawBaseItem; +import flixel.system.render.FlxCameraView; import flixel.system.FlxSplash; import flixel.util.FlxArrayUtil; import flixel.util.FlxDestroyUtil; @@ -803,8 +803,7 @@ class FlxGame extends Sprite FlxG.signals.preDraw.dispatch(); - if (FlxG.renderTile) - FlxDrawBaseItem.drawCalls = 0; + FlxCameraView.totalDrawCalls = 0; FlxG.cameras.lock(); @@ -824,7 +823,7 @@ class FlxGame extends Sprite FlxG.cameras.render(); #if FLX_DEBUG - debugger.stats.drawCalls(FlxDrawBaseItem.drawCalls); + debugger.stats.drawCalls(FlxCameraView.totalDrawCalls); #end } diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index fc91f4d8a1..d89be00aef 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -2,6 +2,7 @@ package flixel.graphics.tile; import flixel.FlxCamera; import flixel.graphics.frames.FlxFrame; +import flixel.system.render.FlxCameraView; import flixel.math.FlxMatrix; import openfl.display.BlendMode; import openfl.geom.ColorTransform; @@ -14,7 +15,18 @@ class FlxDrawBaseItem /** * Tracks the total number of draw calls made each frame. */ - public static var drawCalls:Int = 0; + @:deprecated("drawCalls is deprecated, use FlxCameraView.totalDrawCalls instead") + public static var drawCalls(get, set):Int; + + static function set_drawCalls(value:Int):Int + { + return FlxCameraView.totalDrawCalls = value; + } + + static function get_drawCalls():Int + { + return FlxCameraView.totalDrawCalls; + } @:noCompletion @:deprecated("blendToInt() is deprecated, remove all references to it") @@ -63,7 +75,7 @@ class FlxDrawBaseItem public function render(camera:FlxCamera):Void { - drawCalls++; + FlxCameraView.totalDrawCalls++; } public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} From f45d5a1e03b01254a800e6eb392f4fe0929eb5df Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:06:22 +0100 Subject: [PATCH 07/72] Fix filters --- flixel/system/render/FlxCameraView.hx | 20 +++++++++++++++++++- flixel/system/render/quad/FlxQuadView.hx | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index e70383fbd5..4bf3e38e7b 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -129,12 +129,30 @@ class FlxCameraView implements IFlxDestroyable */ public var viewBottom(get, never):Float; + /** + * A shortcut for `camera.antialiasing`. Used so implementations can listen to changes. + */ public var antialiasing(get, set):Bool; + + /** + * A shortcut for `camera.angle`. Used so implementations can listen to changes. + */ public var angle(get, set):Float; + + /** + * A shortcut for `camera.alpha`. Used so implementations can listen to changes. + */ public var alpha(get, set):Float; + + /** + * A shortcut for `camera.color`. Used so implementations can listen to changes. + */ public var color(get, set):FlxColor; + + /** + * A shortcut for `camera.visible`. Used so implementations can listen to changes. + */ public var visible(get, set):Bool; - public var filters:Array = []; var _flashOffset:FlxPoint = FlxPoint.get(); diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index aaab60857c..68fc74f63f 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -133,7 +133,7 @@ class FlxQuadView extends FlxCameraView override function render():Void { - flashSprite.filters = camera.filtersEnabled ? filters : null; + flashSprite.filters = camera.filtersEnabled ? camera.filters : null; var currItem:FlxDrawBaseItem = _headOfDrawStack; while (currItem != null) From 5a81eafed44149e9c4cd9cc029bdf0e7d2dd9f9b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:39:27 +0100 Subject: [PATCH 08/72] drawDebugCircle -> drawDebugFilledCircle --- flixel/FlxCamera.hx | 4 ++-- flixel/system/debug/interaction/tools/Transform.hx | 2 +- flixel/system/render/FlxCameraView.hx | 2 +- flixel/system/render/blit/FlxBlitView.hx | 2 +- flixel/system/render/quad/FlxQuadView.hx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 05c5cff0de..4985f060f6 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -695,9 +695,9 @@ class FlxCamera extends FlxBasic view.drawDebugFilledRect(x, y, width, height, color); } - public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { - view.drawDebugCircle(x, y, radius, color); + view.drawDebugFilledCircle(x, y, radius, color); } public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index c26d428700..44b050492d 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -302,7 +302,7 @@ private class Marker public static function draw(screenX:Float, screenY:Float, circle:Bool, camera:FlxCamera) { if (circle) - camera.drawDebugCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); + camera.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); else camera.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 4bf3e38e7b..da814eb7e2 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -189,7 +189,7 @@ class FlxCameraView implements IFlxDestroyable public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} - public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} + public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index fd7c069e7b..86b3613f08 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -213,7 +213,7 @@ class FlxBlitView extends FlxCameraView gfx.endFill(); } - override public function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + override public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { final gfx = FlxSpriteUtil.flashGfx; gfx.beginFill(color.rgb, color.alphaFloat); diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 68fc74f63f..13e42dad8a 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -165,7 +165,7 @@ class FlxQuadView extends FlxCameraView gfx.endFill(); } - override function drawDebugCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + override function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { final gfx = debugLayer.graphics; gfx.beginFill(color.rgb, color.alphaFloat); From dfd46040f1f7c2e97c686fce005bc12e79b2d60a Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:53:39 +0100 Subject: [PATCH 09/72] move view margins back to FlxCamera doesn't seem to be a reason for them to be in FlxCameraView? if I've overlooked something then we can easily move them back at some later point in time --- flixel/FlxCamera.hx | 13 +- flixel/system/render/FlxCameraView.hx | 144 +---------------------- flixel/system/render/blit/FlxBlitView.hx | 16 +-- flixel/system/render/quad/FlxQuadView.hx | 4 +- 4 files changed, 17 insertions(+), 160 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 4985f060f6..3f5ab8e4b0 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -53,6 +53,7 @@ using flixel.util.FlxColorTransformUtil; * |-> `canvas:Sprite` (its graphics is used for rendering objects in tile render mode) * |-> `debugLayer:Sprite` (this sprite is used in tile render mode for rendering debug info, like bounding boxes) */ +@:allow(flixel.system.render.FlxCameraView) class FlxCamera extends FlxBasic { /** @@ -1853,8 +1854,7 @@ class FlxCamera extends FlxBasic { width = Value; - if (view != null) - view.calcMarginX(); + calcMarginX(); updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); @@ -1870,8 +1870,7 @@ class FlxCamera extends FlxBasic { height = Value; - if (view != null) - view.calcMarginY(); + calcMarginY(); updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); @@ -1936,16 +1935,14 @@ class FlxCamera extends FlxBasic return this.visible = visible; } - @:deprecated("depshared") inline function calcMarginX():Void { - view.calcMarginX(); + viewMarginX = 0.5 * width * (scaleX - initialZoom) / scaleX; } - @:deprecated("depshared") inline function calcMarginY():Void { - view.calcMarginY(); + viewMarginY = 0.5 * height * (scaleY - initialZoom) / scaleY; } static inline function get_defaultCameras():Array diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index da814eb7e2..7e1de9eae0 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -59,76 +59,6 @@ class FlxCameraView implements IFlxDestroyable */ public var camera(default, null):FlxCamera; - /** - * The margin cut off on the left and right by the camera zooming in (or out), in world space. - */ - public var viewMarginX(default, null):Float; - - /** - * The margin cut off on the top and bottom by the camera zooming in (or out), in world space. - */ - public var viewMarginY(default, null):Float; - - /** - * The margin cut off on the left by the camera zooming in (or out), in world space. - */ - public var viewMarginLeft(get, never):Float; - - /** - * The margin cut off on the top by the camera zooming in (or out), in world space - */ - public var viewMarginTop(get, never):Float; - - /** - * The margin cut off on the right by the camera zooming in (or out), in world space - */ - public var viewMarginRight(get, never):Float; - - /** - * The margin cut off on the bottom by the camera zooming in (or out), in world space - */ - public var viewMarginBottom(get, never):Float; - - /** - * The size of the camera's view, in world space. - */ - public var viewWidth(get, never):Float; - - /** - * The size of the camera's view, in world space. - */ - public var viewHeight(get, never):Float; - - /** - * The left of the camera's view, in world space. - */ - public var viewX(get, never):Float; - - /** - * The top of the camera's view, in world space. - */ - public var viewY(get, never):Float; - - /** - * The left of the camera's view, in world space. - */ - public var viewLeft(get, never):Float; - - /** - * The top of the camera's view, in world space. - */ - public var viewTop(get, never):Float; - - /** - * The right side of the camera's view, in world space. - */ - public var viewRight(get, never):Float; - - /** - * The bottom side of the camera's view, in world space. - */ - public var viewBottom(get, never):Float; - /** * A shortcut for `camera.antialiasing`. Used so implementations can listen to changes. */ @@ -199,8 +129,8 @@ class FlxCameraView implements IFlxDestroyable function updateScale():Void { - calcMarginX(); - calcMarginY(); + camera.calcMarginX(); + camera.calcMarginY(); } function updatePosition():Void {} @@ -270,76 +200,6 @@ class FlxCameraView implements IFlxDestroyable function checkResize():Void {} - public inline function calcMarginX():Void - { - viewMarginX = 0.5 * camera.width * (camera.scaleX - camera.initialZoom) / camera.scaleX; - } - - public inline function calcMarginY():Void - { - viewMarginY = 0.5 * camera.height * (camera.scaleY - camera.initialZoom) / camera.scaleY; - } - - inline function get_viewMarginLeft():Float - { - return viewMarginX; - } - - inline function get_viewMarginTop():Float - { - return viewMarginY; - } - - inline function get_viewMarginRight():Float - { - return camera.width - viewMarginX; - } - - inline function get_viewMarginBottom():Float - { - return camera.height - viewMarginY; - } - - inline function get_viewWidth():Float - { - return camera.width - viewMarginX * 2; - } - - inline function get_viewHeight():Float - { - return camera.height - viewMarginY * 2; - } - - inline function get_viewX():Float - { - return camera.scroll.x + viewMarginX; - } - - inline function get_viewY():Float - { - return camera.scroll.y + viewMarginY; - } - - inline function get_viewLeft():Float - { - return viewX; - } - - inline function get_viewTop():Float - { - return viewY; - } - - inline function get_viewRight():Float - { - return camera.scroll.x + viewMarginRight; - } - - inline function get_viewBottom():Float - { - return camera.scroll.y + viewMarginBottom; - } - function get_display():DisplayObjectContainer { return null; diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 86b3613f08..7b626aafd5 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -241,7 +241,7 @@ class FlxBlitView extends FlxCameraView } else { - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); } } @@ -260,8 +260,8 @@ class FlxBlitView extends FlxCameraView } else { - _helperPoint.x = destPoint.x - Std.int(viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(viewMarginTop); + _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); } } @@ -275,7 +275,7 @@ class FlxBlitView extends FlxCameraView override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { - final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); + final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); if (position == null) position = renderPoint.set(); @@ -327,7 +327,7 @@ class FlxBlitView extends FlxCameraView else { _helperMatrix.identity(); - _helperMatrix.translate(-viewMarginLeft, -viewMarginTop); + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); } buffer.draw(trianglesSprite, _helperMatrix, transform); @@ -443,7 +443,7 @@ class FlxBlitView extends FlxCameraView inline function updateBlitMatrix():Void { _blitMatrix.identity(); - _blitMatrix.translate(-viewMarginLeft, -viewMarginTop); + _blitMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); _blitMatrix.scale(camera.scaleX, camera.scaleY); _useBlitMatrix = (camera.scaleX < camera.initialZoom) || (camera.scaleY < camera.initialZoom); @@ -451,7 +451,7 @@ class FlxBlitView extends FlxCameraView override function transformRect(rect:FlxRect):FlxRect { - rect.offset(-viewMarginLeft, -viewMarginTop); + rect.offset(-camera.viewMarginLeft, -camera.viewMarginTop); if (_useBlitMatrix) { @@ -466,7 +466,7 @@ class FlxBlitView extends FlxCameraView override function transformPoint(point:FlxPoint):FlxPoint { - point.subtract(viewMarginLeft, viewMarginTop); + point.subtract(camera.viewMarginLeft, camera.viewMarginTop); if (_useBlitMatrix) point.scale(camera.zoom); diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 13e42dad8a..5c188814fe 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -216,7 +216,7 @@ class FlxQuadView extends FlxCameraView override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { - final cameraBounds = _bounds.set(viewMarginLeft, viewMarginTop, viewWidth, viewHeight); + final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); @@ -231,7 +231,7 @@ class FlxQuadView extends FlxCameraView canvas.graphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading - canvas.graphics.drawRect(viewMarginLeft - 1, viewMarginTop - 1, viewWidth + 2, viewHeight + 2); + canvas.graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); canvas.graphics.endFill(); } From 3cd97d9b4ea0ef5d4eb36849cf8809eacc02c80e Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 14:18:17 +0100 Subject: [PATCH 10/72] redo unlock/lock --- flixel/FlxCamera.hx | 12 ++--- flixel/FlxGame.hx | 8 ++-- flixel/system/frontEnds/CameraFrontEnd.hx | 57 ++++++++++++++++------- flixel/system/render/FlxCameraView.hx | 14 ++++-- flixel/system/render/blit/FlxBlitView.hx | 12 ++++- flixel/system/render/quad/FlxQuadView.hx | 7 +-- 6 files changed, 68 insertions(+), 42 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 3f5ab8e4b0..bc29a043ef 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -659,9 +659,9 @@ class FlxCamera extends FlxBasic } @:allow(flixel.system.frontEnds.CameraFrontEnd) - inline function lock(?useBufferLocking:Bool):Void + inline function clear():Void { - view.lock(useBufferLocking); + view.clear(); } @:allow(flixel.system.frontEnds.CameraFrontEnd) @@ -669,13 +669,7 @@ class FlxCamera extends FlxBasic { view.render(); } - - @:allow(flixel.system.frontEnds.CameraFrontEnd) - inline function unlock(?useBufferLocking:Bool):Void - { - view.unlock(useBufferLocking); - } - + public function beginDrawDebug():Void { view.beginDrawDebug(); diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 8337763b5b..a71d34cfa7 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -805,7 +805,7 @@ class FlxGame extends Sprite FlxCameraView.totalDrawCalls = 0; - FlxG.cameras.lock(); + FlxG.cameras.clear(); if (FlxG.plugins.drawOnTop) { @@ -818,17 +818,15 @@ class FlxGame extends Sprite _state.draw(); } + FlxG.cameras.render(); + if (FlxG.renderTile) { - FlxG.cameras.render(); - #if FLX_DEBUG debugger.stats.drawCalls(FlxCameraView.totalDrawCalls); #end } - FlxG.cameras.unlock(); - FlxG.signals.postDraw.dispatch(); #if FLX_DEBUG diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index c334b6b849..0afc7fd36c 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -1,5 +1,6 @@ package flixel.system.frontEnds; +import flixel.system.render.blit.FlxBlitView; import openfl.geom.Rectangle; import flixel.FlxCamera; import flixel.FlxG; @@ -44,8 +45,11 @@ class CameraFrontEnd /** * Allows you to possibly slightly optimize the rendering process IF * you are not doing any pre-processing in your game state's draw() call. + * + * **NOTE**: Only works with the blitting renderer. */ - public var useBufferLocking:Bool = false; + @:deprecated("useBufferLocking is deprecated, use FlxBlitView.useBufferLocking, instead.") + public var useBufferLocking(get, set):Bool; /** * Internal helper variable for clearing the cameras each frame. @@ -253,45 +257,50 @@ class CameraFrontEnd * Called by the game object to lock all the camera buffers and clear them for the next draw pass. */ @:allow(flixel.FlxGame) + @:deprecated("lock() is deprecated, use clear() instead.") inline function lock():Void + { + clear(); + } + + /** + * Called by the game object to clear all the camera buffers for the next draw pass. + */ + @:allow(flixel.FlxGame) + inline function clear():Void { for (camera in list) { if ((camera != null) && camera.exists && camera.visible) { - camera.lock(useBufferLocking); + camera.clear(); } } } + /** + * Called by the game object to draw everything onto the screen. + */ @:allow(flixel.FlxGame) inline function render():Void { - if (FlxG.renderTile) + for (camera in list) { - for (camera in list) + if ((camera != null) && camera.exists && camera.visible) { - if ((camera != null) && camera.exists && camera.visible) - { - camera.render(); - } + camera.render(); } } } /** - * Called by the game object to draw the special FX and unlock all the camera buffers. + * Called by the game object to draw everything onto the screen. */ @:allow(flixel.FlxGame) + @:deprecated("unlock() is deprecated, use render() instead.") inline function unlock():Void { - for (camera in list) - { - if ((camera != null) && camera.exists && camera.visible) - { - camera.unlock(useBufferLocking); - } - } + render(); } /** @@ -335,4 +344,20 @@ class CameraFrontEnd return Color; } + + function get_useBufferLocking():Bool + { + if (FlxG.renderBlit) + return FlxBlitView.useBufferLocking; + + return false; + } + + function set_useBufferLocking(value:Bool):Bool + { + if (FlxG.renderBlit) + return FlxBlitView.useBufferLocking = value; + + return value; + } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 7e1de9eae0..f3422c64f1 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -95,13 +95,17 @@ class FlxCameraView implements IFlxDestroyable { _flashOffset = FlxDestroyUtil.put(_flashOffset); } - - public function lock(?useBufferLocking:Bool):Void {} - + + /** + * Called prior to the rendering call, clears the screen and prepares everything needed. + */ + public function clear():Void {} + + /** + * The actual rendering call where everything gets drawn. + */ public function render():Void {} - public function unlock(?useBufferLocking:Bool):Void {} - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 7b626aafd5..e38bdbb1f7 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -28,6 +28,14 @@ import flixel.util.FlxSpriteUtil; class FlxBlitView extends FlxCameraView { + /** + * Whether the camera's buffer should be locked and unlocked during render calls. + * + * Allows you to possibly slightly optimize the rendering process IF + * you are not doing any pre-processing in your game state's draw() call. + */ + public static var useBufferLocking:Bool = false; + /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ @@ -162,7 +170,7 @@ class FlxBlitView extends FlxCameraView _bounds = FlxDestroyUtil.put(_bounds); } - override function lock(?useBufferLocking:Bool) + override function clear():Void { checkResize(); @@ -175,7 +183,7 @@ class FlxBlitView extends FlxCameraView screen.dirty = true; } - override function unlock(?useBufferLocking:Bool):Void + override function render():Void { camera.drawFX(); diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 5c188814fe..f7004f4e91 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -118,7 +118,7 @@ class FlxQuadView extends FlxCameraView _bounds = FlxDestroyUtil.put(_bounds); } - override function lock(?useBufferLocking:Bool):Void + override function clear():Void { clearDrawStack(); @@ -141,10 +141,7 @@ class FlxQuadView extends FlxCameraView currItem.render(camera); currItem = currItem.next; } - } - - override function unlock(?useBufferLocking:Bool):Void - { + camera.drawFX(); } From 1998f39bd4fd7ebef17d69da21b39a374fba2427 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 17:58:38 +0100 Subject: [PATCH 11/72] A bunch of deprecations --- flixel/FlxCamera.hx | 238 ++++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 108 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index bc29a043ef..062b40c828 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -44,16 +44,10 @@ using flixel.util.FlxColorTransformUtil; * The camera class is used to display the game's visuals. * By default one camera is created automatically, that is the same size as window. * You can add more cameras or even replace the main camera using utilities in `FlxG.cameras`. - * - * Every camera has following display list: - * `flashSprite:Sprite` (which is a container for everything else in the camera, it's added to FlxG.game sprite) - * |-> `_scrollRect:Sprite` (which is used for cropping camera's graphic, mostly in tile render mode) - * |-> `_flashBitmap:Bitmap` (its bitmapData property is buffer BitmapData, this var is used in blit render mode. - * Everything is rendered on buffer in blit render mode) - * |-> `canvas:Sprite` (its graphics is used for rendering objects in tile render mode) - * |-> `debugLayer:Sprite` (this sprite is used in tile render mode for rendering debug info, like bounding boxes) */ @:allow(flixel.system.render.FlxCameraView) +@:access(flixel.system.render.blit.FlxBlitView) +@:access(flixel.system.render.quad.FlxQuadView) class FlxCamera extends FlxBasic { /** @@ -117,14 +111,14 @@ class FlxCamera extends FlxBasic public var view(default, null):FlxCameraView; /** - * This camera's `view`, but typed as a `FlxQuadView`. + * This camera's `view`, typed as a `FlxQuadView`. * * **NOTE**: May be null depending on the render implementation used. */ public var viewQuad(default, null):Null; /** - * This camera's `view`, but typed as a `FlxBlitView`. + * This camera's `view`, typed as a `FlxBlitView`. * * **NOTE**: May be null depending on the render implementation used. */ @@ -193,8 +187,10 @@ class FlxCamera extends FlxBasic * The actual `BitmapData` of the camera display itself. * Used in blit render mode, where you can manipulate its pixels for achieving some visual effects. */ - @:deprecated("buffer is deprecated, avoid referencing it directly and use the methods from camera.view instead") + @:deprecated("buffer is deprecated, use camera.viewBlit.buffer, instead") public var buffer(get, set):BitmapData; + inline function set_buffer(value:BitmapData):BitmapData return viewBlit.buffer = value; + inline function get_buffer():BitmapData return viewBlit.buffer; /** * The natural background color of the camera, in `AARRGGBB` format. Defaults to `FlxG.cameras.bgColor`. @@ -209,8 +205,10 @@ class FlxCamera extends FlxBasic * * **NOTE:** This field is only used in blit render mode. */ - @:deprecated("screen is deprecated, avoid referencing it directly and use the methods from camera.view instead") + @:deprecated("screen is deprecated, use camera.viewBlit.screen, instead") public var screen(get, set):FlxSprite; + inline function set_screen(value:FlxSprite):FlxSprite return viewBlit.screen = value; + inline function get_screen():FlxSprite return viewBlit.screen; /** * Whether to use alpha blending for the camera's background fill or not. @@ -231,8 +229,17 @@ class FlxCamera extends FlxBasic * * Its position is modified by `updateFlashSpritePosition()` which is called every frame. */ - @:deprecated("flashSprite is deprecated, avoid referencing it directly and use the methods from camera.view instead") + @:deprecated("flashSprite is deprecated, use camera.viewQuad.flashSprite/camera.viewBlit.flashSprite, instead") public var flashSprite(get, set):Sprite; + inline function set_flashSprite(value:Sprite):Sprite + { + var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; + return sprite = value; + } + inline function get_flashSprite():Sprite + { + return FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; + } /** * Whether the positions of the objects rendered on this camera are rounded. @@ -362,14 +369,18 @@ class FlxCamera extends FlxBasic * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom * (it is applied to all objects rendered on the camera at such circumstances). */ - @:deprecated("depblit") - var _blitMatrix:FlxMatrix = new FlxMatrix(); + @:deprecated("_blitMatrix is deprecated, use camera.viewBlit.blitMatrix, instead") + var _blitMatrix(get, set):FlxMatrix; + inline function get__blitMatrix():FlxMatrix return viewBlit._blitMatrix; + inline function set__blitMatrix(value:FlxMatrix) return viewBlit._blitMatrix = value; /** * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. */ - @:deprecated("depblit") - var _useBlitMatrix:Bool = false; + @:deprecated("_useBlitMatrix is deprecated, use camera.viewBlit._useBlitMatrix, instead") + var _useBlitMatrix(get, set):Bool; + inline function get__useBlitMatrix():Bool return viewBlit._useBlitMatrix; + inline function set__useBlitMatrix(value:Bool) return viewBlit._useBlitMatrix = value; /** * The alpha value of this camera display (a number between `0.0` and `1.0`). @@ -408,16 +419,20 @@ class FlxCamera extends FlxBasic * (the area of camera's buffer which should be filled with `bgColor`). * Do not modify it unless you know what are you doing. */ - @:deprecated("depblit") + @:deprecated("_flashRect is deprecated, use camera.viewBlit._flashRect, instead") var _flashRect:Rectangle; + inline function get__flashRect():Rectangle return viewBlit._flashRect; + inline function set__flashRect(value:Rectangle) return viewBlit._flashRect = value; /** * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: * Its coordinates are always `(0,0)`, where camera's buffer filling should start. * Do not modify it unless you know what are you doing. */ - @:deprecated("depblit") + @:deprecated("_flashPoint is deprecated, use camera.viewBlit._flashPoint, instead") var _flashPoint:Point = new Point(); + inline function get__flashPoint():Point return viewBlit._flashPoint; + inline function set__flashPoint(value:Point) return viewBlit._flashPoint = value; /** * Internal, used for positioning camera's `flashSprite` on screen. @@ -426,7 +441,10 @@ class FlxCamera extends FlxBasic * Its value depends on camera's size (`width` and `height`), game's `scale` and camera's initial zoom factor. * Do not modify it unless you know what are you doing. */ - var _flashOffset:FlxPoint = FlxPoint.get(); + @:deprecated("_flashOffset is deprecated, use camera.view._flashOffset, instead") + var _flashOffset(get, set):FlxPoint; + inline function get__flashOffset():FlxPoint return view._flashOffset; + inline function set__flashOffset(value:FlxPoint) return view._flashOffset = value; /** * Internal, represents the color of `flash()` special effect. @@ -524,8 +542,10 @@ class FlxCamera extends FlxBasic * Internal helper variable for doing better wipes/fills between renders. * Used it blit render mode only (in `fill()` method). */ - @:deprecated("depblit") - var _fill:BitmapData; + @:deprecated("_fill is deprecated, use camera.viewBlit._fill, instead") + var _fill(get, set):BitmapData; + inline function get__fill():BitmapData return viewBlit._fill; + inline function set__fill(value:BitmapData):BitmapData return viewBlit._fill = value; /** * Internal, used to render buffer to screen space. Used it blit render mode only. @@ -533,22 +553,42 @@ class FlxCamera extends FlxBasic * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. * It is a child of the `_scrollRect` `Sprite`. */ - @:deprecated("depblit") - var _flashBitmap:Bitmap; + @:deprecated("_flashBitmap is deprecated, use camera.viewBlit._flashBitmap, instead") + var _flashBitmap(get, set):Bitmap; + inline function get__flashBitmap():Bitmap return viewBlit._flashBitmap; + inline function set__flashBitmap(value:Bitmap):Bitmap return viewBlit._flashBitmap = value; /** * Internal sprite, used for correct trimming of camera viewport. * It is a child of `flashSprite`. * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ - @:deprecated("depshared") - var _scrollRect:Sprite; + @:deprecated("_scrollRect is deprecated, use camera.viewQuad._scrollRect/camera.viewBlit._scrollRect, instead") + var _scrollRect(get, set):Sprite; + inline function get__scrollRect():Sprite + { + return FlxG.renderTile ? viewQuad._scrollRect : viewBlit._scrollRect; + } + inline function set__scrollRect(value:Sprite):Sprite + { + var scrollRect = FlxG.renderTile ? viewQuad._scrollRect : viewBlit._scrollRect; + return scrollRect = value; + } /** * Helper rect for `drawTriangles()` visibility checks */ - @:deprecated("depblit") - var _bounds:FlxRect; + @:deprecated("_bounds is deprecated, use camera.viewQuad._bounds/camera.viewBlit._bounds, instead") + var _bounds(get, set):FlxRect; + inline function get__bounds():FlxRect + { + return FlxG.renderTile ? viewQuad._bounds : viewBlit._bounds; + } + inline function set__bounds(value:FlxRect):FlxRect + { + var bounds = FlxG.renderTile ? viewQuad._bounds : viewBlit._bounds; + return bounds = value; + } /** * Sprite used for actual rendering in tile render mode (instead of `_flashBitmap` for blitting). @@ -556,8 +596,10 @@ class FlxCamera extends FlxBasic * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. */ - @:deprecated("canvas is deprecated, avoid referencing it directly and use the methods from camera.view instead") + @:deprecated("canvas is deprecated, use camera.viewQuad.canvas, instead") public var canvas(get, set):Sprite; + inline function set_canvas(value:Sprite):Sprite return viewQuad.canvas = value; + inline function get_canvas():Sprite return viewQuad.canvas; #if FLX_DEBUG /** @@ -566,73 +608,106 @@ class FlxCamera extends FlxBasic * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. */ - @:deprecated("debugLayer is deprecated, avoid referencing it directly and use the methods from camera.view instead") + @:deprecated("debugLayer is deprecated, use camera.viewQuad.debugLayer, instead") public var debugLayer(get, set):Sprite; + inline function set_debugLayer(value:Sprite):Sprite return viewQuad.debugLayer; + inline function get_debugLayer():Sprite return viewQuad.debugLayer; #end - @:deprecated("depshared") - var _helperMatrix:FlxMatrix = new FlxMatrix(); + @:deprecated("_helperMatrix is deprecated, use camera.viewQuad._helperMatrix/camera.viewBlit._helperMatrix, instead") + var _helperMatrix(get, set):FlxMatrix; + inline function get__helperMatrix():FlxMatrix + { + return FlxG.renderTile ? viewQuad._helperMatrix : viewBlit._helperMatrix; + } + inline function set__helperMatrix(value:FlxMatrix):FlxMatrix + { + var mat = FlxG.renderTile ? viewQuad._helperMatrix : viewBlit._helperMatrix; + return mat = value; + } - @:deprecated("depblit") - var _helperPoint:Point = new Point(); + @:deprecated("_helperPoint is deprecated, use camera.viewBlit._helperPoint, instead") + var _helperPoint(get, set):Point; + inline function get__helperPoint():Point return viewBlit._helperPoint; + inline function set__helperPoint(value:Point):Point return viewBlit._helperPoint = value; /** * Currently used draw stack item */ - @:deprecated("depquad") - var _currentDrawItem:FlxDrawBaseItem; + @:deprecated("_currentDrawItem is deprecated, use camera.viewQuad._currentDrawItem, instead") + var _currentDrawItem(get, set):FlxDrawBaseItem; + inline function get__currentDrawItem():FlxDrawBaseItem return viewQuad._currentDrawItem; + inline function set__currentDrawItem(value:FlxDrawBaseItem):FlxDrawBaseItem return viewQuad._currentDrawItem = value; /** * Pointer to head of stack with draw items */ - @:deprecated("depquad") - var _headOfDrawStack:FlxDrawBaseItem; + @:deprecated("_headOfDrawStack is deprecated, use camera.viewQuad._headOfDrawStack, instead") + var _headOfDrawStack(get, set):FlxDrawBaseItem; + inline function get__headOfDrawStack():FlxDrawBaseItem return viewQuad._headOfDrawStack; + inline function set__headOfDrawStack(value:FlxDrawBaseItem):FlxDrawBaseItem return viewQuad._headOfDrawStack = value; /** * Last draw tiles item */ - @:deprecated("depquad") - var _headTiles:FlxDrawQuadsItem; + @:deprecated("_headTiles is deprecated, use camera.viewQuad._headTiles, instead") + var _headTiles(get, set):FlxDrawQuadsItem; + inline function get__headTiles():FlxDrawQuadsItem return viewQuad._headTiles; + inline function set__headTiles(value:FlxDrawQuadsItem):FlxDrawQuadsItem return viewQuad._headTiles = value; /** * Last draw triangles item */ - @:deprecated("depquad") - var _headTriangles:FlxDrawTrianglesItem; + @:deprecated("_headTriangles is deprecated, use camera.viewQuad._headTriangles, instead") + var _headTriangles(get, set):FlxDrawTrianglesItem; + inline function get__headTriangles():FlxDrawTrianglesItem return viewQuad._headTriangles; + inline function set__headTriangles(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return viewQuad._headTriangles = value; /** * Draw tiles stack items that can be reused */ - @:deprecated("depquad") - static var _storageTilesHead:FlxDrawQuadsItem; + @:deprecated("_storageTilesHead is deprecated, use FlxQuadView._storageTilesHead, instead") + static var _storageTilesHead(get, set):FlxDrawQuadsItem; + static inline function get__storageTilesHead():FlxDrawQuadsItem return FlxQuadView._storageTilesHead; + static inline function set__storageTilesHead(value:FlxDrawQuadsItem):FlxDrawQuadsItem return FlxQuadView._storageTilesHead = value; /** * Draw triangles stack items that can be reused */ - @:deprecated("depquad") - static var _storageTrianglesHead:FlxDrawTrianglesItem; + @:deprecated("_storageTrianglesHead is deprecated, use FlxQuadView._storageTrianglesHead, instead") + static var _storageTrianglesHead(get, set):FlxDrawTrianglesItem; + static inline function get__storageTrianglesHead():FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead; + static inline function set__storageTrianglesHead(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead = value; /** * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. */ - @:deprecated("depblit") - static var drawVertices:Vector = new Vector(); + @:deprecated("drawVertices is deprecated, use FlxBlitView.drawVertices, instead") + static var drawVertices(get, set):Vector; + static inline function get_drawVertices():Vector return FlxBlitView.drawVertices; + static inline function set_drawVertices(value:Vector):Vector return FlxBlitView.drawVertices = value; /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ - @:deprecated("depblit") - static var trianglesSprite:Sprite = new Sprite(); + @:deprecated("trianglesSprite is deprecated, use FlxBlitView.trianglesSprite, instead") + static var trianglesSprite(get, set):Sprite; + static inline function get_trianglesSprite():Sprite return FlxBlitView.trianglesSprite; + static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitView.trianglesSprite = value; /** * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. * Added for less garbage creation. */ - @:deprecated("depblit") - static var renderPoint:FlxPoint = FlxPoint.get(); + @:deprecated("renderPoint is deprecated, use FlxBlitView.renderPoint, instead") + static var renderPoint(get, set):FlxPoint; + static inline function get_renderPoint():FlxPoint return FlxBlitView.renderPoint; + static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitView.renderPoint = value; - @:deprecated("depblit") - static var renderRect:FlxRect = FlxRect.get(); + @:deprecated("renderRect is deprecated, use FlxBlitView.renderRect, instead") + static var renderRect(get, set):FlxRect; + static inline function get_renderRect():FlxRect return FlxBlitView.renderRect; + static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitView.renderRect = value; @:noCompletion public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) @@ -669,7 +744,7 @@ class FlxCamera extends FlxBasic { view.render(); } - + public function beginDrawDebug():Void { view.beginDrawDebug(); @@ -2013,59 +2088,6 @@ class FlxCamera extends FlxBasic { return view.display; } - - inline function set_flashSprite(value:Sprite):Sprite - { - var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; - return sprite = value; - } - - inline function get_flashSprite():Sprite - { - return FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; - } - - inline function set_screen(value:FlxSprite):FlxSprite - { - return viewBlit.screen = value; - } - - inline function get_screen():FlxSprite - { - return viewBlit.screen; - } - - inline function set_buffer(value:BitmapData):BitmapData - { - return viewBlit.buffer = value; - } - - inline function get_buffer():BitmapData - { - return viewBlit.buffer; - } - - inline function set_canvas(value:Sprite):Sprite - { - return viewQuad.canvas = value; - } - - inline function get_canvas():Sprite - { - return viewQuad.canvas; - } - - #if FLX_DEBUG - inline function set_debugLayer(value:Sprite):Sprite - { - return viewQuad.debugLayer; - } - - inline function get_debugLayer():Sprite - { - return viewQuad.debugLayer; - } - #end /** * Do not use the following fields! They only exists because FlxCamera extends FlxBasic, From d7c4f9e38d27cad7fe9c58c266cfacb3b02a5f1e Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 18:08:57 +0100 Subject: [PATCH 12/72] missed this deprecation --- flixel/FlxCamera.hx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 062b40c828..04fa23db4b 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1448,14 +1448,10 @@ class FlxCamera extends FlxBasic view.checkResize(); } - @:deprecated("depblit") + @:deprecated("updateBlitMatrix() is deprecated, use camera.viewBlit.updateBlitMatrix(), instead") inline function updateBlitMatrix():Void { - _blitMatrix.identity(); - _blitMatrix.translate(-viewMarginLeft, -viewMarginTop); - _blitMatrix.scale(scaleX, scaleY); - - _useBlitMatrix = (scaleX < initialZoom) || (scaleY < initialZoom); + viewBlit.updateBlitMatrix(); } /** From 50357c79365310f8c69a756f5af241b31d1486bb Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 24 Dec 2025 21:02:48 +0100 Subject: [PATCH 13/72] checkResize() shouldn't be a global thing --- flixel/FlxCamera.hx | 14 +++----------- flixel/system/render/FlxCameraView.hx | 2 -- flixel/system/render/blit/FlxBlitView.hx | 2 +- flixel/system/render/quad/FlxQuadView.hx | 15 ++++++++++----- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 04fa23db4b..41a091be5c 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1,13 +1,5 @@ package flixel; -import openfl.display.Bitmap; -import openfl.display.BitmapData; -import openfl.display.DisplayObject; -import openfl.display.Graphics; -import openfl.display.Sprite; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; import flixel.graphics.tile.FlxDrawBaseItem; @@ -24,7 +16,6 @@ import flixel.system.render.blit.FlxBlitView; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; -import flixel.util.FlxSpriteUtil; import openfl.Vector; import openfl.display.Bitmap; import openfl.display.BitmapData; @@ -1442,10 +1433,11 @@ class FlxCamera extends FlxBasic } } - @:allow(flixel.system.frontEnds.CameraFrontEnd) + @:deprecated("checkResize() is deprecated") function checkResize():Void { - view.checkResize(); + if (FlxG.renderBlit) + viewBlit.checkResize(); } @:deprecated("updateBlitMatrix() is deprecated, use camera.viewBlit.updateBlitMatrix(), instead") diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index f3422c64f1..90e3ad3c74 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -202,8 +202,6 @@ class FlxCameraView implements IFlxDestroyable return object; } - function checkResize():Void {} - function get_display():DisplayObjectContainer { return null; diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index e38bdbb1f7..30a1c07607 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -429,7 +429,7 @@ class FlxBlitView extends FlxCameraView } } - override function checkResize() + function checkResize():Void { if (camera.width != buffer.width || camera.height != buffer.height) { diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index f7004f4e91..2c4ddfde5e 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -1,5 +1,6 @@ package flixel.system.render.quad; +import openfl.display.Graphics; import flixel.math.FlxRect; import openfl.display.DisplayObjectContainer; import flixel.system.render.FlxCameraView; @@ -67,8 +68,10 @@ class FlxQuadView extends FlxCameraView * Helper rect for `drawTriangles()` visibility checks */ var _bounds:FlxRect = FlxRect.get(); - + var _helperMatrix:FlxMatrix = new FlxMatrix(); + + var targetGraphics:Graphics; @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) @@ -85,6 +88,8 @@ class FlxQuadView extends FlxCameraView debugLayer = new Sprite(); _scrollRect.addChild(debugLayer); #end + + targetGraphics = canvas.graphics; } override function destroy():Void @@ -224,12 +229,12 @@ class FlxQuadView extends FlxCameraView override function fill(color:FlxColor, blendAlpha:Bool = true):Void { - canvas.graphics.overrideBlendMode(null); - canvas.graphics.beginFill(color.rgb, color.alphaFloat); + targetGraphics.overrideBlendMode(null); + targetGraphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading - canvas.graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - canvas.graphics.endFill(); + targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + targetGraphics.endFill(); } override function offsetView(x:Float, y:Float):Void From ac364da622199672e622f91e78cc0800cefe7052 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Thu, 22 Jan 2026 22:02:13 +0100 Subject: [PATCH 14/72] FlxRenderer draft WIP; debug drawing is not functional yet and there's a bunch of temporary code that needs to be cleaned up --- flixel/FlxCamera.hx | 71 +++-- flixel/FlxG.hx | 63 ++-- flixel/FlxGame.hx | 6 +- flixel/graphics/tile/FlxDrawBaseItem.hx | 10 +- flixel/system/frontEnds/BitmapFrontEnd.hx | 18 +- flixel/system/frontEnds/CameraFrontEnd.hx | 14 +- flixel/system/render/FlxCameraView.hx | 53 +--- flixel/system/render/FlxRenderer.hx | 186 ++++++++++++ flixel/system/render/blit/FlxBlitRenderer.hx | 300 +++++++++++++++++++ flixel/system/render/blit/FlxBlitView.hx | 228 +------------- flixel/system/render/quad/FlxQuadRenderer.hx | 179 +++++++++++ flixel/system/render/quad/FlxQuadView.hx | 114 ------- 12 files changed, 757 insertions(+), 485 deletions(-) create mode 100644 flixel/system/render/FlxRenderer.hx create mode 100644 flixel/system/render/blit/FlxBlitRenderer.hx create mode 100644 flixel/system/render/quad/FlxQuadRenderer.hx diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 41a091be5c..f38d91ef95 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -13,6 +13,7 @@ import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; import flixel.system.render.quad.FlxQuadView; import flixel.system.render.blit.FlxBlitView; +import flixel.system.render.blit.FlxBlitRenderer; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -36,9 +37,8 @@ using flixel.util.FlxColorTransformUtil; * By default one camera is created automatically, that is the same size as window. * You can add more cameras or even replace the main camera using utilities in `FlxG.cameras`. */ -@:allow(flixel.system.render.FlxCameraView) -@:access(flixel.system.render.blit.FlxBlitView) -@:access(flixel.system.render.quad.FlxQuadView) +@:allow(flixel.system.render) +@:access(flixel.system.render) class FlxCamera extends FlxBasic { /** @@ -675,16 +675,16 @@ class FlxCamera extends FlxBasic */ @:deprecated("drawVertices is deprecated, use FlxBlitView.drawVertices, instead") static var drawVertices(get, set):Vector; - static inline function get_drawVertices():Vector return FlxBlitView.drawVertices; - static inline function set_drawVertices(value:Vector):Vector return FlxBlitView.drawVertices = value; + static inline function get_drawVertices():Vector return FlxBlitRenderer.drawVertices; + static inline function set_drawVertices(value:Vector):Vector return FlxBlitRenderer.drawVertices = value; /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ @:deprecated("trianglesSprite is deprecated, use FlxBlitView.trianglesSprite, instead") static var trianglesSprite(get, set):Sprite; - static inline function get_trianglesSprite():Sprite return FlxBlitView.trianglesSprite; - static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitView.trianglesSprite = value; + static inline function get_trianglesSprite():Sprite return FlxBlitRenderer.trianglesSprite; + static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitRenderer.trianglesSprite = value; /** * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. @@ -692,13 +692,13 @@ class FlxCamera extends FlxBasic */ @:deprecated("renderPoint is deprecated, use FlxBlitView.renderPoint, instead") static var renderPoint(get, set):FlxPoint; - static inline function get_renderPoint():FlxPoint return FlxBlitView.renderPoint; - static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitView.renderPoint = value; + static inline function get_renderPoint():FlxPoint return FlxBlitRenderer.renderPoint; + static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitRenderer.renderPoint = value; @:deprecated("renderRect is deprecated, use FlxBlitView.renderRect, instead") static var renderRect(get, set):FlxRect; - static inline function get_renderRect():FlxRect return FlxBlitView.renderRect; - static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitView.renderRect = value; + static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; + static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; @:noCompletion public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) @@ -724,64 +724,59 @@ class FlxCamera extends FlxBasic viewQuad.clearDrawStack(); } - @:allow(flixel.system.frontEnds.CameraFrontEnd) - inline function clear():Void - { - view.clear(); - } - - @:allow(flixel.system.frontEnds.CameraFrontEnd) - function render():Void - { - view.render(); - } - public function beginDrawDebug():Void { - view.beginDrawDebug(); + // view.beginDrawDebug(); } public function endDrawDebug(?matrix:FlxMatrix):Void { - view.endDrawDebug(matrix); + // view.endDrawDebug(matrix); } public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void { - view.drawDebugRect(x, y, width, height, color, thickness); + // FlxG.renderer.begin(this); + // view.drawDebugRect(x, y, width, height, color, thickness); } public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void { - view.drawDebugFilledRect(x, y, width, height, color); + // FlxG.renderer.begin(this); + // view.drawDebugFilledRect(x, y, width, height, color); } public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { - view.drawDebugFilledCircle(x, y, radius, color); + // FlxG.renderer.begin(this); + // view.drawDebugFilledCircle(x, y, radius, color); } public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void { - view.drawDebugLine(x1, y1, x2, y2, color, thickness); + // FlxG.renderer.begin(this); + // view.drawDebugLine(x1, y1, x2, y2, color, thickness); } public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - view.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + FlxG.renderer.begin(this); + FlxG.renderer.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); } public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - view.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + FlxG.renderer.begin(this); + FlxG.renderer.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); } public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void { - view.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + FlxG.renderer.begin(this); + FlxG.renderer.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); } /** @@ -1396,7 +1391,9 @@ class FlxCamera extends FlxBasic overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void { color.alphaFloat = fxAlpha; - view.fill(color, blendAlpha); + + FlxG.renderer.begin(this); + FlxG.renderer.fill(color, blendAlpha); } /** @@ -1407,7 +1404,7 @@ class FlxCamera extends FlxBasic */ overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true):Void { - view.fill(color, blendAlpha); + FlxG.renderer.fill(color, blendAlpha); } /** @@ -1416,12 +1413,14 @@ class FlxCamera extends FlxBasic @:allow(flixel.system.render.FlxCameraView) function drawFX():Void { + FlxG.renderer.begin(this); + // Draw the "flash" special effect onto the buffer if (_fxFlashAlpha > 0.0) { var color = _fxFlashColor; color.alphaFloat *= _fxFlashAlpha; - view.fill(color); + FlxG.renderer.fill(color); } // Draw the "fade" special effect onto the buffer @@ -1429,7 +1428,7 @@ class FlxCamera extends FlxBasic { var color = _fxFadeColor; color.alphaFloat *= _fxFadeAlpha; - view.fill(color); + FlxG.renderer.fill(color); } } diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 99559cddc7..493c381123 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -1,5 +1,6 @@ package flixel; +import flixel.system.render.FlxRenderer; import flixel.math.FlxMath; import flixel.math.FlxRandom; import flixel.math.FlxRect; @@ -143,10 +144,31 @@ class FlxG */ public static var onMobile(get, never):Bool; - public static var renderMethod(default, null):FlxRenderMethod; + @:deprecated("renderMethod is deprecated, use FlxG.render.method, instead.") + public static var renderMethod(get, null):FlxRenderMethod; + static inline function get_renderMethod():FlxRenderMethod + { + return FlxG.renderer.method; + } + + @:deprecated("renderBlit is deprecated, compare against FlxG.render.method, instead.") + public static var renderBlit(get, never):Bool; + @:noCompletion static inline function get_renderBlit():Bool + { + return FlxG.renderer.method == BLITTING; + } + + @:deprecated("renderTile is deprecated, compare against FlxG.render.method, instead.") + public static var renderTile(get, never):Bool; + @:noCompletion static inline function get_renderTile():Bool + { + return FlxG.renderer.method == DRAW_TILES; + } - public static var renderBlit(default, null):Bool; - public static var renderTile(default, null):Bool; + /** + * The global renderer instance. + */ + public static var renderer(default, null):FlxRenderer; /** * Represents the amount of time in seconds that passed since last frame. @@ -541,10 +563,6 @@ class FlxG FlxG.height = height; initRenderMethod(); - #if FLX_OPENGL_AVAILABLE - // Query once when window is created and cache for later - bitmap.get_maxTextureSize(); - #end FlxG.initialWidth = width; FlxG.initialHeight = height; @@ -590,28 +608,10 @@ class FlxG static function initRenderMethod():Void { - #if !flash - renderMethod = switch (stage.window.context.type) - { - case OPENGL, OPENGLES, WEBGL: DRAW_TILES; - default: BLITTING; - } - #else - #if web - renderMethod = BLITTING; - #else - renderMethod = DRAW_TILES; - #end - #end + renderer = FlxRenderer.create(); + renderer.init(); - #if air - renderMethod = BLITTING; - #end - - renderBlit = renderMethod == BLITTING; - renderTile = renderMethod == DRAW_TILES; - - FlxObject.defaultPixelPerfectPosition = renderBlit; + FlxObject.defaultPixelPerfectPosition = FlxG.renderer.method == BLITTING; } #if FLX_SAVE @@ -750,8 +750,5 @@ class FlxG } } -enum FlxRenderMethod -{ - DRAW_TILES; - BLITTING; -} +@:deprecated("FlxG.FlxRenderMethod is deprecated, use FlxRenderer.FlxRenderMethod instead") +typedef FlxRenderMethod = flixel.system.render.FlxRenderer.FlxRenderMethod; diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index a71d34cfa7..ba020c62d9 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -1,6 +1,6 @@ package flixel; -import flixel.system.render.FlxCameraView; +import flixel.system.render.FlxRenderer; import flixel.system.FlxSplash; import flixel.util.FlxArrayUtil; import flixel.util.FlxDestroyUtil; @@ -803,7 +803,7 @@ class FlxGame extends Sprite FlxG.signals.preDraw.dispatch(); - FlxCameraView.totalDrawCalls = 0; + FlxRenderer.totalDrawCalls = 0; FlxG.cameras.clear(); @@ -823,7 +823,7 @@ class FlxGame extends Sprite if (FlxG.renderTile) { #if FLX_DEBUG - debugger.stats.drawCalls(FlxCameraView.totalDrawCalls); + debugger.stats.drawCalls(FlxRenderer.totalDrawCalls); #end } diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index d89be00aef..6127ce907a 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -2,7 +2,7 @@ package flixel.graphics.tile; import flixel.FlxCamera; import flixel.graphics.frames.FlxFrame; -import flixel.system.render.FlxCameraView; +import flixel.system.render.FlxRenderer; import flixel.math.FlxMatrix; import openfl.display.BlendMode; import openfl.geom.ColorTransform; @@ -15,17 +15,17 @@ class FlxDrawBaseItem /** * Tracks the total number of draw calls made each frame. */ - @:deprecated("drawCalls is deprecated, use FlxCameraView.totalDrawCalls instead") + @:deprecated("drawCalls is deprecated, use FlxRenderer.totalDrawCalls instead") public static var drawCalls(get, set):Int; static function set_drawCalls(value:Int):Int { - return FlxCameraView.totalDrawCalls = value; + return FlxRenderer.totalDrawCalls = value; } static function get_drawCalls():Int { - return FlxCameraView.totalDrawCalls; + return FlxRenderer.totalDrawCalls; } @:noCompletion @@ -75,7 +75,7 @@ class FlxDrawBaseItem public function render(camera:FlxCamera):Void { - FlxCameraView.totalDrawCalls++; + FlxRenderer.totalDrawCalls++; } public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} diff --git a/flixel/system/frontEnds/BitmapFrontEnd.hx b/flixel/system/frontEnds/BitmapFrontEnd.hx index 8e17339206..02b9b34a12 100644 --- a/flixel/system/frontEnds/BitmapFrontEnd.hx +++ b/flixel/system/frontEnds/BitmapFrontEnd.hx @@ -8,9 +8,6 @@ import flixel.system.FlxAssets; import flixel.util.FlxColor; import openfl.Assets; import openfl.display.BitmapData; -#if FLX_OPENGL_AVAILABLE -import lime.graphics.opengl.GL; -#end /** * Internal storage system to prevent graphics from being used repeatedly in memory. @@ -19,7 +16,6 @@ import lime.graphics.opengl.GL; */ class BitmapFrontEnd { - #if FLX_OPENGL_AVAILABLE /** * Returns the maximum allowed width and height (in pixels) for a texture. * This value is only available on hardware-accelerated targets that use OpenGL. @@ -27,8 +23,8 @@ class BitmapFrontEnd * * @see https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_TEXTURE_SIZE */ + @:deprecated("maxTextureSize is deprecated, use FlxG.renderer.maxTextureSize instead.") public var maxTextureSize(get, never):Int; - #end /** * Helper FlxFrame object. Containing only one frame. @@ -341,18 +337,10 @@ class BitmapFrontEnd } } - #if FLX_OPENGL_AVAILABLE - static var _maxTextureSize = -1; - - @:allow(flixel.FlxG) - function get_maxTextureSize():Int + inline function get_maxTextureSize():Int { - if (_maxTextureSize < 0) - _maxTextureSize = FlxG.renderTile ? cast GL.getParameter(GL.MAX_TEXTURE_SIZE) : 0; - - return _maxTextureSize; + return FlxG.renderer.maxTextureSize; } - #end function get_whitePixel():FlxFrame { diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 0afc7fd36c..50477396a1 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -1,6 +1,6 @@ package flixel.system.frontEnds; -import flixel.system.render.blit.FlxBlitView; +import flixel.system.render.blit.FlxBlitRenderer; import openfl.geom.Rectangle; import flixel.FlxCamera; import flixel.FlxG; @@ -48,7 +48,7 @@ class CameraFrontEnd * * **NOTE**: Only works with the blitting renderer. */ - @:deprecated("useBufferLocking is deprecated, use FlxBlitView.useBufferLocking, instead.") + @:deprecated("useBufferLocking is deprecated, use FlxBlitRenderer.useBufferLocking, instead.") public var useBufferLocking(get, set):Bool; /** @@ -273,7 +273,8 @@ class CameraFrontEnd { if ((camera != null) && camera.exists && camera.visible) { - camera.clear(); + FlxG.renderer.begin(camera); + FlxG.renderer.clear(); } } } @@ -288,7 +289,8 @@ class CameraFrontEnd { if ((camera != null) && camera.exists && camera.visible) { - camera.render(); + FlxG.renderer.begin(camera); + FlxG.renderer.render(); } } } @@ -348,7 +350,7 @@ class CameraFrontEnd function get_useBufferLocking():Bool { if (FlxG.renderBlit) - return FlxBlitView.useBufferLocking; + return FlxBlitRenderer.useBufferLocking; return false; } @@ -356,7 +358,7 @@ class CameraFrontEnd function set_useBufferLocking(value:Bool):Bool { if (FlxG.renderBlit) - return FlxBlitView.useBufferLocking = value; + return FlxBlitRenderer.useBufferLocking = value; return value; } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 90e3ad3c74..476e1b154b 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -21,33 +21,27 @@ import openfl.display.DisplayObject; import openfl.display.BitmapData; /** - * A `FlxCameraView` is the base class for all rendering functionality. - * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. + * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects */ @:allow(flixel.FlxCamera) class FlxCameraView implements IFlxDestroyable -{ - /** - * The number of total draw calls in a frame. - */ - public static var totalDrawCalls:Int = 0; - +{ /** * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. * @param camera The camera to create the view for */ public static inline function create(camera:FlxCamera):FlxCameraView { - if (FlxG.renderTile) + if (!FlxG.renderer.isHardware) { - return cast new flixel.system.render.quad.FlxQuadView(camera); + return cast new flixel.system.render.blit.FlxBlitView(camera); } else { - return cast new flixel.system.render.blit.FlxBlitView(camera); + return cast new flixel.system.render.quad.FlxQuadView(camera); } } - + /** * Display object which is used as a container for all of the camera's graphics. * This object is added to the display tree. @@ -95,41 +89,6 @@ class FlxCameraView implements IFlxDestroyable { _flashOffset = FlxDestroyUtil.put(_flashOffset); } - - /** - * Called prior to the rendering call, clears the screen and prepares everything needed. - */ - public function clear():Void {} - - /** - * The actual rendering call where everything gets drawn. - */ - public function render():Void {} - - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void {} - - public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader):Void {} - - public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} - - public function beginDrawDebug():Void {} - - public function endDrawDebug(?matrix:FlxMatrix):Void {} - - public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} - - public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} - - public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} - - public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} - - public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} - - function drawFX():Void {} function updateScale():Void { diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx new file mode 100644 index 0000000000..6c887ce27e --- /dev/null +++ b/flixel/system/render/FlxRenderer.hx @@ -0,0 +1,186 @@ +package flixel.system.render; + +import flixel.util.FlxDestroyUtil.IFlxDestroyable; +import flixel.math.FlxPoint; +import openfl.geom.Point; +import openfl.geom.Rectangle; +import flixel.system.FlxAssets.FlxShader; +import openfl.display.BitmapData; +import openfl.geom.ColorTransform; +import openfl.display.BlendMode; +import flixel.math.FlxMatrix; +import flixel.util.FlxColor; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.graphics.frames.FlxFrame; +import flixel.graphics.FlxGraphic; + +/** + * A `FlxRenderer` is the base class for all rendering functionality. + * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. + */ +class FlxRenderer implements IFlxDestroyable +{ + /** + * The number of total draw calls in the current frame. + */ + public static var totalDrawCalls:Int = 0; + + /** + * Creates a renderer instance, based on the used rendering backend. + * This function is dynamic, which means that you can change the return value yourself. + * + * @return FlxRenderer + */ + public static dynamic function create():FlxRenderer + { + if (!FlxG.renderer.isHardware) + { + return new flixel.system.render.blit.FlxBlitRenderer(); + } + else + { + return new flixel.system.render.quad.FlxQuadRenderer(); + } + } + + /** + * Returns the current render method as an enum. + */ + public var method(default, null):FlxRenderMethod; + + /** + * Returns whether the current renderer is hardware accelerated. + */ + public var isHardware(get, never):Bool; + @:noCompletion inline function get_isHardware():Bool + { + return FlxG.stage.window.context.attributes.hardware; + } + + /** + * Returns whether OpenGL access is available for the current renderer. + */ + public var isGL(get, never):Bool; + @:noCompletion inline function get_isGL():Bool + { + #if FLX_OPENGL_AVAILABLE + return isHardware && method == DRAW_TILES; + #else + return false; + #end + } + + /** + * Returns the maximum allowed width and height (in pixels) for a texture. + * This value is only available on hardware-accelerated targets that use OpenGL. + * On unsupported targets, the returned value will always be -1. + * + * @see https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_TEXTURE_SIZE + */ + public var maxTextureSize(default, null):Int; + + /** + * The current camera in use. + */ + public var camera(default, null):FlxCamera; + + /** + * Shortcut to `currentCamera.view`. + * Renderer implementations may override this to cast the return value to the + * corresponding type for the implementation. + */ + // public var currentView(get, never):FlxCameraView; + // @:noCompletion function get_currentView():T + // { + // return currentCamera.view; + // } + + + public function new() {} + + public function destroy():Void + { + camera = null; + } + + /** + * Called internally when it's safe to initialize rendering related properties. + */ + @:allow(flixel.FlxG) + function init():Void {} + + // ------------------------ RENDERING ------------------------ + + /** + * Sets `camera` as the current render target. + * Any drawing commands will be executed on the camera. + * + * **NOTE:** Manually calling this during the draw phase could mess things up. + * If you must, please remember to reset the state back to where it was + * + * @param camera The camera to draw to. + */ + public function begin(camera:FlxCamera):Void + { + if (this.camera == camera) + return; + + this.camera = camera; + } + + /** + * Called before a new rendering frame, clears all previously drawn graphics. + */ + public function clear():Void {} + + /** + * Flushes any remaining graphics and renders everything to the screen. + */ + public function render():Void {} + + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader):Void {} + + public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader):Void {} + + public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} + + public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} + + // ------------------------ DEBUG DRAW ------------------------ + + /** + * Begins debug draw on the current (or optionally specified) camera. + * Any debug drawing commands will be executed on the camera. + * + * @param camera Optional, the camera to draw to. + */ + public function beginDrawDebug(?camera:FlxCamera):Void + { + if (camera != null) + { + if (this.camera == camera) + return; + + this.camera = camera; + } + } + + public function endDrawDebug():Void {} + + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} + + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} + + public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} + + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} +} + +enum FlxRenderMethod +{ + DRAW_TILES; + BLITTING; +} diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx new file mode 100644 index 0000000000..11ebd38d02 --- /dev/null +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -0,0 +1,300 @@ +package flixel.system.render.blit; + +import flixel.graphics.tile.FlxDrawTrianglesItem; +import openfl.display.Graphics; +import openfl.display.BitmapData; +import openfl.geom.Rectangle; +import openfl.geom.Point; +import openfl.display.BlendMode; +import openfl.display.Sprite; +import openfl.Vector; +import flixel.math.FlxPoint; +import flixel.math.FlxRect; +import flixel.util.FlxColor; +import flixel.util.FlxSpriteUtil; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxMatrix; +import openfl.geom.ColorTransform; +import flixel.system.FlxAssets.FlxShader; +import flixel.graphics.FlxGraphic; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; + +@:access(flixel.FlxCamera) +@:access(flixel.system.render.blit) +class FlxBlitRenderer extends FlxRenderer +{ + /** + * Whether the camera's buffer should be locked and unlocked during render calls. + * + * Allows you to possibly slightly optimize the rendering process IF + * you are not doing any pre-processing in your game state's draw() call. + */ + public static var useBufferLocking:Bool = false; + + /** + * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. + */ + static var trianglesSprite:Sprite = new Sprite(); + + /** + * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. + * Added for less garbage creation. + */ + static var renderPoint:FlxPoint = FlxPoint.get(); + static var renderRect:FlxRect = FlxRect.get(); + + /** + * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. + */ + static var drawVertices:Vector = new Vector(); + + @:deprecated("temp") + var buffer(get, never):BitmapData; + inline function get_buffer() return camera.viewBlit.buffer; + + @:deprecated("temp") + var _flashPoint(get, never):Point; + inline function get__flashPoint() return camera.viewBlit._flashPoint; + + @:deprecated("temp") + var _flashRect(get, never):Rectangle; + inline function get__flashRect() return camera.viewBlit._flashRect; + + @:deprecated("temp") + var _fill(get, never):BitmapData; + inline function get__fill() return camera.viewBlit._fill; + + @:deprecated("temp") + var screen(get, never):FlxSprite; + inline function get_screen() return camera.viewBlit.screen; + + @:deprecated("temp") + var _helperMatrix(get, never):FlxMatrix; + inline function get__helperMatrix() return camera.viewBlit._helperMatrix; + + @:deprecated("temp") + var _blitMatrix(get, never):FlxMatrix; + inline function get__blitMatrix() return camera.viewBlit._blitMatrix; + + @:deprecated("temp") + var _useBlitMatrix(get, never):Bool; + inline function get__useBlitMatrix() return camera.viewBlit._useBlitMatrix; + + @:deprecated("temp") + var _helperPoint(get, never):Point; + inline function get__helperPoint() return camera.viewBlit._helperPoint; + + @:deprecated("temp") + var _bounds(get, never):FlxRect; + inline function get__bounds() return camera.viewBlit._bounds; + + public function new() + { + super(); + method = BLITTING; + } + + override function clear():Void + { + camera.viewBlit.checkResize(); + + if (useBufferLocking) + { + buffer.lock(); + } + + fill(camera.bgColor, camera.useBgAlphaBlending); + screen.dirty = true; + } + + override function render():Void + { + camera.drawFX(); + + if (useBufferLocking) + { + buffer.unlock(); + } + + screen.dirty = true; + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader):Void + { + _helperMatrix.copyFrom(matrix); + + if (_useBlitMatrix) + { + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + } + else + { + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); + buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || camera.antialiasing)); + } + } + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) + { + if (pixels != null) + { + if (_useBlitMatrix) + { + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x, destPoint.y); + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + } + else + { + _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); + buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); + } + } + else if (frame != null) + { + // TODO: fix this case for zoom less than initial zoom... + frame.paint(buffer, destPoint, true); + } + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); + + if (position == null) + position = renderPoint.set(); + + var verticesLength:Int = vertices.length; + var currentVertexPosition:Int = 0; + + var tempX:Float, tempY:Float; + var i:Int = 0; + var bounds = renderRect.set(); + drawVertices.splice(0, drawVertices.length); + + while (i < verticesLength) + { + tempX = position.x + vertices[i]; + tempY = position.y + vertices[i + 1]; + + drawVertices[currentVertexPosition++] = tempX; + drawVertices[currentVertexPosition++] = tempY; + + if (i == 0) + { + bounds.set(tempX, tempY, 0, 0); + } + else + { + FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); + } + + i += 2; + } + + position.putWeak(); + + if (!cameraBounds.overlaps(bounds)) + { + drawVertices.splice(drawVertices.length - verticesLength, verticesLength); + } + else + { + trianglesSprite.graphics.clear(); + trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); + trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); + trianglesSprite.graphics.endFill(); + + // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... + if (_useBlitMatrix) + _helperMatrix.copyFrom(_blitMatrix); + else + { + _helperMatrix.identity(); + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); + } + + buffer.draw(trianglesSprite, _helperMatrix, transform); + + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + { + // TODO: add a drawDebugTriangles method + var gfx:Graphics = FlxSpriteUtil.flashGfx; + gfx.clear(); + gfx.lineStyle(1, FlxColor.BLUE, 0.5); + gfx.drawTriangles(drawVertices, indices); + buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); + } + #end + // End of TODO... + } + + bounds.put(); + } + + override function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) + { + _fill.fillRect(_flashRect, color); + buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); + } + else + { + buffer.fillRect(_flashRect, color); + } + } + + override function beginDrawDebug(?camera:FlxCamera):Void + { + super.beginDrawDebug(camera); + + FlxSpriteUtil.flashGfx.clear(); + } + + override function endDrawDebug():Void + { + camera.viewBlit.buffer.draw(FlxSpriteUtil.flashGfxSprite); + } + + #if FLX_DEBUG + override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + override public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = FlxSpriteUtil.flashGfx; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, x2); + gfx.lineTo(x2, y2); + } + #end +} diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 30a1c07607..193dbcb64a 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -27,33 +27,7 @@ import openfl.display.Graphics; import flixel.util.FlxSpriteUtil; class FlxBlitView extends FlxCameraView -{ - /** - * Whether the camera's buffer should be locked and unlocked during render calls. - * - * Allows you to possibly slightly optimize the rendering process IF - * you are not doing any pre-processing in your game state's draw() call. - */ - public static var useBufferLocking:Bool = false; - - /** - * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. - */ - static var trianglesSprite:Sprite = new Sprite(); - - /** - * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. - * Added for less garbage creation. - */ - static var renderPoint:FlxPoint = FlxPoint.get(); - - static var renderRect:FlxRect = FlxRect.get(); - - /** - * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. - */ - static var drawVertices:Vector = new Vector(); - +{ /** * Used to render buffer to screen space. * NOTE: We don't recommend modifying this directly unless you are fairly experienced. @@ -131,6 +105,7 @@ class FlxBlitView extends FlxCameraView */ var _blitMatrix:FlxMatrix = new FlxMatrix(); + // TODO: destroy var _helperMatrix:FlxMatrix = new FlxMatrix(); var _helperPoint:Point = new Point(); @@ -170,205 +145,6 @@ class FlxBlitView extends FlxCameraView _bounds = FlxDestroyUtil.put(_bounds); } - override function clear():Void - { - checkResize(); - - if (useBufferLocking) - { - buffer.lock(); - } - - fill(camera.bgColor, camera.useBgAlphaBlending); - screen.dirty = true; - } - - override function render():Void - { - camera.drawFX(); - - if (useBufferLocking) - { - buffer.unlock(); - } - - screen.dirty = true; - } - - override function beginDrawDebug():Void - { - FlxSpriteUtil.flashGfx.clear(); - } - - override function endDrawDebug(?matrix:FlxMatrix):Void - { - buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - - override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - - override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); - } - - override public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); - } - - override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, x2); - gfx.lineTo(x2, y2); - } - - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void - { - _helperMatrix.copyFrom(matrix); - - if (_useBlitMatrix) - { - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); - } - } - - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader) - { - if (pixels != null) - { - if (_useBlitMatrix) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); - buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); - } - } - else if (frame != null) - { - // TODO: fix this case for zoom less than initial zoom... - frame.paint(buffer, destPoint, true); - } - } - - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) - { - final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); - - if (position == null) - position = renderPoint.set(); - - var verticesLength:Int = vertices.length; - var currentVertexPosition:Int = 0; - - var tempX:Float, tempY:Float; - var i:Int = 0; - var bounds = renderRect.set(); - drawVertices.splice(0, drawVertices.length); - - while (i < verticesLength) - { - tempX = position.x + vertices[i]; - tempY = position.y + vertices[i + 1]; - - drawVertices[currentVertexPosition++] = tempX; - drawVertices[currentVertexPosition++] = tempY; - - if (i == 0) - { - bounds.set(tempX, tempY, 0, 0); - } - else - { - FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); - } - - i += 2; - } - - position.putWeak(); - - if (!cameraBounds.overlaps(bounds)) - { - drawVertices.splice(drawVertices.length - verticesLength, verticesLength); - } - else - { - trianglesSprite.graphics.clear(); - trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); - trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); - trianglesSprite.graphics.endFill(); - - // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... - if (_useBlitMatrix) - _helperMatrix.copyFrom(_blitMatrix); - else - { - _helperMatrix.identity(); - _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - } - - buffer.draw(trianglesSprite, _helperMatrix, transform); - - #if FLX_DEBUG - if (FlxG.debugger.drawDebug) - { - var gfx:Graphics = FlxSpriteUtil.flashGfx; - gfx.clear(); - gfx.lineStyle(1, FlxColor.BLUE, 0.5); - gfx.drawTriangles(drawVertices, indices); - buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); - } - #end - // End of TODO... - } - - bounds.put(); - } - - override function fill(color:FlxColor, blendAlpha:Bool = true) - { - if (blendAlpha) - { - _fill.fillRect(_flashRect, color); - buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); - } - else - { - buffer.fillRect(_flashRect, color); - } - } - override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx new file mode 100644 index 0000000000..5907d85f56 --- /dev/null +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -0,0 +1,179 @@ +package flixel.system.render.quad; + +import flixel.graphics.tile.FlxDrawQuadsItem; +import openfl.display.BitmapData; +import openfl.geom.Rectangle; +import openfl.geom.Point; +import openfl.display.BlendMode; +import flixel.math.FlxPoint; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxMatrix; +import openfl.geom.ColorTransform; +import flixel.system.FlxAssets.FlxShader; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.graphics.FlxGraphic; +import flixel.graphics.tile.FlxDrawBaseItem; +import openfl.display.Graphics; +import flixel.util.FlxColor; +import openfl.display.Sprite; +#if FLX_OPENGL_AVAILABLE +import lime.graphics.opengl.GL; +#end + +using flixel.util.FlxColorTransformUtil; + +@:access(flixel.FlxCamera) +@:access(flixel.system.render.quad) +class FlxQuadRenderer extends FlxRenderer +{ + @:deprecated("temp") + var flashSprite(get, never):Sprite; + function get_flashSprite():Sprite + return camera.viewQuad.flashSprite; + + @:deprecated("temp") + var canvas(get, never):Sprite; + function get_canvas():Sprite + return camera.viewQuad.canvas; + + @:deprecated("temp") + var debugLayer(get, never):Sprite; + function get_debugLayer():Sprite + return camera.viewQuad.debugLayer; + + @:deprecated("temp") + var targetGraphics(get, never):Graphics; + function get_targetGraphics():Graphics + return camera.viewQuad.targetGraphics; + + public function new() + { + super(); + method = DRAW_TILES; + } + + override function init():Void + { + if (isGL) + maxTextureSize = cast GL.getParameter(GL.MAX_TEXTURE_SIZE); + } + + override function clear():Void + { + camera.viewQuad.clearDrawStack(); + + canvas.graphics.clear(); + // Clearing camera's debug sprite + #if FLX_DEBUG + debugLayer.graphics.clear(); + #end + + fill(camera.bgColor, camera.useBgAlphaBlending); + } + + override function render():Void + { + flashSprite.filters = camera.filtersEnabled ? camera.filters : null; + + var currItem:FlxDrawBaseItem = camera.viewQuad._headOfDrawStack; + while (currItem != null) + { + currItem.render(camera); + currItem = currItem.next; + } + + camera.drawFX(); + } + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader) + { + var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = camera.viewQuad.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + #else + final drawItem:FlxDrawQuadsItem = camera.viewQuad.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #end + drawItem.addQuad(frame, matrix, transform); + } + + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) + { + camera.viewQuad._helperMatrix.identity(); + camera.viewQuad._helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); + + var isColored = (transform != null && transform.hasRGBMultipliers()); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = camera.viewQuad.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + #else + final drawItem:FlxDrawQuadsItem = camera.viewQuad.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #end + drawItem.addQuad(frame, camera.viewQuad._helperMatrix, transform); + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + final cameraBounds = camera.viewQuad._bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); + + final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); + final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); + + final drawItem = camera.viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); + } + + override function fill(color:FlxColor, blendAlpha:Bool = true):Void + { + targetGraphics.overrideBlendMode(null); + targetGraphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + targetGraphics.endFill(); + } + + #if FLX_DEBUG + override function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + override function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + override function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + override function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, x2); + gfx.lineTo(x2, y2); + } + #end + + // override function get_currentView():T + // { + // return camera.viewQuad; + // } +} diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 2c4ddfde5e..9929f93263 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -123,120 +123,6 @@ class FlxQuadView extends FlxCameraView _bounds = FlxDestroyUtil.put(_bounds); } - override function clear():Void - { - clearDrawStack(); - - canvas.graphics.clear(); - // Clearing camera's debug sprite - #if FLX_DEBUG - debugLayer.graphics.clear(); - #end - - fill(camera.bgColor, camera.useBgAlphaBlending); - } - - override function render():Void - { - flashSprite.filters = camera.filtersEnabled ? camera.filters : null; - - var currItem:FlxDrawBaseItem = _headOfDrawStack; - while (currItem != null) - { - currItem.render(camera); - currItem = currItem.next; - } - - camera.drawFX(); - } - - #if FLX_DEBUG - override function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - - override function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - final gfx = debugLayer.graphics; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); - } - - override function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - final gfx = debugLayer.graphics; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); - } - - override function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, x2); - gfx.lineTo(x2, y2); - } - #end - - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader) - { - var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); - #else - final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #end - drawItem.addQuad(frame, matrix, transform); - } - - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); - - var isColored = (transform != null && transform.hasRGBMultipliers()); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); - #else - final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #end - drawItem.addQuad(frame, _helperMatrix, transform); - } - - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) - { - final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); - - final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); - final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); - - final drawItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); - } - - override function fill(color:FlxColor, blendAlpha:Bool = true):Void - { - targetGraphics.overrideBlendMode(null); - targetGraphics.beginFill(color.rgb, color.alphaFloat); - // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, - // which could appear while cameras fading - targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - targetGraphics.endFill(); - } - override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; From 08b09932721e569e0a582b88b0915a9f699f0b3b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Fri, 23 Jan 2026 23:23:53 +0100 Subject: [PATCH 15/72] some polishing in progress --- flixel/FlxCamera.hx | 53 ++--- flixel/FlxG.hx | 2 - flixel/system/render/FlxCameraView.hx | 21 +- flixel/system/render/FlxRenderer.hx | 38 +-- flixel/system/render/blit/FlxBlitRenderer.hx | 231 +++++++++---------- flixel/system/render/blit/FlxBlitView.hx | 48 +--- flixel/system/render/quad/FlxQuadRenderer.hx | 119 +++++----- flixel/system/render/quad/FlxQuadView.hx | 33 +-- 8 files changed, 230 insertions(+), 315 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index f38d91ef95..cd67801b0c 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -96,8 +96,7 @@ class FlxCamera extends FlxBasic public var totalScaleY(default, null):Float; /** - * Render view for this camera. - * All rendering related commands (like draw rectangle or fill camera view with specified color) are handled by this object. + * Holds various rendering related objects */ public var view(default, null):FlxCameraView; @@ -220,17 +219,15 @@ class FlxCamera extends FlxBasic * * Its position is modified by `updateFlashSpritePosition()` which is called every frame. */ - @:deprecated("flashSprite is deprecated, use camera.viewQuad.flashSprite/camera.viewBlit.flashSprite, instead") + @:deprecated("flashSprite is deprecated, use camera.display, instead") public var flashSprite(get, set):Sprite; - inline function set_flashSprite(value:Sprite):Sprite + inline function set_flashSprite(value:Sprite):Sprite { var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; return sprite = value; } - inline function get_flashSprite():Sprite - { - return FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; - } + + inline function get_flashSprite():Sprite return cast view.display; /** * Whether the positions of the objects rendered on this camera are rounded. @@ -420,10 +417,10 @@ class FlxCamera extends FlxBasic * Its coordinates are always `(0,0)`, where camera's buffer filling should start. * Do not modify it unless you know what are you doing. */ - @:deprecated("_flashPoint is deprecated, use camera.viewBlit._flashPoint, instead") + @:deprecated("_flashPoint is deprecated, use FlxBlitRenderer._flashPoint, instead") var _flashPoint:Point = new Point(); - inline function get__flashPoint():Point return viewBlit._flashPoint; - inline function set__flashPoint(value:Point) return viewBlit._flashPoint = value; + inline function get__flashPoint():Point return cast (FlxG.renderer, FlxBlitRenderer)._flashPoint; + inline function set__flashPoint(value:Point) return cast (FlxG.renderer, FlxBlitRenderer)._flashPoint = value; /** * Internal, used for positioning camera's `flashSprite` on screen. @@ -569,16 +566,15 @@ class FlxCamera extends FlxBasic /** * Helper rect for `drawTriangles()` visibility checks */ - @:deprecated("_bounds is deprecated, use camera.viewQuad._bounds/camera.viewBlit._bounds, instead") + @:deprecated("_bounds is deprecated, use FlxBlitRenderer/FlxQuadRender._bounds, instead") var _bounds(get, set):FlxRect; inline function get__bounds():FlxRect { - return FlxG.renderTile ? viewQuad._bounds : viewBlit._bounds; + return untyped FlxG.renderer._bounds; } inline function set__bounds(value:FlxRect):FlxRect { - var bounds = FlxG.renderTile ? viewQuad._bounds : viewBlit._bounds; - return bounds = value; + return untyped FlxG.renderer._bounds = value; } /** @@ -605,22 +601,27 @@ class FlxCamera extends FlxBasic inline function get_debugLayer():Sprite return viewQuad.debugLayer; #end - @:deprecated("_helperMatrix is deprecated, use camera.viewQuad._helperMatrix/camera.viewBlit._helperMatrix, instead") + @:deprecated("_helperMatrix is deprecated, use FlxBlitRenderer/FlxQuadRenderer._helperMatrix, instead") var _helperMatrix(get, set):FlxMatrix; inline function get__helperMatrix():FlxMatrix { - return FlxG.renderTile ? viewQuad._helperMatrix : viewBlit._helperMatrix; + return untyped FlxG.renderer._helperMatrix; } inline function set__helperMatrix(value:FlxMatrix):FlxMatrix { - var mat = FlxG.renderTile ? viewQuad._helperMatrix : viewBlit._helperMatrix; - return mat = value; + return untyped FlxG.renderer._helperMatrix = value; } - @:deprecated("_helperPoint is deprecated, use camera.viewBlit._helperPoint, instead") + @:deprecated("_helperPoint is deprecated, use FlxBlitRenderer._helperPoint, instead") var _helperPoint(get, set):Point; - inline function get__helperPoint():Point return viewBlit._helperPoint; - inline function set__helperPoint(value:Point):Point return viewBlit._helperPoint = value; + inline function get__helperPoint():Point + { + return cast(FlxG.renderer, FlxBlitRenderer)._helperPoint; + } + inline function set__helperPoint(value:Point):Point + { + return cast(FlxG.renderer, FlxBlitRenderer)._helperPoint = value; + } /** * Currently used draw stack item @@ -673,7 +674,7 @@ class FlxCamera extends FlxBasic /** * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. */ - @:deprecated("drawVertices is deprecated, use FlxBlitView.drawVertices, instead") + @:deprecated("drawVertices is deprecated, use FlxBlitRenderer.drawVertices, instead") static var drawVertices(get, set):Vector; static inline function get_drawVertices():Vector return FlxBlitRenderer.drawVertices; static inline function set_drawVertices(value:Vector):Vector return FlxBlitRenderer.drawVertices = value; @@ -681,7 +682,7 @@ class FlxCamera extends FlxBasic /** * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ - @:deprecated("trianglesSprite is deprecated, use FlxBlitView.trianglesSprite, instead") + @:deprecated("trianglesSprite is deprecated, use FlxBlitRenderer.trianglesSprite, instead") static var trianglesSprite(get, set):Sprite; static inline function get_trianglesSprite():Sprite return FlxBlitRenderer.trianglesSprite; static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitRenderer.trianglesSprite = value; @@ -690,12 +691,12 @@ class FlxCamera extends FlxBasic * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. * Added for less garbage creation. */ - @:deprecated("renderPoint is deprecated, use FlxBlitView.renderPoint, instead") + @:deprecated("renderPoint is deprecated, use FlxBlitRenderer.renderPoint, instead") static var renderPoint(get, set):FlxPoint; static inline function get_renderPoint():FlxPoint return FlxBlitRenderer.renderPoint; static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitRenderer.renderPoint = value; - @:deprecated("renderRect is deprecated, use FlxBlitView.renderRect, instead") + @:deprecated("renderRect is deprecated, use FlxBlitRenderer.renderRect, instead") static var renderRect(get, set):FlxRect; static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 493c381123..dacb389b52 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -609,8 +609,6 @@ class FlxG static function initRenderMethod():Void { renderer = FlxRenderer.create(); - renderer.init(); - FlxObject.defaultPixelPerfectPosition = FlxG.renderer.method == BLITTING; } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 476e1b154b..9d0fe92429 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -1,24 +1,13 @@ package flixel.system.render; -import flixel.math.FlxRect; import openfl.display.DisplayObjectContainer; +import openfl.display.DisplayObject; +import flixel.math.FlxRect; import flixel.FlxG; import flixel.FlxCamera; import flixel.util.FlxDestroyUtil; -import flixel.graphics.FlxGraphic; -import flixel.system.FlxAssets.FlxShader; -import flixel.graphics.frames.FlxFrame; import flixel.math.FlxPoint; -import flixel.math.FlxMatrix; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; import flixel.util.FlxColor; -import openfl.filters.BitmapFilter; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.display.BlendMode; -import openfl.display.DisplayObject; -import openfl.display.BitmapData; /** * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects @@ -47,7 +36,7 @@ class FlxCameraView implements IFlxDestroyable * This object is added to the display tree. */ public var display(get, never):DisplayObjectContainer; - + /** * The parent camera for this view. */ @@ -90,6 +79,8 @@ class FlxCameraView implements IFlxDestroyable _flashOffset = FlxDestroyUtil.put(_flashOffset); } + public function offsetView(x:Float, y:Float):Void {} + function updateScale():Void { camera.calcMarginX(); @@ -106,8 +97,6 @@ class FlxCameraView implements IFlxDestroyable _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; } - public function offsetView(x:Float, y:Float):Void {} - function updateScrollRect():Void {} /** diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 6c887ce27e..4b70280998 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -1,18 +1,18 @@ package flixel.system.render; -import flixel.util.FlxDestroyUtil.IFlxDestroyable; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.math.FlxMatrix; import flixel.math.FlxPoint; -import openfl.geom.Point; -import openfl.geom.Rectangle; import flixel.system.FlxAssets.FlxShader; +import flixel.util.FlxColor; +import flixel.util.FlxDestroyUtil.IFlxDestroyable; import openfl.display.BitmapData; -import openfl.geom.ColorTransform; import openfl.display.BlendMode; -import flixel.math.FlxMatrix; -import flixel.util.FlxColor; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; -import flixel.graphics.frames.FlxFrame; -import flixel.graphics.FlxGraphic; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; /** * A `FlxRenderer` is the base class for all rendering functionality. @@ -64,7 +64,7 @@ class FlxRenderer implements IFlxDestroyable @:noCompletion inline function get_isGL():Bool { #if FLX_OPENGL_AVAILABLE - return isHardware && method == DRAW_TILES; + return isHardware && method != BLITTING; #else return false; #end @@ -84,18 +84,6 @@ class FlxRenderer implements IFlxDestroyable */ public var camera(default, null):FlxCamera; - /** - * Shortcut to `currentCamera.view`. - * Renderer implementations may override this to cast the return value to the - * corresponding type for the implementation. - */ - // public var currentView(get, never):FlxCameraView; - // @:noCompletion function get_currentView():T - // { - // return currentCamera.view; - // } - - public function new() {} public function destroy():Void @@ -103,12 +91,6 @@ class FlxRenderer implements IFlxDestroyable camera = null; } - /** - * Called internally when it's safe to initialize rendering related properties. - */ - @:allow(flixel.FlxG) - function init():Void {} - // ------------------------ RENDERING ------------------------ /** diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 11ebd38d02..03d4840ad2 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -1,138 +1,135 @@ package flixel.system.render.blit; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; import flixel.graphics.tile.FlxDrawTrianglesItem; -import openfl.display.Graphics; -import openfl.display.BitmapData; -import openfl.geom.Rectangle; -import openfl.geom.Point; -import openfl.display.BlendMode; -import openfl.display.Sprite; -import openfl.Vector; +import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; +import flixel.system.FlxAssets.FlxShader; import flixel.util.FlxColor; +import flixel.util.FlxDestroyUtil; import flixel.util.FlxSpriteUtil; -import flixel.graphics.frames.FlxFrame; -import flixel.math.FlxMatrix; +import openfl.Vector; +import openfl.display.BitmapData; +import openfl.display.BlendMode; +import openfl.display.Graphics; +import openfl.display.Sprite; import openfl.geom.ColorTransform; -import flixel.system.FlxAssets.FlxShader; -import flixel.graphics.FlxGraphic; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import openfl.geom.Point; +import openfl.geom.Rectangle; @:access(flixel.FlxCamera) @:access(flixel.system.render.blit) class FlxBlitRenderer extends FlxRenderer { - /** - * Whether the camera's buffer should be locked and unlocked during render calls. + /** + * Whether the camera's view.buffer should be locked and unlocked during render calls. * * Allows you to possibly slightly optimize the rendering process IF * you are not doing any pre-processing in your game state's draw() call. + * + * This property only has effects when targeting Flash. */ public static var useBufferLocking:Bool = false; - - /** - * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. + + /** + * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's view.buffer. */ static var trianglesSprite:Sprite = new Sprite(); /** - * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. + * Internal variables, used in blit render mode to draw trianglesSprite on camera's view.buffer. * Added for less garbage creation. */ static var renderPoint:FlxPoint = FlxPoint.get(); + static var renderRect:FlxRect = FlxRect.get(); /** * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. */ static var drawVertices:Vector = new Vector(); - - @:deprecated("temp") - var buffer(get, never):BitmapData; - inline function get_buffer() return camera.viewBlit.buffer; - - @:deprecated("temp") - var _flashPoint(get, never):Point; - inline function get__flashPoint() return camera.viewBlit._flashPoint; - - @:deprecated("temp") - var _flashRect(get, never):Rectangle; - inline function get__flashRect() return camera.viewBlit._flashRect; - - @:deprecated("temp") - var _fill(get, never):BitmapData; - inline function get__fill() return camera.viewBlit._fill; - - @:deprecated("temp") - var screen(get, never):FlxSprite; - inline function get_screen() return camera.viewBlit.screen; - - @:deprecated("temp") - var _helperMatrix(get, never):FlxMatrix; - inline function get__helperMatrix() return camera.viewBlit._helperMatrix; - - @:deprecated("temp") - var _blitMatrix(get, never):FlxMatrix; - inline function get__blitMatrix() return camera.viewBlit._blitMatrix; - - @:deprecated("temp") - var _useBlitMatrix(get, never):Bool; - inline function get__useBlitMatrix() return camera.viewBlit._useBlitMatrix; - - @:deprecated("temp") - var _helperPoint(get, never):Point; - inline function get__helperPoint() return camera.viewBlit._helperPoint; - - @:deprecated("temp") - var _bounds(get, never):FlxRect; - inline function get__bounds() return camera.viewBlit._bounds; - - public function new() - { - super(); - method = BLITTING; - } - - override function clear():Void + + /** + * Helper rect for `drawTriangles()` visibility checks + */ + var _bounds:FlxRect = FlxRect.get(); + + var _helperMatrix:FlxMatrix = new FlxMatrix(); + var _helperPoint:Point = new Point(); + + /** + * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: + * Its coordinates are always `(0,0)`, where camera's buffer filling should start. + * Do not modify it unless you know what are you doing. + */ + var _flashPoint:Point = new Point(); + + /** + * Convenience shortcut for `camera.viewBlit` + */ + var view(get, never):FlxBlitView; + + @:noCompletion inline function get_view():FlxBlitView + return camera.viewBlit; + + public function new() { - camera.viewBlit.checkResize(); + super(); + method = BLITTING; + maxTextureSize = -1; + } + + override function destroy():Void + { + super.destroy(); + _bounds = FlxDestroyUtil.put(_bounds); + _helperMatrix = null; + _helperPoint = null; + _flashPoint = null; + } + + override function clear():Void + { + view.checkResize(); if (useBufferLocking) { - buffer.lock(); + view.buffer.lock(); } fill(camera.bgColor, camera.useBgAlphaBlending); - screen.dirty = true; + view.screen.dirty = true; } - - override function render():Void + + override function render():Void { camera.drawFX(); if (useBufferLocking) { - buffer.unlock(); + view.buffer.unlock(); } - screen.dirty = true; + view.screen.dirty = true; } - - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void + + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader):Void { _helperMatrix.copyFrom(matrix); - if (_useBlitMatrix) + if (view._useBlitMatrix) { - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + _helperMatrix.concat(view._blitMatrix); + view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); } else { _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || camera.antialiasing)); + view.buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || camera.antialiasing)); } } @@ -141,24 +138,24 @@ class FlxBlitRenderer extends FlxRenderer { if (pixels != null) { - if (_useBlitMatrix) + if (view._useBlitMatrix) { _helperMatrix.identity(); _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + _helperMatrix.concat(view._blitMatrix); + view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); } else { _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); - buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); + view.buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); } } else if (frame != null) { // TODO: fix this case for zoom less than initial zoom... - frame.paint(buffer, destPoint, true); + frame.paint(view.buffer, destPoint, true); } } @@ -212,25 +209,25 @@ class FlxBlitRenderer extends FlxRenderer trianglesSprite.graphics.endFill(); // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... - if (_useBlitMatrix) - _helperMatrix.copyFrom(_blitMatrix); + if (view._useBlitMatrix) + _helperMatrix.copyFrom(view._blitMatrix); else { _helperMatrix.identity(); _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); } - buffer.draw(trianglesSprite, _helperMatrix, transform); + view.buffer.draw(trianglesSprite, _helperMatrix, transform); #if FLX_DEBUG if (FlxG.debugger.drawDebug) { - // TODO: add a drawDebugTriangles method + // TODO: add a drawDebugTriangles method var gfx:Graphics = FlxSpriteUtil.flashGfx; gfx.clear(); gfx.lineStyle(1, FlxColor.BLUE, 0.5); gfx.drawTriangles(drawVertices, indices); - buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); + view.buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); } #end // End of TODO... @@ -238,40 +235,40 @@ class FlxBlitRenderer extends FlxRenderer bounds.put(); } - - override function fill(color:FlxColor, blendAlpha:Bool = true) - { - if (blendAlpha) + + override function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) { - _fill.fillRect(_flashRect, color); - buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); + view._fill.fillRect(view._flashRect, color); + view.buffer.copyPixels(view._fill, view._flashRect, _flashPoint, null, null, blendAlpha); } else { - buffer.fillRect(_flashRect, color); + view.buffer.fillRect(view._flashRect, color); } - } - - override function beginDrawDebug(?camera:FlxCamera):Void - { - super.beginDrawDebug(camera); - - FlxSpriteUtil.flashGfx.clear(); - } - - override function endDrawDebug():Void - { - camera.viewBlit.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - - #if FLX_DEBUG - override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + } + + override function beginDrawDebug(?camera:FlxCamera):Void + { + super.beginDrawDebug(camera); + + FlxSpriteUtil.flashGfx.clear(); + } + + override function endDrawDebug():Void + { + view.buffer.draw(FlxSpriteUtil.flashGfxSprite); + } + + #if FLX_DEBUG + override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void { final gfx = FlxSpriteUtil.flashGfx; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); gfx.drawRect(x, y, width, height); } - + override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void { final gfx = FlxSpriteUtil.flashGfx; @@ -280,7 +277,7 @@ class FlxBlitRenderer extends FlxRenderer gfx.drawRect(x, y, width, height); gfx.endFill(); } - + override public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { final gfx = FlxSpriteUtil.flashGfx; @@ -288,7 +285,7 @@ class FlxBlitRenderer extends FlxRenderer gfx.drawCircle(x, y, radius); gfx.endFill(); } - + override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void { final gfx = FlxSpriteUtil.flashGfx; @@ -296,5 +293,5 @@ class FlxBlitRenderer extends FlxRenderer gfx.moveTo(x1, x2); gfx.lineTo(x2, y2); } - #end + #end } diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 193dbcb64a..d35df84630 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -1,33 +1,23 @@ package flixel.system.render.blit; -import flixel.math.FlxRect; -import openfl.display.Bitmap; -import openfl.display.DisplayObjectContainer; -import flixel.system.render.FlxCameraView; -import flixel.FlxG; import flixel.FlxCamera; -import flixel.util.FlxDestroyUtil; +import flixel.FlxG; import flixel.graphics.FlxGraphic; -import flixel.system.FlxAssets.FlxShader; -import flixel.graphics.frames.FlxFrame; -import flixel.math.FlxPoint; +import flixel.math.FlxRect; import flixel.math.FlxMatrix; -import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.math.FlxPoint; +import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; -import openfl.filters.BitmapFilter; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.display.BlendMode; -import openfl.display.DisplayObject; +import flixel.util.FlxDestroyUtil; +import openfl.display.Bitmap; import openfl.display.BitmapData; +import openfl.display.DisplayObjectContainer; import openfl.display.Sprite; -import openfl.Vector; -import openfl.display.Graphics; -import flixel.util.FlxSpriteUtil; +import openfl.geom.Rectangle; +import openfl.geom.ColorTransform; class FlxBlitView extends FlxCameraView -{ +{ /** * Used to render buffer to screen space. * NOTE: We don't recommend modifying this directly unless you are fairly experienced. @@ -68,13 +58,6 @@ class FlxBlitView extends FlxCameraView */ var _flashRect:Rectangle; - /** - * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: - * Its coordinates are always `(0,0)`, where camera's buffer filling should start. - * Do not modify it unless you know what are you doing. - */ - var _flashPoint:Point = new Point(); - /** * Internal, used to render buffer to screen space. Used it blit render mode only. * This Bitmap used for rendering camera's buffer (`_flashBitmap.bitmapData = buffer;`) @@ -89,11 +72,6 @@ class FlxBlitView extends FlxCameraView */ var _fill:BitmapData; - /** - * Helper rect for `drawTriangles()` visibility checks - */ - var _bounds:FlxRect = FlxRect.get(); - /** * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. */ @@ -105,10 +83,6 @@ class FlxBlitView extends FlxCameraView */ var _blitMatrix:FlxMatrix = new FlxMatrix(); - // TODO: destroy - var _helperMatrix:FlxMatrix = new FlxMatrix(); - var _helperPoint:Point = new Point(); - @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) { @@ -141,8 +115,6 @@ class FlxBlitView extends FlxCameraView flashSprite = null; _scrollRect = null; _flashRect = null; - _flashPoint = null; - _bounds = FlxDestroyUtil.put(_bounds); } override function offsetView(x:Float, y:Float):Void diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 5907d85f56..7f4cfc46ee 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -1,21 +1,21 @@ package flixel.system.render.quad; -import flixel.graphics.tile.FlxDrawQuadsItem; -import openfl.display.BitmapData; -import openfl.geom.Rectangle; import openfl.geom.Point; -import openfl.display.BlendMode; -import flixel.math.FlxPoint; +import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; +import flixel.graphics.tile.FlxDrawBaseItem; +import flixel.graphics.tile.FlxDrawQuadsItem; +import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; import flixel.math.FlxMatrix; -import openfl.geom.ColorTransform; +import flixel.math.FlxPoint; +import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; -import flixel.graphics.FlxGraphic; -import flixel.graphics.tile.FlxDrawBaseItem; -import openfl.display.Graphics; import flixel.util.FlxColor; -import openfl.display.Sprite; +import flixel.util.FlxDestroyUtil; +import openfl.display.BitmapData; +import openfl.display.BlendMode; +import openfl.geom.ColorTransform; +import openfl.geom.Rectangle; #if FLX_OPENGL_AVAILABLE import lime.graphics.opengl.GL; #end @@ -26,46 +26,44 @@ using flixel.util.FlxColorTransformUtil; @:access(flixel.system.render.quad) class FlxQuadRenderer extends FlxRenderer { - @:deprecated("temp") - var flashSprite(get, never):Sprite; - function get_flashSprite():Sprite - return camera.viewQuad.flashSprite; - - @:deprecated("temp") - var canvas(get, never):Sprite; - function get_canvas():Sprite - return camera.viewQuad.canvas; - - @:deprecated("temp") - var debugLayer(get, never):Sprite; - function get_debugLayer():Sprite - return camera.viewQuad.debugLayer; - - @:deprecated("temp") - var targetGraphics(get, never):Graphics; - function get_targetGraphics():Graphics - return camera.viewQuad.targetGraphics; + /** + * Convenience shortcut for `camera.viewQuad` + */ + var view(get, never):FlxQuadView; + @:noCompletion inline function get_view():FlxQuadView + return camera.viewQuad; + + var _helperMatrix:FlxMatrix = new FlxMatrix(); + + /** + * Helper rect for `drawTriangles()` visibility checks + */ + var _bounds:FlxRect = FlxRect.get(); public function new() { super(); method = DRAW_TILES; - } - override function init():Void - { if (isGL) maxTextureSize = cast GL.getParameter(GL.MAX_TEXTURE_SIZE); } + override function destroy():Void + { + super.destroy(); + _bounds = FlxDestroyUtil.put(_bounds); + _helperMatrix = null; + } + override function clear():Void { - camera.viewQuad.clearDrawStack(); + view.clearDrawStack(); - canvas.graphics.clear(); - // Clearing camera's debug sprite + view.canvas.graphics.clear(); #if FLX_DEBUG - debugLayer.graphics.clear(); + // Clearing camera's debug sprite + view.debugLayer.graphics.clear(); #end fill(camera.bgColor, camera.useBgAlphaBlending); @@ -73,9 +71,9 @@ class FlxQuadRenderer extends FlxRenderer override function render():Void { - flashSprite.filters = camera.filtersEnabled ? camera.filters : null; + view.flashSprite.filters = camera.filtersEnabled ? camera.filters : null; - var currItem:FlxDrawBaseItem = camera.viewQuad._headOfDrawStack; + var currItem:FlxDrawBaseItem = view._headOfDrawStack; while (currItem != null) { currItem.render(camera); @@ -85,16 +83,16 @@ class FlxQuadRenderer extends FlxRenderer camera.drawFX(); } - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader) + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader) { var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = camera.viewQuad.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + final drawItem:FlxDrawTrianglesItem = view.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else - final drawItem:FlxDrawQuadsItem = camera.viewQuad.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + final drawItem:FlxDrawQuadsItem = view.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); #end drawItem.addQuad(frame, matrix, transform); } @@ -102,53 +100,53 @@ class FlxQuadRenderer extends FlxRenderer override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { - camera.viewQuad._helperMatrix.identity(); - camera.viewQuad._helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); var isColored = (transform != null && transform.hasRGBMultipliers()); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = camera.viewQuad.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + final drawItem:FlxDrawTrianglesItem = view.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else - final drawItem:FlxDrawQuadsItem = camera.viewQuad.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + final drawItem:FlxDrawQuadsItem = view.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); #end - drawItem.addQuad(frame, camera.viewQuad._helperMatrix, transform); + drawItem.addQuad(frame, _helperMatrix, transform); } override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { - final cameraBounds = camera.viewQuad._bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); + final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); - final drawItem = camera.viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + final drawItem = view.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); } override function fill(color:FlxColor, blendAlpha:Bool = true):Void { - targetGraphics.overrideBlendMode(null); - targetGraphics.beginFill(color.rgb, color.alphaFloat); + view.targetGraphics.overrideBlendMode(null); + view.targetGraphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading - targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - targetGraphics.endFill(); + view.targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + view.targetGraphics.endFill(); } #if FLX_DEBUG override function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void { - final gfx = debugLayer.graphics; + final gfx = view.debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); gfx.drawRect(x, y, width, height); } override function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void { - final gfx = debugLayer.graphics; + final gfx = view.debugLayer.graphics; gfx.lineStyle(); gfx.beginFill(color.rgb, color.alphaFloat); gfx.drawRect(x, y, width, height); @@ -157,7 +155,7 @@ class FlxQuadRenderer extends FlxRenderer override function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void { - final gfx = debugLayer.graphics; + final gfx = view.debugLayer.graphics; gfx.beginFill(color.rgb, color.alphaFloat); gfx.drawCircle(x, y, radius); gfx.endFill(); @@ -165,15 +163,10 @@ class FlxQuadRenderer extends FlxRenderer override function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void { - final gfx = debugLayer.graphics; + final gfx = view.debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); gfx.moveTo(x1, x2); gfx.lineTo(x2, y2); } #end - - // override function get_currentView():T - // { - // return camera.viewQuad; - // } } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 9929f93263..5d8713562b 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -1,29 +1,21 @@ package flixel.system.render.quad; -import openfl.display.Graphics; -import flixel.math.FlxRect; -import openfl.display.DisplayObjectContainer; -import flixel.system.render.FlxCameraView; -import flixel.FlxG; import flixel.FlxCamera; -import flixel.util.FlxDestroyUtil; +import flixel.FlxG; import flixel.graphics.FlxGraphic; -import flixel.system.FlxAssets.FlxShader; -import flixel.graphics.frames.FlxFrame; -import flixel.math.FlxPoint; -import flixel.math.FlxMatrix; import flixel.graphics.tile.FlxDrawBaseItem; import flixel.graphics.tile.FlxDrawQuadsItem; import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.system.FlxAssets.FlxShader; +import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; -import openfl.filters.BitmapFilter; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; +import flixel.util.FlxDestroyUtil; import openfl.display.BlendMode; -import openfl.display.DisplayObject; -import openfl.display.BitmapData; +import openfl.display.DisplayObjectContainer; +import openfl.display.Graphics; import openfl.display.Sprite; +import openfl.geom.ColorTransform; +import openfl.geom.Rectangle; using flixel.util.FlxColorTransformUtil; @@ -63,13 +55,6 @@ class FlxQuadView extends FlxCameraView * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ var _scrollRect:Sprite = new Sprite(); - - /** - * Helper rect for `drawTriangles()` visibility checks - */ - var _bounds:FlxRect = FlxRect.get(); - - var _helperMatrix:FlxMatrix = new FlxMatrix(); var targetGraphics:Graphics; @@ -119,8 +104,6 @@ class FlxQuadView extends FlxCameraView flashSprite = null; _scrollRect = null; - _helperMatrix = null; - _bounds = FlxDestroyUtil.put(_bounds); } override function offsetView(x:Float, y:Float):Void From af8a67a5b35ebdb5ea7c11bd24378e1b84c83e22 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Fri, 23 Jan 2026 23:25:02 +0100 Subject: [PATCH 16/72] oops --- flixel/system/render/blit/FlxBlitRenderer.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 03d4840ad2..95f21fdd37 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -25,7 +25,7 @@ import openfl.geom.Rectangle; class FlxBlitRenderer extends FlxRenderer { /** - * Whether the camera's view.buffer should be locked and unlocked during render calls. + * Whether the camera's buffer should be locked and unlocked during render calls. * * Allows you to possibly slightly optimize the rendering process IF * you are not doing any pre-processing in your game state's draw() call. @@ -35,12 +35,12 @@ class FlxBlitRenderer extends FlxRenderer public static var useBufferLocking:Bool = false; /** - * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's view.buffer. + * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. */ static var trianglesSprite:Sprite = new Sprite(); /** - * Internal variables, used in blit render mode to draw trianglesSprite on camera's view.buffer. + * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. * Added for less garbage creation. */ static var renderPoint:FlxPoint = FlxPoint.get(); From 5cf309cab31cdebd58f5b98f2d65f1133930c707 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sat, 24 Jan 2026 14:33:28 +0100 Subject: [PATCH 17/72] fixes and a whole lot of docs --- flixel/FlxCamera.hx | 54 ++------ flixel/FlxObject.hx | 13 +- flixel/FlxSprite.hx | 6 +- flixel/system/FlxBGSprite.hx | 4 +- flixel/system/render/FlxRenderer.hx | 124 +++++++++++++++++-- flixel/system/render/quad/FlxQuadRenderer.hx | 1 + flixel/text/FlxBitmapText.hx | 4 +- flixel/tile/FlxTilemapBuffer.hx | 6 +- flixel/ui/FlxBar.hx | 4 +- 9 files changed, 146 insertions(+), 70 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index cd67801b0c..7d492bd6ff 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -725,40 +725,7 @@ class FlxCamera extends FlxBasic viewQuad.clearDrawStack(); } - public function beginDrawDebug():Void - { - // view.beginDrawDebug(); - } - - public function endDrawDebug(?matrix:FlxMatrix):Void - { - // view.endDrawDebug(matrix); - } - - public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - // FlxG.renderer.begin(this); - // view.drawDebugRect(x, y, width, height, color, thickness); - } - - public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - // FlxG.renderer.begin(this); - // view.drawDebugFilledRect(x, y, width, height, color); - } - - public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - // FlxG.renderer.begin(this); - // view.drawDebugFilledCircle(x, y, radius, color); - } - - public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - // FlxG.renderer.begin(this); - // view.drawDebugLine(x1, y1, x2, y2, color, thickness); - } - + @:deprecated("camera.drawPixels() is deprecated, use FlxG.renderer.drawPixels() instead.") public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { @@ -766,6 +733,7 @@ class FlxCamera extends FlxBasic FlxG.renderer.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); } + @:deprecated("camera.copyPixels() is deprecated, use FlxG.renderer.copyPixels() instead.") public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { @@ -773,6 +741,7 @@ class FlxCamera extends FlxBasic FlxG.renderer.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); } + @:deprecated("camera.drawTriangles() is deprecated, use FlxG.renderer.drawTriangles() instead.") public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void { @@ -1388,23 +1357,16 @@ class FlxCamera extends FlxBasic * @param color The color to fill with in `0xAARRGGBB` hex format. * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. */ - @:deprecated("The 4-arg fill(color, blendAlpha, fxAlpha, ?graphics) is deprecated, use the 2-arg fill(color, blendAlpha) instead.") - overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void + @:deprecated("camera.fill() is deprecated, use FlxG.renderer.fill() instead.") + public function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void { color.alphaFloat = fxAlpha; FlxG.renderer.begin(this); - FlxG.renderer.fill(color, blendAlpha); - } - /** - * Fill the camera with the specified color. - * - * @param color The color to fill with in `0xAARRGGBB` hex format. - * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. - */ - overload public inline extern function fill(color:FlxColor, blendAlpha:Bool = true):Void - { + if (viewQuad != null && graphics != null) + viewQuad.targetGraphics = graphics; + FlxG.renderer.fill(color, blendAlpha); } diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 4647ac5cf8..cd38db88f1 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1287,6 +1287,7 @@ class FlxObject extends FlxBasic for (camera in getCamerasLegacy()) { + FlxG.renderer.begin(camera); drawDebugOnCamera(camera); if (drawPath) @@ -1318,9 +1319,7 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - camera.beginDrawDebug(); drawDebugBoundingBox(camera, rect, allowCollisions); - camera.endDrawDebug(); } } @@ -1365,13 +1364,13 @@ class FlxObject extends FlxBasic overload extern inline function drawDebugBoundingBoxColor(camera:FlxCamera, rect:FlxRect, color:FlxColor) { - camera.drawDebugRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color); + FlxG.renderer.drawDebugRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color); } - @:deprecated("use object.beginDrawDebug(camera) is deprecated, camera.beginDrawDebug() instead") + @:deprecated("use object.beginDrawDebug(camera) is deprecated, FlxG.renderer.beginDrawDebug(camera) instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { - camera.beginDrawDebug(); + FlxG.renderer.beginDrawDebug(camera); if (FlxG.renderBlit) { @@ -1383,10 +1382,10 @@ class FlxObject extends FlxBasic } } - @:deprecated("use object.endDrawDebug(camera) is deprecated, camera.endDrawDebug() instead") + @:deprecated("use object.endDrawDebug(camera) is deprecated, FlxG.renderer.endDrawDebug() instead") inline function endDrawDebug(camera:FlxCamera) { - camera.endDrawDebug(); + FlxG.renderer.endDrawDebug(); } #end diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 3894e93e40..c53bebc7cb 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -963,6 +963,8 @@ class FlxSprite extends FlxObject for (camera in getCamerasLegacy()) { + FlxG.renderer.begin(camera); + if (!camera.visible || !camera.exists || !isOnScreen(camera)) continue; @@ -1009,7 +1011,7 @@ class FlxSprite extends FlxObject _point.floor(); _point.copyTo(_flashPoint); - camera.copyPixels(_frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); + FlxG.renderer.copyPixels(_frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); } @:noCompletion @@ -1025,7 +1027,7 @@ class FlxSprite extends FlxObject final matrix = drawComplexMatrix; // TODO: Just use local? prepareComplexMatrix(matrix, frame, camera); - camera.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); + FlxG.renderer.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); } function prepareComplexMatrix(matrix:FlxMatrix, frame:FlxFrame, camera:FlxCamera) diff --git a/flixel/system/FlxBGSprite.hx b/flixel/system/FlxBGSprite.hx index b5608493ab..b3928322dc 100644 --- a/flixel/system/FlxBGSprite.hx +++ b/flixel/system/FlxBGSprite.hx @@ -28,10 +28,12 @@ class FlxBGSprite extends FlxSprite continue; } + FlxG.renderer.begin(camera); + _matrix.identity(); _matrix.scale(camera.viewWidth + 1, camera.viewHeight + 1); _matrix.translate(camera.viewMarginLeft, camera.viewMarginTop); - camera.drawPixels(frame, _matrix, colorTransform); + FlxG.renderer.drawPixels(frame, _matrix, colorTransform); #if FLX_DEBUG FlxBasic.visibleCount++; diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 4b70280998..c9b2315e6c 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -15,8 +15,16 @@ import openfl.geom.Point; import openfl.geom.Rectangle; /** - * A `FlxRenderer` is the base class for all rendering functionality. + * `FlxRenderer` is the base class for all rendering functionality. * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. + * + * You can access a global renderer instance via `FlxG.renderer`. + * + * The `FlxRenderer` API replaces the previous renderer implementation in `FlxCamera`. + * Because it's not tied to a camera, it also works slightly differently. + * Before any drawing commands are executed, `FlxG.renderer.begin(camera);` is called to use the camera as a render target. + * This is called internally by Flixel during a sprite's draw phase, so you shouldn't worry about calling it yourself unless + * you have a reason to. */ class FlxRenderer implements IFlxDestroyable { @@ -29,7 +37,7 @@ class FlxRenderer implements IFlxDestroyable * Creates a renderer instance, based on the used rendering backend. * This function is dynamic, which means that you can change the return value yourself. * - * @return FlxRenderer + * @return A `FlxRenderer` instance. */ public static dynamic function create():FlxRenderer { @@ -104,9 +112,6 @@ class FlxRenderer implements IFlxDestroyable */ public function begin(camera:FlxCamera):Void { - if (this.camera == camera) - return; - this.camera = camera; } @@ -120,15 +125,62 @@ class FlxRenderer implements IFlxDestroyable */ public function render():Void {} + /** + * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param matrix The transformation matrix to use. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} - + + /** + * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * + * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations + * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). + * @param destPoint A point representing the top-left position to draw to. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} - + + /** + * Draws a set of triangles onto the current render target. + * + * @param graphic The graphic to use for the triangles. + * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. + * @param indices A vector containing the indices of the triangles' vertices. + * @param uvtData A vector containing the UV data for the graphic. + * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. + * @param position A point representing the top-left position to draw to. + * @param blend The blend mode to use, optional. + * @param repeat Whether the graphic should repeat. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param transform The color transform to use, optional. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} + /** + * Fills the current render target with `color`. + * + * @param color The color (in 0xAARRGGBB format) to fill the screen with. + * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. + */ public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} // ------------------------ DEBUG DRAW ------------------------ @@ -143,26 +195,78 @@ class FlxRenderer implements IFlxDestroyable { if (camera != null) { - if (this.camera == camera) - return; - this.camera = camera; } } + /** + * Cleans up and finalizes the debug draw. + */ public function endDrawDebug():Void {} + /** + * Draws a rectangle with an outline. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's outline. + * @param thickness The thickness of the rectangle's outline. + */ public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} + /** + * Draws a filled rectangle. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. + */ public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} + /** + * Draws a filled circle. + * + * @param x The x position of the circle. + * @param y The y position of the circle. + * @param radius The radius of the circle. + * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. + */ public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} + /** + * Draws a line. + * + * @param x1 The start x position of the line. + * @param y1 The start y position of the line. + * @param x2 The end x position of the line. + * @param y2 The end y position of the line. + * @param color The color (in 0xAARRGGBB hex format) of the line. + * @param thickness The thickness of the line. + */ public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} } +/** + * An enum represnting the implemented rendering methods. + */ enum FlxRenderMethod { + /** + * Uses the `drawQuads()` method from OpenFL's Graphics API to achieve hardware accelerated rendering. + * + * This method is the default and is used on all targets (when hardware acceleration is available) except for Flash. + */ DRAW_TILES; + + /** + * Draws sprites directly onto bitmaps using a software renderer. + * + * This method is mainly used by the Flash target, though other targets will use it too if + * hardware acceleration is unavailable. + */ BLITTING; } diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 7f4cfc46ee..600bbf87ab 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -66,6 +66,7 @@ class FlxQuadRenderer extends FlxRenderer view.debugLayer.graphics.clear(); #end + view.targetGraphics = view.canvas.graphics; fill(camera.bgColor, camera.useBgAlphaBlending); } diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index e6f5ead1a2..2b2d3ed8a6 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -374,6 +374,8 @@ class FlxBitmapText extends FlxSprite continue; } + FlxG.renderer.begin(camera); + getScreenPosition(screenPos, camera).subtract(offset); if (isPixelPerfectRender(camera)) @@ -400,7 +402,7 @@ class FlxBitmapText extends FlxSprite matrix.translate(screenPos.x + originX, screenPos.y + originY); final colorTransform = bgColorTransformDrawHelper.reset(); colorTransform.setMultipliers(colorHelper).scaleMultipliers(backgroundColor); - camera.drawPixels(FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); + FlxG.renderer.drawPixels(FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); } final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index e5593b3d7c..de43add469 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -175,6 +175,8 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function draw(camera:FlxCamera, flashPoint:Point, scaleX = 1.0, scaleY = 1.0):Void { + FlxG.renderer.begin(camera); + if (isPixelPerfectRender(camera)) { flashPoint.x = Math.floor(flashPoint.x); @@ -183,14 +185,14 @@ class FlxTilemapBuffer implements IFlxDestroyable if (isPixelPerfectRender(camera) && (scaleX == 1.0 && scaleY == 1.0) && blend == null) { - camera.copyPixels(pixels, _flashRect, flashPoint, null, null, true); + FlxG.renderer.copyPixels(pixels, _flashRect, flashPoint, null, null, true); } else { _matrix.identity(); _matrix.scale(scaleX, scaleY); _matrix.translate(flashPoint.x, flashPoint.y); - camera.drawPixels(pixels, _matrix, null, blend, antialiasing); + FlxG.renderer.drawPixels(pixels, _matrix, null, blend, antialiasing); } } diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index dcc0ac13d1..c486681085 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -866,6 +866,8 @@ class FlxBar extends FlxSprite { continue; } + + FlxG.renderer.begin(camera); _frontFrame.prepareMatrix(_matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY()); _matrix.translate(-origin.x, -origin.y); @@ -890,7 +892,7 @@ class FlxBar extends FlxSprite _matrix.ty = Math.floor(_matrix.ty); } - camera.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); + FlxG.renderer.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); } } } From 552bdb76fbcc7d9628f352b72865b2545a24559b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sat, 24 Jan 2026 14:41:26 +0100 Subject: [PATCH 18/72] fix debug drawing --- flixel/path/FlxBasePath.hx | 8 ++++---- flixel/system/debug/interaction/Interaction.hx | 6 +++--- flixel/system/debug/interaction/tools/Pointer.hx | 6 +++--- .../system/debug/interaction/tools/Transform.hx | 15 ++++++++------- flixel/system/render/FlxRenderer.hx | 4 ++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index b993c338f3..3ab5d9a717 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -318,7 +318,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy */ public function drawDebugOnCamera(camera:FlxCamera):Void { - camera.beginDrawDebug(); + FlxG.renderer.beginDrawDebug(camera); final length = nodes.length; // Then fill up the object with node and path graphics @@ -358,7 +358,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy prevNodeScreen.put(); } - camera.endDrawDebug(); + FlxG.renderer.endDrawDebug(); } @:access(flixel.FlxCamera) @@ -385,7 +385,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy inline function drawNode(camera:FlxCamera, node:FlxPoint, size:Int, color:FlxColor) { final offset = Math.floor(size * 0.5); - camera.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); + FlxG.renderer.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); } @:deprecated("drawLine(gfx, node1, node2) is deprecated. Use drawLine(camera, node1, node2) instead.") @@ -408,7 +408,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy final size = debugDrawData.lineSize; final lineOffset = debugDrawData.lineSize / 2; - camera.drawDebugLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, color, size); + FlxG.renderer.drawDebugLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, color, size); } #end } diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index 9c68f03c05..ee6e5e3353 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -397,7 +397,7 @@ class Interaction extends Window function drawItemsSelection():Void { final camera = FlxG.camera; - camera.beginDrawDebug(); + FlxG.renderer.beginDrawDebug(camera); for (member in selectedItems) { @@ -408,11 +408,11 @@ class Interaction extends Window // Render a white rectangle centered at the selected item final color:FlxColor = FlxColor.fromRGBFloat(1, 1, 1, 0.75); - camera.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); + FlxG.renderer.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); } } - camera.endDrawDebug(); + FlxG.renderer.endDrawDebug(); } /** diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index e11a070126..050ffb3814 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -134,7 +134,7 @@ class Pointer extends Tool override public function draw():Void { - FlxG.camera.beginDrawDebug(); + FlxG.renderer.beginDrawDebug(FlxG.camera); switch state { @@ -145,11 +145,11 @@ class Pointer extends Tool // Render the selection rectangle var color:FlxColor = 0xbb0000; color.alphaFloat = 0.9; - FlxG.camera.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); + FlxG.renderer.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); rect.put(); } - FlxG.camera.endDrawDebug(); + FlxG.renderer.endDrawDebug(); } static function setAbsRect(rect:FlxRect, x1:Float, y1:Float, x2:Float, y2:Float) diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index 44b050492d..0c3bf0a3d3 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -233,13 +233,12 @@ class Transform extends Tool target; } - FlxG.camera.beginDrawDebug(); - final camera = target.getDefaultCamera(); + + FlxG.renderer.beginDrawDebug(camera); drawSelection(camera); Marker.draw(target.x + target.origin.x, target.y + target.origin.y, false, camera); - - FlxG.camera.endDrawDebug(); + FlxG.renderer.endDrawDebug(); } function drawSelection(camera:FlxCamera) @@ -249,7 +248,7 @@ class Transform extends Tool var prevY = markers[3].y; for (marker in markers) { - camera.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); + FlxG.renderer.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); prevX = marker.x; prevY = marker.y; @@ -301,10 +300,12 @@ private class Marker public static function draw(screenX:Float, screenY:Float, circle:Bool, camera:FlxCamera) { + FlxG.renderer.begin(camera); + if (circle) - camera.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); + FlxG.renderer.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); else - camera.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); + FlxG.renderer.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); } } diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index c9b2315e6c..8f4b12233f 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -162,8 +162,8 @@ class FlxRenderer implements IFlxDestroyable * * @param graphic The graphic to use for the triangles. * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. - * @param indices A vector containing the indices of the triangles' vertices. - * @param uvtData A vector containing the UV data for the graphic. + * @param indices A vector where each element is an index to a vertex (x, y) pair. 3 indices make up a triangle. + * @param uvtData A vector where each element is a normalized coordinate (from 0.0 to 1.0), per vertex, used to apply texture mapping. * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. * @param position A point representing the top-left position to draw to. * @param blend The blend mode to use, optional. From f4775d5965b0e388dff605f817a4fe0d3fa8cb42 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sat, 24 Jan 2026 14:59:01 +0100 Subject: [PATCH 19/72] fix flash --- flixel/system/render/FlxRenderer.hx | 5 ++++- flixel/system/render/blit/FlxBlitRenderer.hx | 1 - flixel/system/render/quad/FlxQuadRenderer.hx | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 8f4b12233f..df954e8ed0 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -92,7 +92,10 @@ class FlxRenderer implements IFlxDestroyable */ public var camera(default, null):FlxCamera; - public function new() {} + public function new() + { + maxTextureSize = -1; + } public function destroy():Void { diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 95f21fdd37..823c12d21f 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -79,7 +79,6 @@ class FlxBlitRenderer extends FlxRenderer { super(); method = BLITTING; - maxTextureSize = -1; } override function destroy():Void diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 600bbf87ab..464a2e5d31 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -45,8 +45,10 @@ class FlxQuadRenderer extends FlxRenderer super(); method = DRAW_TILES; + #if FLX_OPENGL_AVAILBLE if (isGL) maxTextureSize = cast GL.getParameter(GL.MAX_TEXTURE_SIZE); + #end } override function destroy():Void From 79fd40f8eec31d275cfbf5c97850566d6957754e Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:14:49 +0100 Subject: [PATCH 20/72] fix deprecation warnings --- flixel/FlxCamera.hx | 10 ++-- flixel/FlxG.hx | 6 ++- flixel/FlxGame.hx | 2 +- flixel/FlxObject.hx | 4 +- flixel/FlxSprite.hx | 26 +++++------ flixel/FlxStrip.hx | 3 +- flixel/FlxSubState.hx | 11 +++-- flixel/effects/FlxMatrixSprite.hx | 4 +- flixel/effects/particles/FlxEmitter.hx | 2 +- flixel/graphics/FlxGraphic.hx | 2 +- flixel/graphics/frames/FlxFrame.hx | 6 +-- flixel/path/FlxBasePath.hx | 2 +- flixel/system/FlxBGSprite.hx | 4 +- .../system/debug/interaction/Interaction.hx | 6 +-- flixel/system/debug/stats/Stats.hx | 13 ++++-- flixel/system/frontEnds/CameraFrontEnd.hx | 6 +-- flixel/system/render/FlxRenderer.hx | 8 ++-- flixel/text/FlxBitmapText.hx | 46 +++++++++---------- flixel/text/FlxText.hx | 2 +- flixel/tile/FlxTilemap.hx | 30 ++++++------ flixel/tile/FlxTilemapBuffer.hx | 10 ++-- flixel/ui/FlxBar.hx | 37 ++++++++------- 22 files changed, 124 insertions(+), 116 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 7d492bd6ff..70ea2a2293 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -223,7 +223,7 @@ class FlxCamera extends FlxBasic public var flashSprite(get, set):Sprite; inline function set_flashSprite(value:Sprite):Sprite { - var sprite = FlxG.renderTile ? viewQuad.flashSprite : viewBlit.flashSprite; + var sprite = FlxG.renderer.method == DRAW_TILES ? viewQuad.flashSprite : viewBlit.flashSprite; return sprite = value; } @@ -555,11 +555,11 @@ class FlxCamera extends FlxBasic var _scrollRect(get, set):Sprite; inline function get__scrollRect():Sprite { - return FlxG.renderTile ? viewQuad._scrollRect : viewBlit._scrollRect; + return FlxG.renderer.method == DRAW_TILES ? viewQuad._scrollRect : viewBlit._scrollRect; } inline function set__scrollRect(value:Sprite):Sprite { - var scrollRect = FlxG.renderTile ? viewQuad._scrollRect : viewBlit._scrollRect; + var scrollRect = FlxG.renderer.method == DRAW_TILES ? viewQuad._scrollRect : viewBlit._scrollRect; return scrollRect = value; } @@ -826,7 +826,7 @@ class FlxCamera extends FlxBasic else if (view is FlxBlitView) viewBlit = cast view; - pixelPerfectRender = FlxG.renderBlit; + pixelPerfectRender = FlxG.renderer.method == BLITTING; set_color(FlxColor.WHITE); @@ -1398,7 +1398,7 @@ class FlxCamera extends FlxBasic @:deprecated("checkResize() is deprecated") function checkResize():Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) viewBlit.checkResize(); } diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index dacb389b52..b505b52d20 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -145,8 +145,8 @@ class FlxG public static var onMobile(get, never):Bool; @:deprecated("renderMethod is deprecated, use FlxG.render.method, instead.") - public static var renderMethod(get, null):FlxRenderMethod; - static inline function get_renderMethod():FlxRenderMethod + public static var renderMethod(get, null):flixel.system.render.FlxRenderer.FlxRenderMethod; + static inline function get_renderMethod():flixel.system.render.FlxRenderer.FlxRenderMethod { return FlxG.renderer.method; } @@ -167,6 +167,8 @@ class FlxG /** * The global renderer instance. + * + * @see `FlxRenderer` */ public static var renderer(default, null):FlxRenderer; diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index ba020c62d9..dcf7dda1d2 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -820,7 +820,7 @@ class FlxGame extends Sprite FlxG.cameras.render(); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { #if FLX_DEBUG debugger.stats.drawCalls(FlxRenderer.totalDrawCalls); diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index cd38db88f1..1d8838a2ce 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1309,7 +1309,7 @@ class FlxObject extends FlxBasic return; final rect = getBoundingBox(camera); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { final view = camera.getViewMarginRect(); view.pad(2); @@ -1372,7 +1372,7 @@ class FlxObject extends FlxBasic { FlxG.renderer.beginDrawDebug(camera); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { return FlxSpriteUtil.flashGfx; } diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index c53bebc7cb..d9afabfcc1 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -384,7 +384,7 @@ class FlxSprite extends FlxObject { super(X, Y); - useFramePixels = FlxG.renderBlit; + useFramePixels = FlxG.renderer.method == BLITTING; if (SimpleGraphic != null) loadGraphic(SimpleGraphic); } @@ -908,7 +908,7 @@ class FlxSprite extends FlxObject centerOrigin(); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { dirty = true; updateFramePixels(); @@ -1097,7 +1097,7 @@ class FlxSprite extends FlxObject graphic.bitmap.draw(bitmapData, _matrix, null, brushBlend, null, Brush.antialiasing); } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { dirty = true; calcFrame(); @@ -1112,7 +1112,7 @@ class FlxSprite extends FlxObject */ public function drawFrame(Force:Bool = false):Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { if (Force || dirty) { @@ -1566,7 +1566,7 @@ class FlxSprite extends FlxObject { checkEmptyFrame(); - if (FlxG.renderTile && !force) + if (FlxG.renderer.method == DRAW_TILES && !force) return; updateFramePixels(); @@ -1582,7 +1582,7 @@ class FlxSprite extends FlxObject // don't try to regenerate frame pixels if _frame already uses it as source of graphics // if you'll try then it will clear framePixels and you won't see anything - if (FlxG.renderTile && _frameGraphic != null) + if (FlxG.renderer.method == DRAW_TILES && _frameGraphic != null) { dirty = false; return framePixels; @@ -1600,12 +1600,12 @@ class FlxSprite extends FlxObject framePixels = _frame.paintRotatedAndFlipped(framePixels, _flashPointZero, FlxFrameAngle.ANGLE_0, doFlipX, doFlipY, false, true); } - if (FlxG.renderBlit && hasColorTransform()) + if (FlxG.renderer.method == BLITTING && hasColorTransform()) { framePixels.colorTransform(_flashRect, colorTransform); } - if (FlxG.renderTile && useFramePixels) + if (FlxG.renderer.method == DRAW_TILES && useFramePixels) { // recreate _frame for native target, so it will use modified framePixels _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); @@ -1679,7 +1679,7 @@ class FlxSprite extends FlxObject */ public function isSimpleRender(?camera:FlxCamera):Bool { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return false; return isSimpleRenderBlit(camera); @@ -1848,7 +1848,7 @@ class FlxSprite extends FlxObject return null; } - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); } @@ -2006,7 +2006,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipX(Value:Bool):Bool { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _facingHorizontalMult = Value ? -1 : 1; } @@ -2017,7 +2017,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipY(Value:Bool):Bool { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _facingVerticalMult = Value ? -1 : 1; } @@ -2034,7 +2034,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_useFramePixels(value:Bool):Bool { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { if (value != useFramePixels) { diff --git a/flixel/FlxStrip.hx b/flixel/FlxStrip.hx index 6696952a97..3fa1d58ddf 100644 --- a/flixel/FlxStrip.hx +++ b/flixel/FlxStrip.hx @@ -58,7 +58,8 @@ class FlxStrip extends FlxSprite getScreenPosition(_point, camera); _point -= offset; - camera.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); + FlxG.renderer.begin(camera); + FlxG.renderer.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); } } } diff --git a/flixel/FlxSubState.hx b/flixel/FlxSubState.hx index e7cca132f6..e39a509331 100644 --- a/flixel/FlxSubState.hx +++ b/flixel/FlxSubState.hx @@ -53,7 +53,7 @@ class FlxSubState extends FlxState closeCallback = null; openCallback = null; - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _bgSprite = new FlxBGSprite(); } @@ -63,14 +63,15 @@ class FlxSubState extends FlxState override public function draw():Void { // Draw background - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { for (camera in getCamerasLegacy()) { - camera.fill(bgColor); + FlxG.renderer.begin(camera); + FlxG.renderer.fill(bgColor); } } - else // FlxG.renderTile + else // FlxG.renderer.method == DRAW_TILES { if (_bgSprite != null && _bgSprite.visible) { @@ -110,7 +111,7 @@ class FlxSubState extends FlxState @:noCompletion override function set_bgColor(value:FlxColor):FlxColor { - if (FlxG.renderTile && _bgSprite != null) + if (FlxG.renderer.method == DRAW_TILES && _bgSprite != null) { _bgSprite.alpha = value.alphaFloat; _bgSprite.visible = _bgSprite.alpha > 0; diff --git a/flixel/effects/FlxMatrixSprite.hx b/flixel/effects/FlxMatrixSprite.hx index 67676a32f3..96ca1652db 100644 --- a/flixel/effects/FlxMatrixSprite.hx +++ b/flixel/effects/FlxMatrixSprite.hx @@ -23,7 +23,7 @@ class FlxMatrixSprite extends FlxSprite super(x, y, simpleGraphic); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) FlxG.log.warn("FlxMatrixSprites do not work on blit targets"); } @@ -59,4 +59,4 @@ class FlxMatrixSprite extends FlxSprite matrix.ty = Math.floor(matrix.ty); } } -} \ No newline at end of file +} diff --git a/flixel/effects/particles/FlxEmitter.hx b/flixel/effects/particles/FlxEmitter.hx index 53021ab8ab..1538b97a29 100644 --- a/flixel/effects/particles/FlxEmitter.hx +++ b/flixel/effects/particles/FlxEmitter.hx @@ -264,7 +264,7 @@ class FlxTypedEmitter extends FlxTypedGroup var particle:T = Type.createInstance(particleClass, []); var frame = Multiple ? FlxG.random.int(0, totalFrames - 1) : -1; - if (FlxG.renderBlit && bakedRotationAngles > 0) + if (FlxG.renderer.method == BLITTING && bakedRotationAngles > 0) particle.loadRotatedGraphic(Graphics, bakedRotationAngles, frame, false, AutoBuffer); else particle.loadGraphic(Graphics, Multiple); diff --git a/flixel/graphics/FlxGraphic.hx b/flixel/graphics/FlxGraphic.hx index 656a0ace93..a668ab0b11 100644 --- a/flixel/graphics/FlxGraphic.hx +++ b/flixel/graphics/FlxGraphic.hx @@ -609,7 +609,7 @@ class FlxGraphic implements IFlxDestroyable height = bitmap.height; #if FLX_OPENGL_AVAILABLE - var max:Int = FlxG.bitmap.maxTextureSize; + var max:Int = FlxG.renderer.maxTextureSize; if (max > 0) { if (width > max || height > max) diff --git a/flixel/graphics/frames/FlxFrame.hx b/flixel/graphics/frames/FlxFrame.hx index 40f2cf87b6..5435b01bce 100644 --- a/flixel/graphics/frames/FlxFrame.hx +++ b/flixel/graphics/frames/FlxFrame.hx @@ -159,7 +159,7 @@ class FlxFrame implements IFlxDestroyable offset = FlxPoint.get(); blitMatrix = new MatrixVector(); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) tileMatrix = new MatrixVector(); } @@ -169,7 +169,7 @@ class FlxFrame implements IFlxDestroyable { blitMatrix.copyFrom(this, true); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) tileMatrix.copyFrom(this, false); } @@ -279,7 +279,7 @@ class FlxFrame implements IFlxDestroyable */ public function prepareMatrix(mat:FlxMatrix, rotation:FlxFrameAngle = FlxFrameAngle.ANGLE_0, flipX:Bool = false, flipY:Bool = false):FlxMatrix { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { mat.identity(); return mat; diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 3ab5d9a717..a84e621fda 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -372,7 +372,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy result.y -= camera.scroll.y * object.scrollFactor.y; } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { result.x -= camera.viewMarginX; result.y -= camera.viewMarginY; diff --git a/flixel/system/FlxBGSprite.hx b/flixel/system/FlxBGSprite.hx index b3928322dc..25a6f55050 100644 --- a/flixel/system/FlxBGSprite.hx +++ b/flixel/system/FlxBGSprite.hx @@ -28,11 +28,11 @@ class FlxBGSprite extends FlxSprite continue; } - FlxG.renderer.begin(camera); - _matrix.identity(); _matrix.scale(camera.viewWidth + 1, camera.viewHeight + 1); _matrix.translate(camera.viewMarginLeft, camera.viewMarginTop); + + FlxG.renderer.begin(camera); FlxG.renderer.drawPixels(frame, _matrix, colorTransform); #if FLX_DEBUG diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index ee6e5e3353..f0663f4b33 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -381,7 +381,7 @@ class Interaction extends Window @:deprecated("getDebugGraphics() is deprecated. Use the debug draw functions from FlxCamera instead.") public function getDebugGraphics():Graphics { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { FlxSpriteUtil.flashGfx.clear(); return FlxSpriteUtil.flashGfx; @@ -790,7 +790,7 @@ class Interaction extends Window public function toDebugX(worldX:Float, camera:FlxCamera) { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return camera.viewQuad.canvas.localToGlobal(new Point(worldX, 0)).x; else @:privateAccess @@ -799,7 +799,7 @@ class Interaction extends Window public function toDebugY(worldY:Float, camera:FlxCamera) { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return camera.viewQuad.canvas.localToGlobal(new Point(0, worldY)).y; else @:privateAccess diff --git a/flixel/system/debug/stats/Stats.hx b/flixel/system/debug/stats/Stats.hx index c76b12963b..4293798c3c 100644 --- a/flixel/system/debug/stats/Stats.hx +++ b/flixel/system/debug/stats/Stats.hx @@ -88,7 +88,7 @@ class Stats extends Window { super("Stats", Icon.stats, 0, 0, false); - var minHeight = if (FlxG.renderTile) 200 else 185; + var minHeight = if (FlxG.renderer.method == DRAW_TILES) 200 else 185; minSize.y = minHeight; resize(INITIAL_WIDTH, minHeight); @@ -130,7 +130,7 @@ class Stats extends Window _leftTextField.multiline = _rightTextField.multiline = true; var drawMethod = ""; - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { drawMethod = #if FLX_RENDER_TRIANGLE @@ -267,7 +267,7 @@ class Stats extends Window } visibleCount = Std.int(divide(visibleCount, _visibleObjectMarker)); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { for (i in 0..._drawCallsMarker) { @@ -280,7 +280,7 @@ class Stats extends Window _drawMarker = 0; _activeObjectMarker = 0; _visibleObjectMarker = 0; - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _drawCallsMarker = 0; } @@ -298,7 +298,10 @@ class Stats extends Window updateTimeGraph.update(updTime); _rightTextField.text = activeCount + " (" + updTime + "ms)\n" + visibleCount + " (" + drwTime + "ms)\n" - + (FlxG.renderTile ? (drawCallsCount + "\n") : "") + FlxQuadTree._NUM_CACHED_QUAD_TREES + "\n" + FlxLinkedList._NUM_CACHED_FLX_LIST; + + (FlxG.renderer.method == DRAW_TILES ? (drawCallsCount + "\n") : "") + + FlxQuadTree._NUM_CACHED_QUAD_TREES + + "\n" + + FlxLinkedList._NUM_CACHED_FLX_LIST; } function divide(f1:Float, f2:Float):Float diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 50477396a1..833a31408b 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -136,7 +136,7 @@ class CameraFrontEnd return; } - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { for (i in 0...list.length) { @@ -349,7 +349,7 @@ class CameraFrontEnd function get_useBufferLocking():Bool { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) return FlxBlitRenderer.useBufferLocking; return false; @@ -357,7 +357,7 @@ class CameraFrontEnd function set_useBufferLocking(value:Bool):Bool { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) return FlxBlitRenderer.useBufferLocking = value; return value; diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index df954e8ed0..2d0036c47f 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -72,7 +72,9 @@ class FlxRenderer implements IFlxDestroyable @:noCompletion inline function get_isGL():Bool { #if FLX_OPENGL_AVAILABLE - return isHardware && method != BLITTING; + return FlxG.stage.window.context.type == OPENGL + || FlxG.stage.window.context.type == OPENGLES + || FlxG.stage.window.context.type == WEBGL; #else return false; #end @@ -254,14 +256,14 @@ class FlxRenderer implements IFlxDestroyable } /** - * An enum represnting the implemented rendering methods. + * An enum representing the available rendering methods. */ enum FlxRenderMethod { /** * Uses the `drawQuads()` method from OpenFL's Graphics API to achieve hardware accelerated rendering. * - * This method is the default and is used on all targets (when hardware acceleration is available) except for Flash. + * This method is the default and is used on all targets (when hardware acceleration is available), except for Flash. */ DRAW_TILES; diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 2b2d3ed8a6..a814eab587 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -235,7 +235,7 @@ class FlxBitmapText extends FlxSprite this.font = (font == null) ? FlxBitmapFont.getDefaultFont() : font; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pixels = new BitmapData(1, 1, true, FlxColor.TRANSPARENT); } @@ -264,7 +264,7 @@ class FlxBitmapText extends FlxSprite _colorParams = null; - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { textData = null; textDrawData = null; @@ -278,13 +278,13 @@ class FlxBitmapText extends FlxSprite */ override public function drawFrame(Force:Bool = false):Void { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { Force = true; } pendingTextBitmapChange = pendingTextBitmapChange || Force; checkPendingChanges(false); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { super.drawFrame(Force); } @@ -298,7 +298,7 @@ class FlxBitmapText extends FlxSprite function checkPendingChanges(useTiles:Bool = false):Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { useTiles = false; } @@ -329,7 +329,7 @@ class FlxBitmapText extends FlxSprite static final frameDrawHelper = new ReusableFrame(); override function draw() { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { checkPendingChanges(false); super.draw(); @@ -454,7 +454,7 @@ class FlxBitmapText extends FlxSprite override function set_clipRect(Rect:FlxRect):FlxRect { super.set_clipRect(Rect); - if (!FlxG.renderBlit) + if (FlxG.renderer.method != BLITTING) { pendingTextBitmapChange = true; } @@ -464,7 +464,7 @@ class FlxBitmapText extends FlxSprite override function set_color(Color:FlxColor):FlxColor { super.set_color(Color); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingTextBitmapChange = true; } @@ -474,7 +474,7 @@ class FlxBitmapText extends FlxSprite override function set_alpha(value:Float):Float { super.set_alpha(value); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingTextBitmapChange = true; } @@ -486,7 +486,7 @@ class FlxBitmapText extends FlxSprite if (textColor != value) { textColor = value; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingPixelsChange = true; } @@ -500,7 +500,7 @@ class FlxBitmapText extends FlxSprite if (useTextColor != value) { useTextColor = value; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingPixelsChange = true; } @@ -511,7 +511,7 @@ class FlxBitmapText extends FlxSprite override function calcFrame(RunOnCpp:Bool = false):Void { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { drawFrame(RunOnCpp); } @@ -1003,7 +1003,7 @@ class FlxBitmapText extends FlxSprite { computeTextSize(); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { useTiles = false; } @@ -1023,7 +1023,7 @@ class FlxBitmapText extends FlxSprite textBitmap.lock(); } - else if (FlxG.renderTile) + else if (FlxG.renderer.method == DRAW_TILES) { textData.clear(); } @@ -1071,7 +1071,7 @@ class FlxBitmapText extends FlxSprite function drawLine(line:UnicodeString, posX:Int, posY:Int, useTiles:Bool = false):Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { useTiles = false; } @@ -1101,7 +1101,7 @@ class FlxBitmapText extends FlxSprite function tileLine(line:UnicodeString, startX:Int, startY:Int) { - if (!FlxG.renderTile) + if (FlxG.renderer.method != DRAW_TILES) return; addLineData(line, startX, startY, textData); @@ -1174,7 +1174,7 @@ class FlxBitmapText extends FlxSprite var colorForFill:Int = background ? backgroundColor : FlxColor.TRANSPARENT; var bitmap:BitmapData = null; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { if (pixels == null || (frameWidth != pixels.width || frameHeight != pixels.height)) { @@ -1226,7 +1226,7 @@ class FlxBitmapText extends FlxSprite bitmap.unlock(); } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { dirty = true; } @@ -1321,7 +1321,7 @@ class FlxBitmapText extends FlxSprite function drawText(posX:Int, posY:Int, isFront:Bool = true, ?bitmap:BitmapData, useTiles:Bool = false):Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { useTiles = false; } @@ -1368,7 +1368,7 @@ class FlxBitmapText extends FlxSprite function tileText(posX:Int, posY:Int, isFront:Bool = true):Void { - if (!FlxG.renderTile) + if (FlxG.renderer.method != DRAW_TILES) return; final data:CharList = isFront ? textDrawData : borderDrawData; @@ -1555,7 +1555,7 @@ class FlxBitmapText extends FlxSprite if (background != value) { background = value; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingPixelsChange = true; } @@ -1569,7 +1569,7 @@ class FlxBitmapText extends FlxSprite if (backgroundColor != value) { backgroundColor = value; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingPixelsChange = true; } @@ -1594,7 +1594,7 @@ class FlxBitmapText extends FlxSprite if (borderColor != value) { borderColor = value; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pendingPixelsChange = true; } diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index b3dad3d00f..3ecc41a7f0 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -1071,7 +1071,7 @@ class FlxText extends FlxSprite if (textField == null) return; - if (FlxG.renderTile && !RunOnCpp) + if (FlxG.renderer.method == DRAW_TILES && !RunOnCpp) return; regenGraphic(); diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index bca2cc2548..202af69d82 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -286,7 +286,7 @@ class FlxTypedTilemap extends FlxBaseTilemap { super(); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { _helperPoint = new Point(); _matrix = new FlxMatrix(); @@ -305,7 +305,7 @@ class FlxTypedTilemap extends FlxBaseTilemap debugBoundingBoxColorPartial = FlxColor.PINK; debugBoundingBoxColorNotSolid = FlxColor.TRANSPARENT; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) FlxG.debugger.drawDebugChanged.add(onDrawDebugChanged); #end } @@ -321,7 +321,7 @@ class FlxTypedTilemap extends FlxBaseTilemap _tileObjects = FlxDestroyUtil.destroyArray(_tileObjects); _buffers = FlxDestroyUtil.destroyArray(_buffers); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { #if FLX_DEBUG _debugRect = null; @@ -351,7 +351,7 @@ class FlxTypedTilemap extends FlxBaseTilemap FlxG.cameras.cameraResized.remove(onCameraChanged); #if FLX_DEBUG - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) FlxG.debugger.drawDebugChanged.remove(onDrawDebugChanged); #end @@ -499,7 +499,7 @@ class FlxTypedTilemap extends FlxBaseTilemap function updateDebugTile(tileBitmap:BitmapData, color:FlxColor):BitmapData { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return null; if (tileWidth <= 0 || tileHeight <= 0) @@ -530,7 +530,7 @@ class FlxTypedTilemap extends FlxBaseTilemap override function updateMap():Void { #if FLX_DEBUG - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) _debugRect = new Rectangle(0, 0, tileWidth, tileHeight); #end @@ -542,7 +542,7 @@ class FlxTypedTilemap extends FlxBaseTilemap #if FLX_DEBUG override function drawDebugOnCamera(camera:FlxCamera):Void { - if (!FlxG.renderTile) + if (FlxG.renderer.method != DRAW_TILES) return; var buffer:FlxTilemapBuffer = null; @@ -656,7 +656,7 @@ class FlxTypedTilemap extends FlxBaseTilemap buffer = _buffers[i]; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { if (buffer.isDirty(this, camera)) drawTilemap(buffer, camera); @@ -704,7 +704,7 @@ class FlxTypedTilemap extends FlxBaseTilemap */ override function setDirty(dirty:Bool = true):Void { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return; for (buffer in _buffers) @@ -1214,7 +1214,7 @@ class FlxTypedTilemap extends FlxBaseTilemap var scaledHeight:Float = 0; var drawItem = null; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { buffer.fill(); } @@ -1268,7 +1268,7 @@ class FlxTypedTilemap extends FlxBaseTilemap { frame = tile.frame; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { frame.paint(buffer.pixels, _flashPoint, true); @@ -1316,13 +1316,13 @@ class FlxTypedTilemap extends FlxBaseTilemap } } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) _flashPoint.x += tileWidth; columnIndex++; } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) _flashPoint.y += tileHeight; rowIndex += widthInTiles; } @@ -1330,7 +1330,7 @@ class FlxTypedTilemap extends FlxBaseTilemap buffer.x = screenXInTiles * scaledTileWidth; buffer.y = screenYInTiles * scaledTileHeight; - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { if (isColored) buffer.colorTransform(colorTransform); @@ -1347,7 +1347,7 @@ class FlxTypedTilemap extends FlxBaseTilemap #if FLX_DEBUG function makeDebugTile(color:FlxColor):BitmapData { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) return null; var debugTile = new BitmapData(tileWidth, tileHeight, true, 0); diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index de43add469..a29485f2c4 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -117,7 +117,7 @@ class FlxTilemapBuffer implements IFlxDestroyable updateColumns(tileWidth, widthInTiles, scaleX, camera); updateRows(tileHeight, heightInTiles, scaleY, camera); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { final newWidth = Std.int(columns * tileWidth); final newHeight = Std.int(rows * tileHeight); @@ -144,7 +144,7 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function destroy():Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pixels = FlxDestroyUtil.dispose(pixels); blend = null; @@ -161,7 +161,7 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function fill(color = FlxColor.TRANSPARENT):Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pixels.fillRect(_flashRect, color); } @@ -175,13 +175,13 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function draw(camera:FlxCamera, flashPoint:Point, scaleX = 1.0, scaleY = 1.0):Void { - FlxG.renderer.begin(camera); - if (isPixelPerfectRender(camera)) { flashPoint.x = Math.floor(flashPoint.x); flashPoint.y = Math.floor(flashPoint.y); } + + FlxG.renderer.begin(camera); if (isPixelPerfectRender(camera) && (scaleX == 1.0 && scaleY == 1.0) && blend == null) { diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index c486681085..e4804c1bbc 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -172,7 +172,7 @@ class FlxBar extends FlxSprite _filledBarPoint = new Point(); _filledBarRect = new Rectangle(); - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { _zeroOffset = new Point(); _emptyBarRect = new Rectangle(); @@ -198,7 +198,7 @@ class FlxBar extends FlxSprite { positionOffset = FlxDestroyUtil.put(positionOffset); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { frontFrames = null; _filledFlxRect = FlxDestroyUtil.put(_filledFlxRect); @@ -352,7 +352,7 @@ class FlxBar extends FlxSprite */ public function createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { var emptyKey:String = "empty: " + barWidth + "x" + barHeight + ":" + empty.toHexString(); if (showBorder) @@ -406,7 +406,7 @@ class FlxBar extends FlxSprite */ public function createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { var filledKey:String = "filled: " + barWidth + "x" + barHeight + ":" + fill.toHexString(); if (showBorder) @@ -484,7 +484,7 @@ class FlxBar extends FlxSprite public function createGradientEmptyBar(empty:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { var emptyKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; for (col in empty) @@ -552,7 +552,7 @@ class FlxBar extends FlxSprite public function createGradientFilledBar(fill:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { var filledKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; for (col in fill) @@ -639,7 +639,7 @@ class FlxBar extends FlxSprite { var emptyGraphic:FlxGraphic = FlxG.bitmap.add(empty); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { frames = emptyGraphic.imageFrame; } @@ -681,7 +681,7 @@ class FlxBar extends FlxSprite { var filledGraphic:FlxGraphic = FlxG.bitmap.add(fill); - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { frontFrames = filledGraphic.imageFrame; } @@ -744,7 +744,7 @@ class FlxBar extends FlxSprite */ public function updateEmptyBar():Void { - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pixels.copyPixels(_emptyBar, _emptyBarRect, _zeroOffset); dirty = true; @@ -806,7 +806,7 @@ class FlxBar extends FlxSprite _filledBarPoint.y = Std.int((barHeight - _filledBarRect.height) / 2); } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { pixels.copyPixels(_filledBar, _filledBarRect, _filledBarPoint, null, null, true); } @@ -823,7 +823,7 @@ class FlxBar extends FlxSprite } } - if (FlxG.renderBlit) + if (FlxG.renderer.method == BLITTING) { dirty = true; } @@ -852,7 +852,7 @@ class FlxBar extends FlxSprite { super.draw(); - if (!FlxG.renderTile) + if (FlxG.renderer.method != DRAW_TILES) return; if (alpha == 0) @@ -866,8 +866,6 @@ class FlxBar extends FlxSprite { continue; } - - FlxG.renderer.begin(camera); _frontFrame.prepareMatrix(_matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY()); _matrix.translate(-origin.x, -origin.y); @@ -892,6 +890,7 @@ class FlxBar extends FlxSprite _matrix.ty = Math.floor(_matrix.ty); } + FlxG.renderer.begin(camera); FlxG.renderer.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); } } @@ -899,7 +898,7 @@ class FlxBar extends FlxSprite override function set_pixels(pixels:BitmapData):BitmapData { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { return pixels; // hack } @@ -984,7 +983,7 @@ class FlxBar extends FlxSprite function get_frontFrames():FlxImageFrame { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { return frontFrames; } @@ -993,7 +992,7 @@ class FlxBar extends FlxSprite function set_frontFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { if (value != null) value.parent.incrementUseCount(); @@ -1013,7 +1012,7 @@ class FlxBar extends FlxSprite function get_backFrames():FlxImageFrame { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { return cast frames; } @@ -1022,7 +1021,7 @@ class FlxBar extends FlxSprite function set_backFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderTile) + if (FlxG.renderer.method == DRAW_TILES) { frames = value; } From 468f65edd2ba225b890018429feffeedb5631052 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:19:48 +0100 Subject: [PATCH 21/72] update some more docs --- flixel/FlxCamera.hx | 2 +- flixel/FlxSprite.hx | 10 +++++----- flixel/system/frontEnds/BitmapFrontEnd.hx | 2 +- flixel/tile/FlxTilemapBuffer.hx | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 70ea2a2293..4d236ec0b6 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -232,7 +232,7 @@ class FlxCamera extends FlxBasic /** * Whether the positions of the objects rendered on this camera are rounded. * If set on individual objects, they ignore the global camera setting. - * Defaults to `false` with `FlxG.renderTile` and to `true` with `FlxG.renderBlit`. + * Defaults to `true` with the blitting renderer and `false` elsewhere. * WARNING: setting this to `false` on blitting targets is very expensive. */ public var pixelPerfectRender:Bool; diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index d9afabfcc1..7d147cc8af 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -149,7 +149,7 @@ class FlxSprite extends FlxObject public var framePixels:BitmapData; /** - * Always `true` on `FlxG.renderBlit`. On `FlxG.renderTile` it determines whether + * Always `true` when using the blitting renderer. On other renderers it determines whether * `framePixels` is used and defaults to `false` for performance reasons. */ public var useFramePixels(default, set):Bool = true; @@ -248,7 +248,7 @@ class FlxSprite extends FlxObject /** * Change the size of your sprite's graphic. * NOTE: The hitbox is not automatically adjusted, use `updateHitbox()` for that. - * **WARNING:** With `FlxG.renderBlit`, scaling sprites decreases rendering performance by a factor of about x10! + * **WARNING:** With `the blitting renderer, scaling sprites decreases rendering performance by a factor of about x10! * @see https://snippets.haxeflixel.com/sprites/scale/ */ public var scale(default, null):FlxPoint; @@ -1171,7 +1171,7 @@ class FlxSprite extends FlxObject /** * Sets the sprite's color transformation with control over color offsets. - * With `FlxG.renderTile`, offsets are only supported on OpenFL Next version 3.6.0 or higher. + * With the DRAW_TILES renderer, offsets are only supported on OpenFL Next version 3.6.0 or higher. * * @param redMultiplier The value for the red multiplier, in the range from `0` to `1`. * @param greenMultiplier The value for the green multiplier, in the range from `0` to `1`. @@ -1674,8 +1674,8 @@ class FlxSprite extends FlxObject } /** - * Returns the result of `isSimpleRenderBlit()` if `FlxG.renderBlit` is - * `true`, or `false` if `FlxG.renderTile` is `true`. + * Returns the result of `isSimpleRenderBlit()` if the blitting renderer is used, + * or `false` elsewhere. */ public function isSimpleRender(?camera:FlxCamera):Bool { diff --git a/flixel/system/frontEnds/BitmapFrontEnd.hx b/flixel/system/frontEnds/BitmapFrontEnd.hx index 02b9b34a12..cd8bf697f8 100644 --- a/flixel/system/frontEnds/BitmapFrontEnd.hx +++ b/flixel/system/frontEnds/BitmapFrontEnd.hx @@ -28,7 +28,7 @@ class BitmapFrontEnd /** * Helper FlxFrame object. Containing only one frame. - * Useful for drawing colored rectangles of all sizes in FlxG.renderTile mode. + * Useful for drawing colored rectangles of all sizes when not using the blitting renderer. */ public var whitePixel(get, never):FlxFrame; diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index a29485f2c4..454650fb2a 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -61,7 +61,7 @@ class FlxTilemapBuffer implements IFlxDestroyable public var pixelPerfectRender:Null; /** - * The actual buffer BitmapData. (Only used if FlxG.renderBlit == true) + * The actual buffer BitmapData. (Only used with the blitting renderer) */ public var pixels(default, null):BitmapData; @@ -182,7 +182,7 @@ class FlxTilemapBuffer implements IFlxDestroyable } FlxG.renderer.begin(camera); - + if (isPixelPerfectRender(camera) && (scaleX == 1.0 && scaleY == 1.0) && blend == null) { FlxG.renderer.copyPixels(pixels, _flashRect, flashPoint, null, null, true); From 726c0be602da08a2e3b4b7357a9653d734e7877a Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:10:22 +0100 Subject: [PATCH 22/72] change `method == DRAW_TILES` checks into `method != BLITTING` the code hidden by this check is generally valid for any other non-blitting renderer like opengl --- flixel/FlxCamera.hx | 6 ++--- flixel/FlxG.hx | 2 +- flixel/FlxGame.hx | 2 +- flixel/FlxObject.hx | 2 +- flixel/FlxSprite.hx | 16 ++++++------- flixel/FlxSubState.hx | 6 ++--- flixel/graphics/frames/FlxFrame.hx | 4 ++-- .../system/debug/interaction/Interaction.hx | 4 ++-- flixel/system/debug/stats/Stats.hx | 10 ++++---- flixel/system/frontEnds/CameraFrontEnd.hx | 2 +- flixel/text/FlxBitmapText.hx | 8 +++---- flixel/text/FlxText.hx | 2 +- flixel/tile/FlxTilemap.hx | 8 +++---- flixel/ui/FlxBar.hx | 24 +++++++++---------- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 4d236ec0b6..2610aa9875 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -223,7 +223,7 @@ class FlxCamera extends FlxBasic public var flashSprite(get, set):Sprite; inline function set_flashSprite(value:Sprite):Sprite { - var sprite = FlxG.renderer.method == DRAW_TILES ? viewQuad.flashSprite : viewBlit.flashSprite; + var sprite = FlxG.renderer.method != BLITTING ? viewQuad.flashSprite : viewBlit.flashSprite; return sprite = value; } @@ -555,11 +555,11 @@ class FlxCamera extends FlxBasic var _scrollRect(get, set):Sprite; inline function get__scrollRect():Sprite { - return FlxG.renderer.method == DRAW_TILES ? viewQuad._scrollRect : viewBlit._scrollRect; + return FlxG.renderer.method != BLITTING ? viewQuad._scrollRect : viewBlit._scrollRect; } inline function set__scrollRect(value:Sprite):Sprite { - var scrollRect = FlxG.renderer.method == DRAW_TILES ? viewQuad._scrollRect : viewBlit._scrollRect; + var scrollRect = FlxG.renderer.method != BLITTING ? viewQuad._scrollRect : viewBlit._scrollRect; return scrollRect = value; } diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index b505b52d20..61900b7c91 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -162,7 +162,7 @@ class FlxG public static var renderTile(get, never):Bool; @:noCompletion static inline function get_renderTile():Bool { - return FlxG.renderer.method == DRAW_TILES; + return FlxG.renderer.method != BLITTING; } /** diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index dcf7dda1d2..9a6af108ce 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -820,7 +820,7 @@ class FlxGame extends Sprite FlxG.cameras.render(); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { #if FLX_DEBUG debugger.stats.drawCalls(FlxRenderer.totalDrawCalls); diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 1d8838a2ce..34f9452501 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1309,7 +1309,7 @@ class FlxObject extends FlxBasic return; final rect = getBoundingBox(camera); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { final view = camera.getViewMarginRect(); view.pad(2); diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 7d147cc8af..d9a67b2a93 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -1566,7 +1566,7 @@ class FlxSprite extends FlxObject { checkEmptyFrame(); - if (FlxG.renderer.method == DRAW_TILES && !force) + if (FlxG.renderer.method != BLITTING && !force) return; updateFramePixels(); @@ -1582,7 +1582,7 @@ class FlxSprite extends FlxObject // don't try to regenerate frame pixels if _frame already uses it as source of graphics // if you'll try then it will clear framePixels and you won't see anything - if (FlxG.renderer.method == DRAW_TILES && _frameGraphic != null) + if (FlxG.renderer.method != BLITTING && _frameGraphic != null) { dirty = false; return framePixels; @@ -1605,7 +1605,7 @@ class FlxSprite extends FlxObject framePixels.colorTransform(_flashRect, colorTransform); } - if (FlxG.renderer.method == DRAW_TILES && useFramePixels) + if (FlxG.renderer.method != BLITTING && useFramePixels) { // recreate _frame for native target, so it will use modified framePixels _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); @@ -1679,7 +1679,7 @@ class FlxSprite extends FlxObject */ public function isSimpleRender(?camera:FlxCamera):Bool { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return false; return isSimpleRenderBlit(camera); @@ -1848,7 +1848,7 @@ class FlxSprite extends FlxObject return null; } - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); } @@ -2006,7 +2006,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipX(Value:Bool):Bool { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _facingHorizontalMult = Value ? -1 : 1; } @@ -2017,7 +2017,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipY(Value:Bool):Bool { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _facingVerticalMult = Value ? -1 : 1; } @@ -2034,7 +2034,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_useFramePixels(value:Bool):Bool { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { if (value != useFramePixels) { diff --git a/flixel/FlxSubState.hx b/flixel/FlxSubState.hx index e39a509331..0edb330869 100644 --- a/flixel/FlxSubState.hx +++ b/flixel/FlxSubState.hx @@ -53,7 +53,7 @@ class FlxSubState extends FlxState closeCallback = null; openCallback = null; - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _bgSprite = new FlxBGSprite(); } @@ -71,7 +71,7 @@ class FlxSubState extends FlxState FlxG.renderer.fill(bgColor); } } - else // FlxG.renderer.method == DRAW_TILES + else // FlxG.renderer.method != BLITTING { if (_bgSprite != null && _bgSprite.visible) { @@ -111,7 +111,7 @@ class FlxSubState extends FlxState @:noCompletion override function set_bgColor(value:FlxColor):FlxColor { - if (FlxG.renderer.method == DRAW_TILES && _bgSprite != null) + if (FlxG.renderer.method != BLITTING && _bgSprite != null) { _bgSprite.alpha = value.alphaFloat; _bgSprite.visible = _bgSprite.alpha > 0; diff --git a/flixel/graphics/frames/FlxFrame.hx b/flixel/graphics/frames/FlxFrame.hx index 5435b01bce..24ee97351e 100644 --- a/flixel/graphics/frames/FlxFrame.hx +++ b/flixel/graphics/frames/FlxFrame.hx @@ -159,7 +159,7 @@ class FlxFrame implements IFlxDestroyable offset = FlxPoint.get(); blitMatrix = new MatrixVector(); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) tileMatrix = new MatrixVector(); } @@ -169,7 +169,7 @@ class FlxFrame implements IFlxDestroyable { blitMatrix.copyFrom(this, true); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) tileMatrix.copyFrom(this, false); } diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index f0663f4b33..200c379f20 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -790,7 +790,7 @@ class Interaction extends Window public function toDebugX(worldX:Float, camera:FlxCamera) { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return camera.viewQuad.canvas.localToGlobal(new Point(worldX, 0)).x; else @:privateAccess @@ -799,7 +799,7 @@ class Interaction extends Window public function toDebugY(worldY:Float, camera:FlxCamera) { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return camera.viewQuad.canvas.localToGlobal(new Point(0, worldY)).y; else @:privateAccess diff --git a/flixel/system/debug/stats/Stats.hx b/flixel/system/debug/stats/Stats.hx index 4293798c3c..8b82b00dac 100644 --- a/flixel/system/debug/stats/Stats.hx +++ b/flixel/system/debug/stats/Stats.hx @@ -88,7 +88,7 @@ class Stats extends Window { super("Stats", Icon.stats, 0, 0, false); - var minHeight = if (FlxG.renderer.method == DRAW_TILES) 200 else 185; + var minHeight = if (FlxG.renderer.method != BLITTING) 200 else 185; minSize.y = minHeight; resize(INITIAL_WIDTH, minHeight); @@ -130,7 +130,7 @@ class Stats extends Window _leftTextField.multiline = _rightTextField.multiline = true; var drawMethod = ""; - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { drawMethod = #if FLX_RENDER_TRIANGLE @@ -267,7 +267,7 @@ class Stats extends Window } visibleCount = Std.int(divide(visibleCount, _visibleObjectMarker)); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { for (i in 0..._drawCallsMarker) { @@ -280,7 +280,7 @@ class Stats extends Window _drawMarker = 0; _activeObjectMarker = 0; _visibleObjectMarker = 0; - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _drawCallsMarker = 0; } @@ -298,7 +298,7 @@ class Stats extends Window updateTimeGraph.update(updTime); _rightTextField.text = activeCount + " (" + updTime + "ms)\n" + visibleCount + " (" + drwTime + "ms)\n" - + (FlxG.renderer.method == DRAW_TILES ? (drawCallsCount + "\n") : "") + + (FlxG.renderer.method != BLITTING ? (drawCallsCount + "\n") : "") + FlxQuadTree._NUM_CACHED_QUAD_TREES + "\n" + FlxLinkedList._NUM_CACHED_FLX_LIST; diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 833a31408b..eb28bcb776 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -136,7 +136,7 @@ class CameraFrontEnd return; } - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { for (i in 0...list.length) { diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index a814eab587..8610f60560 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -264,7 +264,7 @@ class FlxBitmapText extends FlxSprite _colorParams = null; - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { textData = null; textDrawData = null; @@ -278,7 +278,7 @@ class FlxBitmapText extends FlxSprite */ override public function drawFrame(Force:Bool = false):Void { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { Force = true; } @@ -511,7 +511,7 @@ class FlxBitmapText extends FlxSprite override function calcFrame(RunOnCpp:Bool = false):Void { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { drawFrame(RunOnCpp); } @@ -1023,7 +1023,7 @@ class FlxBitmapText extends FlxSprite textBitmap.lock(); } - else if (FlxG.renderer.method == DRAW_TILES) + else if (FlxG.renderer.method != BLITTING) { textData.clear(); } diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index 3ecc41a7f0..b608b7f57f 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -1071,7 +1071,7 @@ class FlxText extends FlxSprite if (textField == null) return; - if (FlxG.renderer.method == DRAW_TILES && !RunOnCpp) + if (FlxG.renderer.method != BLITTING && !RunOnCpp) return; regenGraphic(); diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 202af69d82..09e17d4d87 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -286,7 +286,7 @@ class FlxTypedTilemap extends FlxBaseTilemap { super(); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { _helperPoint = new Point(); _matrix = new FlxMatrix(); @@ -499,7 +499,7 @@ class FlxTypedTilemap extends FlxBaseTilemap function updateDebugTile(tileBitmap:BitmapData, color:FlxColor):BitmapData { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return null; if (tileWidth <= 0 || tileHeight <= 0) @@ -704,7 +704,7 @@ class FlxTypedTilemap extends FlxBaseTilemap */ override function setDirty(dirty:Bool = true):Void { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return; for (buffer in _buffers) @@ -1347,7 +1347,7 @@ class FlxTypedTilemap extends FlxBaseTilemap #if FLX_DEBUG function makeDebugTile(color:FlxColor):BitmapData { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) return null; var debugTile = new BitmapData(tileWidth, tileHeight, true, 0); diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index e4804c1bbc..fa26277b06 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -198,7 +198,7 @@ class FlxBar extends FlxSprite { positionOffset = FlxDestroyUtil.put(positionOffset); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { frontFrames = null; _filledFlxRect = FlxDestroyUtil.put(_filledFlxRect); @@ -352,7 +352,7 @@ class FlxBar extends FlxSprite */ public function createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { var emptyKey:String = "empty: " + barWidth + "x" + barHeight + ":" + empty.toHexString(); if (showBorder) @@ -406,7 +406,7 @@ class FlxBar extends FlxSprite */ public function createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { var filledKey:String = "filled: " + barWidth + "x" + barHeight + ":" + fill.toHexString(); if (showBorder) @@ -484,7 +484,7 @@ class FlxBar extends FlxSprite public function createGradientEmptyBar(empty:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { var emptyKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; for (col in empty) @@ -552,7 +552,7 @@ class FlxBar extends FlxSprite public function createGradientFilledBar(fill:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { var filledKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; for (col in fill) @@ -639,7 +639,7 @@ class FlxBar extends FlxSprite { var emptyGraphic:FlxGraphic = FlxG.bitmap.add(empty); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { frames = emptyGraphic.imageFrame; } @@ -681,7 +681,7 @@ class FlxBar extends FlxSprite { var filledGraphic:FlxGraphic = FlxG.bitmap.add(fill); - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { frontFrames = filledGraphic.imageFrame; } @@ -898,7 +898,7 @@ class FlxBar extends FlxSprite override function set_pixels(pixels:BitmapData):BitmapData { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { return pixels; // hack } @@ -983,7 +983,7 @@ class FlxBar extends FlxSprite function get_frontFrames():FlxImageFrame { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { return frontFrames; } @@ -992,7 +992,7 @@ class FlxBar extends FlxSprite function set_frontFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { if (value != null) value.parent.incrementUseCount(); @@ -1012,7 +1012,7 @@ class FlxBar extends FlxSprite function get_backFrames():FlxImageFrame { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { return cast frames; } @@ -1021,7 +1021,7 @@ class FlxBar extends FlxSprite function set_backFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderer.method == DRAW_TILES) + if (FlxG.renderer.method != BLITTING) { frames = value; } From 9441d8c45e35e49310a049a8c700b52f6014177c Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:11:50 +0100 Subject: [PATCH 23/72] Make `FlxCameraView.create()` dynamic --- flixel/system/render/FlxCameraView.hx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 9d0fe92429..05cad513a0 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -17,9 +17,11 @@ class FlxCameraView implements IFlxDestroyable { /** * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. - * @param camera The camera to create the view for + * This function is dynamic, which means that you can change the return value yourself. + * + * @param camera The camera to create the view for */ - public static inline function create(camera:FlxCamera):FlxCameraView + public static dynamic function create(camera:FlxCamera):FlxCameraView { if (!FlxG.renderer.isHardware) { From 181cec83f0dedd783aefab9da5d3d38d0b79daac Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sun, 25 Jan 2026 19:27:43 -0600 Subject: [PATCH 24/72] change import --- flixel/system/render/quad/FlxQuadRenderer.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 464a2e5d31..32c6f44d2f 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -5,7 +5,7 @@ import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; import flixel.graphics.tile.FlxDrawBaseItem; import flixel.graphics.tile.FlxDrawQuadsItem; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.graphics.tile.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; From fb9d27cea9cb9c18889ef8baa1f56e4456657962 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:37:17 +0100 Subject: [PATCH 25/72] Bring back accidentally removed method --- flixel/FlxCamera.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 2610aa9875..c45ebb893d 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -719,6 +719,14 @@ class FlxCamera extends FlxBasic return viewQuad.getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } + @:allow(flixel.system.frontEnds.CameraFrontEnd) + @:deprecated("camera.render() is deprecated, use FlxG.renderer.render() instead.") + function render():Void + { + FlxG.renderer.begin(this); + FlxG.renderer.render(); + } + @:allow(flixel.system.frontEnds.CameraFrontEnd) function clearDrawStack():Void { From f45c61e9862353769dd0c585440aa3b2737dd928 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 26 Jan 2026 12:16:28 +0100 Subject: [PATCH 26/72] fix line debug draw --- flixel/FlxG.hx | 2 +- flixel/FlxObject.hx | 15 ++++++++------- flixel/system/render/blit/FlxBlitRenderer.hx | 2 +- flixel/system/render/quad/FlxQuadRenderer.hx | 2 +- flixel/tile/FlxTilemap.hx | 4 +++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 61900b7c91..7229b2fa6a 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -146,7 +146,7 @@ class FlxG @:deprecated("renderMethod is deprecated, use FlxG.render.method, instead.") public static var renderMethod(get, null):flixel.system.render.FlxRenderer.FlxRenderMethod; - static inline function get_renderMethod():flixel.system.render.FlxRenderer.FlxRenderMethod + @:noCompletion static inline function get_renderMethod():flixel.system.render.FlxRenderer.FlxRenderMethod { return FlxG.renderer.method; } diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 34f9452501..936875fc43 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1287,7 +1287,6 @@ class FlxObject extends FlxBasic for (camera in getCamerasLegacy()) { - FlxG.renderer.begin(camera); drawDebugOnCamera(camera); if (drawPath) @@ -1319,11 +1318,13 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - drawDebugBoundingBox(camera, rect, allowCollisions); + FlxG.renderer.beginDrawDebug(camera); + drawDebugBoundingBox(rect, allowCollisions); + FlxG.renderer.endDrawDebug(); } } - @:deprecated("drawDebugBoundingBox(gfx, rect, allowCollisions, partial) is deprecated. Use drawDebugBoundingBox(camera, rect, allowCollisions) instead.") + @:deprecated("drawDebugBoundingBox(gfx, rect, allowCollisions, partial) is deprecated. Use drawDebugBoundingBox(rect, allowCollisions) instead.") overload extern inline function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) { // Find the color to use @@ -1331,12 +1332,12 @@ class FlxObject extends FlxBasic drawDebugBoundingBoxColor(gfx, rect, color); } - overload extern inline function drawDebugBoundingBox(camera:FlxCamera, rect:FlxRect, allowCollisions:FlxDirectionFlags) + overload extern inline function drawDebugBoundingBox(rect:FlxRect, allowCollisions:FlxDirectionFlags) { // Find the color to use var color = getDebugBoundingBoxColor(allowCollisions); color.alphaFloat = 0.75; - drawDebugBoundingBoxColor(camera, rect, color); + drawDebugBoundingBoxColor(rect, color); } function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) @@ -1354,7 +1355,7 @@ class FlxObject extends FlxBasic } - @:deprecated("drawDebugBoundingBoxColor(gfx, rect, color) is deprecated, use drawDebugBoundingBoxColor(camera, rect, color) instead") + @:deprecated("drawDebugBoundingBoxColor(gfx, rect, color) is deprecated, use drawDebugBoundingBoxColor(rect, color) instead") overload extern inline function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { // fill static graphics object with square shape @@ -1362,7 +1363,7 @@ class FlxObject extends FlxBasic gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } - overload extern inline function drawDebugBoundingBoxColor(camera:FlxCamera, rect:FlxRect, color:FlxColor) + overload extern inline function drawDebugBoundingBoxColor(rect:FlxRect, color:FlxColor) { FlxG.renderer.drawDebugRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color); } diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 823c12d21f..3fb13042c3 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -289,7 +289,7 @@ class FlxBlitRenderer extends FlxRenderer { final gfx = FlxSpriteUtil.flashGfx; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, x2); + gfx.moveTo(x1, y1); gfx.lineTo(x2, y2); } #end diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 32c6f44d2f..b21d2d4ccb 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -168,7 +168,7 @@ class FlxQuadRenderer extends FlxRenderer { final gfx = view.debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, x2); + gfx.moveTo(x1, y1); gfx.lineTo(x2, y2); } #end diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 09e17d4d87..2694519df5 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -545,6 +545,8 @@ class FlxTypedTilemap extends FlxBaseTilemap if (FlxG.renderer.method != DRAW_TILES) return; + FlxG.renderer.beginDrawDebug(camera); + var buffer:FlxTilemapBuffer = null; var l:Int = FlxG.cameras.list.length; @@ -595,7 +597,7 @@ class FlxTypedTilemap extends FlxBaseTilemap if (color != null) { final colStr = color.toHexString(); - drawDebugBoundingBoxColor(camera, rect, color); + drawDebugBoundingBoxColor(rect, color); } } } From b4c0c8a82a7f53294644a20513562f055756227d Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 27 Jan 2026 15:33:44 +0100 Subject: [PATCH 27/72] Fix C++ CI --- flixel/text/FlxBitmapText.hx | 7 ++++++- tests/unit/src/flixel/FlxGTest.hx | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 8610f60560..39a1536eb5 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -247,6 +247,11 @@ class FlxBitmapText extends FlxSprite } this.text = text; + + // initialize at runtime instead of statically to avoid a crash + // because FlxG.renderer(.method) is null + if (frameDrawHelper == null) + frameDrawHelper = new ReusableFrame(); } /** @@ -326,7 +331,7 @@ class FlxBitmapText extends FlxSprite static final borderColorTransformDrawHelper = new ColorTransform(); static final textColorTransformDrawHelper = new ColorTransform(); static final matrixDrawHelper = new FlxMatrix(); - static final frameDrawHelper = new ReusableFrame(); + static var frameDrawHelper:Null; override function draw() { if (FlxG.renderer.method == BLITTING) diff --git a/tests/unit/src/flixel/FlxGTest.hx b/tests/unit/src/flixel/FlxGTest.hx index 58d3daac76..1db3789e96 100644 --- a/tests/unit/src/flixel/FlxGTest.hx +++ b/tests/unit/src/flixel/FlxGTest.hx @@ -23,6 +23,9 @@ class FlxGTest extends FlxTest @Test function testSaveNull():Void Assert.isNotNull(FlxG.save); + @Test function testRendererNull():Void + Assert.isNotNull(FlxG.renderer); + #if FLX_MOUSE @Test function testMouseNull():Void Assert.isNotNull(FlxG.mouse); From 39b08cea5f9d75a12f329381af1a2020957c2a55 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:17:12 +0100 Subject: [PATCH 28/72] no longer need to recreate MatrixVector in ReusableFrame --- flixel/text/FlxBitmapText.hx | 2 -- 1 file changed, 2 deletions(-) diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 39a1536eb5..f1ab0b7b8d 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -1800,8 +1800,6 @@ private class ReusableFrame extends FlxFrame public function new () { super(null); - // We need to define this now, since it's created before renderTile is set - tileMatrix = new MatrixVector(); } override function destroy() {} From 51ffbed9534c0fd5f39fb46e5c92eaed1ecb1850 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Tue, 24 Feb 2026 16:02:16 -0600 Subject: [PATCH 29/72] some hail mary stuff --- flixel/FlxCamera.hx | 28 ++-- flixel/FlxObject.hx | 45 ++----- flixel/FlxSprite.hx | 6 +- flixel/FlxStrip.hx | 3 +- flixel/FlxSubState.hx | 5 +- flixel/path/FlxBasePath.hx | 31 ++--- flixel/system/FlxBGSprite.hx | 3 +- .../system/debug/interaction/Interaction.hx | 12 +- .../system/debug/interaction/tools/Pointer.hx | 15 ++- .../debug/interaction/tools/Transform.hx | 13 +- flixel/system/frontEnds/CameraFrontEnd.hx | 14 +- flixel/system/render/FlxCameraView.hx | 118 ++++++++++++++--- flixel/system/render/FlxRenderer.hx | 122 +++--------------- flixel/system/render/blit/FlxBlitRenderer.hx | 91 ++----------- flixel/system/render/blit/FlxBlitView.hx | 90 ++++++++++++- flixel/system/render/quad/FlxQuadRenderer.hx | 80 +++--------- flixel/system/render/quad/FlxQuadView.hx | 59 ++++++++- flixel/tile/FlxTilemap.hx | 4 +- flixel/tile/FlxTilemapBuffer.hx | 12 +- flixel/ui/FlxBar.hx | 9 +- 20 files changed, 365 insertions(+), 395 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index c45ebb893d..613dd4561a 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -11,9 +11,9 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; -import flixel.system.render.quad.FlxQuadView; -import flixel.system.render.blit.FlxBlitView; import flixel.system.render.blit.FlxBlitRenderer; +import flixel.system.render.blit.FlxBlitView; +import flixel.system.render.quad.FlxQuadView; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -22,9 +22,9 @@ import openfl.display.Bitmap; import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.display.DisplayObject; +import openfl.display.DisplayObjectContainer; import openfl.display.Graphics; import openfl.display.Sprite; -import openfl.display.DisplayObjectContainer; import openfl.filters.BitmapFilter; import openfl.geom.ColorTransform; import openfl.geom.Point; @@ -723,8 +723,7 @@ class FlxCamera extends FlxBasic @:deprecated("camera.render() is deprecated, use FlxG.renderer.render() instead.") function render():Void { - FlxG.renderer.begin(this); - FlxG.renderer.render(); + FlxG.renderer.render(view); } @:allow(flixel.system.frontEnds.CameraFrontEnd) @@ -737,24 +736,21 @@ class FlxCamera extends FlxBasic public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - FlxG.renderer.begin(this); - FlxG.renderer.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + FlxG.renderer.drawPixels(view, frame, pixels, matrix, transform, blend, smoothing, shader); } @:deprecated("camera.copyPixels() is deprecated, use FlxG.renderer.copyPixels() instead.") public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - FlxG.renderer.begin(this); - FlxG.renderer.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + FlxG.renderer.copyPixels(view, frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); } @:deprecated("camera.drawTriangles() is deprecated, use FlxG.renderer.drawTriangles() instead.") public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void { - FlxG.renderer.begin(this); - FlxG.renderer.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + FlxG.renderer.drawTriangles(view, graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); } /** @@ -1370,12 +1366,10 @@ class FlxCamera extends FlxBasic { color.alphaFloat = fxAlpha; - FlxG.renderer.begin(this); - if (viewQuad != null && graphics != null) viewQuad.targetGraphics = graphics; - FlxG.renderer.fill(color, blendAlpha); + view.fill(color, blendAlpha); } /** @@ -1384,14 +1378,12 @@ class FlxCamera extends FlxBasic @:allow(flixel.system.render.FlxCameraView) function drawFX():Void { - FlxG.renderer.begin(this); - // Draw the "flash" special effect onto the buffer if (_fxFlashAlpha > 0.0) { var color = _fxFlashColor; color.alphaFloat *= _fxFlashAlpha; - FlxG.renderer.fill(color); + view.fill(color); } // Draw the "fade" special effect onto the buffer @@ -1399,7 +1391,7 @@ class FlxCamera extends FlxBasic { var color = _fxFadeColor; color.alphaFloat *= _fxFadeAlpha; - FlxG.renderer.fill(color); + view.fill(color); } } diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 936875fc43..be3674c6fb 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1302,6 +1302,7 @@ class FlxObject extends FlxBasic * * @param Camera Which camera to draw the debug visuals to. */ + @:haxe.warning("-WDeprecated") public function drawDebugOnCamera(camera:FlxCamera):Void { if (!camera.visible || !camera.exists || !isOnScreen(camera)) @@ -1318,28 +1319,22 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - FlxG.renderer.beginDrawDebug(camera); - drawDebugBoundingBox(rect, allowCollisions); - FlxG.renderer.endDrawDebug(); + final view = camera.view; + final gfx = beginDrawDebug(camera); + drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); + endDrawDebug(camera); } } - @:deprecated("drawDebugBoundingBox(gfx, rect, allowCollisions, partial) is deprecated. Use drawDebugBoundingBox(rect, allowCollisions) instead.") - overload extern inline function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) + // TODO: throw warning on overrides + function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) { // Find the color to use final color = getDebugBoundingBoxColor(allowCollisions); drawDebugBoundingBoxColor(gfx, rect, color); } - - overload extern inline function drawDebugBoundingBox(rect:FlxRect, allowCollisions:FlxDirectionFlags) - { - // Find the color to use - var color = getDebugBoundingBoxColor(allowCollisions); - color.alphaFloat = 0.75; - drawDebugBoundingBoxColor(rect, color); - } + // TODO: throw warning on overrides function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) { if (debugBoundingBoxColor != null) @@ -1355,38 +1350,26 @@ class FlxObject extends FlxBasic } - @:deprecated("drawDebugBoundingBoxColor(gfx, rect, color) is deprecated, use drawDebugBoundingBoxColor(rect, color) instead") - overload extern inline function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) + // TODO: throw warning on overrides + function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { // fill static graphics object with square shape gfx.lineStyle(1, color, 0.75, false, null, null, MITER, 255); gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } - overload extern inline function drawDebugBoundingBoxColor(rect:FlxRect, color:FlxColor) - { - FlxG.renderer.drawDebugRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color); - } - + // TODO: throw warning on overrides @:deprecated("use object.beginDrawDebug(camera) is deprecated, FlxG.renderer.beginDrawDebug(camera) instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { - FlxG.renderer.beginDrawDebug(camera); - - if (FlxG.renderer.method == BLITTING) - { - return FlxSpriteUtil.flashGfx; - } - else - { - return camera.viewQuad.debugLayer.graphics; - } + return camera.view.beginDrawDebug(); } + // TODO: throw warning on overrides @:deprecated("use object.endDrawDebug(camera) is deprecated, FlxG.renderer.endDrawDebug() instead") inline function endDrawDebug(camera:FlxCamera) { - FlxG.renderer.endDrawDebug(); + camera.view.endDrawDebug(); } #end diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index d9a67b2a93..f4f253b97c 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -963,8 +963,6 @@ class FlxSprite extends FlxObject for (camera in getCamerasLegacy()) { - FlxG.renderer.begin(camera); - if (!camera.visible || !camera.exists || !isOnScreen(camera)) continue; @@ -1011,7 +1009,7 @@ class FlxSprite extends FlxObject _point.floor(); _point.copyTo(_flashPoint); - FlxG.renderer.copyPixels(_frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); + FlxG.renderer.copyPixels(camera.view, _frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); } @:noCompletion @@ -1027,7 +1025,7 @@ class FlxSprite extends FlxObject final matrix = drawComplexMatrix; // TODO: Just use local? prepareComplexMatrix(matrix, frame, camera); - FlxG.renderer.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); + FlxG.renderer.drawPixels(camera.view, frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); } function prepareComplexMatrix(matrix:FlxMatrix, frame:FlxFrame, camera:FlxCamera) diff --git a/flixel/FlxStrip.hx b/flixel/FlxStrip.hx index 3fa1d58ddf..04e4d2644f 100644 --- a/flixel/FlxStrip.hx +++ b/flixel/FlxStrip.hx @@ -58,8 +58,7 @@ class FlxStrip extends FlxSprite getScreenPosition(_point, camera); _point -= offset; - FlxG.renderer.begin(camera); - FlxG.renderer.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); + FlxG.renderer.drawTriangles(camera.view, graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); } } } diff --git a/flixel/FlxSubState.hx b/flixel/FlxSubState.hx index 0edb330869..9375046846 100644 --- a/flixel/FlxSubState.hx +++ b/flixel/FlxSubState.hx @@ -66,10 +66,7 @@ class FlxSubState extends FlxState if (FlxG.renderer.method == BLITTING) { for (camera in getCamerasLegacy()) - { - FlxG.renderer.begin(camera); - FlxG.renderer.fill(bgColor); - } + camera.view.fill(bgColor); } else // FlxG.renderer.method != BLITTING { diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index a84e621fda..89d96f7a54 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -318,8 +318,9 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy */ public function drawDebugOnCamera(camera:FlxCamera):Void { - FlxG.renderer.beginDrawDebug(camera); - + // Set up our global flash graphics object to draw out the path + final gfx:Graphics = camera.view.beginDrawDebug(); + final length = nodes.length; // Then fill up the object with node and path graphics for (i=>node in nodes) @@ -345,20 +346,20 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy } // draw a box for the node - drawNode(camera, prevNodeScreen, nodeSize, nodeColor); + drawNode(gfx, prevNodeScreen, nodeSize, nodeColor); if (i + 1 < length || loopType == LOOP) { // draw a line to the next node, if LOOP, get connect the tail and head final nextNode = nodes[(i + 1) % length]; final nextNodeScreen = copyWorldToScreenPos(nextNode, camera); - drawLine(camera, prevNodeScreen, nextNodeScreen); + drawLine(gfx, prevNodeScreen, nextNodeScreen); nextNodeScreen.put(); } prevNodeScreen.put(); } - FlxG.renderer.endDrawDebug(); + camera.view.endDrawDebug(); } @:access(flixel.FlxCamera) @@ -382,14 +383,16 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - inline function drawNode(camera:FlxCamera, node:FlxPoint, size:Int, color:FlxColor) + inline function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) { + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.lineStyle(); final offset = Math.floor(size * 0.5); - FlxG.renderer.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); + gfx.drawRect(node.x - offset, node.y - offset, size, size); + gfx.endFill(); } - @:deprecated("drawLine(gfx, node1, node2) is deprecated. Use drawLine(camera, node1, node2) instead.") - overload extern inline function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) + function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) { // then draw a line to the next node final color = debugDrawData.lineColor; @@ -400,16 +403,6 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy gfx.moveTo(node1.x + lineOffset, node1.y + lineOffset); gfx.lineTo(node2.x + lineOffset, node2.y + lineOffset); } - - overload extern inline function drawLine(camera:FlxCamera, node1:FlxPoint, node2:FlxPoint) - { - // then draw a line to the next node - final color = debugDrawData.lineColor; - final size = debugDrawData.lineSize; - final lineOffset = debugDrawData.lineSize / 2; - - FlxG.renderer.drawDebugLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, color, size); - } #end } diff --git a/flixel/system/FlxBGSprite.hx b/flixel/system/FlxBGSprite.hx index 25a6f55050..dfb81e19f2 100644 --- a/flixel/system/FlxBGSprite.hx +++ b/flixel/system/FlxBGSprite.hx @@ -32,8 +32,7 @@ class FlxBGSprite extends FlxSprite _matrix.scale(camera.viewWidth + 1, camera.viewHeight + 1); _matrix.translate(camera.viewMarginLeft, camera.viewMarginTop); - FlxG.renderer.begin(camera); - FlxG.renderer.drawPixels(frame, _matrix, colorTransform); + FlxG.renderer.drawPixels(camera.view, frame, _matrix, colorTransform); #if FLX_DEBUG FlxBasic.visibleCount++; diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index 200c379f20..ba19a286d2 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -14,9 +14,9 @@ import flixel.system.debug.interaction.tools.ToggleBounds; import flixel.system.debug.interaction.tools.Tool; import flixel.system.debug.interaction.tools.TrackObject; import flixel.system.debug.interaction.tools.Transform; +import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxSpriteUtil; -import flixel.util.FlxColor; import openfl.display.BitmapData; import openfl.display.DisplayObject; import openfl.display.Graphics; @@ -396,23 +396,23 @@ class Interaction extends Window function drawItemsSelection():Void { - final camera = FlxG.camera; - FlxG.renderer.beginDrawDebug(camera); + final view = FlxG.camera.view; + view.beginDrawDebug(); for (member in selectedItems) { if (member != null && member.scrollFactor != null && member.isOnScreen()) { final margin = 0.5; - final scroll = camera.scroll; + final scroll = FlxG.camera.scroll; // Render a white rectangle centered at the selected item final color:FlxColor = FlxColor.fromRGBFloat(1, 1, 1, 0.75); - FlxG.renderer.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); + view.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); } } - FlxG.renderer.endDrawDebug(); + view.endDrawDebug(); } /** diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index 050ffb3814..f397f80187 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -1,15 +1,15 @@ package flixel.system.debug.interaction.tools; -import openfl.display.BitmapData; -import openfl.display.Graphics; -import openfl.ui.Keyboard; import flixel.FlxBasic; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.debug.Icon; import flixel.system.debug.interaction.Interaction; -import flixel.util.FlxSpriteUtil; import flixel.util.FlxColor; +import flixel.util.FlxSpriteUtil; +import openfl.display.BitmapData; +import openfl.display.Graphics; +import openfl.ui.Keyboard; using flixel.util.FlxArrayUtil; @@ -134,7 +134,8 @@ class Pointer extends Tool override public function draw():Void { - FlxG.renderer.beginDrawDebug(FlxG.camera); + final view = FlxG.camera.view; + view.beginDrawDebug(); switch state { @@ -145,11 +146,11 @@ class Pointer extends Tool // Render the selection rectangle var color:FlxColor = 0xbb0000; color.alphaFloat = 0.9; - FlxG.renderer.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); + view.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); rect.put(); } - FlxG.renderer.endDrawDebug(); + view.endDrawDebug(); } static function setAbsRect(rect:FlxRect, x1:Float, y1:Float, x2:Float, y2:Float) diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index 0c3bf0a3d3..b14296645e 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -235,10 +235,11 @@ class Transform extends Tool final camera = target.getDefaultCamera(); - FlxG.renderer.beginDrawDebug(camera); + final view = camera.view; + view.beginDrawDebug(); drawSelection(camera); Marker.draw(target.x + target.origin.x, target.y + target.origin.y, false, camera); - FlxG.renderer.endDrawDebug(); + view.endDrawDebug(); } function drawSelection(camera:FlxCamera) @@ -248,7 +249,7 @@ class Transform extends Tool var prevY = markers[3].y; for (marker in markers) { - FlxG.renderer.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); + camera.view.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); prevX = marker.x; prevY = marker.y; @@ -300,12 +301,10 @@ private class Marker public static function draw(screenX:Float, screenY:Float, circle:Bool, camera:FlxCamera) { - FlxG.renderer.begin(camera); - if (circle) - FlxG.renderer.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); + camera.view.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); else - FlxG.renderer.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); + camera.view.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); } } diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index eb28bcb776..36dc3b475e 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -1,12 +1,12 @@ package flixel.system.frontEnds; -import flixel.system.render.blit.FlxBlitRenderer; -import openfl.geom.Rectangle; import flixel.FlxCamera; import flixel.FlxG; +import flixel.system.render.blit.FlxBlitRenderer; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxSignal.FlxTypedSignal; +import openfl.geom.Rectangle; using flixel.util.FlxArrayUtil; @@ -272,10 +272,7 @@ class CameraFrontEnd for (camera in list) { if ((camera != null) && camera.exists && camera.visible) - { - FlxG.renderer.begin(camera); - FlxG.renderer.clear(); - } + FlxG.renderer.clear(camera.view); } } @@ -288,10 +285,7 @@ class CameraFrontEnd for (camera in list) { if ((camera != null) && camera.exists && camera.visible) - { - FlxG.renderer.begin(camera); - FlxG.renderer.render(); - } + FlxG.renderer.render(camera.view); } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 05cad513a0..6060ad33d0 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -1,19 +1,20 @@ package flixel.system.render; -import openfl.display.DisplayObjectContainer; -import openfl.display.DisplayObject; -import flixel.math.FlxRect; -import flixel.FlxG; import flixel.FlxCamera; -import flixel.util.FlxDestroyUtil; +import flixel.FlxG; import flixel.math.FlxPoint; +import flixel.math.FlxRect; import flixel.util.FlxColor; +import flixel.util.FlxDestroyUtil; +import openfl.display.DisplayObject; +import openfl.display.DisplayObjectContainer; +import openfl.display.Graphics; /** * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects */ @:allow(flixel.FlxCamera) -class FlxCameraView implements IFlxDestroyable +abstract class FlxCameraView implements IFlxDestroyable { /** * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. @@ -101,6 +102,80 @@ class FlxCameraView implements IFlxDestroyable function updateScrollRect():Void {} + //{ region ------------------------ DEBUG DRAW ------------------------ + + /** + * Begins debug draw on the current (or optionally specified) camera. + * Any debug drawing commands will be executed on the camera. + * + * @param camera Optional, the camera to draw to. + */ + abstract public function beginDrawDebug():Graphics; + + abstract public function getDebugGraphics():Graphics; + + /** + * Cleans up and finalizes the debug draw. + */ + abstract public function endDrawDebug():Void; + + /** + * Draws a rectangle with an outline. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's outline. + * @param thickness The thickness of the rectangle's outline. + */ + abstract public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void; + + /** + * Draws a filled rectangle. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. + */ + abstract public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void; + + /** + * Draws a filled circle. + * + * @param x The x position of the circle. + * @param y The y position of the circle. + * @param radius The radius of the circle. + * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. + */ + abstract public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void; + + /** + * Draws a line. + * + * @param x1 The start x position of the line. + * @param y1 The start y position of the line. + * @param x2 The end x position of the line. + * @param y2 The end y position of the line. + * @param color The color (in 0xAARRGGBB hex format) of the line. + * @param thickness The thickness of the line. + */ + abstract public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void; + + //} endregion --------------------- DEBUG DRAW ------------------------ + + //{ region ------------------------ HELPERS ------------------------ + + /** + * Fills the current render target with `color`. + * + * @param color The color (in 0xAARRGGBB format) to fill the screen with. + * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. + */ + abstract public function fill(color:FlxColor, blendAlpha:Bool = true):Void; + /** * Helper method preparing debug rectangle for rendering in blit render mode * @param rect rectangle to prepare for rendering @@ -152,19 +227,20 @@ class FlxCameraView implements IFlxDestroyable return object; } - function get_display():DisplayObjectContainer - { - return null; - } + //} endregion --------------------- HELPERS ------------------------ + + //{ region ------------------------ GETTERS ------------------------ + + abstract function get_display():DisplayObjectContainer; function get_color():FlxColor { return camera.color; } - function set_color(color:FlxColor):FlxColor + function set_color(value:FlxColor):FlxColor { - return color; + return camera.color = value; } function get_antialiasing():Bool @@ -172,9 +248,9 @@ class FlxCameraView implements IFlxDestroyable return camera.antialiasing; } - function set_antialiasing(antialiasing:Bool):Bool + function set_antialiasing(value:Bool):Bool { - return antialiasing; + return camera.antialiasing = value; } function get_angle():Float @@ -182,9 +258,9 @@ class FlxCameraView implements IFlxDestroyable return camera.angle; } - function set_angle(angle:Float):Float + function set_angle(value:Float):Float { - return angle; + return camera.angle = value; } function get_visible():Bool @@ -192,9 +268,9 @@ class FlxCameraView implements IFlxDestroyable return camera.visible; } - function set_visible(visible:Bool):Bool + function set_visible(value:Bool):Bool { - return visible; + return camera.visible = value; } function get_alpha():Float @@ -202,8 +278,10 @@ class FlxCameraView implements IFlxDestroyable return camera.alpha; } - function set_alpha(alpha:Float):Float + function set_alpha(value:Float):Float { - return alpha; + return camera.alpha = value; } + + //} endregion --------------------- GETTERS ------------------------ } diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 2d0036c47f..0394354023 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -26,7 +26,12 @@ import openfl.geom.Rectangle; * This is called internally by Flixel during a sprite's draw phase, so you shouldn't worry about calling it yourself unless * you have a reason to. */ -class FlxRenderer implements IFlxDestroyable +typedef FlxRenderer = FlxTypedRenderer; + +/** + * Typed Renderer, override this to handle specific backends that require specific cavera views + */ +class FlxTypedRenderer implements IFlxDestroyable { /** * The number of total draw calls in the current frame. @@ -43,11 +48,11 @@ class FlxRenderer implements IFlxDestroyable { if (!FlxG.renderer.isHardware) { - return new flixel.system.render.blit.FlxBlitRenderer(); + return cast new flixel.system.render.blit.FlxBlitRenderer(); } else { - return new flixel.system.render.quad.FlxQuadRenderer(); + return cast new flixel.system.render.quad.FlxQuadRenderer(); } } @@ -89,46 +94,25 @@ class FlxRenderer implements IFlxDestroyable */ public var maxTextureSize(default, null):Int; - /** - * The current camera in use. - */ - public var camera(default, null):FlxCamera; - public function new() { maxTextureSize = -1; } - public function destroy():Void - { - camera = null; - } - + public function destroy():Void {} + + // ------------------------ RENDERING ------------------------ - /** - * Sets `camera` as the current render target. - * Any drawing commands will be executed on the camera. - * - * **NOTE:** Manually calling this during the draw phase could mess things up. - * If you must, please remember to reset the state back to where it was - * - * @param camera The camera to draw to. - */ - public function begin(camera:FlxCamera):Void - { - this.camera = camera; - } - /** * Called before a new rendering frame, clears all previously drawn graphics. */ - public function clear():Void {} + public function clear(view:TView):Void {} /** * Flushes any remaining graphics and renders everything to the screen. */ - public function render():Void {} + public function render(view:TView):Void {} /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. @@ -141,8 +125,8 @@ class FlxRenderer implements IFlxDestroyable * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void {} + public function drawPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, + ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. @@ -159,7 +143,7 @@ class FlxRenderer implements IFlxDestroyable * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + public function copyPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} /** @@ -177,82 +161,10 @@ class FlxRenderer implements IFlxDestroyable * @param transform The color transform to use, optional. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} - /** - * Fills the current render target with `color`. - * - * @param color The color (in 0xAARRGGBB format) to fill the screen with. - * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. - */ - public function fill(color:FlxColor, blendAlpha:Bool = true):Void {} - - // ------------------------ DEBUG DRAW ------------------------ - - /** - * Begins debug draw on the current (or optionally specified) camera. - * Any debug drawing commands will be executed on the camera. - * - * @param camera Optional, the camera to draw to. - */ - public function beginDrawDebug(?camera:FlxCamera):Void - { - if (camera != null) - { - this.camera = camera; - } - } - - /** - * Cleans up and finalizes the debug draw. - */ - public function endDrawDebug():Void {} - /** - * Draws a rectangle with an outline. - * - * @param x The x position of the rectangle. - * @param y The y position of the rectangle. - * @param width The width of the rectangle (in pixels). - * @param height The height of the rectangle (in pixels). - * @param color The color (in 0xAARRGGBB hex format) of the rectangle's outline. - * @param thickness The thickness of the rectangle's outline. - */ - public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void {} - - /** - * Draws a filled rectangle. - * - * @param x The x position of the rectangle. - * @param y The y position of the rectangle. - * @param width The width of the rectangle (in pixels). - * @param height The height of the rectangle (in pixels). - * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. - */ - public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void {} - - /** - * Draws a filled circle. - * - * @param x The x position of the circle. - * @param y The y position of the circle. - * @param radius The radius of the circle. - * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. - */ - public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void {} - - /** - * Draws a line. - * - * @param x1 The start x position of the line. - * @param y1 The start y position of the line. - * @param x2 The end x position of the line. - * @param y2 The end y position of the line. - * @param color The color (in 0xAARRGGBB hex format) of the line. - * @param thickness The thickness of the line. - */ - public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void {} } /** diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 3fb13042c3..efa4e14f4b 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -2,12 +2,12 @@ package flixel.system.render.blit; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; import flixel.graphics.tile.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; -import flixel.system.FlxAssets.FlxShader; +import flixel.system.FlxAssets; +import flixel.system.render.FlxRenderer; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxSpriteUtil; @@ -22,7 +22,7 @@ import openfl.geom.Rectangle; @:access(flixel.FlxCamera) @:access(flixel.system.render.blit) -class FlxBlitRenderer extends FlxRenderer +class FlxBlitRenderer extends FlxTypedRenderer { /** * Whether the camera's buffer should be locked and unlocked during render calls. @@ -67,14 +67,6 @@ class FlxBlitRenderer extends FlxRenderer */ var _flashPoint:Point = new Point(); - /** - * Convenience shortcut for `camera.viewBlit` - */ - var view(get, never):FlxBlitView; - - @:noCompletion inline function get_view():FlxBlitView - return camera.viewBlit; - public function new() { super(); @@ -90,7 +82,7 @@ class FlxBlitRenderer extends FlxRenderer _flashPoint = null; } - override function clear():Void + override function clear(view:FlxBlitView):Void { view.checkResize(); @@ -99,13 +91,14 @@ class FlxBlitRenderer extends FlxRenderer view.buffer.lock(); } - fill(camera.bgColor, camera.useBgAlphaBlending); + final camera = view.camera; + view.fill(camera.bgColor, camera.useBgAlphaBlending); view.screen.dirty = true; } - override function render():Void + override function render(view:FlxBlitView):Void { - camera.drawFX(); + view.camera.drawFX(); if (useBufferLocking) { @@ -115,11 +108,12 @@ class FlxBlitRenderer extends FlxRenderer view.screen.dirty = true; } - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + override function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void { _helperMatrix.copyFrom(matrix); + final camera = view.camera; if (view._useBlitMatrix) { _helperMatrix.concat(view._blitMatrix); @@ -132,9 +126,10 @@ class FlxBlitRenderer extends FlxRenderer } } - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + override function copyPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { + final camera = view.camera; if (pixels != null) { if (view._useBlitMatrix) @@ -158,9 +153,10 @@ class FlxBlitRenderer extends FlxRenderer } } - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + override function drawTriangles(view:FlxBlitView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { + final camera = view.camera; final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); if (position == null) @@ -234,63 +230,4 @@ class FlxBlitRenderer extends FlxRenderer bounds.put(); } - - override function fill(color:FlxColor, blendAlpha:Bool = true) - { - if (blendAlpha) - { - view._fill.fillRect(view._flashRect, color); - view.buffer.copyPixels(view._fill, view._flashRect, _flashPoint, null, null, blendAlpha); - } - else - { - view.buffer.fillRect(view._flashRect, color); - } - } - - override function beginDrawDebug(?camera:FlxCamera):Void - { - super.beginDrawDebug(camera); - - FlxSpriteUtil.flashGfx.clear(); - } - - override function endDrawDebug():Void - { - view.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - - #if FLX_DEBUG - override public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - - override public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); - } - - override public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); - } - - override public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = FlxSpriteUtil.flashGfx; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); - } - #end } diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index d35df84630..1fc69011ea 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -3,18 +3,19 @@ package flixel.system.render.blit; import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; -import flixel.math.FlxRect; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; +import flixel.math.FlxRect; import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import openfl.display.Bitmap; import openfl.display.BitmapData; import openfl.display.DisplayObjectContainer; +import openfl.display.Graphics; import openfl.display.Sprite; -import openfl.geom.Rectangle; import openfl.geom.ColorTransform; +import openfl.geom.Rectangle; class FlxBlitView extends FlxCameraView { @@ -43,6 +44,13 @@ class FlxBlitView extends FlxCameraView */ public var buffer:BitmapData; + #if FLX_DEBUG + /** + * Sprite for drawDebug information + */ + public var debugSprite:Sprite = new Sprite(); + #end + /** * Internal sprite, used for correct trimming of camera viewport. * It is a child of `flashSprite`. @@ -177,6 +185,76 @@ class FlxBlitView extends FlxCameraView } } + //{ region ------------------------ DEBUG DRAW ------------------------ + + public function beginDrawDebug() + { + debugSprite.graphics.clear(); + return debugSprite.graphics; + } + + public function getDebugGraphics() + { + return debugSprite.graphics; + } + + public function endDrawDebug():Void + { + buffer.draw(debugSprite); + } + + #if FLX_DEBUG + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugSprite.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = debugSprite.graphics; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = debugSprite.graphics; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugSprite.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, y1); + gfx.lineTo(x2, y2); + } + #end + + //} endregion --------------------- DEBUG DRAW ------------------------ + + //{ region ------------------------ HELPERS ------------------------ + + @:haxe.warning("-WDeprecated") + public function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) + { + _fill.fillRect(_flashRect, color); + buffer.copyPixels(_fill, _flashRect, camera._flashPoint, null, null, blendAlpha); + } + else + { + buffer.fillRect(_flashRect, color); + } + } + function checkResize():Void { if (camera.width != buffer.width || camera.height != buffer.height) @@ -238,7 +316,11 @@ class FlxBlitView extends FlxCameraView return vector; } - override function get_display():DisplayObjectContainer + //} endregion --------------------- HELPERS ------------------------ + + //{ region ------------------------ GETTERS ------------------------ + + function get_display():DisplayObjectContainer { return flashSprite; } @@ -279,4 +361,6 @@ class FlxBlitView extends FlxCameraView flashSprite.visible = visible; return visible; } + + //} endregion --------------------- GETTERS ------------------------ } diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index b21d2d4ccb..324ec30150 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -1,6 +1,5 @@ package flixel.system.render.quad; -import openfl.geom.Point; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; import flixel.graphics.tile.FlxDrawBaseItem; @@ -9,30 +8,26 @@ import flixel.graphics.tile.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; -import flixel.system.FlxAssets.FlxShader; +import flixel.system.FlxAssets; +import flixel.system.render.FlxRenderer; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.geom.ColorTransform; +import openfl.geom.Point; import openfl.geom.Rectangle; + +using flixel.util.FlxColorTransformUtil; #if FLX_OPENGL_AVAILABLE import lime.graphics.opengl.GL; #end -using flixel.util.FlxColorTransformUtil; @:access(flixel.FlxCamera) @:access(flixel.system.render.quad) -class FlxQuadRenderer extends FlxRenderer +class FlxQuadRenderer extends FlxTypedRenderer { - /** - * Convenience shortcut for `camera.viewQuad` - */ - var view(get, never):FlxQuadView; - @:noCompletion inline function get_view():FlxQuadView - return camera.viewQuad; - var _helperMatrix:FlxMatrix = new FlxMatrix(); /** @@ -58,7 +53,7 @@ class FlxQuadRenderer extends FlxRenderer _helperMatrix = null; } - override function clear():Void + override function clear(view:FlxQuadView):Void { view.clearDrawStack(); @@ -69,24 +64,24 @@ class FlxQuadRenderer extends FlxRenderer #end view.targetGraphics = view.canvas.graphics; - fill(camera.bgColor, camera.useBgAlphaBlending); + view.fill(view.camera.bgColor, view.camera.useBgAlphaBlending); } - override function render():Void + override function render(view:FlxQuadView):Void { - view.flashSprite.filters = camera.filtersEnabled ? camera.filters : null; + view.flashSprite.filters = view.camera.filtersEnabled ? view.camera.filters : null; var currItem:FlxDrawBaseItem = view._headOfDrawStack; while (currItem != null) { - currItem.render(camera); + currItem.render(view.camera); currItem = currItem.next; } - camera.drawFX(); + view.camera.drawFX(); } - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + override function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); @@ -100,7 +95,7 @@ class FlxQuadRenderer extends FlxRenderer drawItem.addQuad(frame, matrix, transform); } - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + override function copyPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { _helperMatrix.identity(); @@ -117,9 +112,10 @@ class FlxQuadRenderer extends FlxRenderer drawItem.addQuad(frame, _helperMatrix, transform); } - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + override function drawTriangles(view:FlxQuadView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { + final camera = view.camera; final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); @@ -128,48 +124,4 @@ class FlxQuadRenderer extends FlxRenderer final drawItem = view.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); } - - override function fill(color:FlxColor, blendAlpha:Bool = true):Void - { - view.targetGraphics.overrideBlendMode(null); - view.targetGraphics.beginFill(color.rgb, color.alphaFloat); - // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, - // which could appear while cameras fading - view.targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - view.targetGraphics.endFill(); - } - - #if FLX_DEBUG - override function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = view.debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - - override function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - final gfx = view.debugLayer.graphics; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); - } - - override function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - final gfx = view.debugLayer.graphics; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); - } - - override function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = view.debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); - } - #end } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 5d8713562b..e17e0f5bf7 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -191,7 +191,7 @@ class FlxQuadView extends FlxCameraView return visible; } - override function get_display():DisplayObjectContainer + function get_display():DisplayObjectContainer { return flashSprite; } @@ -382,4 +382,61 @@ class FlxQuadView extends FlxCameraView _headTiles = null; _headTriangles = null; } + + public function fill(color:FlxColor, blendAlpha:Bool = true):Void + { + targetGraphics.overrideBlendMode(null); + targetGraphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + targetGraphics.endFill(); + } + + public function beginDrawDebug() + { + debugLayer.graphics.clear(); + return debugLayer.graphics; + } + + public function getDebugGraphics() + { + return debugLayer.graphics; + } + + public function endDrawDebug():Void {} + + #if FLX_DEBUG + public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.drawRect(x, y, width, height); + } + + public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(); + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawRect(x, y, width, height); + gfx.endFill(); + } + + public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + final gfx = debugLayer.graphics; + gfx.beginFill(color.rgb, color.alphaFloat); + gfx.drawCircle(x, y, radius); + gfx.endFill(); + } + + public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + final gfx = debugLayer.graphics; + gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + gfx.moveTo(x1, y1); + gfx.lineTo(x2, y2); + } + #end } diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 2694519df5..05a18065b1 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -545,8 +545,6 @@ class FlxTypedTilemap extends FlxBaseTilemap if (FlxG.renderer.method != DRAW_TILES) return; - FlxG.renderer.beginDrawDebug(camera); - var buffer:FlxTilemapBuffer = null; var l:Int = FlxG.cameras.list.length; @@ -597,7 +595,7 @@ class FlxTypedTilemap extends FlxBaseTilemap if (color != null) { final colStr = color.toHexString(); - drawDebugBoundingBoxColor(rect, color); + drawDebugBoundingBoxColor(camera.view.getDebugGraphics(), rect, color); } } } diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index 454650fb2a..1c9f92dc31 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -1,16 +1,16 @@ package flixel.tile; -import openfl.display.BitmapData; -import openfl.geom.Point; -import openfl.geom.Rectangle; import flixel.FlxCamera; import flixel.FlxG; import flixel.math.FlxMatrix; import flixel.tile.FlxTilemap; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; /** * A helper object to keep tilemap drawing performance decent across the new multi-camera system. @@ -180,19 +180,17 @@ class FlxTilemapBuffer implements IFlxDestroyable flashPoint.x = Math.floor(flashPoint.x); flashPoint.y = Math.floor(flashPoint.y); } - - FlxG.renderer.begin(camera); if (isPixelPerfectRender(camera) && (scaleX == 1.0 && scaleY == 1.0) && blend == null) { - FlxG.renderer.copyPixels(pixels, _flashRect, flashPoint, null, null, true); + FlxG.renderer.copyPixels(camera.view, pixels, _flashRect, flashPoint, null, null, true); } else { _matrix.identity(); _matrix.scale(scaleX, scaleY); _matrix.translate(flashPoint.x, flashPoint.y); - FlxG.renderer.drawPixels(pixels, _matrix, null, blend, antialiasing); + FlxG.renderer.drawPixels(camera.view, pixels, _matrix, null, blend, antialiasing); } } diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index fa26277b06..d2059502b4 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -1,8 +1,5 @@ package flixel.ui; -import openfl.display.BitmapData; -import openfl.geom.Point; -import openfl.geom.Rectangle; import flixel.FlxG; import flixel.FlxSprite; import flixel.graphics.FlxGraphic; @@ -15,6 +12,9 @@ import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxGradient; import flixel.util.FlxStringUtil; +import openfl.display.BitmapData; +import openfl.geom.Point; +import openfl.geom.Rectangle; // TODO: better handling bars with borders (don't take border into account while drawing its front). @@ -890,8 +890,7 @@ class FlxBar extends FlxSprite _matrix.ty = Math.floor(_matrix.ty); } - FlxG.renderer.begin(camera); - FlxG.renderer.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); + FlxG.renderer.drawPixels(camera.view, _frontFrame, _matrix, colorTransform, blend, antialiasing, shader); } } } From 1043633365f459f1979274efeb03c328110743a2 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Tue, 24 Feb 2026 20:40:18 -0600 Subject: [PATCH 30/72] fix debug draw --- flixel/system/render/quad/FlxQuadView.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index e17e0f5bf7..6400da6786 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -395,7 +395,6 @@ class FlxQuadView extends FlxCameraView public function beginDrawDebug() { - debugLayer.graphics.clear(); return debugLayer.graphics; } From b6fc6bb4b0492ff569c708e8004e2fbeab8858df Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 11:05:51 -0600 Subject: [PATCH 31/72] move some rendereer methods to view --- flixel/FlxCamera.hx | 2 +- flixel/system/frontEnds/CameraFrontEnd.hx | 4 +- flixel/system/render/FlxCameraView.hx | 10 ++++ flixel/system/render/FlxRenderer.hx | 17 ++---- flixel/system/render/blit/FlxBlitRenderer.hx | 26 ---------- flixel/system/render/blit/FlxBlitView.hx | 54 +++++++++++++++----- flixel/system/render/quad/FlxQuadRenderer.hx | 28 ---------- flixel/system/render/quad/FlxQuadView.hx | 40 ++++++++++++--- 8 files changed, 88 insertions(+), 93 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 613dd4561a..cd920efa7c 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -723,7 +723,7 @@ class FlxCamera extends FlxBasic @:deprecated("camera.render() is deprecated, use FlxG.renderer.render() instead.") function render():Void { - FlxG.renderer.render(view); + view.render(); } @:allow(flixel.system.frontEnds.CameraFrontEnd) diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 36dc3b475e..e76a7a604a 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -272,7 +272,7 @@ class CameraFrontEnd for (camera in list) { if ((camera != null) && camera.exists && camera.visible) - FlxG.renderer.clear(camera.view); + camera.view.clear(); } } @@ -285,7 +285,7 @@ class CameraFrontEnd for (camera in list) { if ((camera != null) && camera.exists && camera.visible) - FlxG.renderer.render(camera.view); + camera.view.render(); } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 6060ad33d0..9c983fb4a7 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -168,6 +168,16 @@ abstract class FlxCameraView implements IFlxDestroyable //{ region ------------------------ HELPERS ------------------------ + /** + * Flushes any remaining graphics and renders everything to the screen. + */ + abstract public function render():Void; + + /** + * Called before a new rendering frame, clears all previously drawn graphics. + */ + abstract public function clear():Void; + /** * Fills the current render target with `color`. * diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 0394354023..d14b6a9eb9 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -101,18 +101,7 @@ class FlxTypedRenderer implements IFlxDestroyable public function destroy():Void {} - - // ------------------------ RENDERING ------------------------ - - /** - * Called before a new rendering frame, clears all previously drawn graphics. - */ - public function clear(view:TView):Void {} - - /** - * Flushes any remaining graphics and renders everything to the screen. - */ - public function render(view:TView):Void {} + //{ region ------------------------ RENDERING ------------------------ /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. @@ -163,8 +152,8 @@ class FlxTypedRenderer implements IFlxDestroyable */ public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} - - + + //} endregion ------------------------ RENDERING ------------------------ } /** diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index efa4e14f4b..6ac76c1af6 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -82,32 +82,6 @@ class FlxBlitRenderer extends FlxTypedRenderer _flashPoint = null; } - override function clear(view:FlxBlitView):Void - { - view.checkResize(); - - if (useBufferLocking) - { - view.buffer.lock(); - } - - final camera = view.camera; - view.fill(camera.bgColor, camera.useBgAlphaBlending); - view.screen.dirty = true; - } - - override function render(view:FlxBlitView):Void - { - view.camera.drawFX(); - - if (useBufferLocking) - { - view.buffer.unlock(); - } - - view.screen.dirty = true; - } - override function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void { diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 1fc69011ea..c1d50c172b 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -125,6 +125,45 @@ class FlxBlitView extends FlxCameraView _flashRect = null; } + function render():Void + { + camera.drawFX(); + + if (FlxBlitRenderer.useBufferLocking) + { + buffer.unlock(); + } + + screen.dirty = true; + } + + public function clear():Void + { + checkResize(); + + if (FlxBlitRenderer.useBufferLocking) + { + buffer.lock(); + } + + fill(camera.bgColor, camera.useBgAlphaBlending); + screen.dirty = true; + } + + @:haxe.warning("-WDeprecated") + public function fill(color:FlxColor, blendAlpha:Bool = true) + { + if (blendAlpha) + { + _fill.fillRect(_flashRect, color); + buffer.copyPixels(_fill, _flashRect, camera._flashPoint, null, null, blendAlpha); + } + else + { + buffer.fillRect(_flashRect, color); + } + } + override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; @@ -239,21 +278,8 @@ class FlxBlitView extends FlxCameraView //} endregion --------------------- DEBUG DRAW ------------------------ - //{ region ------------------------ HELPERS ------------------------ + //{ region ------------------------ HELPERS --------------------------- - @:haxe.warning("-WDeprecated") - public function fill(color:FlxColor, blendAlpha:Bool = true) - { - if (blendAlpha) - { - _fill.fillRect(_flashRect, color); - buffer.copyPixels(_fill, _flashRect, camera._flashPoint, null, null, blendAlpha); - } - else - { - buffer.fillRect(_flashRect, color); - } - } function checkResize():Void { diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 324ec30150..8774fd8921 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -53,34 +53,6 @@ class FlxQuadRenderer extends FlxTypedRenderer _helperMatrix = null; } - override function clear(view:FlxQuadView):Void - { - view.clearDrawStack(); - - view.canvas.graphics.clear(); - #if FLX_DEBUG - // Clearing camera's debug sprite - view.debugLayer.graphics.clear(); - #end - - view.targetGraphics = view.canvas.graphics; - view.fill(view.camera.bgColor, view.camera.useBgAlphaBlending); - } - - override function render(view:FlxQuadView):Void - { - view.flashSprite.filters = view.camera.filtersEnabled ? view.camera.filters : null; - - var currItem:FlxDrawBaseItem = view._headOfDrawStack; - while (currItem != null) - { - currItem.render(view.camera); - currItem = currItem.next; - } - - view.camera.drawFX(); - } - override function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 6400da6786..cd595eece4 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -226,8 +226,7 @@ class FlxQuadView extends FlxCameraView */ static var _storageTrianglesHead:FlxDrawTrianglesItem; - @:noCompletion - public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) + function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) { #if FLX_RENDER_TRIANGLE return startTrianglesBatch(graphic, smooth, colored, blend); @@ -288,8 +287,7 @@ class FlxQuadView extends FlxCameraView #end } - @:noCompletion - public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { if (_currentDrawItem != null @@ -307,8 +305,7 @@ class FlxQuadView extends FlxCameraView return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } - @:noCompletion - public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { var itemToReturn:FlxDrawTrianglesItem = null; @@ -350,8 +347,35 @@ class FlxQuadView extends FlxCameraView return itemToReturn; } - @:noCompletion - public function clearDrawStack():Void + public function render():Void + { + flashSprite.filters = camera.filtersEnabled ? camera.filters : null; + + var currItem:FlxDrawBaseItem = _headOfDrawStack; + while (currItem != null) + { + currItem.render(camera); + currItem = currItem.next; + } + + camera.drawFX(); + } + + public function clear():Void + { + clearDrawStack(); + + canvas.graphics.clear(); + #if FLX_DEBUG + // Clearing camera's debug sprite + debugLayer.graphics.clear(); + #end + + targetGraphics = canvas.graphics; + fill(camera.bgColor, camera.useBgAlphaBlending); + } + + function clearDrawStack():Void { var currTiles = _headTiles; var newTilesHead; From bb17eb19b94b7a9c960be6fd7bed8aaee2f927ee Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 11:05:57 -0600 Subject: [PATCH 32/72] whitespace --- flixel/system/render/FlxRenderer.hx | 97 ++++++++++++++--------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index d14b6a9eb9..a3db5a14cd 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -103,52 +103,52 @@ class FlxTypedRenderer implements IFlxDestroyable //{ region ------------------------ RENDERING ------------------------ - /** - * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. - * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param matrix The transformation matrix to use. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). - */ + /** + * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param matrix The transformation matrix to use. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ public function drawPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. - * - * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations - * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. - * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). - * @param destPoint A point representing the top-left position to draw to. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + * + * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations + * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). + * @param destPoint A point representing the top-left position to draw to. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ public function copyPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} /** * Draws a set of triangles onto the current render target. - * - * @param graphic The graphic to use for the triangles. - * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. - * @param indices A vector where each element is an index to a vertex (x, y) pair. 3 indices make up a triangle. - * @param uvtData A vector where each element is a normalized coordinate (from 0.0 to 1.0), per vertex, used to apply texture mapping. - * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. - * @param position A point representing the top-left position to draw to. - * @param blend The blend mode to use, optional. - * @param repeat Whether the graphic should repeat. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param transform The color transform to use, optional. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + * + * @param graphic The graphic to use for the triangles. + * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. + * @param indices A vector where each element is an index to a vertex (x, y) pair. 3 indices make up a triangle. + * @param uvtData A vector where each element is a normalized coordinate (from 0.0 to 1.0), per vertex, used to apply texture mapping. + * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. + * @param position A point representing the top-left position to draw to. + * @param blend The blend mode to use, optional. + * @param repeat Whether the graphic should repeat. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param transform The color transform to use, optional. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} @@ -161,18 +161,17 @@ class FlxTypedRenderer implements IFlxDestroyable */ enum FlxRenderMethod { - /** - * Uses the `drawQuads()` method from OpenFL's Graphics API to achieve hardware accelerated rendering. - * - * This method is the default and is used on all targets (when hardware acceleration is available), except for Flash. - */ - DRAW_TILES; - - /** - * Draws sprites directly onto bitmaps using a software renderer. - * - * This method is mainly used by the Flash target, though other targets will use it too if - * hardware acceleration is unavailable. - */ - BLITTING; + /** + * Uses the `drawQuads()` method from OpenFL's Graphics API to achieve hardware accelerated rendering. + * + * This method is the default and is used on all targets (when hardware acceleration is available), except for Flash. + */ + DRAW_TILES; + /** + * Draws sprites directly onto bitmaps using a software renderer. + * + * This method is mainly used by the Flash target, though other targets will use it too if + * hardware acceleration is unavailable. + */ + BLITTING; } From 9bfbceec32712bf5466769de135a901222061baa Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 11:20:47 -0600 Subject: [PATCH 33/72] organize methods --- flixel/system/render/FlxCameraView.hx | 38 +++--- flixel/system/render/quad/FlxQuadView.hx | 142 ++++++++++++----------- 2 files changed, 92 insertions(+), 88 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 9c983fb4a7..c866680e34 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -82,6 +82,24 @@ abstract class FlxCameraView implements IFlxDestroyable _flashOffset = FlxDestroyUtil.put(_flashOffset); } + /** + * Flushes any remaining graphics and renders everything to the screen. + */ + abstract public function render():Void; + + /** + * Called before a new rendering frame, clears all previously drawn graphics. + */ + abstract public function clear():Void; + + /** + * Fills the current render target with `color`. + * + * @param color The color (in 0xAARRGGBB format) to fill the screen with. + * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. + */ + abstract public function fill(color:FlxColor, blendAlpha:Bool = true):Void; + public function offsetView(x:Float, y:Float):Void {} function updateScale():Void @@ -166,25 +184,7 @@ abstract class FlxCameraView implements IFlxDestroyable //} endregion --------------------- DEBUG DRAW ------------------------ - //{ region ------------------------ HELPERS ------------------------ - - /** - * Flushes any remaining graphics and renders everything to the screen. - */ - abstract public function render():Void; - - /** - * Called before a new rendering frame, clears all previously drawn graphics. - */ - abstract public function clear():Void; - - /** - * Fills the current render target with `color`. - * - * @param color The color (in 0xAARRGGBB format) to fill the screen with. - * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. - */ - abstract public function fill(color:FlxColor, blendAlpha:Bool = true):Void; + //{ region ------------------------ HELPERS --------------------------- /** * Helper method preparing debug rectangle for rendering in blit render mode diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index cd595eece4..9f46428d21 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -106,6 +106,76 @@ class FlxQuadView extends FlxCameraView _scrollRect = null; } + public function render():Void + { + flashSprite.filters = camera.filtersEnabled ? camera.filters : null; + + var currItem:FlxDrawBaseItem = _headOfDrawStack; + while (currItem != null) + { + currItem.render(camera); + currItem = currItem.next; + } + + camera.drawFX(); + } + + public function clear():Void + { + clearDrawStack(); + + canvas.graphics.clear(); + #if FLX_DEBUG + // Clearing camera's debug sprite + debugLayer.graphics.clear(); + #end + + targetGraphics = canvas.graphics; + fill(camera.bgColor, camera.useBgAlphaBlending); + } + + function clearDrawStack():Void + { + var currTiles = _headTiles; + var newTilesHead; + + while (currTiles != null) + { + newTilesHead = currTiles.nextTyped; + currTiles.reset(); + currTiles.nextTyped = _storageTilesHead; + _storageTilesHead = currTiles; + currTiles = newTilesHead; + } + + var currTriangles:FlxDrawTrianglesItem = _headTriangles; + var newTrianglesHead:FlxDrawTrianglesItem; + + while (currTriangles != null) + { + newTrianglesHead = currTriangles.nextTyped; + currTriangles.reset(); + currTriangles.nextTyped = _storageTrianglesHead; + _storageTrianglesHead = currTriangles; + currTriangles = newTrianglesHead; + } + + _currentDrawItem = null; + _headOfDrawStack = null; + _headTiles = null; + _headTriangles = null; + } + + public function fill(color:FlxColor, blendAlpha:Bool = true):Void + { + targetGraphics.overrideBlendMode(null); + targetGraphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + targetGraphics.endFill(); + } + override function offsetView(x:Float, y:Float):Void { flashSprite.x += x; @@ -347,75 +417,7 @@ class FlxQuadView extends FlxCameraView return itemToReturn; } - public function render():Void - { - flashSprite.filters = camera.filtersEnabled ? camera.filters : null; - - var currItem:FlxDrawBaseItem = _headOfDrawStack; - while (currItem != null) - { - currItem.render(camera); - currItem = currItem.next; - } - - camera.drawFX(); - } - - public function clear():Void - { - clearDrawStack(); - - canvas.graphics.clear(); - #if FLX_DEBUG - // Clearing camera's debug sprite - debugLayer.graphics.clear(); - #end - - targetGraphics = canvas.graphics; - fill(camera.bgColor, camera.useBgAlphaBlending); - } - - function clearDrawStack():Void - { - var currTiles = _headTiles; - var newTilesHead; - - while (currTiles != null) - { - newTilesHead = currTiles.nextTyped; - currTiles.reset(); - currTiles.nextTyped = _storageTilesHead; - _storageTilesHead = currTiles; - currTiles = newTilesHead; - } - - var currTriangles:FlxDrawTrianglesItem = _headTriangles; - var newTrianglesHead:FlxDrawTrianglesItem; - - while (currTriangles != null) - { - newTrianglesHead = currTriangles.nextTyped; - currTriangles.reset(); - currTriangles.nextTyped = _storageTrianglesHead; - _storageTrianglesHead = currTriangles; - currTriangles = newTrianglesHead; - } - - _currentDrawItem = null; - _headOfDrawStack = null; - _headTiles = null; - _headTriangles = null; - } - - public function fill(color:FlxColor, blendAlpha:Bool = true):Void - { - targetGraphics.overrideBlendMode(null); - targetGraphics.beginFill(color.rgb, color.alphaFloat); - // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, - // which could appear while cameras fading - targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - targetGraphics.endFill(); - } + //{ region ------------------------ DEBUG DRAW ------------------------ public function beginDrawDebug() { @@ -462,4 +464,6 @@ class FlxQuadView extends FlxCameraView gfx.lineTo(x2, y2); } #end + + //} endregion ------------------------ DEBUG DRAW ------------------------ } From dc6102dd06cfe4efec5bc49d9e7fe2b5e5baa241 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 12:28:54 -0600 Subject: [PATCH 34/72] use existing drawDebug methods --- flixel/FlxObject.hx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index be3674c6fb..817adb8488 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -5,6 +5,7 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.path.FlxPath; +import flixel.system.render.FlxCameraView; import flixel.tile.FlxBaseTilemap; import flixel.util.FlxAxes; import flixel.util.FlxColor; @@ -1302,13 +1303,14 @@ class FlxObject extends FlxBasic * * @param Camera Which camera to draw the debug visuals to. */ - @:haxe.warning("-WDeprecated") public function drawDebugOnCamera(camera:FlxCamera):Void { if (!camera.visible || !camera.exists || !isOnScreen(camera)) return; final rect = getBoundingBox(camera); + + // TODO: Remove and handle this in the view via drawDebugRect if (FlxG.renderer.method != BLITTING) { final view = camera.getViewMarginRect(); @@ -1319,14 +1321,12 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - final view = camera.view; - final gfx = beginDrawDebug(camera); - drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); - endDrawDebug(camera); + drawDebugBoundingBoxTo(camera.view, rect); } } // TODO: throw warning on overrides + @:deprecated("drawDebugBoundingBox is deprecated, use drawDebugBoundingBoxTo instead") // 6.2.0 function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:FlxDirectionFlags, partial:Bool) { // Find the color to use @@ -1334,7 +1334,14 @@ class FlxObject extends FlxBasic drawDebugBoundingBoxColor(gfx, rect, color); } - // TODO: throw warning on overrides + @:haxe.warning("-WDeprecated") + function drawDebugBoundingBoxTo(view:FlxCameraView, rect:FlxRect) + { + final gfx = view.beginDrawDebug(); + drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); + view.endDrawDebug(); + } + function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) { if (debugBoundingBoxColor != null) @@ -1351,6 +1358,7 @@ class FlxObject extends FlxBasic } // TODO: throw warning on overrides + @:deprecated("beginDrawDebug(gfx) is deprecated, camera.view.drawDebugRect instead") function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { // fill static graphics object with square shape @@ -1358,15 +1366,13 @@ class FlxObject extends FlxBasic gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } - // TODO: throw warning on overrides - @:deprecated("use object.beginDrawDebug(camera) is deprecated, FlxG.renderer.beginDrawDebug(camera) instead") + @:deprecated("beginDrawDebug(camera) is deprecated, use camera.view.beginDrawDebug() instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { return camera.view.beginDrawDebug(); } - // TODO: throw warning on overrides - @:deprecated("use object.endDrawDebug(camera) is deprecated, FlxG.renderer.endDrawDebug() instead") + @:deprecated("endDrawDebug(camera) is deprecated, use camera.view.endDrawDebug() instead") inline function endDrawDebug(camera:FlxCamera) { camera.view.endDrawDebug(); From 8362c911b7b365e1065f62578678bb3cbd4cb824 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 13:24:09 -0600 Subject: [PATCH 35/72] use existing debug draw methods to prevent breaking changes in overrides --- flixel/FlxObject.hx | 20 +++++++++++++------- flixel/path/FlxBasePath.hx | 22 +++++++++++++++++++--- flixel/system/render/blit/FlxBlitView.hx | 5 +++-- flixel/system/render/quad/FlxQuadView.hx | 5 +++-- flixel/tile/FlxTilemap.hx | 2 +- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 817adb8488..72c9dd7356 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1307,7 +1307,7 @@ class FlxObject extends FlxBasic { if (!camera.visible || !camera.exists || !isOnScreen(camera)) return; - + final rect = getBoundingBox(camera); // TODO: Remove and handle this in the view via drawDebugRect @@ -1321,7 +1321,9 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { + final gfx = camera.view.beginDrawDebug(); drawDebugBoundingBoxTo(camera.view, rect); + camera.view.endDrawDebug(); } } @@ -1337,9 +1339,7 @@ class FlxObject extends FlxBasic @:haxe.warning("-WDeprecated") function drawDebugBoundingBoxTo(view:FlxCameraView, rect:FlxRect) { - final gfx = view.beginDrawDebug(); - drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); - view.endDrawDebug(); + drawDebugBoundingBox(view.getDebugGraphics(), rect, allowCollisions, immovable); } function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) @@ -1365,14 +1365,20 @@ class FlxObject extends FlxBasic gfx.lineStyle(1, color, 0.75, false, null, null, MITER, 255); gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); } - - @:deprecated("beginDrawDebug(camera) is deprecated, use camera.view.beginDrawDebug() instead") + + @:haxe.warning("-WDeprecated") + function drawDebugBoundingBoxColorTo(view:FlxCameraView, bounds:FlxRect, color:FlxColor) + { + drawDebugBoundingBoxColor(view.getDebugGraphics(), bounds, color); + } + + @:deprecated("beginDrawDebug(camera) is deprecated, use camera.view.beginDrawDebug instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { return camera.view.beginDrawDebug(); } - @:deprecated("endDrawDebug(camera) is deprecated, use camera.view.endDrawDebug() instead") + @:deprecated("endDrawDebug(camera) is deprecated, use camera.view.endDrawDebug instead") inline function endDrawDebug(camera:FlxCamera) { camera.view.endDrawDebug(); diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 89d96f7a54..8586c00ed3 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -4,6 +4,7 @@ import flixel.FlxBasic; import flixel.FlxG; import flixel.FlxObject; import flixel.math.FlxPoint; +import flixel.system.render.FlxCameraView; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -316,6 +317,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy * * @param camera The camera object the path will draw to. */ + @:haxe.warning("-WDeprecated") public function drawDebugOnCamera(camera:FlxCamera):Void { // Set up our global flash graphics object to draw out the path @@ -346,14 +348,14 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy } // draw a box for the node - drawNode(gfx, prevNodeScreen, nodeSize, nodeColor); + drawNode(camera.view, prevNodeScreen, nodeSize, nodeColor); if (i + 1 < length || loopType == LOOP) { // draw a line to the next node, if LOOP, get connect the tail and head final nextNode = nodes[(i + 1) % length]; final nextNodeScreen = copyWorldToScreenPos(nextNode, camera); - drawLine(gfx, prevNodeScreen, nextNodeScreen); + drawCable(camera.view, prevNodeScreen, nextNodeScreen); nextNodeScreen.put(); } prevNodeScreen.put(); @@ -383,7 +385,8 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - inline function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) + @:deprecated("drawNode(graphics, ...) is deprecated, use the overloaded drawNode(camera.view, ...) instead") + overload inline extern function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) { gfx.beginFill(color.rgb, color.alphaFloat); gfx.lineStyle(); @@ -392,6 +395,13 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy gfx.endFill(); } + overload inline extern function drawNode(view:FlxCameraView, node:FlxPoint, size:Int, color:FlxColor) + { + final offset = Math.floor(size * 0.5); + view.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); + } + + @:deprecated("drawLine is deprecated, use drawCable, instead") function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) { // then draw a line to the next node @@ -403,6 +413,12 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy gfx.moveTo(node1.x + lineOffset, node1.y + lineOffset); gfx.lineTo(node2.x + lineOffset, node2.y + lineOffset); } + + @:haxe.warning("-WDeprecated") + function drawCable(view:FlxCameraView, node1:FlxPoint, node2:FlxPoint) + { + drawLine(view.getDebugGraphics(), node1, node2); + } #end } diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index c1d50c172b..21707b01bb 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -271,8 +271,9 @@ class FlxBlitView extends FlxCameraView { final gfx = debugSprite.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); + final offset = thickness / 2; + gfx.moveTo(x1 + offset, y1 + offset); + gfx.lineTo(x2 + offset, y2 + offset); } #end diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 9f46428d21..7ed4053616 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -460,8 +460,9 @@ class FlxQuadView extends FlxCameraView { final gfx = debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); + final offset = thickness / 2; + gfx.moveTo(x1 + offset, y1 + offset); + gfx.lineTo(x2 + offset, y2 + offset); } #end diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 05a18065b1..bbbcb764dd 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -595,7 +595,7 @@ class FlxTypedTilemap extends FlxBaseTilemap if (color != null) { final colStr = color.toHexString(); - drawDebugBoundingBoxColor(camera.view.getDebugGraphics(), rect, color); + drawDebugBoundingBoxColorTo(camera.view, rect, color); } } } From 29d23c8015fb253cac1299b38f5db2c304a274d4 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 13:44:41 -0600 Subject: [PATCH 36/72] make FlxRenderer an abstract class --- flixel/system/render/FlxRenderer.hx | 16 ++++++++-------- flixel/system/render/blit/FlxBlitRenderer.hx | 6 +++--- flixel/system/render/quad/FlxQuadRenderer.hx | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index a3db5a14cd..f453b724b2 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -31,7 +31,7 @@ typedef FlxRenderer = FlxTypedRenderer; /** * Typed Renderer, override this to handle specific backends that require specific cavera views */ -class FlxTypedRenderer implements IFlxDestroyable +abstract class FlxTypedRenderer implements IFlxDestroyable { /** * The number of total draw calls in the current frame. @@ -94,7 +94,7 @@ class FlxTypedRenderer implements IFlxDestroyable */ public var maxTextureSize(default, null):Int; - public function new() + function new() { maxTextureSize = -1; } @@ -114,8 +114,8 @@ class FlxTypedRenderer implements IFlxDestroyable * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function drawPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, - ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void {} + abstract public function drawPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, + ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void; /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. @@ -132,8 +132,8 @@ class FlxTypedRenderer implements IFlxDestroyable * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function copyPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader):Void {} + abstract public function copyPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader):Void; /** * Draws a set of triangles onto the current render target. @@ -150,8 +150,8 @@ class FlxTypedRenderer implements IFlxDestroyable * @param transform The color transform to use, optional. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void {} + abstract public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void; //} endregion ------------------------ RENDERING ------------------------ } diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 6ac76c1af6..bea59ce000 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -82,7 +82,7 @@ class FlxBlitRenderer extends FlxTypedRenderer _flashPoint = null; } - override function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + public function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void { _helperMatrix.copyFrom(matrix); @@ -100,7 +100,7 @@ class FlxBlitRenderer extends FlxTypedRenderer } } - override function copyPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + public function copyPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { final camera = view.camera; @@ -127,7 +127,7 @@ class FlxBlitRenderer extends FlxTypedRenderer } } - override function drawTriangles(view:FlxBlitView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + public function drawTriangles(view:FlxBlitView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { final camera = view.camera; diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index 8774fd8921..c26b22b3ac 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -53,7 +53,7 @@ class FlxQuadRenderer extends FlxTypedRenderer _helperMatrix = null; } - override function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + public function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); @@ -67,7 +67,7 @@ class FlxQuadRenderer extends FlxTypedRenderer drawItem.addQuad(frame, matrix, transform); } - override function copyPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + public function copyPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { _helperMatrix.identity(); @@ -84,7 +84,7 @@ class FlxQuadRenderer extends FlxTypedRenderer drawItem.addQuad(frame, _helperMatrix, transform); } - override function drawTriangles(view:FlxQuadView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + public function drawTriangles(view:FlxQuadView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { final camera = view.camera; From bf583332a42fd90313b69a572bbc26a146cf5322 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 16:36:01 -0600 Subject: [PATCH 37/72] remove targetGraphics from quad view --- flixel/FlxCamera.hx | 13 ++++++++++--- flixel/system/render/quad/FlxQuadView.hx | 13 ++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index cd920efa7c..474633de16 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1361,13 +1361,20 @@ class FlxCamera extends FlxBasic * @param color The color to fill with in `0xAARRGGBB` hex format. * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. */ - @:deprecated("camera.fill() is deprecated, use FlxG.renderer.fill() instead.") + @:deprecated("camera.fill() is deprecated, use camera.view.fill() instead.") public function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void { color.alphaFloat = fxAlpha; - if (viewQuad != null && graphics != null) - viewQuad.targetGraphics = graphics; + if (viewQuad != null && graphics != null && graphics != view.getDebugGraphics()) + { + graphics.overrideBlendMode(null); + graphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + graphics.endFill(); + } view.fill(color, blendAlpha); } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 7ed4053616..94a2822685 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -55,8 +55,6 @@ class FlxQuadView extends FlxCameraView * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. */ var _scrollRect:Sprite = new Sprite(); - - var targetGraphics:Graphics; @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) @@ -73,8 +71,6 @@ class FlxQuadView extends FlxCameraView debugLayer = new Sprite(); _scrollRect.addChild(debugLayer); #end - - targetGraphics = canvas.graphics; } override function destroy():Void @@ -130,7 +126,6 @@ class FlxQuadView extends FlxCameraView debugLayer.graphics.clear(); #end - targetGraphics = canvas.graphics; fill(camera.bgColor, camera.useBgAlphaBlending); } @@ -168,12 +163,12 @@ class FlxQuadView extends FlxCameraView public function fill(color:FlxColor, blendAlpha:Bool = true):Void { - targetGraphics.overrideBlendMode(null); - targetGraphics.beginFill(color.rgb, color.alphaFloat); + canvas.graphics.overrideBlendMode(null); + canvas.graphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading - targetGraphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - targetGraphics.endFill(); + canvas.graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + canvas.graphics.endFill(); } override function offsetView(x:Float, y:Float):Void From 29684d759ef28c153f900168b31b438c77a85cc3 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 16:36:40 -0600 Subject: [PATCH 38/72] add createView for custom views --- flixel/FlxCamera.hx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 474633de16..684bbdd424 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -824,7 +824,7 @@ class FlxCamera extends FlxBasic this.width = width; this.height = height; - view = FlxCameraView.create(this); + view = createView(); if (view is FlxQuadView) viewQuad = cast view; else if (view is FlxBlitView) @@ -844,6 +844,11 @@ class FlxCamera extends FlxBasic bgColor = FlxG.cameras.bgColor; } + + function createView() + { + return FlxCameraView.create(this); + } /** * Clean up memory. From e5267a4eb6ca8f62d4a48f93b08c239b92a7221c Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 19:11:04 -0600 Subject: [PATCH 39/72] revert offset in drawDebugLine --- flixel/system/render/blit/FlxBlitView.hx | 5 ++--- flixel/system/render/quad/FlxQuadView.hx | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 21707b01bb..c1d50c172b 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -271,9 +271,8 @@ class FlxBlitView extends FlxCameraView { final gfx = debugSprite.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - final offset = thickness / 2; - gfx.moveTo(x1 + offset, y1 + offset); - gfx.lineTo(x2 + offset, y2 + offset); + gfx.moveTo(x1, y1); + gfx.lineTo(x2, y2); } #end diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 94a2822685..b619822ae0 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -455,9 +455,8 @@ class FlxQuadView extends FlxCameraView { final gfx = debugLayer.graphics; gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - final offset = thickness / 2; - gfx.moveTo(x1 + offset, y1 + offset); - gfx.lineTo(x2 + offset, y2 + offset); + gfx.moveTo(x1, y1); + gfx.lineTo(x2, y2); } #end From 0ad6a68fc3d04989d9014768e1c55bf0e6027afd Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 19:15:36 -0600 Subject: [PATCH 40/72] doc --- flixel/system/render/FlxCameraView.hx | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index c866680e34..b56272208d 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -152,33 +152,33 @@ abstract class FlxCameraView implements IFlxDestroyable /** * Draws a filled rectangle. * - * @param x The x position of the rectangle. - * @param y The y position of the rectangle. - * @param width The width of the rectangle (in pixels). - * @param height The height of the rectangle (in pixels). - * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. */ abstract public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void; /** * Draws a filled circle. * - * @param x The x position of the circle. - * @param y The y position of the circle. - * @param radius The radius of the circle. - * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. + * @param x The x position of the circle. + * @param y The y position of the circle. + * @param radius The radius of the circle. + * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. */ abstract public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void; /** * Draws a line. * - * @param x1 The start x position of the line. - * @param y1 The start y position of the line. - * @param x2 The end x position of the line. - * @param y2 The end y position of the line. - * @param color The color (in 0xAARRGGBB hex format) of the line. - * @param thickness The thickness of the line. + * @param x1 The start x position of the line. + * @param y1 The start y position of the line. + * @param x2 The end x position of the line. + * @param y2 The end y position of the line. + * @param color The color (in 0xAARRGGBB hex format) of the line. + * @param thickness The thickness of the line. */ abstract public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void; @@ -188,8 +188,8 @@ abstract class FlxCameraView implements IFlxDestroyable /** * Helper method preparing debug rectangle for rendering in blit render mode - * @param rect rectangle to prepare for rendering - * @return transformed rectangle with respect to camera's zoom factor + * @param rect Rectangle to prepare for rendering + * @return Transformed rectangle with respect to camera's zoom factor */ function transformRect(rect:FlxRect):FlxRect { @@ -198,8 +198,8 @@ abstract class FlxCameraView implements IFlxDestroyable /** * Helper method preparing debug point for rendering in blit render mode (for debug path rendering, for example) - * @param point point to prepare for rendering - * @return transformed point with respect to camera's zoom factor + * @param point Point to prepare for rendering + * @return Transformed point with respect to camera's zoom factor */ function transformPoint(point:FlxPoint):FlxPoint { @@ -208,8 +208,8 @@ abstract class FlxCameraView implements IFlxDestroyable /** * Helper method preparing debug vectors (relative positions) for rendering in blit render mode - * @param vector relative position to prepare for rendering - * @return transformed vector with respect to camera's zoom factor + * @param vector Relative position to prepare for rendering + * @return Transformed vector with respect to camera's zoom factor */ function transformVector(vector:FlxPoint):FlxPoint { @@ -221,7 +221,7 @@ abstract class FlxCameraView implements IFlxDestroyable * to specified display objects which has been added to the camera display list. * For example, debug sprite for nape debug rendering. * @param object display object to apply transformations to. - * @return transformed object. + * @return Transformed object. */ function transformObject(object:DisplayObject):DisplayObject { From 1c9c167460c65105d280eedae369e4092a001536 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 19:23:36 -0600 Subject: [PATCH 41/72] make viewQuad and viewBlit private --- flixel/FlxCamera.hx | 4 ++-- flixel/graphics/tile/FlxDrawQuadsItem.hx | 12 +++++++----- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 15 +++++++++------ flixel/system/debug/interaction/Interaction.hx | 14 ++++---------- .../system/debug/interaction/tools/Pointer.hx | 5 ++--- .../system/debug/interaction/tools/Transform.hx | 13 +++++-------- flixel/system/render/FlxCameraView.hx | 3 +++ flixel/system/render/blit/FlxBlitView.hx | 17 +++++++++++++++++ flixel/system/render/quad/FlxQuadView.hx | 13 +++++++++++++ 9 files changed, 62 insertions(+), 34 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 684bbdd424..e98b45720f 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -105,14 +105,14 @@ class FlxCamera extends FlxBasic * * **NOTE**: May be null depending on the render implementation used. */ - public var viewQuad(default, null):Null; + var viewQuad(default, null):Null; /** * This camera's `view`, typed as a `FlxBlitView`. * * **NOTE**: May be null depending on the render implementation used. */ - public var viewBlit(default, null):Null; + var viewBlit(default, null):Null; /** * Tells the camera to use this following style. diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index 97c09d9dac..5de84e2857 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -132,11 +132,13 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - - camera.viewQuad.canvas.graphics.overrideBlendMode(blend); - camera.viewQuad.canvas.graphics.beginShaderFill(shader); - camera.viewQuad.canvas.graphics.drawQuads(rects, null, transforms); - camera.viewQuad.canvas.graphics.endFill(); + + @:privateAccess + final view = camera.viewQuad; + view.canvas.graphics.overrideBlendMode(blend); + view.canvas.graphics.beginShaderFill(shader); + view.canvas.graphics.drawQuads(rects, null, transforms); + view.canvas.graphics.endFill(); super.render(camera); } diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index e3ac8acb43..bfe3b59184 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -54,6 +54,9 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem if (numTriangles <= 0) return; + @:privateAccess + final view = camera.viewQuad; + #if !flash var shader = shader != null ? shader : graphics.shader; shader.bitmap.input = graphics.bitmap; @@ -75,20 +78,20 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - camera.viewQuad.canvas.graphics.overrideBlendMode(blend); + view.canvas.graphics.overrideBlendMode(blend); - camera.viewQuad.canvas.graphics.beginShaderFill(shader); + view.canvas.graphics.beginShaderFill(shader); #else - camera.viewQuad.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); + view.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); #end - camera.viewQuad.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); - camera.viewQuad.canvas.graphics.endFill(); + view.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); + view.canvas.graphics.endFill(); #if FLX_DEBUG if (FlxG.debugger.drawDebug) { - var gfx:Graphics = camera.viewQuad.debugLayer.graphics; + var gfx:Graphics = view.debugLayer.graphics; gfx.lineStyle(1, FlxColor.BLUE, 0.5); gfx.drawTriangles(vertices, indices, uvtData); } diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index ba19a286d2..c8d1be1cb8 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -790,19 +790,13 @@ class Interaction extends Window public function toDebugX(worldX:Float, camera:FlxCamera) { - if (FlxG.renderer.method != BLITTING) - return camera.viewQuad.canvas.localToGlobal(new Point(worldX, 0)).x; - else - @:privateAccess - return camera.viewBlit._flashBitmap.localToGlobal(new Point(worldX, 0)).x; + @:privateAccess + return camera.view.worldToDebugX(worldX); } public function toDebugY(worldY:Float, camera:FlxCamera) { - if (FlxG.renderer.method != BLITTING) - return camera.viewQuad.canvas.localToGlobal(new Point(0, worldY)).y; - else - @:privateAccess - return camera.viewBlit._flashBitmap.localToGlobal(new Point(0, worldY)).y; + @:privateAccess + return camera.view.worldToDebugY(worldY); } } diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index f397f80187..69ae32bd41 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -144,9 +144,8 @@ class Pointer extends Tool final rect = FlxRect.get(); setAbsRect(rect, startX, startY, _brain.flixelPointer.x, _brain.flixelPointer.y); // Render the selection rectangle - var color:FlxColor = 0xbb0000; - color.alphaFloat = 0.9; - view.drawDebugRect(FlxG.camera.scroll.x + rect.x, FlxG.camera.scroll.y + rect.y, rect.width, rect.height, color); + final scroll = view.camera.scroll; + view.drawDebugRect(rect.x - scroll.x, rect.y - scroll.y, rect.width, rect.height, 0xFFbb0000, 0.9); rect.put(); } diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index b14296645e..171cc5efe6 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -245,14 +245,11 @@ class Transform extends Tool function drawSelection(camera:FlxCamera) { // draw lines - var prevX = markers[3].x; - var prevY = markers[3].y; - for (marker in markers) + final scroll = camera.scroll; + for (i => marker in markers) { - camera.view.drawDebugLine(prevX, prevY, marker.x, marker.y, FlxColor.MAGENTA); - - prevX = marker.x; - prevY = marker.y; + final prev = markers[(i + 3) % 4]; + camera.view.drawDebugLine(prev.x - scroll.x, prev.y - scroll.y, marker.x - scroll.x, marker.y - scroll.y, FlxColor.MAGENTA); } // draw markers @@ -260,7 +257,7 @@ class Transform extends Tool { final x = marker.x; final y = marker.y; - Marker.draw(x, y, marker.type == ROTATE, camera); + Marker.draw(x - scroll.x, y - scroll.y, marker.type == ROTATE, camera); } } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index b56272208d..a00a793b74 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -186,6 +186,9 @@ abstract class FlxCameraView implements IFlxDestroyable //{ region ------------------------ HELPERS --------------------------- + abstract function worldToDebugX(worldX:Float):Float;//TODO: find out what "debug space" actually is, rename and make public + abstract function worldToDebugY(worldY:Float):Float;//TODO: find out what "debug space" actually is, rename and make public + /** * Helper method preparing debug rectangle for rendering in blit render mode * @param rect Rectangle to prepare for rendering diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index c1d50c172b..97890b3b99 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -389,4 +389,21 @@ class FlxBlitView extends FlxCameraView } //} endregion --------------------- GETTERS ------------------------ + + //{ region ------------------------ HELPERS ------------------------ + + static final toDebugHelper = new openfl.geom.Point(); + function worldToDebugX(worldX:Float)//TODO: rename + { + toDebugHelper.setTo(worldX, 0); + return _flashBitmap.localToGlobal(toDebugHelper).x; + } + + function worldToDebugY(worldY:Float)//TODO: rename + { + toDebugHelper.setTo(0, worldY); + return _flashBitmap.localToGlobal(toDebugHelper).y; + } + + //} endregion --------------------- HELPERS ------------------------ } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index b619822ae0..5282eeb0db 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -204,6 +204,19 @@ class FlxQuadView extends FlxCameraView } } + static final toDebugHelper = new openfl.geom.Point(); + function worldToDebugX(worldX:Float)//TODO: rename + { + toDebugHelper.setTo(worldX, 0); + return canvas.localToGlobal(toDebugHelper).x; + } + + function worldToDebugY(worldY:Float)//TODO: rename + { + toDebugHelper.setTo(worldY, 0); + return canvas.localToGlobal(toDebugHelper).y; + } + override function updateInternals():Void { if (canvas != null) From 1d4937cf441a2620517db71873ffbbd499a150a3 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 26 Feb 2026 19:29:45 -0600 Subject: [PATCH 42/72] deprecate transformObject --- flixel/FlxCamera.hx | 26 +++++++++++++++----------- flixel/system/render/FlxCameraView.hx | 21 --------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index e98b45720f..3a322c31bd 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -782,19 +782,23 @@ class FlxCamera extends FlxBasic { return view.transformVector(vector); } - - /** - * Helper method for applying transformations (scaling and offsets) - * to specified display objects which has been added to the camera display list. - * For example, debug sprite for nape debug rendering. - * @param object display object to apply transformations to. - * @return transformed object. - */ - inline function transformObject(object:DisplayObject):DisplayObject + + @:noCompletion + @:deprecated("transformObject is deprecated, there is no replacement") + function transformObject(object:DisplayObject):DisplayObject { - return view.transformObject(object); + object.scaleX *= totalScaleX; + object.scaleY *= totalScaleY; + + object.x -= scroll.x * totalScaleX; + object.y -= scroll.y * totalScaleY; + + object.x -= 0.5 * width * (scaleX - initialZoom) * FlxG.scaleMode.scale.x; + object.y -= 0.5 * height * (scaleY - initialZoom) * FlxG.scaleMode.scale.y; + + return object; } - + /** * Instantiates a new camera at the specified location, with the specified size and zoom level. * diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index a00a793b74..3656486fc7 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -219,27 +219,6 @@ abstract class FlxCameraView implements IFlxDestroyable return vector; } - /** - * Helper method for applying transformations (scaling and offsets) - * to specified display objects which has been added to the camera display list. - * For example, debug sprite for nape debug rendering. - * @param object display object to apply transformations to. - * @return Transformed object. - */ - function transformObject(object:DisplayObject):DisplayObject - { - object.scaleX *= camera.totalScaleX; - object.scaleY *= camera.totalScaleY; - - object.x -= camera.scroll.x * camera.totalScaleX; - object.y -= camera.scroll.y * camera.totalScaleY; - - object.x -= 0.5 * camera.width * (camera.scaleX - camera.initialZoom) * FlxG.scaleMode.scale.x; - object.y -= 0.5 * camera.height * (camera.scaleY - camera.initialZoom) * FlxG.scaleMode.scale.y; - - return object; - } - //} endregion --------------------- HELPERS ------------------------ //{ region ------------------------ GETTERS ------------------------ From e43175f6b6b4dbb9b6b290d49ecba09981d76745 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 09:44:15 -0600 Subject: [PATCH 43/72] call calc in camera, not view --- flixel/FlxCamera.hx | 3 +++ flixel/system/render/FlxCameraView.hx | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 3a322c31bd..23b90be214 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1828,6 +1828,9 @@ class FlxCamera extends FlxBasic totalScaleY = scaleY * FlxG.scaleMode.scale.y; view.updateScale(); + + calcMarginX(); + calcMarginY(); updateScrollRect(); updateInternalSpritePositions(); diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 3656486fc7..3ad599a2e3 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -102,11 +102,7 @@ abstract class FlxCameraView implements IFlxDestroyable public function offsetView(x:Float, y:Float):Void {} - function updateScale():Void - { - camera.calcMarginX(); - camera.calcMarginY(); - } + function updateScale():Void {} function updatePosition():Void {} From 840ff6dac3375b83e9d769e5c874cdf87e1da990 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 11:29:15 -0600 Subject: [PATCH 44/72] rework and group deprecated getters --- flixel/FlxCamera.hx | 972 ++++++++++++------- flixel/system/render/FlxCameraView.hx | 13 +- flixel/system/render/FlxRenderer.hx | 2 +- flixel/system/render/blit/FlxBlitRenderer.hx | 8 - flixel/system/render/blit/FlxBlitView.hx | 31 +- flixel/system/render/quad/FlxQuadView.hx | 26 +- flixel/tile/FlxTilemap.hx | 3 +- 7 files changed, 653 insertions(+), 402 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 23b90be214..3c60513a98 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -13,6 +13,7 @@ import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; import flixel.system.render.blit.FlxBlitRenderer; import flixel.system.render.blit.FlxBlitView; +import flixel.system.render.quad.FlxQuadRenderer; import flixel.system.render.quad.FlxQuadView; import flixel.util.FlxAxes; import flixel.util.FlxColor; @@ -37,7 +38,6 @@ using flixel.util.FlxColorTransformUtil; * By default one camera is created automatically, that is the same size as window. * You can add more cameras or even replace the main camera using utilities in `FlxG.cameras`. */ -@:allow(flixel.system.render) @:access(flixel.system.render) class FlxCamera extends FlxBasic { @@ -173,33 +173,12 @@ class FlxCamera extends FlxBasic */ public var scroll:FlxPoint = FlxPoint.get(); - /** - * The actual `BitmapData` of the camera display itself. - * Used in blit render mode, where you can manipulate its pixels for achieving some visual effects. - */ - @:deprecated("buffer is deprecated, use camera.viewBlit.buffer, instead") - public var buffer(get, set):BitmapData; - inline function set_buffer(value:BitmapData):BitmapData return viewBlit.buffer = value; - inline function get_buffer():BitmapData return viewBlit.buffer; - /** * The natural background color of the camera, in `AARRGGBB` format. Defaults to `FlxG.cameras.bgColor`. * On Flash, transparent backgrounds can be used in conjunction with `useBgAlphaBlending`. */ public var bgColor:FlxColor; - /** - * Sometimes it's easier to just work with a `FlxSprite`, than it is to work directly with the `BitmapData` buffer. - * This sprite reference will allow you to do exactly that. - * Basically, this sprite's `pixels` property is the camera's `BitmapData` buffer. - * - * **NOTE:** This field is only used in blit render mode. - */ - @:deprecated("screen is deprecated, use camera.viewBlit.screen, instead") - public var screen(get, set):FlxSprite; - inline function set_screen(value:FlxSprite):FlxSprite return viewBlit.screen = value; - inline function get_screen():FlxSprite return viewBlit.screen; - /** * Whether to use alpha blending for the camera's background fill or not. * If `true`, then the previously drawn graphics won't be erased, @@ -211,24 +190,6 @@ class FlxCamera extends FlxBasic */ public var useBgAlphaBlending:Bool = false; - /** - * Used to render buffer to screen space. - * NOTE: We don't recommend modifying this directly unless you are fairly experienced. - * Uses include 3D projection, advanced display list modification, and more. - * This is container for everything else that is used by camera and rendered to the camera. - * - * Its position is modified by `updateFlashSpritePosition()` which is called every frame. - */ - @:deprecated("flashSprite is deprecated, use camera.display, instead") - public var flashSprite(get, set):Sprite; - inline function set_flashSprite(value:Sprite):Sprite - { - var sprite = FlxG.renderer.method != BLITTING ? viewQuad.flashSprite : viewBlit.flashSprite; - return sprite = value; - } - - inline function get_flashSprite():Sprite return cast view.display; - /** * Whether the positions of the objects rendered on this camera are rounded. * If set on individual objects, they ignore the global camera setting. @@ -353,23 +314,6 @@ class FlxCamera extends FlxBasic */ public var display(get, never):DisplayObjectContainer; - /** - * Helper matrix object. Used in blit render mode when camera's zoom is less than initialZoom - * (it is applied to all objects rendered on the camera at such circumstances). - */ - @:deprecated("_blitMatrix is deprecated, use camera.viewBlit.blitMatrix, instead") - var _blitMatrix(get, set):FlxMatrix; - inline function get__blitMatrix():FlxMatrix return viewBlit._blitMatrix; - inline function set__blitMatrix(value:FlxMatrix) return viewBlit._blitMatrix = value; - - /** - * Logical flag for tracking whether to apply _blitMatrix transformation to objects or not. - */ - @:deprecated("_useBlitMatrix is deprecated, use camera.viewBlit._useBlitMatrix, instead") - var _useBlitMatrix(get, set):Bool; - inline function get__useBlitMatrix():Bool return viewBlit._useBlitMatrix; - inline function set__useBlitMatrix(value:Bool) return viewBlit._useBlitMatrix = value; - /** * The alpha value of this camera display (a number between `0.0` and `1.0`). */ @@ -401,39 +345,6 @@ class FlxCamera extends FlxBasic */ public var filtersEnabled:Bool = true; - /** - * Internal, used in blit render mode in camera's `fill()` method for less garbage creation. - * It represents the size of buffer `BitmapData` - * (the area of camera's buffer which should be filled with `bgColor`). - * Do not modify it unless you know what are you doing. - */ - @:deprecated("_flashRect is deprecated, use camera.viewBlit._flashRect, instead") - var _flashRect:Rectangle; - inline function get__flashRect():Rectangle return viewBlit._flashRect; - inline function set__flashRect(value:Rectangle) return viewBlit._flashRect = value; - - /** - * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: - * Its coordinates are always `(0,0)`, where camera's buffer filling should start. - * Do not modify it unless you know what are you doing. - */ - @:deprecated("_flashPoint is deprecated, use FlxBlitRenderer._flashPoint, instead") - var _flashPoint:Point = new Point(); - inline function get__flashPoint():Point return cast (FlxG.renderer, FlxBlitRenderer)._flashPoint; - inline function set__flashPoint(value:Point) return cast (FlxG.renderer, FlxBlitRenderer)._flashPoint = value; - - /** - * Internal, used for positioning camera's `flashSprite` on screen. - * Basically it represents position of camera's center point in game sprite. - * It's recalculated every time you resize game or camera. - * Its value depends on camera's size (`width` and `height`), game's `scale` and camera's initial zoom factor. - * Do not modify it unless you know what are you doing. - */ - @:deprecated("_flashOffset is deprecated, use camera.view._flashOffset, instead") - var _flashOffset(get, set):FlxPoint; - inline function get__flashOffset():FlxPoint return view._flashOffset; - inline function set__flashOffset(value:FlxPoint) return view._flashOffset = value; - /** * Internal, represents the color of `flash()` special effect. */ @@ -525,234 +436,7 @@ class FlxCamera extends FlxBasic * Camera's initial zoom value. Used for camera's scale handling. */ public var initialZoom(default, null):Float = 1; - - /** - * Internal helper variable for doing better wipes/fills between renders. - * Used it blit render mode only (in `fill()` method). - */ - @:deprecated("_fill is deprecated, use camera.viewBlit._fill, instead") - var _fill(get, set):BitmapData; - inline function get__fill():BitmapData return viewBlit._fill; - inline function set__fill(value:BitmapData):BitmapData return viewBlit._fill = value; - - /** - * Internal, used to render buffer to screen space. Used it blit render mode only. - * This Bitmap used for rendering camera's buffer (`_flashBitmap.bitmapData = buffer;`) - * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. - * It is a child of the `_scrollRect` `Sprite`. - */ - @:deprecated("_flashBitmap is deprecated, use camera.viewBlit._flashBitmap, instead") - var _flashBitmap(get, set):Bitmap; - inline function get__flashBitmap():Bitmap return viewBlit._flashBitmap; - inline function set__flashBitmap(value:Bitmap):Bitmap return viewBlit._flashBitmap = value; - - /** - * Internal sprite, used for correct trimming of camera viewport. - * It is a child of `flashSprite`. - * Its position is modified by `updateScrollRect()` method, which is called on camera's resize and scale events. - */ - @:deprecated("_scrollRect is deprecated, use camera.viewQuad._scrollRect/camera.viewBlit._scrollRect, instead") - var _scrollRect(get, set):Sprite; - inline function get__scrollRect():Sprite - { - return FlxG.renderer.method != BLITTING ? viewQuad._scrollRect : viewBlit._scrollRect; - } - inline function set__scrollRect(value:Sprite):Sprite - { - var scrollRect = FlxG.renderer.method != BLITTING ? viewQuad._scrollRect : viewBlit._scrollRect; - return scrollRect = value; - } - - /** - * Helper rect for `drawTriangles()` visibility checks - */ - @:deprecated("_bounds is deprecated, use FlxBlitRenderer/FlxQuadRender._bounds, instead") - var _bounds(get, set):FlxRect; - inline function get__bounds():FlxRect - { - return untyped FlxG.renderer._bounds; - } - inline function set__bounds(value:FlxRect):FlxRect - { - return untyped FlxG.renderer._bounds = value; - } - - /** - * Sprite used for actual rendering in tile render mode (instead of `_flashBitmap` for blitting). - * Its graphics is used as a drawing surface for `drawTriangles()` and `drawTiles()` methods. - * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). - * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. - */ - @:deprecated("canvas is deprecated, use camera.viewQuad.canvas, instead") - public var canvas(get, set):Sprite; - inline function set_canvas(value:Sprite):Sprite return viewQuad.canvas = value; - inline function get_canvas():Sprite return viewQuad.canvas; - - #if FLX_DEBUG - /** - * Sprite for visual effects (flash and fade) and drawDebug information - * (bounding boxes are drawn on it) for tile render mode. - * It is a child of `_scrollRect` `Sprite` (which trims graphics that should be invisible). - * Its position is modified by `updateInternalSpritePositions()`, which is called on camera's resize and scale events. - */ - @:deprecated("debugLayer is deprecated, use camera.viewQuad.debugLayer, instead") - public var debugLayer(get, set):Sprite; - inline function set_debugLayer(value:Sprite):Sprite return viewQuad.debugLayer; - inline function get_debugLayer():Sprite return viewQuad.debugLayer; - #end - - @:deprecated("_helperMatrix is deprecated, use FlxBlitRenderer/FlxQuadRenderer._helperMatrix, instead") - var _helperMatrix(get, set):FlxMatrix; - inline function get__helperMatrix():FlxMatrix - { - return untyped FlxG.renderer._helperMatrix; - } - inline function set__helperMatrix(value:FlxMatrix):FlxMatrix - { - return untyped FlxG.renderer._helperMatrix = value; - } - - @:deprecated("_helperPoint is deprecated, use FlxBlitRenderer._helperPoint, instead") - var _helperPoint(get, set):Point; - inline function get__helperPoint():Point - { - return cast(FlxG.renderer, FlxBlitRenderer)._helperPoint; - } - inline function set__helperPoint(value:Point):Point - { - return cast(FlxG.renderer, FlxBlitRenderer)._helperPoint = value; - } - - /** - * Currently used draw stack item - */ - @:deprecated("_currentDrawItem is deprecated, use camera.viewQuad._currentDrawItem, instead") - var _currentDrawItem(get, set):FlxDrawBaseItem; - inline function get__currentDrawItem():FlxDrawBaseItem return viewQuad._currentDrawItem; - inline function set__currentDrawItem(value:FlxDrawBaseItem):FlxDrawBaseItem return viewQuad._currentDrawItem = value; - - /** - * Pointer to head of stack with draw items - */ - @:deprecated("_headOfDrawStack is deprecated, use camera.viewQuad._headOfDrawStack, instead") - var _headOfDrawStack(get, set):FlxDrawBaseItem; - inline function get__headOfDrawStack():FlxDrawBaseItem return viewQuad._headOfDrawStack; - inline function set__headOfDrawStack(value:FlxDrawBaseItem):FlxDrawBaseItem return viewQuad._headOfDrawStack = value; - - /** - * Last draw tiles item - */ - @:deprecated("_headTiles is deprecated, use camera.viewQuad._headTiles, instead") - var _headTiles(get, set):FlxDrawQuadsItem; - inline function get__headTiles():FlxDrawQuadsItem return viewQuad._headTiles; - inline function set__headTiles(value:FlxDrawQuadsItem):FlxDrawQuadsItem return viewQuad._headTiles = value; - - /** - * Last draw triangles item - */ - @:deprecated("_headTriangles is deprecated, use camera.viewQuad._headTriangles, instead") - var _headTriangles(get, set):FlxDrawTrianglesItem; - inline function get__headTriangles():FlxDrawTrianglesItem return viewQuad._headTriangles; - inline function set__headTriangles(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return viewQuad._headTriangles = value; - - /** - * Draw tiles stack items that can be reused - */ - @:deprecated("_storageTilesHead is deprecated, use FlxQuadView._storageTilesHead, instead") - static var _storageTilesHead(get, set):FlxDrawQuadsItem; - static inline function get__storageTilesHead():FlxDrawQuadsItem return FlxQuadView._storageTilesHead; - static inline function set__storageTilesHead(value:FlxDrawQuadsItem):FlxDrawQuadsItem return FlxQuadView._storageTilesHead = value; - - /** - * Draw triangles stack items that can be reused - */ - @:deprecated("_storageTrianglesHead is deprecated, use FlxQuadView._storageTrianglesHead, instead") - static var _storageTrianglesHead(get, set):FlxDrawTrianglesItem; - static inline function get__storageTrianglesHead():FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead; - static inline function set__storageTrianglesHead(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead = value; - - /** - * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. - */ - @:deprecated("drawVertices is deprecated, use FlxBlitRenderer.drawVertices, instead") - static var drawVertices(get, set):Vector; - static inline function get_drawVertices():Vector return FlxBlitRenderer.drawVertices; - static inline function set_drawVertices(value:Vector):Vector return FlxBlitRenderer.drawVertices = value; - - /** - * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. - */ - @:deprecated("trianglesSprite is deprecated, use FlxBlitRenderer.trianglesSprite, instead") - static var trianglesSprite(get, set):Sprite; - static inline function get_trianglesSprite():Sprite return FlxBlitRenderer.trianglesSprite; - static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitRenderer.trianglesSprite = value; - - /** - * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. - * Added for less garbage creation. - */ - @:deprecated("renderPoint is deprecated, use FlxBlitRenderer.renderPoint, instead") - static var renderPoint(get, set):FlxPoint; - static inline function get_renderPoint():FlxPoint return FlxBlitRenderer.renderPoint; - static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitRenderer.renderPoint = value; - - @:deprecated("renderRect is deprecated, use FlxBlitRenderer.renderRect, instead") - static var renderRect(get, set):FlxRect; - static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; - static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; - - @:noCompletion - public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) - { - return viewQuad.startQuadBatch(graphic, colored, hasColorOffsets, blend, smooth, shader); - } - - @:noCompletion - public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem - { - return viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - } - - @:noCompletion - public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem - { - return viewQuad.getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - } - - @:allow(flixel.system.frontEnds.CameraFrontEnd) - @:deprecated("camera.render() is deprecated, use FlxG.renderer.render() instead.") - function render():Void - { - view.render(); - } - - @:allow(flixel.system.frontEnds.CameraFrontEnd) - function clearDrawStack():Void - { - viewQuad.clearDrawStack(); - } - - @:deprecated("camera.drawPixels() is deprecated, use FlxG.renderer.drawPixels() instead.") - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, - ?shader:FlxShader):Void - { - FlxG.renderer.drawPixels(view, frame, pixels, matrix, transform, blend, smoothing, shader); - } - - @:deprecated("camera.copyPixels() is deprecated, use FlxG.renderer.copyPixels() instead.") - public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - ?smoothing:Bool = false, ?shader:FlxShader):Void - { - FlxG.renderer.copyPixels(view, frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); - } - - @:deprecated("camera.drawTriangles() is deprecated, use FlxG.renderer.drawTriangles() instead.") - public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void - { - FlxG.renderer.drawTriangles(view, graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); - } - + /** * Helper method preparing debug rectangle for rendering in blit render mode * @param rect rectangle to prepare for rendering @@ -783,22 +467,6 @@ class FlxCamera extends FlxBasic return view.transformVector(vector); } - @:noCompletion - @:deprecated("transformObject is deprecated, there is no replacement") - function transformObject(object:DisplayObject):DisplayObject - { - object.scaleX *= totalScaleX; - object.scaleY *= totalScaleY; - - object.x -= scroll.x * totalScaleX; - object.y -= scroll.y * totalScaleY; - - object.x -= 0.5 * width * (scaleX - initialZoom) * FlxG.scaleMode.scale.x; - object.y -= 0.5 * height * (scaleY - initialZoom) * FlxG.scaleMode.scale.y; - - return object; - } - /** * Instantiates a new camera at the specified location, with the specified size and zoom level. * @@ -809,6 +477,7 @@ class FlxCamera extends FlxBasic * @param zoom The initial zoom level of the camera. * A zoom level of 2 will make all pixels display at 2x resolution. */ + @:haxe.warning("-WDeprecated") public function new(x = 0.0, y = 0.0, width = 0, height = 0, zoom = 0.0) { super(); @@ -830,9 +499,45 @@ class FlxCamera extends FlxBasic view = createView(); if (view is FlxQuadView) - viewQuad = cast view; + { + viewQuad = Std.downcast(view, FlxQuadView); + @:bypassAccessor _flashPoint = new Point(); + @:bypassAccessor _blitMatrix = new FlxMatrix(); + @:bypassAccessor _flashRect = new Rectangle(); + + @:bypassAccessor flashSprite = viewQuad.flashSprite; + @:bypassAccessor _flashOffset = viewQuad._flashOffset; + @:bypassAccessor _scrollRect = viewQuad._scrollRect; + @:bypassAccessor canvas = viewQuad.canvas; + #if FLX_DEBUG + @:bypassAccessor debugLayer = viewQuad.canvas; + #end + + final renderQuad = cast(FlxG.renderer, FlxQuadRenderer); + @:privateAccess @:bypassAccessor _bounds = renderQuad._bounds; + @:privateAccess @:bypassAccessor _helperMatrix = renderQuad._helperMatrix; + @:bypassAccessor _helperPoint = new Point(); + } else if (view is FlxBlitView) - viewBlit = cast view; + { + viewBlit = Std.downcast(view, FlxBlitView); + @:bypassAccessor _flashPoint = viewBlit._flashPoint; + @:bypassAccessor flashSprite = viewQuad.flashSprite; + @:bypassAccessor _flashOffset = viewBlit._flashOffset; + @:bypassAccessor _scrollRect = viewBlit._scrollRect; + @:bypassAccessor _flashRect = viewBlit._flashRect; + + @:bypassAccessor screen = viewBlit.screen; + @:bypassAccessor buffer = viewBlit.buffer; + @:bypassAccessor _flashBitmap = viewBlit._flashBitmap; + @:bypassAccessor _blitMatrix = viewBlit._blitMatrix; + @:bypassAccessor _fill = viewBlit._fill; + + final renderBlit = cast(FlxG.renderer, FlxBlitRenderer); + @:privateAccess @:bypassAccessor _bounds = renderBlit._bounds; + @:privateAccess @:bypassAccessor _helperMatrix = renderBlit._helperMatrix; + @:privateAccess @:bypassAccessor _helperPoint = renderBlit._helperPoint; + } pixelPerfectRender = FlxG.renderer.method == BLITTING; @@ -857,6 +562,7 @@ class FlxCamera extends FlxBasic /** * Clean up memory. */ + @:haxe.warning("-WDeprecated") override public function destroy():Void { view.destroy(); @@ -869,6 +575,27 @@ class FlxCamera extends FlxBasic _fxFlashComplete = null; _fxFadeComplete = null; _fxShakeComplete = null; + + // --- deprecated view fields + @:bypassAccessor buffer = null; + @:bypassAccessor screen = null; + @:bypassAccessor flashSprite = null; + @:bypassAccessor _blitMatrix = null; + @:bypassAccessor _flashRect = null; + @:bypassAccessor _flashPoint = null; + @:bypassAccessor _flashOffset = null; + @:bypassAccessor _fill = null; + @:bypassAccessor _flashBitmap = null; + @:bypassAccessor _scrollRect = null; + @:bypassAccessor canvas = null; + @:bypassAccessor debugLayer = null; + @:bypassAccessor _currentDrawItem = null; + @:bypassAccessor _headOfDrawStack = null; + @:bypassAccessor _headTiles = null; + @:bypassAccessor _headTriangles = null; + @:bypassAccessor _bounds = null; + @:bypassAccessor _helperMatrix = null; + @:bypassAccessor _helperPoint = null; super.destroy(); } @@ -1364,30 +1091,6 @@ class FlxCamera extends FlxBasic return this; } - /** - * Fill the camera with the specified color. - * - * @param color The color to fill with in `0xAARRGGBB` hex format. - * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. Default is `true`. - */ - @:deprecated("camera.fill() is deprecated, use camera.view.fill() instead.") - public function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void - { - color.alphaFloat = fxAlpha; - - if (viewQuad != null && graphics != null && graphics != view.getDebugGraphics()) - { - graphics.overrideBlendMode(null); - graphics.beginFill(color.rgb, color.alphaFloat); - // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, - // which could appear while cameras fading - graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - graphics.endFill(); - } - - view.fill(color, blendAlpha); - } - /** * Internal helper function, handles the actual drawing of all the special effects. */ @@ -1410,20 +1113,7 @@ class FlxCamera extends FlxBasic view.fill(color); } } - - @:deprecated("checkResize() is deprecated") - function checkResize():Void - { - if (FlxG.renderer.method == BLITTING) - viewBlit.checkResize(); - } - - @:deprecated("updateBlitMatrix() is deprecated, use camera.viewBlit.updateBlitMatrix(), instead") - inline function updateBlitMatrix():Void - { - viewBlit.updateBlitMatrix(); - } - + /** * Shortcut for setting both `width` and `height`. * @@ -2077,6 +1767,538 @@ class FlxCamera extends FlxBasic @:deprecated("don't reference camera.cameras") @:noCompletion override function set_cameras(value:Array):Array throw "don't reference camera.cameras"; + + //{ region ------ DEPRECATED VIEW FIELDS ------ + + @:noCompletion + @:deprecated("camera.startQuadBatch() is deprecated, use view.startQuadBatch() instead.") // 6.2.0 + public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) + { + return viewQuad.startQuadBatch(graphic, colored, hasColorOffsets, blend, smooth, shader); + } + + @:noCompletion + @:deprecated("camera.startTrianglesBatch() is deprecated, use view.startTrianglesBatch() instead.") // 6.2.0 + public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + { + return viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + } + + @:noCompletion + @:deprecated("camera.getNewDrawTrianglesItem() is deprecated, use view.getNewDrawTrianglesItem() instead.") // 6.2.0 + public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem + { + return viewQuad.getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + } + + @:noCompletion + @:deprecated("camera.render() is deprecated, use view.render() instead.") // 6.2.0 + function render():Void + { + view.render(); + } + + @:noCompletion + @:deprecated("camera.fill() is deprecated, use camera.view.fill() instead.") // 6.2.0 + public function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void + { + color.alphaFloat = fxAlpha; + + if (viewQuad != null && graphics != null && graphics != view.getDebugGraphics()) + { + graphics.overrideBlendMode(null); + graphics.beginFill(color.rgb, color.alphaFloat); + // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, + // which could appear while cameras fading + graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); + graphics.endFill(); + } + + view.fill(color, blendAlpha); + } + + @:noCompletion + @:deprecated("camera.clearDrawStack() is deprecated, use FlxG.renderer.render() instead.") // 6.2.0 + function clearDrawStack():Void + { + viewQuad.clearDrawStack(); + } + + @:noCompletion + @:deprecated("camera.drawPixels() is deprecated, use FlxG.renderer.drawPixels() instead.") // 6.2.0 + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, + ?shader:FlxShader):Void + { + FlxG.renderer.drawPixels(view, frame, pixels, matrix, transform, blend, smoothing, shader); + } + + @:noCompletion + @:deprecated("camera.copyPixels() is deprecated, use FlxG.renderer.copyPixels() instead.") // 6.2.0 + public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + ?smoothing:Bool = false, ?shader:FlxShader):Void + { + FlxG.renderer.copyPixels(view, frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + } + + @:noCompletion + @:deprecated("camera.drawTriangles() is deprecated, use FlxG.renderer.drawTriangles() instead.") // 6.2.0 + public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void + { + FlxG.renderer.drawTriangles(view, graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + } + + @:noCompletion + @:deprecated("checkResize() is deprecated") // 6.2.0 + function checkResize():Void + { + if (FlxG.renderer.method == BLITTING) + viewBlit.checkResize(); + } + + @:noCompletion + @:deprecated("updateBlitMatrix() is deprecated, use camera.viewBlit.updateBlitMatrix(), instead") // 6.2.0 + inline function updateBlitMatrix():Void + { + viewBlit.updateBlitMatrix(); + } + + @:noCompletion + @:deprecated("buffer is deprecated, use camera.viewBlit.buffer, instead") // 6.2.0 + @:isVar public var buffer(get, set):Null; + function get_buffer() + { + if (viewBlit != null) + this.buffer = viewBlit.buffer; + + return this.buffer; + } + function set_buffer(value:BitmapData) + { + return if (viewBlit != null) + this.buffer = viewBlit.buffer = value; + else + this.buffer = value; + } + + @:noCompletion + @:deprecated("screen is deprecated, use camera.viewBlit.screen, instead") // 6.2.0 + @:isVar public var screen(get, set):Null; + function get_screen() + { + if (viewBlit != null) + this.screen = viewBlit.screen; + + return this.screen; + } + function set_screen(value:FlxSprite) + { + return if (viewBlit != null) + this.screen = viewBlit.screen = value; + else + this.screen = value; + } + + @:noCompletion + @:deprecated("flashSprite is deprecated, use camera.display, instead") // 6.2.0 + @:isVar public var flashSprite(get, set):Sprite; + function get_flashSprite() + { + if (viewBlit != null) + this.flashSprite = viewBlit.flashSprite; + + return this.flashSprite; + } + function set_flashSprite(value:Sprite) + { + return if (viewBlit != null) + this.flashSprite = viewBlit.flashSprite = value; + else + this.flashSprite = value; + } + + @:noCompletion + @:deprecated("_blitMatrix is deprecated, use camera.viewBlit.blitMatrix, instead") // 6.2.0 + @:isVar var _blitMatrix(get, set):FlxMatrix; + function get__blitMatrix() + { + if (viewBlit != null) + this._blitMatrix = viewBlit._blitMatrix; + + return this._blitMatrix; + } + function set__blitMatrix(value:FlxMatrix) + { + return if (viewBlit != null) + this._blitMatrix = viewBlit._blitMatrix = value; + else + this._blitMatrix = value; + } + + @:noCompletion + @:deprecated("_useBlitMatrix is deprecated, use camera.viewBlit._useBlitMatrix, instead") // 6.2.0 + @:isVar var _useBlitMatrix(get, set):Bool; + function get__useBlitMatrix() + { + if (viewBlit != null) + this._useBlitMatrix = viewBlit._useBlitMatrix; + + return this._useBlitMatrix; + } + function set__useBlitMatrix(value:Bool) + { + return if (viewBlit != null) + this._useBlitMatrix = viewBlit._useBlitMatrix = value; + else + this._useBlitMatrix = value; + } + + @:noCompletion + @:deprecated("_flashRect is deprecated, use camera.viewBlit._flashRect, instead") // 6.2.0 + @:isVar var _flashRect(get, set):Rectangle; + function get__flashRect() + { + if (viewBlit != null) + this._flashRect = viewBlit._flashRect; + + return this._flashRect; + } + function set__flashRect(value:Rectangle) + { + return if (viewBlit != null) + this._flashRect = viewBlit._flashRect = value; + else + this._flashRect = value; + } + + @:noCompletion + @:deprecated("_flashPoint is deprecated, use viewBlit._flashPoint, instead") // 6.2.0 + @:isVar var _flashPoint(get, set):Point; + function get__flashPoint() + { + if (viewBlit != null) + this._flashPoint = viewBlit._flashPoint; + + return this._flashPoint; + } + function set__flashPoint(value:Point) + { + return if (viewBlit != null) + this._flashPoint = viewBlit._flashPoint = value; + else + this._flashPoint = value; + } + + @:noCompletion + @:deprecated("_flashOffset is deprecated, use camera.view._flashOffset, instead") // 6.2.0 + @:isVar var _flashOffset(get, set):Null; + function get__flashOffset() + { + if (viewBlit != null) + this._flashOffset = viewBlit._flashOffset; + else if (viewQuad != null) + this._flashOffset = viewQuad._flashOffset; + + return this._flashOffset; + } + function set__flashOffset(value:FlxPoint) + { + return if (viewBlit != null) + this._flashOffset = viewBlit._flashOffset = value; + else if (viewQuad != null) + this._flashOffset = viewQuad._flashOffset = value; + else + this._flashOffset = value; + } + + @:noCompletion + @:deprecated("_fill is deprecated, use camera.viewBlit._fill, instead") // 6.2.0 + @:isVar var _fill(get, set):BitmapData; + function get__fill():BitmapData + { + if (viewBlit != null) + this._fill = viewBlit._fill; + + return this._fill; + } + function set__fill(value:BitmapData):BitmapData + { + return if (viewBlit != null) + this._fill = viewBlit._fill = value; + else + this._fill = value; + } + + @:noCompletion + @:deprecated("_flashBitmap is deprecated, use camera.viewBlit._flashBitmap, instead") // 6.2.0 + @:isVar var _flashBitmap(get, set):Bitmap; + function get__flashBitmap():Bitmap + { + if (viewBlit != null) + this._flashBitmap = viewBlit._flashBitmap; + + return this._flashBitmap; + } + inline function set__flashBitmap(value:Bitmap):Bitmap + { + return if (viewBlit != null) + this._flashBitmap = viewBlit._flashBitmap = value; + else + this._flashBitmap = value; + } + + @:noCompletion + @:deprecated("_scrollRect is deprecated, use camera.viewQuad._scrollRect/camera.viewBlit._scrollRect, instead") // 6.2.0 + @:isVar var _scrollRect(get, set):Sprite; + function get__scrollRect():Sprite + { + if (viewBlit != null) + this._scrollRect = viewBlit._scrollRect; + else if (viewQuad != null) + this._scrollRect = viewQuad._scrollRect; + + return this._scrollRect; + } + function set__scrollRect(value:Sprite):Sprite + { + return if (viewBlit != null) + this._scrollRect = viewBlit._scrollRect = value; + else if (viewQuad != null) + this._scrollRect = viewQuad._scrollRect = value; + else + this._scrollRect = value; + } + + @:noCompletion + @:deprecated("_bounds is deprecated, use FlxBlitRenderer/FlxQuadRender._bounds, instead") // 6.2.0 + @:isVar var _bounds(get, set):FlxRect; + function get__bounds():FlxRect + { + switch FlxG.renderer.method + { + case BLITTING: + this._bounds = cast(FlxG.renderer, FlxBlitRenderer)._bounds; + case DRAW_TILES: + this._bounds = cast(FlxG.renderer, FlxQuadRenderer)._bounds; + default: + } + + return this._bounds; + } + function set__bounds(value:FlxRect):FlxRect + { + return this._bounds = switch FlxG.renderer.method + { + case BLITTING: + cast(FlxG.renderer, FlxBlitRenderer)._bounds = value; + case DRAW_TILES: + cast(FlxG.renderer, FlxQuadRenderer)._bounds = value; + default: + value; + } + } + + @:noCompletion + @:deprecated("canvas is deprecated, use camera.viewQuad.canvas, instead") // 6.2.0 + @:isVar public var canvas(get, set):Null; + function get_canvas() + { + if (viewQuad != null) + this.canvas = viewQuad.canvas; + + return this.canvas; + } + function set_canvas(value:Null) + { + return if (viewQuad != null) + this.canvas = viewQuad.canvas = value; + else + this.canvas = value; + } + + #if FLX_DEBUG + @:noCompletion + @:deprecated("debugLayer is deprecated, use camera.viewQuad.debugLayer, instead") // 6.2.0 + @:isVar public var debugLayer(get, set):Null; + function get_debugLayer() + { + if (viewQuad != null) + this.debugLayer = viewQuad.debugLayer; + + return this.debugLayer; + } + function set_debugLayer(value:Null) + { + return if (viewQuad != null) + this.debugLayer = viewQuad.debugLayer = value; + else + this.debugLayer = value; + } + #end + + @:noCompletion + @:deprecated("_helperMatrix is deprecated, use FlxBlitRenderer/FlxQuadRenderer._helperMatrix, instead") // 6.2.0 + @:isVar var _helperMatrix(get, set):FlxMatrix; + function get__helperMatrix() + { + switch FlxG.renderer.method + { + case BLITTING: + this._helperMatrix = cast(FlxG.renderer, FlxBlitRenderer)._helperMatrix; + case DRAW_TILES: + this._helperMatrix = cast(FlxG.renderer, FlxQuadRenderer)._helperMatrix; + default: + } + + return this._helperMatrix; + } + function set__helperMatrix(value:FlxMatrix):FlxMatrix + { + return this._helperMatrix = switch FlxG.renderer.method + { + case BLITTING: + cast(FlxG.renderer, FlxBlitRenderer)._helperMatrix = value; + case DRAW_TILES: + cast(FlxG.renderer, FlxQuadRenderer)._helperMatrix = value; + default: + value; + } + } + + @:noCompletion + @:deprecated("_helperPoint is deprecated, use FlxBlitRenderer._helperPoint, instead") // 6.2.0 + @:isVar var _helperPoint(get, set):Point; + function get__helperPoint() + { + switch FlxG.renderer.method + { + case BLITTING: + this._helperPoint = cast(FlxG.renderer, FlxBlitRenderer)._helperPoint; + default: + } + + return this._helperPoint; + } + function set__helperPoint(value:Point):Point + { + return switch FlxG.renderer.method + { + case BLITTING: + this._helperPoint = cast(FlxG.renderer, FlxBlitRenderer)._helperPoint = value; + default: + this._helperPoint = value; + } + } + + @:noCompletion + @:deprecated("_currentDrawItem is deprecated, use camera.viewQuad._currentDrawItem, instead") // 6.2.0 + @:isVar var _currentDrawItem(get, set):Null>; + function get__currentDrawItem() + { + if (viewQuad != null) + this._currentDrawItem = viewQuad._currentDrawItem; + + return this._currentDrawItem; + } + function set__currentDrawItem(value:Null>) + { + return if (viewQuad != null) + this._currentDrawItem = viewQuad._currentDrawItem = value; + else + this._currentDrawItem = value; + } + + @:noCompletion + @:deprecated("_headOfDrawStack is deprecated, use camera.viewQuad._headOfDrawStack, instead") // 6.2.0 + @:isVar var _headOfDrawStack(get, set):Null>; + function get__headOfDrawStack() + { + if (viewQuad != null) + this._headOfDrawStack = viewQuad._headOfDrawStack; + + return this._headOfDrawStack; + } + function set__headOfDrawStack(value:Null>) + { + return if (viewQuad != null) + this._headOfDrawStack = viewQuad._headOfDrawStack = value; + else + this._headOfDrawStack = value; + } + + @:noCompletion + @:deprecated("_headTiles is deprecated, use camera.viewQuad._headTiles, instead") // 6.2.0 + @:isVar var _headTiles(get, set):Null; + function get__headTiles() + { + if (viewQuad != null) + this._headTiles = viewQuad._headTiles; + + return this._headTiles; + } + function set__headTiles(value:Null) + { + return if (viewQuad != null) + this._headTiles = viewQuad._headTiles = value; + else + this._headTiles = value; + } + + @:noCompletion + @:deprecated("_headTriangles is deprecated, use camera.viewQuad._headTriangles, instead") // 6.2.0 + @:isVar var _headTriangles(get, set):Null; + function get__headTriangles() + { + if (viewQuad != null) + this._headTriangles = viewQuad._headTriangles; + + return this._headTriangles; + } + function set__headTriangles(value:Null) + { + return if (viewQuad != null) + this._headTriangles = viewQuad._headTriangles = value; + else + this._headTriangles = value; + } + + @:noCompletion + @:deprecated("_storageTilesHead is deprecated, use FlxQuadView._storageTilesHead, instead") // 6.2.0 + static var _storageTilesHead(get, set):Null; + static inline function get__storageTilesHead():Null return FlxQuadView._storageTilesHead; + static inline function set__storageTilesHead(value:Null):FlxDrawQuadsItem return FlxQuadView._storageTilesHead = value; + + @:noCompletion + @:deprecated("_storageTrianglesHead is deprecated, use FlxQuadView._storageTrianglesHead, instead") // 6.2.0 + static var _storageTrianglesHead(get, set):FlxDrawTrianglesItem; + static inline function get__storageTrianglesHead():FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead; + static inline function set__storageTrianglesHead(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead = value; + + @:noCompletion + @:deprecated("drawVertices is deprecated, use FlxBlitRenderer.drawVertices, instead") // 6.2.0 + static var drawVertices(get, set):Vector; + static inline function get_drawVertices():Vector return FlxBlitRenderer.drawVertices; + static inline function set_drawVertices(value:Vector):Vector return FlxBlitRenderer.drawVertices = value; + + @:noCompletion + @:deprecated("trianglesSprite is deprecated, use FlxBlitRenderer.trianglesSprite, instead") // 6.2.0 + static var trianglesSprite(get, set):Sprite; + static inline function get_trianglesSprite():Sprite return FlxBlitRenderer.trianglesSprite; + static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitRenderer.trianglesSprite = value; + + @:noCompletion + @:deprecated("renderPoint is deprecated, use FlxBlitRenderer.renderPoint, instead") // 6.2.0 + static var renderPoint(get, set):FlxPoint; + static inline function get_renderPoint():FlxPoint return FlxBlitRenderer.renderPoint; + static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitRenderer.renderPoint = value; + + @:noCompletion + @:deprecated("renderRect is deprecated, use FlxBlitRenderer.renderRect, instead") // 6.2.0 + static var renderRect(get, set):FlxRect; + static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; + static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; + + //{ endregion --- DEPRECATED VIEW FIELDS ------ } enum FlxCameraFollowStyle @@ -2110,4 +2332,4 @@ enum FlxCameraFollowStyle * Camera has no deadzone, just tracks the focus object directly and centers it. */ NO_DEAD_ZONE; -} +} \ No newline at end of file diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 3ad599a2e3..f927fd1515 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -70,17 +70,12 @@ abstract class FlxCameraView implements IFlxDestroyable */ public var visible(get, set):Bool; - var _flashOffset:FlxPoint = FlxPoint.get(); - function new(camera:FlxCamera) { this.camera = camera; } - public function destroy():Void - { - _flashOffset = FlxDestroyUtil.put(_flashOffset); - } + public function destroy():Void {} /** * Flushes any remaining graphics and renders everything to the screen. @@ -108,11 +103,7 @@ abstract class FlxCameraView implements IFlxDestroyable function updateInternals():Void {} - function updateOffset():Void - { - _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; - _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; - } + function updateOffset():Void {} function updateScrollRect():Void {} diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index f453b724b2..15fa9eec1e 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -166,7 +166,7 @@ enum FlxRenderMethod * * This method is the default and is used on all targets (when hardware acceleration is available), except for Flash. */ - DRAW_TILES; + DRAW_TILES; /** * Draws sprites directly onto bitmaps using a software renderer. * diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index bea59ce000..5e5ae8657a 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -60,13 +60,6 @@ class FlxBlitRenderer extends FlxTypedRenderer var _helperMatrix:FlxMatrix = new FlxMatrix(); var _helperPoint:Point = new Point(); - /** - * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: - * Its coordinates are always `(0,0)`, where camera's buffer filling should start. - * Do not modify it unless you know what are you doing. - */ - var _flashPoint:Point = new Point(); - public function new() { super(); @@ -79,7 +72,6 @@ class FlxBlitRenderer extends FlxTypedRenderer _bounds = FlxDestroyUtil.put(_bounds); _helperMatrix = null; _helperPoint = null; - _flashPoint = null; } public function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 97890b3b99..68a6b9500d 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -15,6 +15,7 @@ import openfl.display.DisplayObjectContainer; import openfl.display.Graphics; import openfl.display.Sprite; import openfl.geom.ColorTransform; +import openfl.geom.Point; import openfl.geom.Rectangle; class FlxBlitView extends FlxCameraView @@ -74,6 +75,13 @@ class FlxBlitView extends FlxCameraView */ var _flashBitmap:Bitmap; + /** + * Internal, used in blit render mode in camera's `fill()` method for less garbage creation: + * Its coordinates are always `(0,0)`, where camera's buffer filling should start. + * Do not modify it unless you know what are you doing. + */ + var _flashPoint:Point = new Point(); + /** * Internal helper variable for doing better wipes/fills between renders. * Used it blit render mode only (in `fill()` method). @@ -91,6 +99,8 @@ class FlxBlitView extends FlxCameraView */ var _blitMatrix:FlxMatrix = new FlxMatrix(); + var _flashOffset:FlxPoint = FlxPoint.get(); + @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) { @@ -123,6 +133,7 @@ class FlxBlitView extends FlxCameraView flashSprite = null; _scrollRect = null; _flashRect = null; + _flashOffset = FlxDestroyUtil.put(_flashOffset); } function render():Void @@ -156,7 +167,7 @@ class FlxBlitView extends FlxCameraView if (blendAlpha) { _fill.fillRect(_flashRect, color); - buffer.copyPixels(_fill, _flashRect, camera._flashPoint, null, null, blendAlpha); + buffer.copyPixels(_fill, _flashRect, _flashPoint, null, null, blendAlpha); } else { @@ -166,12 +177,16 @@ class FlxBlitView extends FlxCameraView override function offsetView(x:Float, y:Float):Void { + super.offsetView(x, y); + flashSprite.x += x; flashSprite.y += y; } override function updatePosition():Void { + super.updatePosition(); + if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; @@ -179,9 +194,19 @@ class FlxBlitView extends FlxCameraView } } + override function updateOffset() + { + super.updateOffset(); + + _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; + _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; + } + override function updateScrollRect():Void { - var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + super.updateScrollRect(); + + final rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; if (rect != null) { @@ -217,6 +242,8 @@ class FlxBlitView extends FlxCameraView override function updateInternals():Void { + super.updateInternals(); + if (_flashBitmap != null) { _flashBitmap.x = 0; diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 5282eeb0db..fe8afb0814 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -6,6 +6,7 @@ import flixel.graphics.FlxGraphic; import flixel.graphics.tile.FlxDrawBaseItem; import flixel.graphics.tile.FlxDrawQuadsItem; import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.math.FlxPoint; import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; @@ -56,6 +57,8 @@ class FlxQuadView extends FlxCameraView */ var _scrollRect:Sprite = new Sprite(); + var _flashOffset:FlxPoint = FlxPoint.get(); + @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) { @@ -100,6 +103,7 @@ class FlxQuadView extends FlxCameraView flashSprite = null; _scrollRect = null; + _flashOffset = FlxDestroyUtil.put(_flashOffset); } public function render():Void @@ -173,12 +177,16 @@ class FlxQuadView extends FlxCameraView override function offsetView(x:Float, y:Float):Void { + super.offsetView(x, y); + flashSprite.x += x; flashSprite.y += y; } override function updatePosition():Void { + super.updatePosition(); + if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; @@ -186,9 +194,19 @@ class FlxQuadView extends FlxCameraView } } + override function updateOffset() + { + super.updateOffset(); + + _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; + _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; + } + override function updateScrollRect():Void { - var rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; + super.updateScrollRect(); + + final rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; if (rect != null) { @@ -304,7 +322,7 @@ class FlxQuadView extends FlxCameraView */ static var _storageTrianglesHead:FlxDrawTrianglesItem; - function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) + public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) { #if FLX_RENDER_TRIANGLE return startTrianglesBatch(graphic, smooth, colored, blend); @@ -365,7 +383,7 @@ class FlxQuadView extends FlxCameraView #end } - function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { if (_currentDrawItem != null @@ -383,7 +401,7 @@ class FlxQuadView extends FlxCameraView return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } - function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { var itemToReturn:FlxDrawTrianglesItem = null; diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index bbbcb764dd..d2aa70cb62 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -16,6 +16,7 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; import flixel.system.FlxAssets.FlxTilemapGraphicAsset; +import flixel.system.render.quad.FlxQuadView; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxDirectionFlags; @@ -1229,7 +1230,7 @@ class FlxTypedTilemap extends FlxBaseTilemap scaledHeight = scaledTileHeight; var hasColorOffsets:Bool = (colorTransform != null && colorTransform.hasRGBAOffsets()); - drawItem = camera.startQuadBatch(graphic, isColored, hasColorOffsets, blend, antialiasing, shader); + drawItem = cast (camera.view, FlxQuadView).startQuadBatch(graphic, isColored, hasColorOffsets, blend, antialiasing, shader); } // Copy tile images into the tile buffer From 5f8516bbef019f212c2bf6851972d79ae416cb87 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 12:02:03 -0600 Subject: [PATCH 45/72] fix bitmap text --- flixel/text/FlxBitmapText.hx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index f1ab0b7b8d..ba88ef4040 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -379,8 +379,6 @@ class FlxBitmapText extends FlxSprite continue; } - FlxG.renderer.begin(camera); - getScreenPosition(screenPos, camera).subtract(offset); if (isPixelPerfectRender(camera)) @@ -407,7 +405,7 @@ class FlxBitmapText extends FlxSprite matrix.translate(screenPos.x + originX, screenPos.y + originY); final colorTransform = bgColorTransformDrawHelper.reset(); colorTransform.setMultipliers(colorHelper).scaleMultipliers(backgroundColor); - FlxG.renderer.drawPixels(FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); + FlxG.renderer.drawPixels(camera.view, FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); } final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); From 23af18d551c4773a163f650e96417646c404949d Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 12:02:07 -0600 Subject: [PATCH 46/72] remove display --- flixel/FlxCamera.hx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 3c60513a98..aca5376dc3 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -309,11 +309,6 @@ class FlxCamera extends FlxBasic */ public var viewBottom(get, never):Float; - /** - * Reference to camera's `view.display`. - */ - public var display(get, never):DisplayObjectContainer; - /** * The alpha value of this camera display (a number between `0.0` and `1.0`). */ @@ -1742,11 +1737,6 @@ class FlxCamera extends FlxBasic { return scroll.y + viewMarginBottom; } - - inline function get_display():DisplayObjectContainer - { - return view.display; - } /** * Do not use the following fields! They only exists because FlxCamera extends FlxBasic, From d2c7dd1e5a521f36028600a68cdbc5678b816d3d Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 12:36:30 -0600 Subject: [PATCH 47/72] more bitmap text fixes --- flixel/text/FlxBitmapText.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 3f71e0c0cd..1d5d8ae30b 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -409,7 +409,9 @@ class FlxBitmapText extends FlxSprite } final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); - final drawItem = camera.startQuadBatch(font.parent, true, hasColorOffsets, blend, antialiasing, shader); + @:privateAccess + final view = camera.viewQuad; // TODO: handle better + final drawItem = view.startQuadBatch(font.parent, true, hasColorOffsets, blend, antialiasing, shader); function addQuad(charCode:Int, x:Float, y:Float, color:ColorTransform) { var frame = font.getCharFrame(charCode); From caca90ab16aa577cb4dae3109bd6b400900fa3eb Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 15:11:40 -0600 Subject: [PATCH 48/72] whitespace + view creation --- flixel/FlxCamera.hx | 2 +- flixel/system/render/FlxCameraView.hx | 20 +--- flixel/system/render/FlxRenderer.hx | 109 +++++++++---------- flixel/system/render/blit/FlxBlitRenderer.hx | 5 + flixel/system/render/quad/FlxQuadRenderer.hx | 17 ++- 5 files changed, 72 insertions(+), 81 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index aca5376dc3..d29e5e7784 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -551,7 +551,7 @@ class FlxCamera extends FlxBasic function createView() { - return FlxCameraView.create(this); + return FlxG.renderer.createCameraView(this); } /** diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index f927fd1515..ddfb41e116 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -15,25 +15,7 @@ import openfl.display.Graphics; */ @:allow(flixel.FlxCamera) abstract class FlxCameraView implements IFlxDestroyable -{ - /** - * Creates a `FlxCameraView` object tied to a camera, based on the target and project configuration. - * This function is dynamic, which means that you can change the return value yourself. - * - * @param camera The camera to create the view for - */ - public static dynamic function create(camera:FlxCamera):FlxCameraView - { - if (!FlxG.renderer.isHardware) - { - return cast new flixel.system.render.blit.FlxBlitView(camera); - } - else - { - return cast new flixel.system.render.quad.FlxQuadView(camera); - } - } - +{ /** * Display object which is used as a container for all of the camera's graphics. * This object is added to the display tree. diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 15fa9eec1e..9a695e44d3 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -33,75 +33,74 @@ typedef FlxRenderer = FlxTypedRenderer; */ abstract class FlxTypedRenderer implements IFlxDestroyable { - /** + /** * The number of total draw calls in the current frame. */ - public static var totalDrawCalls:Int = 0; - - /** - * Creates a renderer instance, based on the used rendering backend. - * This function is dynamic, which means that you can change the return value yourself. - * - * @return A `FlxRenderer` instance. - */ - public static dynamic function create():FlxRenderer - { - if (!FlxG.renderer.isHardware) - { - return cast new flixel.system.render.blit.FlxBlitRenderer(); - } - else - { - return cast new flixel.system.render.quad.FlxQuadRenderer(); - } - } - - /** - * Returns the current render method as an enum. - */ - public var method(default, null):FlxRenderMethod; - - /** - * Returns whether the current renderer is hardware accelerated. - */ - public var isHardware(get, never):Bool; - @:noCompletion inline function get_isHardware():Bool - { - return FlxG.stage.window.context.attributes.hardware; - } - - /** - * Returns whether OpenGL access is available for the current renderer. - */ - public var isGL(get, never):Bool; - @:noCompletion inline function get_isGL():Bool - { - #if FLX_OPENGL_AVAILABLE + public static var totalDrawCalls:Int = 0; + + /** + * Creates a renderer instance, based on the used rendering backend. + * This function is dynamic, which means that you can change the return value yourself. + * + * @return A `FlxRenderer` instance. + */ + public static dynamic function create():FlxRenderer + { + if (!FlxG.renderer.isHardware) + { + return cast new flixel.system.render.blit.FlxBlitRenderer(); + } + else + { + return cast new flixel.system.render.quad.FlxQuadRenderer(); + } + } + + /** + * Returns the current render method as an enum. + */ + public var method(default, null):FlxRenderMethod; + + /** + * Returns whether the current renderer is hardware accelerated. + */ + public var isHardware(get, never):Bool; + @:noCompletion inline function get_isHardware():Bool + { + return FlxG.stage.window.context.attributes.hardware; + } + + /** + * Returns whether OpenGL access is available for the current renderer. + */ + public var isGL(get, never):Bool; + @:noCompletion inline function get_isGL():Bool + { + #if FLX_OPENGL_AVAILABLE return FlxG.stage.window.context.type == OPENGL || FlxG.stage.window.context.type == OPENGLES || FlxG.stage.window.context.type == WEBGL; - #else - return false; - #end - } - - /** + #else + return false; + #end + } + + /** * Returns the maximum allowed width and height (in pixels) for a texture. * This value is only available on hardware-accelerated targets that use OpenGL. * On unsupported targets, the returned value will always be -1. * * @see https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_TEXTURE_SIZE */ - public var maxTextureSize(default, null):Int; - - function new() - { - maxTextureSize = -1; - } - + public var maxTextureSize(default, null):Int = -1; + + function new() {} + public function destroy():Void {} //{ region ------------------------ RENDERING ------------------------ + + abstract function createCameraView(camera:FlxCamera):TView; /** * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 5e5ae8657a..b87da831a6 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -74,6 +74,11 @@ class FlxBlitRenderer extends FlxTypedRenderer _helperPoint = null; } + public function createCameraView(camera:FlxCamera) + { + return new FlxBlitView(camera); + } + public function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void { diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index c26b22b3ac..b6052aa847 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -35,16 +35,16 @@ class FlxQuadRenderer extends FlxTypedRenderer */ var _bounds:FlxRect = FlxRect.get(); - public function new() - { - super(); - method = DRAW_TILES; - + public function new() + { + super(); + method = DRAW_TILES; + #if FLX_OPENGL_AVAILBLE if (isGL) maxTextureSize = cast GL.getParameter(GL.MAX_TEXTURE_SIZE); #end - } + } override function destroy():Void { @@ -52,6 +52,11 @@ class FlxQuadRenderer extends FlxTypedRenderer _bounds = FlxDestroyUtil.put(_bounds); _helperMatrix = null; } + + public function createCameraView(camera:FlxCamera) + { + return new FlxQuadView(camera); + } public function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) From 8b34e47802655f2cf4bc1ed20c065843c9936780 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 27 Feb 2026 16:16:58 -0600 Subject: [PATCH 49/72] and FlxG.renderer.blit and tile --- flixel/FlxCamera.hx | 4 +- flixel/FlxG.hx | 14 +- flixel/FlxGame.hx | 4 +- flixel/FlxObject.hx | 2 +- flixel/FlxSprite.hx | 62 ++- flixel/FlxSubState.hx | 26 +- flixel/effects/particles/FlxEmitter.hx | 4 +- flixel/graphics/frames/FlxFrame.hx | 6 +- flixel/path/FlxBasePath.hx | 2 +- .../system/debug/interaction/Interaction.hx | 4 +- flixel/system/debug/stats/Stats.hx | 16 +- flixel/system/frontEnds/CameraFrontEnd.hx | 6 +- flixel/system/render/FlxRenderer.hx | 12 + flixel/text/FlxText.hx | 2 +- flixel/tile/FlxTilemap.hx | 52 +- flixel/tile/FlxTilemapBuffer.hx | 6 +- flixel/ui/FlxBar.hx | 448 +++++++++--------- 17 files changed, 337 insertions(+), 333 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index d29e5e7784..b35fc026f1 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -534,7 +534,7 @@ class FlxCamera extends FlxBasic @:privateAccess @:bypassAccessor _helperPoint = renderBlit._helperPoint; } - pixelPerfectRender = FlxG.renderer.method == BLITTING; + pixelPerfectRender = FlxG.renderer.blit; set_color(FlxColor.WHITE); @@ -1842,7 +1842,7 @@ class FlxCamera extends FlxBasic @:deprecated("checkResize() is deprecated") // 6.2.0 function checkResize():Void { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) viewBlit.checkResize(); } diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 7229b2fa6a..1d3c53c8f3 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -1,6 +1,5 @@ package flixel; -import flixel.system.render.FlxRenderer; import flixel.math.FlxMath; import flixel.math.FlxRandom; import flixel.math.FlxRect; @@ -19,6 +18,7 @@ import flixel.system.frontEnds.SignalFrontEnd; import flixel.system.frontEnds.SoundFrontEnd; import flixel.system.frontEnds.VCRFrontEnd; import flixel.system.frontEnds.WatchFrontEnd; +import flixel.system.render.FlxRenderer; import flixel.system.scaleModes.BaseScaleMode; import flixel.system.scaleModes.RatioScaleMode; import flixel.util.FlxCollision; @@ -144,25 +144,25 @@ class FlxG */ public static var onMobile(get, never):Bool; - @:deprecated("renderMethod is deprecated, use FlxG.render.method, instead.") + @:deprecated("renderMethod is deprecated, use FlxG.renderer.method, instead.") public static var renderMethod(get, null):flixel.system.render.FlxRenderer.FlxRenderMethod; @:noCompletion static inline function get_renderMethod():flixel.system.render.FlxRenderer.FlxRenderMethod { return FlxG.renderer.method; } - @:deprecated("renderBlit is deprecated, compare against FlxG.render.method, instead.") + @:deprecated("renderBlit is deprecated, compare against FlxG.renderer.blit, instead.") public static var renderBlit(get, never):Bool; @:noCompletion static inline function get_renderBlit():Bool { - return FlxG.renderer.method == BLITTING; + return FlxG.renderer.blit; } - @:deprecated("renderTile is deprecated, compare against FlxG.render.method, instead.") + @:deprecated("renderTile is deprecated, compare against FlxG.renderer.method, instead.") public static var renderTile(get, never):Bool; @:noCompletion static inline function get_renderTile():Bool { - return FlxG.renderer.method != BLITTING; + return FlxG.renderer.tile; } /** @@ -611,7 +611,7 @@ class FlxG static function initRenderMethod():Void { renderer = FlxRenderer.create(); - FlxObject.defaultPixelPerfectPosition = FlxG.renderer.method == BLITTING; + FlxObject.defaultPixelPerfectPosition = FlxG.renderer.blit; } #if FLX_SAVE diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 9a6af108ce..ee3c0f2763 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -1,7 +1,7 @@ package flixel; -import flixel.system.render.FlxRenderer; import flixel.system.FlxSplash; +import flixel.system.render.FlxRenderer; import flixel.util.FlxArrayUtil; import flixel.util.FlxDestroyUtil; import flixel.util.typeLimit.NextState; @@ -820,7 +820,7 @@ class FlxGame extends Sprite FlxG.cameras.render(); - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { #if FLX_DEBUG debugger.stats.drawCalls(FlxRenderer.totalDrawCalls); diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 72c9dd7356..aadbea3365 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -1311,7 +1311,7 @@ class FlxObject extends FlxBasic final rect = getBoundingBox(camera); // TODO: Remove and handle this in the view via drawDebugRect - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { final view = camera.getViewMarginRect(); view.pad(2); diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 3da9dccc6b..7a1581f3df 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -384,7 +384,7 @@ class FlxSprite extends FlxObject { super(X, Y); - useFramePixels = FlxG.renderer.method == BLITTING; + useFramePixels = FlxG.renderer.blit; if (SimpleGraphic != null) loadGraphic(SimpleGraphic); } @@ -908,7 +908,7 @@ class FlxSprite extends FlxObject centerOrigin(); - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { dirty = true; updateFramePixels(); @@ -1095,7 +1095,7 @@ class FlxSprite extends FlxObject graphic.bitmap.draw(bitmapData, _matrix, null, brushBlend, null, Brush.antialiasing); } - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { dirty = true; calcFrame(); @@ -1110,7 +1110,7 @@ class FlxSprite extends FlxObject */ public function drawFrame(Force:Bool = false):Void { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { if (Force || dirty) { @@ -1564,10 +1564,8 @@ class FlxSprite extends FlxObject { checkEmptyFrame(); - if (FlxG.renderer.method != BLITTING && !force) - return; - - updateFramePixels(); + if (FlxG.renderer.blit || force) + updateFramePixels(); } /** @@ -1580,7 +1578,7 @@ class FlxSprite extends FlxObject // don't try to regenerate frame pixels if _frame already uses it as source of graphics // if you'll try then it will clear framePixels and you won't see anything - if (FlxG.renderer.method != BLITTING && _frameGraphic != null) + if (FlxG.renderer.tile && _frameGraphic != null) { dirty = false; return framePixels; @@ -1598,12 +1596,12 @@ class FlxSprite extends FlxObject framePixels = _frame.paintRotatedAndFlipped(framePixels, _flashPointZero, FlxFrameAngle.ANGLE_0, doFlipX, doFlipY, false, true); } - if (FlxG.renderer.method == BLITTING && hasColorTransform()) + if (FlxG.renderer.blit && hasColorTransform()) { framePixels.colorTransform(_flashRect, colorTransform); } - if (FlxG.renderer.method != BLITTING && useFramePixels) + if (FlxG.renderer.tile && useFramePixels) { // recreate _frame for native target, so it will use modified framePixels _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); @@ -1677,10 +1675,7 @@ class FlxSprite extends FlxObject */ public function isSimpleRender(?camera:FlxCamera):Bool { - if (FlxG.renderer.method != BLITTING) - return false; - - return isSimpleRenderBlit(camera); + return FlxG.renderer.blit && isSimpleRenderBlit(camera); } /** @@ -1846,7 +1841,7 @@ class FlxSprite extends FlxObject return null; } - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); } @@ -2004,7 +1999,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipX(Value:Bool):Bool { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _facingHorizontalMult = Value ? -1 : 1; } @@ -2015,7 +2010,7 @@ class FlxSprite extends FlxObject @:noCompletion function set_flipY(Value:Bool):Bool { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _facingVerticalMult = Value ? -1 : 1; } @@ -2032,25 +2027,26 @@ class FlxSprite extends FlxObject @:noCompletion function set_useFramePixels(value:Bool):Bool { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - if (value != useFramePixels) - { - useFramePixels = value; - resetFrame(); - - if (value) + case DRAW_TILES: + if (value != useFramePixels) { - updateFramePixels(); + useFramePixels = value; + resetFrame(); + + if (value) + { + updateFramePixels(); + } } - } - return value; - } - else - { - useFramePixels = true; - return true; + return value; + case BLITTING: + useFramePixels = true; + return true; + case CUSTOM: + return useFramePixels = value; } } diff --git a/flixel/FlxSubState.hx b/flixel/FlxSubState.hx index 9375046846..fa0d465de9 100644 --- a/flixel/FlxSubState.hx +++ b/flixel/FlxSubState.hx @@ -53,7 +53,7 @@ class FlxSubState extends FlxState closeCallback = null; openCallback = null; - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _bgSprite = new FlxBGSprite(); } @@ -63,18 +63,18 @@ class FlxSubState extends FlxState override public function draw():Void { // Draw background - if (FlxG.renderer.method == BLITTING) + switch FlxG.renderer.method { - for (camera in getCamerasLegacy()) - camera.view.fill(bgColor); - } - else // FlxG.renderer.method != BLITTING - { - if (_bgSprite != null && _bgSprite.visible) - { - _bgSprite.cameras = getCameras(); - _bgSprite.draw(); - } + case BLITTING: + for (camera in getCamerasLegacy()) + camera.view.fill(bgColor); + case DRAW_TILES: + if (_bgSprite != null && _bgSprite.visible) + { + _bgSprite.cameras = getCameras(); + _bgSprite.draw(); + } + case CUSTOM: } // Now draw all children @@ -108,7 +108,7 @@ class FlxSubState extends FlxState @:noCompletion override function set_bgColor(value:FlxColor):FlxColor { - if (FlxG.renderer.method != BLITTING && _bgSprite != null) + if (FlxG.renderer.tile && _bgSprite != null) { _bgSprite.alpha = value.alphaFloat; _bgSprite.visible = _bgSprite.alpha > 0; diff --git a/flixel/effects/particles/FlxEmitter.hx b/flixel/effects/particles/FlxEmitter.hx index 1538b97a29..4b6c05891a 100644 --- a/flixel/effects/particles/FlxEmitter.hx +++ b/flixel/effects/particles/FlxEmitter.hx @@ -1,6 +1,5 @@ package flixel.effects.particles; -import openfl.display.BlendMode; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; @@ -15,6 +14,7 @@ import flixel.util.FlxDirectionFlags; import flixel.util.helpers.FlxBounds; import flixel.util.helpers.FlxPointRangeBounds; import flixel.util.helpers.FlxRangeBounds; +import openfl.display.BlendMode; typedef FlxEmitter = FlxTypedEmitter; @@ -264,7 +264,7 @@ class FlxTypedEmitter extends FlxTypedGroup var particle:T = Type.createInstance(particleClass, []); var frame = Multiple ? FlxG.random.int(0, totalFrames - 1) : -1; - if (FlxG.renderer.method == BLITTING && bakedRotationAngles > 0) + if (FlxG.renderer.blit && bakedRotationAngles > 0) particle.loadRotatedGraphic(Graphics, bakedRotationAngles, frame, false, AutoBuffer); else particle.loadGraphic(Graphics, Multiple); diff --git a/flixel/graphics/frames/FlxFrame.hx b/flixel/graphics/frames/FlxFrame.hx index 24ee97351e..08b19279a4 100644 --- a/flixel/graphics/frames/FlxFrame.hx +++ b/flixel/graphics/frames/FlxFrame.hx @@ -159,7 +159,7 @@ class FlxFrame implements IFlxDestroyable offset = FlxPoint.get(); blitMatrix = new MatrixVector(); - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) tileMatrix = new MatrixVector(); } @@ -169,7 +169,7 @@ class FlxFrame implements IFlxDestroyable { blitMatrix.copyFrom(this, true); - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) tileMatrix.copyFrom(this, false); } @@ -279,7 +279,7 @@ class FlxFrame implements IFlxDestroyable */ public function prepareMatrix(mat:FlxMatrix, rotation:FlxFrameAngle = FlxFrameAngle.ANGLE_0, flipX:Bool = false, flipY:Bool = false):FlxMatrix { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { mat.identity(); return mat; diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 8586c00ed3..10ce3e9894 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -375,7 +375,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy result.y -= camera.scroll.y * object.scrollFactor.y; } - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { result.x -= camera.viewMarginX; result.y -= camera.viewMarginY; diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index c8d1be1cb8..5165165956 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -381,14 +381,14 @@ class Interaction extends Window @:deprecated("getDebugGraphics() is deprecated. Use the debug draw functions from FlxCamera instead.") public function getDebugGraphics():Graphics { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { FlxSpriteUtil.flashGfx.clear(); return FlxSpriteUtil.flashGfx; } #if FLX_DEBUG - return FlxG.camera.debugLayer.graphics; + return FlxG.camera.view.getDebugGraphics(); #end return null; diff --git a/flixel/system/debug/stats/Stats.hx b/flixel/system/debug/stats/Stats.hx index 8b82b00dac..8c4eb88c22 100644 --- a/flixel/system/debug/stats/Stats.hx +++ b/flixel/system/debug/stats/Stats.hx @@ -1,8 +1,5 @@ package flixel.system.debug.stats; -import openfl.display.BitmapData; -import openfl.system.System; -import openfl.text.TextField; import flixel.FlxG; import flixel.math.FlxMath; import flixel.system.FlxLinkedList; @@ -10,6 +7,9 @@ import flixel.system.FlxQuadTree; import flixel.system.debug.DebuggerUtil; import flixel.system.ui.FlxSystemButton; import flixel.util.FlxColor; +import openfl.display.BitmapData; +import openfl.system.System; +import openfl.text.TextField; /** @@ -88,7 +88,7 @@ class Stats extends Window { super("Stats", Icon.stats, 0, 0, false); - var minHeight = if (FlxG.renderer.method != BLITTING) 200 else 185; + var minHeight = if (FlxG.renderer.tile) 200 else 185; minSize.y = minHeight; resize(INITIAL_WIDTH, minHeight); @@ -130,7 +130,7 @@ class Stats extends Window _leftTextField.multiline = _rightTextField.multiline = true; var drawMethod = ""; - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { drawMethod = #if FLX_RENDER_TRIANGLE @@ -267,7 +267,7 @@ class Stats extends Window } visibleCount = Std.int(divide(visibleCount, _visibleObjectMarker)); - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.blit) { for (i in 0..._drawCallsMarker) { @@ -280,7 +280,7 @@ class Stats extends Window _drawMarker = 0; _activeObjectMarker = 0; _visibleObjectMarker = 0; - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _drawCallsMarker = 0; } @@ -298,7 +298,7 @@ class Stats extends Window updateTimeGraph.update(updTime); _rightTextField.text = activeCount + " (" + updTime + "ms)\n" + visibleCount + " (" + drwTime + "ms)\n" - + (FlxG.renderer.method != BLITTING ? (drawCallsCount + "\n") : "") + + (FlxG.renderer.tile ? (drawCallsCount + "\n") : "") + FlxQuadTree._NUM_CACHED_QUAD_TREES + "\n" + FlxLinkedList._NUM_CACHED_FLX_LIST; diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index e76a7a604a..9acb834d38 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -136,7 +136,7 @@ class CameraFrontEnd return; } - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { for (i in 0...list.length) { @@ -343,7 +343,7 @@ class CameraFrontEnd function get_useBufferLocking():Bool { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) return FlxBlitRenderer.useBufferLocking; return false; @@ -351,7 +351,7 @@ class CameraFrontEnd function set_useBufferLocking(value:Bool):Bool { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) return FlxBlitRenderer.useBufferLocking = value; return value; diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 9a695e44d3..51136c784b 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -61,6 +61,12 @@ abstract class FlxTypedRenderer implements IFlxDestroyable */ public var method(default, null):FlxRenderMethod; + public var blit(get, never):Bool; + inline function get_blit() return method.match(BLITTING); + + public var tile(get, never):Bool; + inline function get_tile() return method.match(DRAW_TILES); + /** * Returns whether the current renderer is hardware accelerated. */ @@ -166,6 +172,7 @@ enum FlxRenderMethod * This method is the default and is used on all targets (when hardware acceleration is available), except for Flash. */ DRAW_TILES; + /** * Draws sprites directly onto bitmaps using a software renderer. * @@ -173,4 +180,9 @@ enum FlxRenderMethod * hardware acceleration is unavailable. */ BLITTING; + + /** + * A custom backend + */ + CUSTOM; } diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index b608b7f57f..8cebd3ee04 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -1071,7 +1071,7 @@ class FlxText extends FlxSprite if (textField == null) return; - if (FlxG.renderer.method != BLITTING && !RunOnCpp) + if (!FlxG.renderer.blit && !RunOnCpp) return; regenGraphic(); diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 901c343c56..b47b0814fc 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -287,7 +287,7 @@ class FlxTypedTilemap extends FlxBaseTilemap { super(); - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { _helperPoint = new Point(); _matrix = new FlxMatrix(); @@ -306,7 +306,7 @@ class FlxTypedTilemap extends FlxBaseTilemap debugBoundingBoxColorPartial = FlxColor.PINK; debugBoundingBoxColorNotSolid = FlxColor.TRANSPARENT; - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) FlxG.debugger.drawDebugChanged.add(onDrawDebugChanged); #end } @@ -322,19 +322,19 @@ class FlxTypedTilemap extends FlxBaseTilemap _tileObjects = FlxDestroyUtil.destroyArray(_tileObjects); _buffers = FlxDestroyUtil.destroyArray(_buffers); - if (FlxG.renderer.method == BLITTING) + switch FlxG.renderer.method { - #if FLX_DEBUG - _debugRect = null; - _debugTileNotSolid = FlxDestroyUtil.dispose(_debugTileNotSolid); - _debugTilePartial = FlxDestroyUtil.dispose(_debugTilePartial); - _debugTileSolid = FlxDestroyUtil.dispose(_debugTileSolid); - #end - } - else - { - _helperPoint = null; - _matrix = null; + case BLITTING: + #if FLX_DEBUG + _debugRect = null; + _debugTileNotSolid = FlxDestroyUtil.dispose(_debugTileNotSolid); + _debugTilePartial = FlxDestroyUtil.dispose(_debugTilePartial); + _debugTileSolid = FlxDestroyUtil.dispose(_debugTileSolid); + #end + case DRAW_TILES: + _helperPoint = null; + _matrix = null; + case CUSTOM: } frames = null; @@ -352,7 +352,7 @@ class FlxTypedTilemap extends FlxBaseTilemap FlxG.cameras.cameraResized.remove(onCameraChanged); #if FLX_DEBUG - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) FlxG.debugger.drawDebugChanged.remove(onDrawDebugChanged); #end @@ -500,7 +500,7 @@ class FlxTypedTilemap extends FlxBaseTilemap function updateDebugTile(tileBitmap:BitmapData, color:FlxColor):BitmapData { - if (FlxG.renderer.method != BLITTING) + if (!FlxG.renderer.blit) return null; if (tileWidth <= 0 || tileHeight <= 0) @@ -531,7 +531,7 @@ class FlxTypedTilemap extends FlxBaseTilemap override function updateMap():Void { #if FLX_DEBUG - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) _debugRect = new Rectangle(0, 0, tileWidth, tileHeight); #end @@ -543,7 +543,7 @@ class FlxTypedTilemap extends FlxBaseTilemap #if FLX_DEBUG override function drawDebugOnCamera(camera:FlxCamera):Void { - if (FlxG.renderer.method != DRAW_TILES) + if (!FlxG.renderer.tile) return; var buffer:FlxTilemapBuffer = null; @@ -657,7 +657,7 @@ class FlxTypedTilemap extends FlxBaseTilemap buffer = _buffers[i]; - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { if (buffer.isDirty(this, camera)) drawTilemap(buffer, camera); @@ -705,7 +705,7 @@ class FlxTypedTilemap extends FlxBaseTilemap */ override function setDirty(dirty:Bool = true):Void { - if (FlxG.renderer.method != BLITTING) + if (!FlxG.renderer.blit) return; for (buffer in _buffers) @@ -1035,7 +1035,7 @@ class FlxTypedTilemap extends FlxBaseTilemap var scaledHeight:Float = 0; var drawItem = null; - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { buffer.fill(); } @@ -1089,7 +1089,7 @@ class FlxTypedTilemap extends FlxBaseTilemap { frame = tile.frame; - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { frame.paint(buffer.pixels, _flashPoint, true); @@ -1137,13 +1137,13 @@ class FlxTypedTilemap extends FlxBaseTilemap } } - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) _flashPoint.x += tileWidth; columnIndex++; } - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) _flashPoint.y += tileHeight; rowIndex += widthInTiles; } @@ -1151,7 +1151,7 @@ class FlxTypedTilemap extends FlxBaseTilemap buffer.x = screenXInTiles * scaledTileWidth; buffer.y = screenYInTiles * scaledTileHeight; - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { if (isColored) buffer.colorTransform(colorTransform); @@ -1168,7 +1168,7 @@ class FlxTypedTilemap extends FlxBaseTilemap #if FLX_DEBUG function makeDebugTile(color:FlxColor):BitmapData { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) return null; var debugTile = new BitmapData(tileWidth, tileHeight, true, 0); diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index 1c9f92dc31..2f2c16f62e 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -117,7 +117,7 @@ class FlxTilemapBuffer implements IFlxDestroyable updateColumns(tileWidth, widthInTiles, scaleX, camera); updateRows(tileHeight, heightInTiles, scaleY, camera); - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { final newWidth = Std.int(columns * tileWidth); final newHeight = Std.int(rows * tileHeight); @@ -144,7 +144,7 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function destroy():Void { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { pixels = FlxDestroyUtil.dispose(pixels); blend = null; @@ -161,7 +161,7 @@ class FlxTilemapBuffer implements IFlxDestroyable */ public function fill(color = FlxColor.TRANSPARENT):Void { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { pixels.fillRect(_flashRect, color); } diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index d2059502b4..8bc8c47114 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -172,15 +172,14 @@ class FlxBar extends FlxSprite _filledBarPoint = new Point(); _filledBarRect = new Rectangle(); - if (FlxG.renderer.method == BLITTING) + switch FlxG.renderer.method { - _zeroOffset = new Point(); - _emptyBarRect = new Rectangle(); - makeGraphic(width, height, FlxColor.TRANSPARENT, true); - } - else - { - _filledFlxRect = FlxRect.get(); + case BLITTING: + _zeroOffset = new Point(); + _emptyBarRect = new Rectangle(); + makeGraphic(width, height, FlxColor.TRANSPARENT, true); + case DRAW_TILES | CUSTOM: + _filledFlxRect = FlxRect.get(); } if (parentRef != null) @@ -198,17 +197,17 @@ class FlxBar extends FlxSprite { positionOffset = FlxDestroyUtil.put(positionOffset); - if (FlxG.renderer.method != BLITTING) - { - frontFrames = null; - _filledFlxRect = FlxDestroyUtil.put(_filledFlxRect); - } - else + switch FlxG.renderer.method { - _emptyBarRect = null; - _zeroOffset = null; - _emptyBar = FlxDestroyUtil.dispose(_emptyBar); - _filledBar = FlxDestroyUtil.dispose(_filledBar); + case DRAW_TILES: + frontFrames = null; + _filledFlxRect = FlxDestroyUtil.put(_filledFlxRect); + case BLITTING: + _emptyBarRect = null; + _zeroOffset = null; + _emptyBar = FlxDestroyUtil.dispose(_emptyBar); + _filledBar = FlxDestroyUtil.dispose(_filledBar); + case CUSTOM: } _filledBarRect = null; _filledBarPoint = null; @@ -352,45 +351,45 @@ class FlxBar extends FlxSprite */ public function createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - var emptyKey:String = "empty: " + barWidth + "x" + barHeight + ":" + empty.toHexString(); - if (showBorder) - emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; - - if (!FlxG.bitmap.checkCache(emptyKey)) - { - var emptyBar:BitmapData = null; - + case DRAW_TILES: + var emptyKey:String = "empty: " + barWidth + "x" + barHeight + ":" + empty.toHexString(); if (showBorder) + emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; + + if (!FlxG.bitmap.checkCache(emptyKey)) { - emptyBar = new BitmapData(barWidth, barHeight, true, border); - emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); + var emptyBar:BitmapData = null; + + if (showBorder) + { + emptyBar = new BitmapData(barWidth, barHeight, true, border); + emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); + } + else + { + emptyBar = new BitmapData(barWidth, barHeight, true, empty); + } + + FlxG.bitmap.add(emptyBar, false, emptyKey); + } + + frames = FlxG.bitmap.get(emptyKey).imageFrame; + case BLITTING: + if (showBorder) + { + _emptyBar = new BitmapData(barWidth, barHeight, true, border); + _emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); } else { - emptyBar = new BitmapData(barWidth, barHeight, true, empty); + _emptyBar = new BitmapData(barWidth, barHeight, true, empty); } - FlxG.bitmap.add(emptyBar, false, emptyKey); - } - - frames = FlxG.bitmap.get(emptyKey).imageFrame; - } - else - { - if (showBorder) - { - _emptyBar = new BitmapData(barWidth, barHeight, true, border); - _emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); - } - else - { - _emptyBar = new BitmapData(barWidth, barHeight, true, empty); - } - - _emptyBarRect.setTo(0, 0, barWidth, barHeight); - updateEmptyBar(); + _emptyBarRect.setTo(0, 0, barWidth, barHeight); + updateEmptyBar(); + case CUSTOM: } return this; @@ -406,45 +405,45 @@ class FlxBar extends FlxSprite */ public function createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - var filledKey:String = "filled: " + barWidth + "x" + barHeight + ":" + fill.toHexString(); - if (showBorder) - filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; + case DRAW_TILES: + var filledKey:String = "filled: " + barWidth + "x" + barHeight + ":" + fill.toHexString(); + if (showBorder) + filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; - if (!FlxG.bitmap.checkCache(filledKey)) - { - var filledBar:BitmapData = null; + if (!FlxG.bitmap.checkCache(filledKey)) + { + var filledBar:BitmapData = null; + + if (showBorder) + { + filledBar = new BitmapData(barWidth, barHeight, true, border); + filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); + } + else + { + filledBar = new BitmapData(barWidth, barHeight, true, fill); + } + FlxG.bitmap.add(filledBar, false, filledKey); + } + + frontFrames = FlxG.bitmap.get(filledKey).imageFrame; + case BLITTING: if (showBorder) { - filledBar = new BitmapData(barWidth, barHeight, true, border); - filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); + _filledBar = new BitmapData(barWidth, barHeight, true, border); + _filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); } else { - filledBar = new BitmapData(barWidth, barHeight, true, fill); + _filledBar = new BitmapData(barWidth, barHeight, true, fill); } - FlxG.bitmap.add(filledBar, false, filledKey); - } - - frontFrames = FlxG.bitmap.get(filledKey).imageFrame; - } - else - { - if (showBorder) - { - _filledBar = new BitmapData(barWidth, barHeight, true, border); - _filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); - } - else - { - _filledBar = new BitmapData(barWidth, barHeight, true, fill); - } - - _filledBarRect.setTo(0, 0, barWidth, barHeight); - updateFilledBar(); + _filledBarRect.setTo(0, 0, barWidth, barHeight); + updateFilledBar(); + case CUSTOM: } return this; } @@ -484,57 +483,57 @@ class FlxBar extends FlxSprite public function createGradientEmptyBar(empty:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - var emptyKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; - for (col in empty) - { - emptyKey += col.toHexString() + ","; - } - emptyKey += "],chunkSize: " + chunkSize + ",rotation: " + rotation; - - if (showBorder) - { - emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; - } - - if (!FlxG.bitmap.checkCache(emptyKey)) - { - var emptyBar:BitmapData = null; - + case DRAW_TILES: + var emptyKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; + for (col in empty) + { + emptyKey += col.toHexString() + ","; + } + emptyKey += "],chunkSize: " + chunkSize + ",rotation: " + rotation; + + if (showBorder) + { + emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; + } + + if (!FlxG.bitmap.checkCache(emptyKey)) + { + var emptyBar:BitmapData = null; + + if (showBorder) + { + emptyBar = new BitmapData(barWidth, barHeight, true, border); + FlxGradient.overlayGradientOnBitmapData(emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, + chunkSize, rotation); + } + else + { + emptyBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, empty, chunkSize, rotation); + } + + FlxG.bitmap.add(emptyBar, false, emptyKey); + } + + frames = FlxG.bitmap.get(emptyKey).imageFrame; + case BLITTING: if (showBorder) { - emptyBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, + _emptyBar = new BitmapData(barWidth, barHeight, true, border); + FlxGradient.overlayGradientOnBitmapData(_emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, chunkSize, rotation); } else { - emptyBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, empty, chunkSize, rotation); + _emptyBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, empty, chunkSize, rotation); } - - FlxG.bitmap.add(emptyBar, false, emptyKey); - } - - frames = FlxG.bitmap.get(emptyKey).imageFrame; - } - else - { - if (showBorder) - { - _emptyBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(_emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, - chunkSize, rotation); - } - else - { - _emptyBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, empty, chunkSize, rotation); - } - - _emptyBarRect.setTo(0, 0, barWidth, barHeight); - updateEmptyBar(); + + _emptyBarRect.setTo(0, 0, barWidth, barHeight); + updateEmptyBar(); + case CUSTOM: } - + return this; } @@ -552,57 +551,57 @@ class FlxBar extends FlxSprite public function createGradientFilledBar(fill:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - var filledKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; - for (col in fill) - { - filledKey += col.toHexString() + ","; - } - filledKey += "],chunkSize: " + chunkSize + ",rotation: " + rotation; - - if (showBorder) - { - filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; - } - - if (!FlxG.bitmap.checkCache(filledKey)) - { - var filledBar:BitmapData = null; - + case DRAW_TILES: + var filledKey:String = "Gradient:" + barWidth + "x" + barHeight + ",colors:["; + for (col in fill) + { + filledKey += col.toHexString() + ","; + } + filledKey += "],chunkSize: " + chunkSize + ",rotation: " + rotation; + if (showBorder) { - filledBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, + filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; + } + + if (!FlxG.bitmap.checkCache(filledKey)) + { + var filledBar:BitmapData = null; + + if (showBorder) + { + filledBar = new BitmapData(barWidth, barHeight, true, border); + FlxGradient.overlayGradientOnBitmapData(filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, + chunkSize, rotation); + } + else + { + filledBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, fill, chunkSize, rotation); + } + + FlxG.bitmap.add(filledBar, false, filledKey); + } + + frontFrames = FlxG.bitmap.get(filledKey).imageFrame; + case BLITTING: + if (showBorder) + { + _filledBar = new BitmapData(barWidth, barHeight, true, border); + FlxGradient.overlayGradientOnBitmapData(_filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, chunkSize, rotation); } else { - filledBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, fill, chunkSize, rotation); + _filledBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, fill, chunkSize, rotation); } - - FlxG.bitmap.add(filledBar, false, filledKey); - } - - frontFrames = FlxG.bitmap.get(filledKey).imageFrame; - } - else - { - if (showBorder) - { - _filledBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(_filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, - chunkSize, rotation); - } - else - { - _filledBar = FlxGradient.createGradientBitmapData(barWidth, barHeight, fill, chunkSize, rotation); - } - - _filledBarRect.setTo(0, 0, barWidth, barHeight); - updateFilledBar(); + + _filledBarRect.setTo(0, 0, barWidth, barHeight); + updateFilledBar(); + case CUSTOM: } - + return this; } @@ -638,26 +637,26 @@ class FlxBar extends FlxSprite if (empty != null) { var emptyGraphic:FlxGraphic = FlxG.bitmap.add(empty); - - if (FlxG.renderer.method != BLITTING) - { - frames = emptyGraphic.imageFrame; - } - else + + switch FlxG.renderer.method { - _emptyBar = emptyGraphic.bitmap.clone(); - - barWidth = _emptyBar.width; - barHeight = _emptyBar.height; - - _emptyBarRect.setTo(0, 0, barWidth, barHeight); - - if (graphic == null || (frame.sourceSize.x != barWidth || frame.sourceSize.y != barHeight)) - { - makeGraphic(barWidth, barHeight, FlxColor.TRANSPARENT, true); - } - - updateEmptyBar(); + case DRAW_TILES: + frames = emptyGraphic.imageFrame; + case BLITTING: + _emptyBar = emptyGraphic.bitmap.clone(); + + barWidth = _emptyBar.width; + barHeight = _emptyBar.height; + + _emptyBarRect.setTo(0, 0, barWidth, barHeight); + + if (graphic == null || (frame.sourceSize.x != barWidth || frame.sourceSize.y != barHeight)) + { + makeGraphic(barWidth, barHeight, FlxColor.TRANSPARENT, true); + } + + updateEmptyBar(); + case CUSTOM: } } else @@ -680,24 +679,24 @@ class FlxBar extends FlxSprite if (fill != null) { var filledGraphic:FlxGraphic = FlxG.bitmap.add(fill); - - if (FlxG.renderer.method != BLITTING) - { - frontFrames = filledGraphic.imageFrame; - } - else + + switch FlxG.renderer.method { - _filledBar = filledGraphic.bitmap.clone(); - - _filledBarRect.setTo(0, 0, barWidth, barHeight); - - if (graphic == null || (frame.sourceSize.x != barWidth || frame.sourceSize.y != barHeight)) - { - makeGraphic(barWidth, barHeight, FlxColor.TRANSPARENT, true); - } - - pxPerPercent = (_fillHorizontal) ? (barWidth / _maxPercent) : (barHeight / _maxPercent); - updateFilledBar(); + case DRAW_TILES: + frontFrames = filledGraphic.imageFrame; + case BLITTING: + _filledBar = filledGraphic.bitmap.clone(); + + _filledBarRect.setTo(0, 0, barWidth, barHeight); + + if (graphic == null || (frame.sourceSize.x != barWidth || frame.sourceSize.y != barHeight)) + { + makeGraphic(barWidth, barHeight, FlxColor.TRANSPARENT, true); + } + + pxPerPercent = (_fillHorizontal) ? (barWidth / _maxPercent) : (barHeight / _maxPercent); + updateFilledBar(); + case CUSTOM: } } else @@ -744,7 +743,7 @@ class FlxBar extends FlxSprite */ public function updateEmptyBar():Void { - if (FlxG.renderer.method == BLITTING) + if (FlxG.renderer.blit) { pixels.copyPixels(_emptyBar, _emptyBarRect, _zeroOffset); dirty = true; @@ -806,27 +805,23 @@ class FlxBar extends FlxSprite _filledBarPoint.y = Std.int((barHeight - _filledBarRect.height) / 2); } - if (FlxG.renderer.method == BLITTING) - { - pixels.copyPixels(_filledBar, _filledBarRect, _filledBarPoint, null, null, true); - } - else + switch FlxG.renderer.method { - if (frontFrames != null) - { - _filledFlxRect.copyFromFlash(_filledBarRect).round(); - if (Std.int(percent) > 0) + case BLITTING: + pixels.copyPixels(_filledBar, _filledBarRect, _filledBarPoint, null, null, true); + dirty = true; + case DRAW_TILES: + if (frontFrames != null) { - _frontFrame = frontFrames.frame.clipTo(_filledFlxRect, _frontFrame); + _filledFlxRect.copyFromFlash(_filledBarRect).round(); + if (Std.int(percent) > 0) + { + _frontFrame = frontFrames.frame.clipTo(_filledFlxRect, _frontFrame); + } } - } + case CUSTOM: } } - - if (FlxG.renderer.method == BLITTING) - { - dirty = true; - } } override public function update(elapsed:Float):Void @@ -852,7 +847,7 @@ class FlxBar extends FlxSprite { super.draw(); - if (FlxG.renderer.method != DRAW_TILES) + if (!FlxG.renderer.tile) return; if (alpha == 0) @@ -897,7 +892,7 @@ class FlxBar extends FlxSprite override function set_pixels(pixels:BitmapData):BitmapData { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { return pixels; // hack } @@ -982,7 +977,7 @@ class FlxBar extends FlxSprite function get_frontFrames():FlxImageFrame { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { return frontFrames; } @@ -991,7 +986,7 @@ class FlxBar extends FlxSprite function set_frontFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { if (value != null) value.parent.incrementUseCount(); @@ -1011,7 +1006,7 @@ class FlxBar extends FlxSprite function get_backFrames():FlxImageFrame { - if (FlxG.renderer.method != BLITTING) + if (FlxG.renderer.tile) { return cast frames; } @@ -1020,14 +1015,15 @@ class FlxBar extends FlxSprite function set_backFrames(value:FlxImageFrame):FlxImageFrame { - if (FlxG.renderer.method != BLITTING) + switch FlxG.renderer.method { - frames = value; - } - else - { - createImageEmptyBar(value.frame.paint()); + case DRAW_TILES: + frames = value; + case BLITTING: + createImageEmptyBar(value.frame.paint()); + case CUSTOM: } + return value; } } From d3def2f8551564df25a0871aaf2e2465c9e053f1 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Sat, 28 Feb 2026 09:42:25 -0600 Subject: [PATCH 50/72] add initGlobals --- flixel/FlxG.hx | 8 ++++---- flixel/system/render/FlxRenderer.hx | 6 ++++++ flixel/system/render/blit/FlxBlitRenderer.hx | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 1d3c53c8f3..2ec3b3dcbd 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -148,21 +148,21 @@ class FlxG public static var renderMethod(get, null):flixel.system.render.FlxRenderer.FlxRenderMethod; @:noCompletion static inline function get_renderMethod():flixel.system.render.FlxRenderer.FlxRenderMethod { - return FlxG.renderer.method; + return renderer.method; } @:deprecated("renderBlit is deprecated, compare against FlxG.renderer.blit, instead.") public static var renderBlit(get, never):Bool; @:noCompletion static inline function get_renderBlit():Bool { - return FlxG.renderer.blit; + return renderer.blit; } @:deprecated("renderTile is deprecated, compare against FlxG.renderer.method, instead.") public static var renderTile(get, never):Bool; @:noCompletion static inline function get_renderTile():Bool { - return FlxG.renderer.tile; + return renderer.tile; } /** @@ -611,7 +611,7 @@ class FlxG static function initRenderMethod():Void { renderer = FlxRenderer.create(); - FlxObject.defaultPixelPerfectPosition = FlxG.renderer.blit; + renderer.initGlobals(); } #if FLX_SAVE diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 51136c784b..863c73669b 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -102,6 +102,12 @@ abstract class FlxTypedRenderer implements IFlxDestroyable function new() {} + /** + * Initializes and global fields that are dependant on the global rendering method. + * Called automatically by `FlxG.init` + */ + public function initGlobals() {} + public function destroy():Void {} //{ region ------------------------ RENDERING ------------------------ diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index b87da831a6..124996a3c9 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -66,6 +66,13 @@ class FlxBlitRenderer extends FlxTypedRenderer method = BLITTING; } + override function initGlobals() + { + super.initGlobals(); + + FlxObject.defaultPixelPerfectPosition = true; + } + override function destroy():Void { super.destroy(); From 74a38f4136f9ff56906d174eec40351f9b52e276 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Tue, 3 Mar 2026 13:26:33 -0600 Subject: [PATCH 51/72] view/cam setters/getters --- flixel/FlxCamera.hx | 48 ++++++++------- flixel/graphics/tile/FlxDrawQuadsItem.hx | 2 +- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 2 +- flixel/system/render/FlxCameraView.hx | 64 +++++++++----------- flixel/system/render/blit/FlxBlitRenderer.hx | 6 +- flixel/system/render/blit/FlxBlitView.hx | 31 +++++----- flixel/system/render/quad/FlxQuadView.hx | 26 ++++---- 7 files changed, 88 insertions(+), 91 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index b35fc026f1..2d07c4216b 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -328,6 +328,8 @@ class FlxCamera extends FlxBasic * Whether the camera display is smooth and filtered, or chunky and pixelated. * Default behavior is chunky-style. */ + @:noCompletion + @:deprecated("camera.antialiasing is deprecated, use camera.view.anstialiasing instead") public var antialiasing(default, set):Bool = false; /** @@ -1610,34 +1612,26 @@ class FlxCamera extends FlxBasic return zoom; } - function set_alpha(alpha:Float):Float + function set_alpha(value:Float):Float { - this.alpha = FlxMath.bound(alpha, 0, 1); - view.alpha = alpha; - return alpha; + return this.alpha = view.alpha = FlxMath.bound(value, 0, 1); } - - function set_angle(angle:Float):Float + + function set_angle(value:Float):Float { - this.angle = angle; - view.angle = angle; - return angle; + return this.angle = view.angle = value; } - - function set_color(color:FlxColor):FlxColor + + function set_color(value:FlxColor):FlxColor { - this.color = color; - view.color = color; - return color; + return this.color = view.color = value; } - - function set_antialiasing(antialiasing:Bool):Bool + + function set_antialiasing(value:Bool):Bool { - this.antialiasing = antialiasing; - view.antialiasing = antialiasing; - return antialiasing; + return this.antialiasing = view.antialiasing = value; } - + function set_x(x:Float):Float { this.x = x; @@ -1652,10 +1646,9 @@ class FlxCamera extends FlxBasic return y; } - override function set_visible(visible:Bool):Bool + override function set_visible(value:Bool):Bool { - view.visible = visible; - return this.visible = visible; + return this.visible = view.visible = value; } inline function calcMarginX():Void @@ -2288,6 +2281,15 @@ class FlxCamera extends FlxBasic static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; + // @:bypassAccess doesn't work from external classes in haxe 4. So call this when needed + @:noCompletion inline function setColorBypass (value:FlxColor):FlxColor return @:bypassAccessor this.color = value; + @:noCompletion inline function setAlphaBypass (value:Float ):Float return @:bypassAccessor this.alpha = value; + @:noCompletion inline function setAngleBypass (value:Float ):Float return @:bypassAccessor this.angle = value; + @:noCompletion inline function setVisibleBypass (value:Bool ):Bool return @:bypassAccessor this.visible = value; + @:haxe.warning("-WDeprecated") + @:noCompletion inline function setAntialiasingBypass(value:Bool ):Bool return @:bypassAccessor this.antialiasing = value; + + //{ endregion --- DEPRECATED VIEW FIELDS ------ } diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index 5de84e2857..b4b4b3573f 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -121,7 +121,7 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem final shader = shader != null ? shader : graphics.shader; shader.bitmap.input = graphics.bitmap; - shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST; + shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; shader.alpha.value = alphas; if (colored || hasColorOffsets) diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index bfe3b59184..c98efdf407 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -60,7 +60,7 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem #if !flash var shader = shader != null ? shader : graphics.shader; shader.bitmap.input = graphics.bitmap; - shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST; + shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; shader.bitmap.wrap = REPEAT; // in order to prevent breaking tiling behaviour in classes that use drawTriangles shader.alpha.value = alphas; diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index ddfb41e116..050b855b5b 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -14,6 +14,7 @@ import openfl.display.Graphics; * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects */ @:allow(flixel.FlxCamera) +@:access(flixel.FlxCamera) abstract class FlxCameraView implements IFlxDestroyable { /** @@ -28,29 +29,30 @@ abstract class FlxCameraView implements IFlxDestroyable public var camera(default, null):FlxCamera; /** - * A shortcut for `camera.antialiasing`. Used so implementations can listen to changes. + * Whether the camera display is smooth and filtered, or chunky and pixelated. + * Default behavior is chunky-style. */ - public var antialiasing(get, set):Bool; + public var antialiasing(default, set):Bool; /** * A shortcut for `camera.angle`. Used so implementations can listen to changes. */ - public var angle(get, set):Float; + public var angle(default, set):Float; /** * A shortcut for `camera.alpha`. Used so implementations can listen to changes. */ - public var alpha(get, set):Float; + public var alpha(default, set):Float; /** * A shortcut for `camera.color`. Used so implementations can listen to changes. */ - public var color(get, set):FlxColor; + public var color(default, set):FlxColor; /** * A shortcut for `camera.visible`. Used so implementations can listen to changes. */ - public var visible(get, set):Bool; + public var visible(default, set):Bool; function new(camera:FlxCamera) { @@ -194,55 +196,43 @@ abstract class FlxCameraView implements IFlxDestroyable abstract function get_display():DisplayObjectContainer; - function get_color():FlxColor - { - return camera.color; - } - - function set_color(value:FlxColor):FlxColor - { - return camera.color = value; - } - - function get_antialiasing():Bool - { - return camera.antialiasing; - } - + @:haxe.warning("-WDeprecated") function set_antialiasing(value:Bool):Bool { - return camera.antialiasing = value; + camera.setAntialiasingBypass(value); + return this.antialiasing = value; } - function get_angle():Float + function set_color(value:FlxColor):FlxColor { - return camera.angle; + camera.setColorBypass(value); + return this.color = value; } function set_angle(value:Float):Float { - return camera.angle = value; - } - - function get_visible():Bool - { - return camera.visible; + camera.setAngleBypass(value); + return this.angle = value; } function set_visible(value:Bool):Bool { - return camera.visible = value; - } - - function get_alpha():Float - { - return camera.alpha; + camera.setVisibleBypass(value); + return this.visible = value; } function set_alpha(value:Float):Float { - return camera.alpha = value; + camera.setAlphaBypass(value); + return this.alpha = value; } + // @:bypassAccess doesn't work from external classes in haxe 4. So call this when needed + @:noCompletion inline function setColorBypass (value:FlxColor):FlxColor return @:bypassAccessor this.color = value; + @:noCompletion inline function setAlphaBypass (value:Float ):Float return @:bypassAccessor this.alpha = value; + @:noCompletion inline function setAngleBypass (value:Float ):Float return @:bypassAccessor this.angle = value; + @:noCompletion inline function setAntialiasingBypass(value:Bool ):Bool return @:bypassAccessor this.antialiasing = value; + @:noCompletion inline function setVisibleBypass (value:Bool ):Bool return @:bypassAccessor this.visible = value; + //} endregion --------------------- GETTERS ------------------------ } diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 124996a3c9..03baa94e33 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -95,12 +95,12 @@ class FlxBlitRenderer extends FlxTypedRenderer if (view._useBlitMatrix) { _helperMatrix.concat(view._blitMatrix); - view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || view.antialiasing)); } else { _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - view.buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || camera.antialiasing)); + view.buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || view.antialiasing)); } } @@ -115,7 +115,7 @@ class FlxBlitRenderer extends FlxTypedRenderer _helperMatrix.identity(); _helperMatrix.translate(destPoint.x, destPoint.y); _helperMatrix.concat(view._blitMatrix); - view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || camera.antialiasing)); + view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || view.antialiasing)); } else { diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 68a6b9500d..667332a937 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -378,41 +378,44 @@ class FlxBlitView extends FlxCameraView return flashSprite; } - override function set_color(color:FlxColor):FlxColor + override function set_color(value:FlxColor):FlxColor { if (_flashBitmap != null) { final colorTransform:ColorTransform = _flashBitmap.transform.colorTransform; - colorTransform.redMultiplier = color.redFloat; - colorTransform.greenMultiplier = color.greenFloat; - colorTransform.blueMultiplier = color.blueFloat; + colorTransform.redMultiplier = value.redFloat; + colorTransform.greenMultiplier = value.greenFloat; + colorTransform.blueMultiplier = value.blueFloat; _flashBitmap.transform.colorTransform = colorTransform; } - return color; + return super.set_color(value); } - override function set_antialiasing(antialiasing:Bool):Bool + override function set_antialiasing(value:Bool):Bool { - return _flashBitmap.smoothing = antialiasing; + _flashBitmap.smoothing = value; + return super.set_antialiasing(value); } - override function set_alpha(alpha:Float):Float + override function set_alpha(value:Float):Float { - return _flashBitmap.alpha = alpha; + _flashBitmap.alpha = value; + return super.set_alpha(value); } - override function set_angle(angle:Float):Float + override function set_angle(value:Float):Float { - return flashSprite.rotation = angle; + flashSprite.rotation = value; + return super.set_angle(value); } - override function set_visible(visible:Bool):Bool + override function set_visible(value:Bool):Bool { - flashSprite.visible = visible; - return visible; + flashSprite.visible = value; + return super.set_visible(value); } //} endregion --------------------- GETTERS ------------------------ diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index fe8afb0814..99a3cb9a5f 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -258,33 +258,35 @@ class FlxQuadView extends FlxCameraView } } - override function set_color(color:FlxColor):FlxColor + override function set_color(value:FlxColor):FlxColor { final colorTransform:ColorTransform = canvas.transform.colorTransform; - colorTransform.redMultiplier = color.redFloat; - colorTransform.greenMultiplier = color.greenFloat; - colorTransform.blueMultiplier = color.blueFloat; + colorTransform.redMultiplier = value.redFloat; + colorTransform.greenMultiplier = value.greenFloat; + colorTransform.blueMultiplier = value.blueFloat; canvas.transform.colorTransform = colorTransform; - return color; + return super.set_color(value); } - override function set_alpha(alpha:Float):Float + override function set_alpha(value:Float):Float { - return canvas.alpha = alpha; + canvas.alpha = alpha; + return super.set_alpha(value); } - override function set_angle(angle:Float):Float + override function set_angle(value:Float):Float { - return flashSprite.rotation = angle; + flashSprite.rotation = value; + return super.set_angle(value); } - override function set_visible(visible:Bool):Bool + override function set_visible(value:Bool):Bool { - flashSprite.visible = visible; - return visible; + flashSprite.visible = value; + return super.set_visible(value); } function get_display():DisplayObjectContainer From 3a404cecee9a7cf99e4d921093215c09f5d1623c Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Sun, 8 Mar 2026 11:31:30 -0500 Subject: [PATCH 52/72] add FlxVertexBuffer to wrap Graphics calls --- flixel/FlxCamera.hx | 12 ++- flixel/FlxObject.hx | 25 ++--- flixel/path/FlxBasePath.hx | 39 +++----- .../system/debug/interaction/Interaction.hx | 18 +++- .../system/debug/interaction/tools/Pointer.hx | 5 +- .../debug/interaction/tools/Transform.hx | 20 ++-- flixel/system/render/FlxCameraView.hx | 88 +++++++---------- flixel/system/render/FlxVertexBuffer.hx | 71 ++++++++++++++ flixel/system/render/blit/FlxBlitView.hx | 98 +++++++++---------- flixel/system/render/quad/FlxQuadView.hx | 80 ++++++--------- 10 files changed, 245 insertions(+), 211 deletions(-) create mode 100644 flixel/system/render/FlxVertexBuffer.hx diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 2d07c4216b..2827b059af 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -11,6 +11,7 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; +import flixel.system.render.FlxVertexBuffer; import flixel.system.render.blit.FlxBlitRenderer; import flixel.system.render.blit.FlxBlitView; import flixel.system.render.quad.FlxQuadRenderer; @@ -1786,15 +1787,16 @@ class FlxCamera extends FlxBasic public function fill(color:FlxColor, blendAlpha:Bool = true, fxAlpha:Float = 1.0, ?graphics:Graphics):Void { color.alphaFloat = fxAlpha; - - if (viewQuad != null && graphics != null && graphics != view.getDebugGraphics()) + + final useTargetGraphic = graphics != null #if FLX_DEBUG && graphics != view.getDebugBuffer() #end; + if (useTargetGraphic) { graphics.overrideBlendMode(null); - graphics.beginFill(color.rgb, color.alphaFloat); + final buffer:FlxVertexBuffer = cast graphics; // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading - graphics.drawRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2); - graphics.endFill(); + buffer.drawFilledRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2, color); + return; } view.fill(color, blendAlpha); diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index aadbea3365..03530287e3 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -6,6 +6,7 @@ import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.path.FlxPath; import flixel.system.render.FlxCameraView; +import flixel.system.render.FlxVertexBuffer; import flixel.tile.FlxBaseTilemap; import flixel.util.FlxAxes; import flixel.util.FlxColor; @@ -1321,8 +1322,8 @@ class FlxObject extends FlxBasic if (rect.width > 0 && rect.height > 0) { - final gfx = camera.view.beginDrawDebug(); - drawDebugBoundingBoxTo(camera.view, rect); + camera.view.beginDrawDebug(); + drawDebugBoundingBoxTo(camera.view.getDebugBuffer(), rect); camera.view.endDrawDebug(); } } @@ -1337,9 +1338,9 @@ class FlxObject extends FlxBasic } @:haxe.warning("-WDeprecated") - function drawDebugBoundingBoxTo(view:FlxCameraView, rect:FlxRect) + function drawDebugBoundingBoxTo(buffer:FlxVertexBuffer, rect:FlxRect) { - drawDebugBoundingBox(view.getDebugGraphics(), rect, allowCollisions, immovable); + drawDebugBoundingBox(buffer, rect, allowCollisions, immovable); } function getDebugBoundingBoxColor(allowCollisions:FlxDirectionFlags) @@ -1358,27 +1359,27 @@ class FlxObject extends FlxBasic } // TODO: throw warning on overrides - @:deprecated("beginDrawDebug(gfx) is deprecated, camera.view.drawDebugRect instead") + @:deprecated("beginDrawDebug(gfx) is deprecated, drawDebugBoundingBoxTo instead") function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { - // fill static graphics object with square shape - gfx.lineStyle(1, color, 0.75, false, null, null, MITER, 255); - gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); + final buffer:FlxVertexBuffer = gfx; + buffer.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color, 1); } @:haxe.warning("-WDeprecated") function drawDebugBoundingBoxColorTo(view:FlxCameraView, bounds:FlxRect, color:FlxColor) { - drawDebugBoundingBoxColor(view.getDebugGraphics(), bounds, color); + drawDebugBoundingBoxColor(view.getDebugBuffer(), bounds, color); } - @:deprecated("beginDrawDebug(camera) is deprecated, use camera.view.beginDrawDebug instead") + @:deprecated("beginDrawDebug(camera) is deprecated, use camera.view.beginDrawDebug() instead") inline function beginDrawDebug(camera:FlxCamera):Graphics { - return camera.view.beginDrawDebug(); + camera.view.beginDrawDebug(); + return camera.view.getDebugBuffer(); } - @:deprecated("endDrawDebug(camera) is deprecated, use camera.view.endDrawDebug instead") + @:deprecated("endDrawDebug(camera) is deprecated, use camera.view.endDrawDebug() instead") inline function endDrawDebug(camera:FlxCamera) { camera.view.endDrawDebug(); diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 10ce3e9894..d47856b175 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -5,6 +5,7 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.math.FlxPoint; import flixel.system.render.FlxCameraView; +import flixel.system.render.FlxVertexBuffer; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -321,7 +322,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy public function drawDebugOnCamera(camera:FlxCamera):Void { // Set up our global flash graphics object to draw out the path - final gfx:Graphics = camera.view.beginDrawDebug(); + camera.view.beginDrawDebug(); final length = nodes.length; // Then fill up the object with node and path graphics @@ -347,15 +348,16 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy } } + final buffer = camera.view.getDebugBuffer(); // draw a box for the node - drawNode(camera.view, prevNodeScreen, nodeSize, nodeColor); + drawNode(buffer, prevNodeScreen, nodeSize, nodeColor); if (i + 1 < length || loopType == LOOP) { // draw a line to the next node, if LOOP, get connect the tail and head final nextNode = nodes[(i + 1) % length]; final nextNodeScreen = copyWorldToScreenPos(nextNode, camera); - drawCable(camera.view, prevNodeScreen, nextNodeScreen); + drawLine(buffer, prevNodeScreen, nextNodeScreen); nextNodeScreen.put(); } prevNodeScreen.put(); @@ -385,39 +387,22 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - @:deprecated("drawNode(graphics, ...) is deprecated, use the overloaded drawNode(camera.view, ...) instead") - overload inline extern function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) + inline function drawNode(buffer:FlxVertexBuffer, node:FlxPoint, size:Int, color:FlxColor) { - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.lineStyle(); final offset = Math.floor(size * 0.5); - gfx.drawRect(node.x - offset, node.y - offset, size, size); - gfx.endFill(); - } - - overload inline extern function drawNode(view:FlxCameraView, node:FlxPoint, size:Int, color:FlxColor) - { - final offset = Math.floor(size * 0.5); - view.drawDebugFilledRect(node.x - offset, node.y - offset, size, size, color); + buffer.drawFilledRect(node.x - offset, node.y - offset, size, size, color); } @:deprecated("drawLine is deprecated, use drawCable, instead") - function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) + function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) // TODO: warn on override { - // then draw a line to the next node - final color = debugDrawData.lineColor; - final size = debugDrawData.lineSize; - gfx.lineStyle(size, color.rgb, color.alphaFloat); - - final lineOffset = debugDrawData.lineSize / 2; - gfx.moveTo(node1.x + lineOffset, node1.y + lineOffset); - gfx.lineTo(node2.x + lineOffset, node2.y + lineOffset); + drawLink(gfx, node1, node2); } - @:haxe.warning("-WDeprecated") - function drawCable(view:FlxCameraView, node1:FlxPoint, node2:FlxPoint) + function drawLink(buffer:FlxVertexBuffer, node1:FlxPoint, node2:FlxPoint) { - drawLine(view.getDebugGraphics(), node1, node2); + final lineOffset = debugDrawData.lineSize / 2; + buffer.drawLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, debugDrawData.lineColor); } #end } diff --git a/flixel/system/debug/interaction/Interaction.hx b/flixel/system/debug/interaction/Interaction.hx index 5165165956..a8cebafa13 100644 --- a/flixel/system/debug/interaction/Interaction.hx +++ b/flixel/system/debug/interaction/Interaction.hx @@ -388,7 +388,7 @@ class Interaction extends Window } #if FLX_DEBUG - return FlxG.camera.view.getDebugGraphics(); + return FlxG.camera.view.getDebugBuffer(); #end return null; @@ -396,23 +396,27 @@ class Interaction extends Window function drawItemsSelection():Void { + #if FLX_DEBUG final view = FlxG.camera.view; view.beginDrawDebug(); + final buffer = view.getDebugBuffer(); for (member in selectedItems) { if (member != null && member.scrollFactor != null && member.isOnScreen()) { - final margin = 0.5; final scroll = FlxG.camera.scroll; // Render a white rectangle centered at the selected item final color:FlxColor = FlxColor.fromRGBFloat(1, 1, 1, 0.75); - view.drawDebugRect(member.x - scroll.x - margin, member.y - scroll.y - margin, member.width + margin*2, member.height + margin*2, color); + final MARGIN = 0.5; + final MARGIN_2 = MARGIN * 2; + buffer.drawRect(member.x - scroll.x - MARGIN, member.y - scroll.y - MARGIN, member.width + MARGIN_2, member.height + MARGIN_2, color); } } view.endDrawDebug(); + #end } /** @@ -790,13 +794,21 @@ class Interaction extends Window public function toDebugX(worldX:Float, camera:FlxCamera) { + #if FLX_DEBUG @:privateAccess return camera.view.worldToDebugX(worldX); + #else + return worldX; + #end } public function toDebugY(worldY:Float, camera:FlxCamera) { + #if FLX_DEBUG @:privateAccess return camera.view.worldToDebugY(worldY); + #else + return worldY; + #end } } diff --git a/flixel/system/debug/interaction/tools/Pointer.hx b/flixel/system/debug/interaction/tools/Pointer.hx index 69ae32bd41..d6987cc16c 100644 --- a/flixel/system/debug/interaction/tools/Pointer.hx +++ b/flixel/system/debug/interaction/tools/Pointer.hx @@ -132,10 +132,12 @@ class Pointer extends Tool state = IDLE; } + #if FLX_DEBUG override public function draw():Void { final view = FlxG.camera.view; view.beginDrawDebug(); + final buffer = view.getDebugBuffer(); switch state { @@ -145,12 +147,13 @@ class Pointer extends Tool setAbsRect(rect, startX, startY, _brain.flixelPointer.x, _brain.flixelPointer.y); // Render the selection rectangle final scroll = view.camera.scroll; - view.drawDebugRect(rect.x - scroll.x, rect.y - scroll.y, rect.width, rect.height, 0xFFbb0000, 0.9); + buffer.drawRect(rect.x - scroll.x, rect.y - scroll.y, rect.width, rect.height, 0xFFbb0000, 0.9); rect.put(); } view.endDrawDebug(); } + #end static function setAbsRect(rect:FlxRect, x1:Float, y1:Float, x2:Float, y2:Float) { diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index 171cc5efe6..2e2e1be2df 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -7,6 +7,7 @@ import flixel.math.FlxRect; import flixel.system.debug.Icon; import flixel.system.debug.Tooltip; import flixel.system.debug.interaction.Interaction; +import flixel.system.render.FlxVertexBuffer; import flixel.util.FlxColor; import flixel.util.FlxSpriteUtil; import openfl.display.BitmapData; @@ -218,6 +219,7 @@ class Transform extends Tool } } + #if FLX_DEBUG override function draw():Void { if (!isActive()) @@ -237,19 +239,20 @@ class Transform extends Tool final view = camera.view; view.beginDrawDebug(); - drawSelection(camera); - Marker.draw(target.x + target.origin.x, target.y + target.origin.y, false, camera); + final buffer = view.getDebugBuffer(); + drawSelection(buffer, camera); + Marker.draw(buffer, target.x + target.origin.x, target.y + target.origin.y, false); view.endDrawDebug(); } - function drawSelection(camera:FlxCamera) + function drawSelection(buffer:FlxVertexBuffer, camera:FlxCamera) { // draw lines final scroll = camera.scroll; for (i => marker in markers) { final prev = markers[(i + 3) % 4]; - camera.view.drawDebugLine(prev.x - scroll.x, prev.y - scroll.y, marker.x - scroll.x, marker.y - scroll.y, FlxColor.MAGENTA); + buffer.drawLine(prev.x - scroll.x, prev.y - scroll.y, marker.x - scroll.x, marker.y - scroll.y, FlxColor.MAGENTA); } // draw markers @@ -257,9 +260,10 @@ class Transform extends Tool { final x = marker.x; final y = marker.y; - Marker.draw(x - scroll.x, y - scroll.y, marker.type == ROTATE, camera); + Marker.draw(buffer, x - scroll.x, y - scroll.y, marker.type == ROTATE); } } + #end } private class Marker @@ -296,12 +300,12 @@ private class Marker rot.put(); } - public static function draw(screenX:Float, screenY:Float, circle:Bool, camera:FlxCamera) + public static function draw(buffer:FlxVertexBuffer, screenX:Float, screenY:Float, circle:Bool) { if (circle) - camera.view.drawDebugFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); + buffer.drawFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); else - camera.view.drawDebugFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); + buffer.drawFilledRect(screenX - RECT_MARGIN, screenY - RECT_MARGIN, RECT_SIZE, RECT_SIZE, FlxColor.MAGENTA); } } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 050b855b5b..2eea3dc26e 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -61,6 +61,10 @@ abstract class FlxCameraView implements IFlxDestroyable public function destroy():Void {} + // ============================================================================= + //{ region REDNERING + // ============================================================================= + /** * Flushes any remaining graphics and renders everything to the screen. */ @@ -79,8 +83,13 @@ abstract class FlxCameraView implements IFlxDestroyable */ abstract public function fill(color:FlxColor, blendAlpha:Bool = true):Void; + + // ============================================================================= + //} endregion REDNERING + // ============================================================================= + public function offsetView(x:Float, y:Float):Void {} - + function updateScale():Void {} function updatePosition():Void {} @@ -91,7 +100,9 @@ abstract class FlxCameraView implements IFlxDestroyable function updateScrollRect():Void {} - //{ region ------------------------ DEBUG DRAW ------------------------ + // ============================================================================= + //{ region DEBUG DRAW + // ============================================================================= /** * Begins debug draw on the current (or optionally specified) camera. @@ -99,66 +110,29 @@ abstract class FlxCameraView implements IFlxDestroyable * * @param camera Optional, the camera to draw to. */ - abstract public function beginDrawDebug():Graphics; - - abstract public function getDebugGraphics():Graphics; + abstract public function beginDrawDebug():Void; /** * Cleans up and finalizes the debug draw. */ abstract public function endDrawDebug():Void; - /** - * Draws a rectangle with an outline. - * - * @param x The x position of the rectangle. - * @param y The y position of the rectangle. - * @param width The width of the rectangle (in pixels). - * @param height The height of the rectangle (in pixels). - * @param color The color (in 0xAARRGGBB hex format) of the rectangle's outline. - * @param thickness The thickness of the rectangle's outline. - */ - abstract public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void; + #if FLX_DEBUG - /** - * Draws a filled rectangle. - * - * @param x The x position of the rectangle. - * @param y The y position of the rectangle. - * @param width The width of the rectangle (in pixels). - * @param height The height of the rectangle (in pixels). - * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. - */ - abstract public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void; + abstract public function getDebugBuffer():FlxVertexBuffer; - /** - * Draws a filled circle. - * - * @param x The x position of the circle. - * @param y The y position of the circle. - * @param radius The radius of the circle. - * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. - */ - abstract public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void; - - /** - * Draws a line. - * - * @param x1 The start x position of the line. - * @param y1 The start y position of the line. - * @param x2 The end x position of the line. - * @param y2 The end y position of the line. - * @param color The color (in 0xAARRGGBB hex format) of the line. - * @param thickness The thickness of the line. - */ - abstract public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void; + abstract function worldToDebugX(worldX:Float):Float;//TODO: find out what "debug space" actually is, rename and make public + abstract function worldToDebugY(worldY:Float):Float;//TODO: find out what "debug space" actually is, rename and make public - //} endregion --------------------- DEBUG DRAW ------------------------ + #end - //{ region ------------------------ HELPERS --------------------------- + // ============================================================================= + //} endregion DEBUG DRAW + // ============================================================================= - abstract function worldToDebugX(worldX:Float):Float;//TODO: find out what "debug space" actually is, rename and make public - abstract function worldToDebugY(worldY:Float):Float;//TODO: find out what "debug space" actually is, rename and make public + // ============================================================================= + //{ region HELPERS + // ============================================================================= /** * Helper method preparing debug rectangle for rendering in blit render mode @@ -190,9 +164,13 @@ abstract class FlxCameraView implements IFlxDestroyable return vector; } - //} endregion --------------------- HELPERS ------------------------ + // ============================================================================= + //} endregion HELPERS + // ============================================================================= - //{ region ------------------------ GETTERS ------------------------ + // ============================================================================= + //{ region GETTERS + // ============================================================================= abstract function get_display():DisplayObjectContainer; @@ -234,5 +212,7 @@ abstract class FlxCameraView implements IFlxDestroyable @:noCompletion inline function setAntialiasingBypass(value:Bool ):Bool return @:bypassAccessor this.antialiasing = value; @:noCompletion inline function setVisibleBypass (value:Bool ):Bool return @:bypassAccessor this.visible = value; - //} endregion --------------------- GETTERS ------------------------ + // ============================================================================= + //} endregion GETTERS + // ============================================================================= } diff --git a/flixel/system/render/FlxVertexBuffer.hx b/flixel/system/render/FlxVertexBuffer.hx new file mode 100644 index 0000000000..4d18d2762f --- /dev/null +++ b/flixel/system/render/FlxVertexBuffer.hx @@ -0,0 +1,71 @@ +package flixel.system.render; + +import flixel.util.FlxColor; +import openfl.display.BlendMode; +import openfl.display.Graphics; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; + +/** + * Helper for interfacing with a openfl Graphics, in 7.0.0 this will change from + * an abstract to a class wrapping graphic that implements an interface. All + * references to Graphic need to be removed first + */ +@:forward +abstract FlxVertexBuffer(Graphics) from Graphics to Graphics +{ + /** + * Wipes all drawn vertices from the buffer + */ + public inline function clear():Void + { + this.clear(); + } + + /** + * Draws a hollow axis-aligned rectangle to the buffer + * @param x + * @param y + * @param width + * @param height + * @param color The Color of the outline + * @param thickness The thickness of the outline + */ + public function drawRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + this.drawRect(x, y, width, height); + } + + /** + * Draws a solid axis-aligned rectangle to the buffer + */ + public function drawFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + this.lineStyle(); + this.beginFill(color.rgb, color.alphaFloat); + this.drawRect(x, y, width, height); + this.endFill(); + } + + /** + * Draws an antialiased solid circle to the buffer + */ + public function drawFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + this.beginFill(color.rgb, color.alphaFloat); + this.drawCircle(x, y, radius); + this.endFill(); + } + + /** + * Draws an antialiased line to the buffer + */ + public function drawLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + this.moveTo(x1, y1); + this.lineTo(x2, y2); + } +} \ No newline at end of file diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 667332a937..c85022abe3 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -136,6 +136,10 @@ class FlxBlitView extends FlxCameraView _flashOffset = FlxDestroyUtil.put(_flashOffset); } + // ============================================================================= + //{ region REDNERING + // ============================================================================= + function render():Void { camera.drawFX(); @@ -175,6 +179,14 @@ class FlxBlitView extends FlxCameraView } } + // ============================================================================= + //} endregion REDNERING + // ============================================================================= + + // ============================================================================= + //{ region INTERNALS + // ============================================================================= + override function offsetView(x:Float, y:Float):Void { super.offsetView(x, y); @@ -251,62 +263,55 @@ class FlxBlitView extends FlxCameraView } } - //{ region ------------------------ DEBUG DRAW ------------------------ + // ============================================================================= + //} endregion INTERNALS + // ============================================================================= + + // ============================================================================= + //{ region DEBUG DRAW + // ============================================================================= public function beginDrawDebug() { + #if FLX_DEBUG debugSprite.graphics.clear(); - return debugSprite.graphics; - } - - public function getDebugGraphics() - { - return debugSprite.graphics; + #end } public function endDrawDebug():Void { + #if FLX_DEBUG buffer.draw(debugSprite); + #end } #if FLX_DEBUG - public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = debugSprite.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + public function getDebugBuffer():FlxVertexBuffer { - final gfx = debugSprite.graphics; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); + return debugSprite.graphics; } - public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + static final toDebugHelper = new openfl.geom.Point(); + function worldToDebugX(worldX:Float)//TODO: rename { - final gfx = debugSprite.graphics; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); + toDebugHelper.setTo(worldX, 0); + return _flashBitmap.localToGlobal(toDebugHelper).x; } - public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + function worldToDebugY(worldY:Float)//TODO: rename { - final gfx = debugSprite.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); + toDebugHelper.setTo(0, worldY); + return _flashBitmap.localToGlobal(toDebugHelper).y; } #end - //} endregion --------------------- DEBUG DRAW ------------------------ - - //{ region ------------------------ HELPERS --------------------------- + //} endregion DEBUG DRAW + // ============================================================================= + // ============================================================================= + //{ region HELPERS + // ============================================================================= function checkResize():Void { @@ -369,9 +374,12 @@ class FlxBlitView extends FlxCameraView return vector; } - //} endregion --------------------- HELPERS ------------------------ + //} endregion HELPERS + // ============================================================================= - //{ region ------------------------ GETTERS ------------------------ + // ============================================================================= + //{ region GETTERS + // ============================================================================= function get_display():DisplayObjectContainer { @@ -418,22 +426,6 @@ class FlxBlitView extends FlxCameraView return super.set_visible(value); } - //} endregion --------------------- GETTERS ------------------------ - - //{ region ------------------------ HELPERS ------------------------ - - static final toDebugHelper = new openfl.geom.Point(); - function worldToDebugX(worldX:Float)//TODO: rename - { - toDebugHelper.setTo(worldX, 0); - return _flashBitmap.localToGlobal(toDebugHelper).x; - } - - function worldToDebugY(worldY:Float)//TODO: rename - { - toDebugHelper.setTo(0, worldY); - return _flashBitmap.localToGlobal(toDebugHelper).y; - } - - //} endregion --------------------- HELPERS ------------------------ -} + //} endregion GETTERS + // ============================================================================= +} \ No newline at end of file diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 99a3cb9a5f..ebd0e992c3 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -106,6 +106,10 @@ class FlxQuadView extends FlxCameraView _flashOffset = FlxDestroyUtil.put(_flashOffset); } + // ============================================================================= + //{ region RENDERING + // ============================================================================= + public function render():Void { flashSprite.filters = camera.filtersEnabled ? camera.filters : null; @@ -175,6 +179,14 @@ class FlxQuadView extends FlxCameraView canvas.graphics.endFill(); } + // ============================================================================= + //} endregion RENDERING + // ============================================================================= + + // ============================================================================= + //{ region INTERNALS + // ============================================================================= + override function offsetView(x:Float, y:Float):Void { super.offsetView(x, y); @@ -222,19 +234,6 @@ class FlxQuadView extends FlxCameraView } } - static final toDebugHelper = new openfl.geom.Point(); - function worldToDebugX(worldX:Float)//TODO: rename - { - toDebugHelper.setTo(worldX, 0); - return canvas.localToGlobal(toDebugHelper).x; - } - - function worldToDebugY(worldY:Float)//TODO: rename - { - toDebugHelper.setTo(worldY, 0); - return canvas.localToGlobal(toDebugHelper).y; - } - override function updateInternals():Void { if (canvas != null) @@ -445,53 +444,38 @@ class FlxQuadView extends FlxCameraView return itemToReturn; } - //{ region ------------------------ DEBUG DRAW ------------------------ + //} endregion INTERNALS + // ============================================================================= - public function beginDrawDebug() - { - return debugLayer.graphics; - } + // ============================================================================= + //{ region DEBUG DRAW + // ============================================================================= - public function getDebugGraphics() - { - return debugLayer.graphics; - } + public function beginDrawDebug() {} - public function endDrawDebug():Void {} + public function endDrawDebug() {} #if FLX_DEBUG - public function drawDebugRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - final gfx = debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.drawRect(x, y, width, height); - } - - public function drawDebugFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + + public function getDebugBuffer():FlxVertexBuffer { - final gfx = debugLayer.graphics; - gfx.lineStyle(); - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawRect(x, y, width, height); - gfx.endFill(); + return debugLayer.graphics; } - - public function drawDebugFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + + static final toDebugHelper = new openfl.geom.Point(); + function worldToDebugX(worldX:Float)//TODO: rename? { - final gfx = debugLayer.graphics; - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.drawCircle(x, y, radius); - gfx.endFill(); + toDebugHelper.setTo(worldX, 0); + return canvas.localToGlobal(toDebugHelper).x; } - public function drawDebugLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + function worldToDebugY(worldY:Float)//TODO: rename? { - final gfx = debugLayer.graphics; - gfx.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - gfx.moveTo(x1, y1); - gfx.lineTo(x2, y2); + toDebugHelper.setTo(worldY, 0); + return canvas.localToGlobal(toDebugHelper).y; } #end - //} endregion ------------------------ DEBUG DRAW ------------------------ + //} endregion DEBUG DRAW + // ============================================================================= } From b2d07777c9d921bee8f22bcbb9429b495d7f6b6c Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Sun, 8 Mar 2026 11:41:29 -0500 Subject: [PATCH 53/72] tiny fixes --- flixel/FlxG.hx | 2 +- flixel/system/debug/log/BitmapLog.hx | 1 + tests/coverage/Project.xml | 6 +++--- tests/unit/project.xml | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 2ec3b3dcbd..b7a8270a7a 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -158,7 +158,7 @@ class FlxG return renderer.blit; } - @:deprecated("renderTile is deprecated, compare against FlxG.renderer.method, instead.") + @:deprecated("renderTile is deprecated, compare against FlxG.renderer.tile, instead.") public static var renderTile(get, never):Bool; @:noCompletion static inline function get_renderTile():Bool { diff --git a/flixel/system/debug/log/BitmapLog.hx b/flixel/system/debug/log/BitmapLog.hx index 6ebbb496eb..bd6b48dc6a 100644 --- a/flixel/system/debug/log/BitmapLog.hx +++ b/flixel/system/debug/log/BitmapLog.hx @@ -248,6 +248,7 @@ class BitmapLog extends Window public function clear():Void { entries.resize(0); + index = -1; drawCanvas(); } diff --git a/tests/coverage/Project.xml b/tests/coverage/Project.xml index 089e8ad176..49d23baa7b 100644 --- a/tests/coverage/Project.xml +++ b/tests/coverage/Project.xml @@ -1,6 +1,6 @@ - + @@ -34,7 +34,7 @@ - +
diff --git a/tests/unit/project.xml b/tests/unit/project.xml index 412ea43a19..70a754e2ed 100644 --- a/tests/unit/project.xml +++ b/tests/unit/project.xml @@ -1,6 +1,6 @@ - + From 7b0e0493cc7eef012ba30da298d41875f9ac85cf Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Sun, 8 Mar 2026 11:42:55 -0500 Subject: [PATCH 54/72] add accidentally removed method --- flixel/FlxCamera.hx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 2827b059af..12aa9c8aee 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1754,6 +1754,22 @@ class FlxCamera extends FlxBasic //{ region ------ DEPRECATED VIEW FIELDS ------ + @:noCompletion + @:deprecated("camera.transformObject is deprecated, there will be no replacement") + function transformObject(object:DisplayObject):DisplayObject + { + object.scaleX *= totalScaleX; + object.scaleY *= totalScaleY; + + object.x -= scroll.x * totalScaleX; + object.y -= scroll.y * totalScaleY; + + object.x -= 0.5 * width * (scaleX - initialZoom) * FlxG.scaleMode.scale.x; + object.y -= 0.5 * height * (scaleY - initialZoom) * FlxG.scaleMode.scale.y; + + return object; + } + @:noCompletion @:deprecated("camera.startQuadBatch() is deprecated, use view.startQuadBatch() instead.") // 6.2.0 public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) From 8f7cc5ea98df2f1566bab911d8105c24182cf226 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 11:18:35 -0500 Subject: [PATCH 55/72] remove missed ref to view.display --- flixel/FlxCamera.hx | 2 +- flixel/system/scaleModes/StageSizeScaleMode.hx | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 12aa9c8aee..674d07b3ee 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -520,7 +520,7 @@ class FlxCamera extends FlxBasic { viewBlit = Std.downcast(view, FlxBlitView); @:bypassAccessor _flashPoint = viewBlit._flashPoint; - @:bypassAccessor flashSprite = viewQuad.flashSprite; + @:bypassAccessor flashSprite = viewBlit.flashSprite; @:bypassAccessor _flashOffset = viewBlit._flashOffset; @:bypassAccessor _scrollRect = viewBlit._scrollRect; @:bypassAccessor _flashRect = viewBlit._flashRect; diff --git a/flixel/system/scaleModes/StageSizeScaleMode.hx b/flixel/system/scaleModes/StageSizeScaleMode.hx index 15c041ff63..97c79910d9 100644 --- a/flixel/system/scaleModes/StageSizeScaleMode.hx +++ b/flixel/system/scaleModes/StageSizeScaleMode.hx @@ -25,15 +25,15 @@ class StageSizeScaleMode extends BaseScaleMode if (FlxG.camera != null) { - var oldW = FlxG.camera.width; - var oldH = FlxG.camera.height; + final camera = FlxG.camera; + final oldW = camera.width; + final oldH = camera.height; - var newW = Math.ceil(Width / FlxG.camera.zoom); - var newH = Math.ceil(Height / FlxG.camera.zoom); + final newW = Math.ceil(Width / camera.zoom); + final newH = Math.ceil(Height / camera.zoom); - FlxG.camera.setSize(newW, newH); - FlxG.camera.display.x += (newW - oldW) / 2; - FlxG.camera.display.y += (newH - oldH) / 2; + camera.setPosition(0, 0); + camera.setSize(newW, newH); } } } From 6fc5b80c0048f484e30c141d402aa7bd2d97693f Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 12:28:55 -0500 Subject: [PATCH 56/72] Use abstracts unless there are default values --- flixel/FlxCamera.hx | 6 +++- flixel/system/render/FlxCameraView.hx | 34 ++++++++++++------ flixel/system/render/blit/FlxBlitView.hx | 46 +++++++++++------------- flixel/system/render/quad/FlxQuadView.hx | 40 ++++++++++----------- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 674d07b3ee..acb3a26649 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1901,12 +1901,14 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("flashSprite is deprecated, use camera.display, instead") // 6.2.0 + @:deprecated("flashSprite is deprecated, use camera.viewBlit.flashSprite or camera.viewQuad.flashSprite, instead") // 6.2.0 @:isVar public var flashSprite(get, set):Sprite; function get_flashSprite() { if (viewBlit != null) this.flashSprite = viewBlit.flashSprite; + else if (viewQuad != null) + this.flashSprite = viewQuad.flashSprite; return this.flashSprite; } @@ -1914,6 +1916,8 @@ class FlxCamera extends FlxBasic { return if (viewBlit != null) this.flashSprite = viewBlit.flashSprite = value; + else if (viewQuad != null) + this.flashSprite = viewQuad.flashSprite = value; else this.flashSprite = value; } diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 2eea3dc26e..16792f1f8c 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -62,18 +62,26 @@ abstract class FlxCameraView implements IFlxDestroyable public function destroy():Void {} // ============================================================================= - //{ region REDNERING + //{ region RENDERING // ============================================================================= /** * Flushes any remaining graphics and renders everything to the screen. */ - abstract public function render():Void; + public function render() + { + throw "Not implemented"; + // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } /** * Called before a new rendering frame, clears all previously drawn graphics. */ - abstract public function clear():Void; + public function clear() + { + throw "Not implemented"; + // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } /** * Fills the current render target with `color`. @@ -81,24 +89,28 @@ abstract class FlxCameraView implements IFlxDestroyable * @param color The color (in 0xAARRGGBB format) to fill the screen with. * @param blendAlpha Whether to blend the alpha value or just wipe the previous contents. */ - abstract public function fill(color:FlxColor, blendAlpha:Bool = true):Void; + public function fill(color:FlxColor, blendAlpha:Bool = true) + { + throw "Not implemented"; + // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } // ============================================================================= - //} endregion REDNERING + //} endregion RENDERING // ============================================================================= - public function offsetView(x:Float, y:Float):Void {} + abstract public function offsetView(x:Float, y:Float):Void; - function updateScale():Void {} + abstract function updateScale():Void; - function updatePosition():Void {} + abstract function updatePosition():Void; - function updateInternals():Void {} + abstract function updateInternals():Void; - function updateOffset():Void {} + abstract function updateOffset():Void; - function updateScrollRect():Void {} + abstract function updateScrollRect():Void; // ============================================================================= //{ region DEBUG DRAW diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index c85022abe3..66230b3109 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -137,11 +137,13 @@ class FlxBlitView extends FlxCameraView } // ============================================================================= - //{ region REDNERING + //{ region RENDERING // ============================================================================= - function render():Void + override function render() { + // super.render(); + camera.drawFX(); if (FlxBlitRenderer.useBufferLocking) @@ -152,8 +154,10 @@ class FlxBlitView extends FlxCameraView screen.dirty = true; } - public function clear():Void + override function clear() { + // super.clear(); + checkResize(); if (FlxBlitRenderer.useBufferLocking) @@ -166,8 +170,10 @@ class FlxBlitView extends FlxCameraView } @:haxe.warning("-WDeprecated") - public function fill(color:FlxColor, blendAlpha:Bool = true) + override function fill(color:FlxColor, blendAlpha:Bool = true) { + // super.fill(color, blendAlpha); + if (blendAlpha) { _fill.fillRect(_flashRect, color); @@ -180,25 +186,21 @@ class FlxBlitView extends FlxCameraView } // ============================================================================= - //} endregion REDNERING + //} endregion RENDERING // ============================================================================= // ============================================================================= //{ region INTERNALS // ============================================================================= - override function offsetView(x:Float, y:Float):Void + function offsetView(x:Float, y:Float) { - super.offsetView(x, y); - flashSprite.x += x; flashSprite.y += y; } - override function updatePosition():Void + function updatePosition() { - super.updatePosition(); - if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; @@ -206,18 +208,14 @@ class FlxBlitView extends FlxCameraView } } - override function updateOffset() + function updateOffset() { - super.updateOffset(); - _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; } - override function updateScrollRect():Void + function updateScrollRect() { - super.updateScrollRect(); - final rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; if (rect != null) @@ -234,7 +232,7 @@ class FlxBlitView extends FlxCameraView } } - override function updateScale():Void + function updateScale() { updateBlitMatrix(); @@ -248,14 +246,10 @@ class FlxBlitView extends FlxCameraView _flashBitmap.scaleX = camera.totalScaleX; _flashBitmap.scaleY = camera.totalScaleY; } - - super.updateScale(); } - override function updateInternals():Void + function updateInternals() { - super.updateInternals(); - if (_flashBitmap != null) { _flashBitmap.x = 0; @@ -271,14 +265,14 @@ class FlxBlitView extends FlxCameraView //{ region DEBUG DRAW // ============================================================================= - public function beginDrawDebug() + function beginDrawDebug() { #if FLX_DEBUG debugSprite.graphics.clear(); #end } - public function endDrawDebug():Void + function endDrawDebug():Void { #if FLX_DEBUG buffer.draw(debugSprite); @@ -287,7 +281,7 @@ class FlxBlitView extends FlxCameraView #if FLX_DEBUG - public function getDebugBuffer():FlxVertexBuffer + function getDebugBuffer():FlxVertexBuffer { return debugSprite.graphics; } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index ebd0e992c3..859365dfb2 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -110,8 +110,10 @@ class FlxQuadView extends FlxCameraView //{ region RENDERING // ============================================================================= - public function render():Void + override function render() { + // super.render(); + flashSprite.filters = camera.filtersEnabled ? camera.filters : null; var currItem:FlxDrawBaseItem = _headOfDrawStack; @@ -124,8 +126,10 @@ class FlxQuadView extends FlxCameraView camera.drawFX(); } - public function clear():Void + override function clear() { + // super.clear(); + clearDrawStack(); canvas.graphics.clear(); @@ -169,8 +173,10 @@ class FlxQuadView extends FlxCameraView _headTriangles = null; } - public function fill(color:FlxColor, blendAlpha:Bool = true):Void + override function fill(color:FlxColor, blendAlpha:Bool = true) { + // super.fill(color, blendAlpha); + canvas.graphics.overrideBlendMode(null); canvas.graphics.beginFill(color.rgb, color.alphaFloat); // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, @@ -187,18 +193,14 @@ class FlxQuadView extends FlxCameraView //{ region INTERNALS // ============================================================================= - override function offsetView(x:Float, y:Float):Void + function offsetView(x:Float, y:Float) { - super.offsetView(x, y); - flashSprite.x += x; flashSprite.y += y; } - override function updatePosition():Void + function updatePosition() { - super.updatePosition(); - if (flashSprite != null) { flashSprite.x = camera.x * FlxG.scaleMode.scale.x + _flashOffset.x; @@ -206,18 +208,14 @@ class FlxQuadView extends FlxCameraView } } - override function updateOffset() + function updateOffset() { - super.updateOffset(); - _flashOffset.x = camera.width * 0.5 * FlxG.scaleMode.scale.x * camera.initialZoom; _flashOffset.y = camera.height * 0.5 * FlxG.scaleMode.scale.y * camera.initialZoom; } - override function updateScrollRect():Void + function updateScrollRect() { - super.updateScrollRect(); - final rect:Rectangle = (_scrollRect != null) ? _scrollRect.scrollRect : null; if (rect != null) @@ -234,7 +232,9 @@ class FlxQuadView extends FlxCameraView } } - override function updateInternals():Void + function updateScale() {} + + function updateInternals() { if (canvas != null) { @@ -323,7 +323,7 @@ class FlxQuadView extends FlxCameraView */ static var _storageTrianglesHead:FlxDrawTrianglesItem; - public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) + public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets = false, ?blend:BlendMode, smooth = false, ?shader:FlxShader) { #if FLX_RENDER_TRIANGLE return startTrianglesBatch(graphic, smooth, colored, blend); @@ -384,7 +384,7 @@ class FlxQuadView extends FlxCameraView #end } - public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + public function startTrianglesBatch(graphic:FlxGraphic, smoothing = false, isColored = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { if (_currentDrawItem != null @@ -402,7 +402,7 @@ class FlxQuadView extends FlxCameraView return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } - public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, + public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing = false, isColored = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { var itemToReturn:FlxDrawTrianglesItem = null; @@ -468,7 +468,7 @@ class FlxQuadView extends FlxCameraView toDebugHelper.setTo(worldX, 0); return canvas.localToGlobal(toDebugHelper).x; } - + function worldToDebugY(worldY:Float)//TODO: rename? { toDebugHelper.setTo(worldY, 0); From 2e8dbbb74755b4315d6f481f4f272f4cc610bdf5 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 12:32:07 -0500 Subject: [PATCH 57/72] move rendering methods to view --- flixel/FlxCamera.hx | 139 ++++------------ flixel/FlxSprite.hx | 4 +- flixel/FlxStrip.hx | 2 +- flixel/system/FlxBGSprite.hx | 2 +- flixel/system/render/FlxCameraView.hx | 77 ++++++++- flixel/system/render/FlxRenderer.hx | 58 +------ flixel/system/render/blit/FlxBlitRenderer.hx | 157 ------------------- flixel/system/render/blit/FlxBlitView.hx | 135 ++++++++++++++++ flixel/system/render/quad/FlxQuadRenderer.hx | 74 --------- flixel/system/render/quad/FlxQuadView.hx | 56 +++++++ flixel/text/FlxBitmapText.hx | 2 +- flixel/tile/FlxTilemapBuffer.hx | 4 +- flixel/ui/FlxBar.hx | 2 +- 13 files changed, 301 insertions(+), 411 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index acb3a26649..2481890e3c 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -511,10 +511,6 @@ class FlxCamera extends FlxBasic @:bypassAccessor debugLayer = viewQuad.canvas; #end - final renderQuad = cast(FlxG.renderer, FlxQuadRenderer); - @:privateAccess @:bypassAccessor _bounds = renderQuad._bounds; - @:privateAccess @:bypassAccessor _helperMatrix = renderQuad._helperMatrix; - @:bypassAccessor _helperPoint = new Point(); } else if (view is FlxBlitView) { @@ -530,11 +526,6 @@ class FlxCamera extends FlxBasic @:bypassAccessor _flashBitmap = viewBlit._flashBitmap; @:bypassAccessor _blitMatrix = viewBlit._blitMatrix; @:bypassAccessor _fill = viewBlit._fill; - - final renderBlit = cast(FlxG.renderer, FlxBlitRenderer); - @:privateAccess @:bypassAccessor _bounds = renderBlit._bounds; - @:privateAccess @:bypassAccessor _helperMatrix = renderBlit._helperMatrix; - @:privateAccess @:bypassAccessor _helperPoint = renderBlit._helperPoint; } pixelPerfectRender = FlxG.renderer.blit; @@ -586,14 +577,17 @@ class FlxCamera extends FlxBasic @:bypassAccessor _flashBitmap = null; @:bypassAccessor _scrollRect = null; @:bypassAccessor canvas = null; - @:bypassAccessor debugLayer = null; @:bypassAccessor _currentDrawItem = null; @:bypassAccessor _headOfDrawStack = null; @:bypassAccessor _headTiles = null; @:bypassAccessor _headTriangles = null; - @:bypassAccessor _bounds = null; - @:bypassAccessor _helperMatrix = null; - @:bypassAccessor _helperPoint = null; + @:bypassAccessor _bounds = FlxDestroyUtil.put(_bounds); + #if FLX_DEBUG + @:bypassAccessor debugLayer = null; + #end + + _helperMatrix = null; + _helperPoint = null; super.destroy(); } @@ -1830,23 +1824,23 @@ class FlxCamera extends FlxBasic public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - FlxG.renderer.drawPixels(view, frame, pixels, matrix, transform, blend, smoothing, shader); + view.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); } @:noCompletion - @:deprecated("camera.copyPixels() is deprecated, use FlxG.renderer.copyPixels() instead.") // 6.2.0 + @:deprecated("camera.copyPixels() is deprecated, use camera.view.copyPixels instead.") // 6.2.0 public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - FlxG.renderer.copyPixels(view, frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + view.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); } @:noCompletion - @:deprecated("camera.drawTriangles() is deprecated, use FlxG.renderer.drawTriangles() instead.") // 6.2.0 + @:deprecated("camera.drawTriangles() is deprecated, use camera.view.drawTriangles instead.") // 6.2.0 public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void { - FlxG.renderer.drawTriangles(view, graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + view.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); } @:noCompletion @@ -2053,7 +2047,7 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("_scrollRect is deprecated, use camera.viewQuad._scrollRect/camera.viewBlit._scrollRect, instead") // 6.2.0 + @:deprecated("_scrollRect is deprecated, use camera.viewQuad._scrollRect or camera.viewBlit._scrollRect, instead") // 6.2.0 @:isVar var _scrollRect(get, set):Sprite; function get__scrollRect():Sprite { @@ -2075,33 +2069,8 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("_bounds is deprecated, use FlxBlitRenderer/FlxQuadRender._bounds, instead") // 6.2.0 - @:isVar var _bounds(get, set):FlxRect; - function get__bounds():FlxRect - { - switch FlxG.renderer.method - { - case BLITTING: - this._bounds = cast(FlxG.renderer, FlxBlitRenderer)._bounds; - case DRAW_TILES: - this._bounds = cast(FlxG.renderer, FlxQuadRenderer)._bounds; - default: - } - - return this._bounds; - } - function set__bounds(value:FlxRect):FlxRect - { - return this._bounds = switch FlxG.renderer.method - { - case BLITTING: - cast(FlxG.renderer, FlxBlitRenderer)._bounds = value; - case DRAW_TILES: - cast(FlxG.renderer, FlxQuadRenderer)._bounds = value; - default: - value; - } - } + @:deprecated("_bounds is deprecated, there will be no replacement") // 6.2.0 + var _bounds = new FlxRect(); @:noCompletion @:deprecated("canvas is deprecated, use camera.viewQuad.canvas, instead") // 6.2.0 @@ -2142,58 +2111,12 @@ class FlxCamera extends FlxBasic #end @:noCompletion - @:deprecated("_helperMatrix is deprecated, use FlxBlitRenderer/FlxQuadRenderer._helperMatrix, instead") // 6.2.0 - @:isVar var _helperMatrix(get, set):FlxMatrix; - function get__helperMatrix() - { - switch FlxG.renderer.method - { - case BLITTING: - this._helperMatrix = cast(FlxG.renderer, FlxBlitRenderer)._helperMatrix; - case DRAW_TILES: - this._helperMatrix = cast(FlxG.renderer, FlxQuadRenderer)._helperMatrix; - default: - } - - return this._helperMatrix; - } - function set__helperMatrix(value:FlxMatrix):FlxMatrix - { - return this._helperMatrix = switch FlxG.renderer.method - { - case BLITTING: - cast(FlxG.renderer, FlxBlitRenderer)._helperMatrix = value; - case DRAW_TILES: - cast(FlxG.renderer, FlxQuadRenderer)._helperMatrix = value; - default: - value; - } - } + @:deprecated("_helperMatrix is deprecated, there will be no replacement") // 6.2.0 + var _helperMatrix = new FlxMatrix(); @:noCompletion - @:deprecated("_helperPoint is deprecated, use FlxBlitRenderer._helperPoint, instead") // 6.2.0 - @:isVar var _helperPoint(get, set):Point; - function get__helperPoint() - { - switch FlxG.renderer.method - { - case BLITTING: - this._helperPoint = cast(FlxG.renderer, FlxBlitRenderer)._helperPoint; - default: - } - - return this._helperPoint; - } - function set__helperPoint(value:Point):Point - { - return switch FlxG.renderer.method - { - case BLITTING: - this._helperPoint = cast(FlxG.renderer, FlxBlitRenderer)._helperPoint = value; - default: - this._helperPoint = value; - } - } + @:deprecated("_helperPoint is deprecated, there will be no replacement") // 6.2.0 + var _helperPoint = new Point(); @:noCompletion @:deprecated("_currentDrawItem is deprecated, use camera.viewQuad._currentDrawItem, instead") // 6.2.0 @@ -2280,28 +2203,20 @@ class FlxCamera extends FlxBasic static inline function set__storageTrianglesHead(value:FlxDrawTrianglesItem):FlxDrawTrianglesItem return FlxQuadView._storageTrianglesHead = value; @:noCompletion - @:deprecated("drawVertices is deprecated, use FlxBlitRenderer.drawVertices, instead") // 6.2.0 - static var drawVertices(get, set):Vector; - static inline function get_drawVertices():Vector return FlxBlitRenderer.drawVertices; - static inline function set_drawVertices(value:Vector):Vector return FlxBlitRenderer.drawVertices = value; + @:deprecated("drawVertices is deprecated, there will be no replacement") // 6.2.0 + static var drawVertices = new Vector(); @:noCompletion - @:deprecated("trianglesSprite is deprecated, use FlxBlitRenderer.trianglesSprite, instead") // 6.2.0 - static var trianglesSprite(get, set):Sprite; - static inline function get_trianglesSprite():Sprite return FlxBlitRenderer.trianglesSprite; - static inline function set_trianglesSprite(value:Sprite):Sprite return FlxBlitRenderer.trianglesSprite = value; + @:deprecated("trianglesSprite is deprecated, there will be no replacement") // 6.2.0 + static var trianglesSprite = new Sprite(); @:noCompletion - @:deprecated("renderPoint is deprecated, use FlxBlitRenderer.renderPoint, instead") // 6.2.0 - static var renderPoint(get, set):FlxPoint; - static inline function get_renderPoint():FlxPoint return FlxBlitRenderer.renderPoint; - static inline function set_renderPoint(value:FlxPoint):FlxPoint return FlxBlitRenderer.renderPoint = value; + @:deprecated("renderPoint is deprecated, there will be no replacement") // 6.2.0 + static var renderPoint = new FlxPoint(); @:noCompletion - @:deprecated("renderRect is deprecated, use FlxBlitRenderer.renderRect, instead") // 6.2.0 - static var renderRect(get, set):FlxRect; - static inline function get_renderRect():FlxRect return FlxBlitRenderer.renderRect; - static inline function set_renderRect(value:FlxRect):FlxRect return FlxBlitRenderer.renderRect = value; + @:deprecated("renderRect is deprecated, there will be no replacement") // 6.2.0 + static var renderRect = new FlxRect(); // @:bypassAccess doesn't work from external classes in haxe 4. So call this when needed @:noCompletion inline function setColorBypass (value:FlxColor):FlxColor return @:bypassAccessor this.color = value; diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 7a1581f3df..3f8b2e6178 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -1009,7 +1009,7 @@ class FlxSprite extends FlxObject _point.floor(); _point.copyTo(_flashPoint); - FlxG.renderer.copyPixels(camera.view, _frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); + camera.view.copyPixels(_frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); } @:noCompletion @@ -1025,7 +1025,7 @@ class FlxSprite extends FlxObject final matrix = drawComplexMatrix; // TODO: Just use local? prepareComplexMatrix(matrix, frame, camera); - FlxG.renderer.drawPixels(camera.view, frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); + camera.view.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); } function prepareComplexMatrix(matrix:FlxMatrix, frame:FlxFrame, camera:FlxCamera) diff --git a/flixel/FlxStrip.hx b/flixel/FlxStrip.hx index 04e4d2644f..9f34e21b50 100644 --- a/flixel/FlxStrip.hx +++ b/flixel/FlxStrip.hx @@ -58,7 +58,7 @@ class FlxStrip extends FlxSprite getScreenPosition(_point, camera); _point -= offset; - FlxG.renderer.drawTriangles(camera.view, graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); + camera.view.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader); } } } diff --git a/flixel/system/FlxBGSprite.hx b/flixel/system/FlxBGSprite.hx index dfb81e19f2..29b3edcc38 100644 --- a/flixel/system/FlxBGSprite.hx +++ b/flixel/system/FlxBGSprite.hx @@ -32,7 +32,7 @@ class FlxBGSprite extends FlxSprite _matrix.scale(camera.viewWidth + 1, camera.viewHeight + 1); _matrix.translate(camera.viewMarginLeft, camera.viewMarginTop); - FlxG.renderer.drawPixels(camera.view, frame, _matrix, colorTransform); + camera.view.drawPixels(frame, _matrix, colorTransform); #if FLX_DEBUG FlxBasic.visibleCount++; diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 16792f1f8c..47ce038232 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -2,13 +2,23 @@ package flixel.system.render; import flixel.FlxCamera; import flixel.FlxG; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; +import flixel.system.FlxAssets; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import openfl.display.BitmapData; +import openfl.display.BlendMode; import openfl.display.DisplayObject; import openfl.display.DisplayObjectContainer; import openfl.display.Graphics; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; /** * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects @@ -71,7 +81,7 @@ abstract class FlxCameraView implements IFlxDestroyable public function render() { throw "Not implemented"; - // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 } /** @@ -80,7 +90,7 @@ abstract class FlxCameraView implements IFlxDestroyable public function clear() { throw "Not implemented"; - // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 } /** @@ -92,9 +102,70 @@ abstract class FlxCameraView implements IFlxDestroyable public function fill(color:FlxColor, blendAlpha:Bool = true) { throw "Not implemented"; - // Note: abstracts mehtods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 } + /** + * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param matrix The transformation matrix to use. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, + ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + { + throw "Not implemented"; + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } + + /** + * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * + * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations + * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. + * + * @param frame The frame to draw (used only with the DRAW_TILES renderer). + * @param pixels The pixels to draw (used only with the BLITTING renderer). + * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). + * @param destPoint A point representing the top-left position to draw to. + * @param transform The color transform to use, optional. + * @param blend The blend mode to use, optional. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ + public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) + { + throw "Not implemented"; + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } + + /** + * Draws a set of triangles onto the current render target. + * + * @param graphic The graphic to use for the triangles. + * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. + * @param indices A vector where each element is an index to a vertex (x, y) pair. 3 indices make up a triangle. + * @param uvtData A vector where each element is a normalized coordinate (from 0.0 to 1.0), per vertex, used to apply texture mapping. + * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. + * @param position A point representing the top-left position to draw to. + * @param blend The blend mode to use, optional. + * @param repeat Whether the graphic should repeat. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param transform The color transform to use, optional. + * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + */ + public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) + { + throw "Not implemented"; + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } // ============================================================================= //} endregion RENDERING diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index 863c73669b..bb24a2bbd1 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -2,12 +2,10 @@ package flixel.system.render; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; -import flixel.system.FlxAssets.FlxShader; import flixel.util.FlxColor; -import flixel.util.FlxDestroyUtil.IFlxDestroyable; +import flixel.util.FlxDestroyUtil; import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.geom.ColorTransform; @@ -110,61 +108,7 @@ abstract class FlxTypedRenderer implements IFlxDestroyable public function destroy():Void {} - //{ region ------------------------ RENDERING ------------------------ - abstract function createCameraView(camera:FlxCamera):TView; - - /** - * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. - * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param matrix The transformation matrix to use. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). - */ - abstract public function drawPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, - ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader):Void; - - /** - * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. - * - * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations - * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. - * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). - * @param destPoint A point representing the top-left position to draw to. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). - */ - abstract public function copyPixels(view:TView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader):Void; - - /** - * Draws a set of triangles onto the current render target. - * - * @param graphic The graphic to use for the triangles. - * @param vertices A vector where each element is a coordinate location. 2 elements make up an (x, y) pair. - * @param indices A vector where each element is an index to a vertex (x, y) pair. 3 indices make up a triangle. - * @param uvtData A vector where each element is a normalized coordinate (from 0.0 to 1.0), per vertex, used to apply texture mapping. - * @param colors A vector containing the colors to use per vertex. Currently does not work with any renderer. - * @param position A point representing the top-left position to draw to. - * @param blend The blend mode to use, optional. - * @param repeat Whether the graphic should repeat. - * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param transform The color transform to use, optional. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). - */ - abstract public function drawTriangles(view:TView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void; - - //} endregion ------------------------ RENDERING ------------------------ } /** diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index 03baa94e33..ef7326ae8f 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -34,32 +34,6 @@ class FlxBlitRenderer extends FlxTypedRenderer */ public static var useBufferLocking:Bool = false; - /** - * Internal variable, used in blit render mode to render triangles (`drawTriangles()`) on camera's buffer. - */ - static var trianglesSprite:Sprite = new Sprite(); - - /** - * Internal variables, used in blit render mode to draw trianglesSprite on camera's buffer. - * Added for less garbage creation. - */ - static var renderPoint:FlxPoint = FlxPoint.get(); - - static var renderRect:FlxRect = FlxRect.get(); - - /** - * Internal variable, used for visibility checks to minimize `drawTriangles()` calls. - */ - static var drawVertices:Vector = new Vector(); - - /** - * Helper rect for `drawTriangles()` visibility checks - */ - var _bounds:FlxRect = FlxRect.get(); - - var _helperMatrix:FlxMatrix = new FlxMatrix(); - var _helperPoint:Point = new Point(); - public function new() { super(); @@ -73,139 +47,8 @@ class FlxBlitRenderer extends FlxTypedRenderer FlxObject.defaultPixelPerfectPosition = true; } - override function destroy():Void - { - super.destroy(); - _bounds = FlxDestroyUtil.put(_bounds); - _helperMatrix = null; - _helperPoint = null; - } - public function createCameraView(camera:FlxCamera) { return new FlxBlitView(camera); } - - public function drawPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader):Void - { - _helperMatrix.copyFrom(matrix); - - final camera = view.camera; - if (view._useBlitMatrix) - { - _helperMatrix.concat(view._blitMatrix); - view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || view.antialiasing)); - } - else - { - _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - view.buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || view.antialiasing)); - } - } - - public function copyPixels(view:FlxBlitView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader) - { - final camera = view.camera; - if (pixels != null) - { - if (view._useBlitMatrix) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(view._blitMatrix); - view.buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || view.antialiasing)); - } - else - { - _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); - view.buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); - } - } - else if (frame != null) - { - // TODO: fix this case for zoom less than initial zoom... - frame.paint(view.buffer, destPoint, true); - } - } - - public function drawTriangles(view:FlxBlitView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) - { - final camera = view.camera; - final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); - - if (position == null) - position = renderPoint.set(); - - var verticesLength:Int = vertices.length; - var currentVertexPosition:Int = 0; - - var tempX:Float, tempY:Float; - var i:Int = 0; - var bounds = renderRect.set(); - drawVertices.splice(0, drawVertices.length); - - while (i < verticesLength) - { - tempX = position.x + vertices[i]; - tempY = position.y + vertices[i + 1]; - - drawVertices[currentVertexPosition++] = tempX; - drawVertices[currentVertexPosition++] = tempY; - - if (i == 0) - { - bounds.set(tempX, tempY, 0, 0); - } - else - { - FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); - } - - i += 2; - } - - position.putWeak(); - - if (!cameraBounds.overlaps(bounds)) - { - drawVertices.splice(drawVertices.length - verticesLength, verticesLength); - } - else - { - trianglesSprite.graphics.clear(); - trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); - trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); - trianglesSprite.graphics.endFill(); - - // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... - if (view._useBlitMatrix) - _helperMatrix.copyFrom(view._blitMatrix); - else - { - _helperMatrix.identity(); - _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); - } - - view.buffer.draw(trianglesSprite, _helperMatrix, transform); - - #if FLX_DEBUG - if (FlxG.debugger.drawDebug) - { - // TODO: add a drawDebugTriangles method - var gfx:Graphics = FlxSpriteUtil.flashGfx; - gfx.clear(); - gfx.lineStyle(1, FlxColor.BLUE, 0.5); - gfx.drawTriangles(drawVertices, indices); - view.buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); - } - #end - // End of TODO... - } - - bounds.put(); - } } diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 66230b3109..f8d34d2afc 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -3,14 +3,19 @@ package flixel.system.render.blit; import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.graphics.tile.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; +import flixel.system.FlxAssets; import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import flixel.util.FlxSpriteUtil; import openfl.display.Bitmap; import openfl.display.BitmapData; +import openfl.display.BlendMode; import openfl.display.DisplayObjectContainer; import openfl.display.Graphics; import openfl.display.Sprite; @@ -185,6 +190,136 @@ class FlxBlitView extends FlxCameraView } } + @:noCompletion + static final _helperMatrix = new FlxMatrix(); + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, + ?shader:FlxShader) + { + // super.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + + _helperMatrix.copyFrom(matrix); + + if (_useBlitMatrix) + { + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); + buffer.draw(pixels, _helperMatrix, null, blend, null, (smoothing || antialiasing)); + } + } + + @:noCompletion + static final _helperPoint:Point = new Point(); + override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + smoothing:Bool = false, ?shader:FlxShader) + { + // super.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + + if (pixels != null) + { + if (_useBlitMatrix) + { + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x, destPoint.y); + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); + } + else + { + _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); + buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); + } + } + else if (frame != null) + { + // TODO: fix this case for zoom less than initial zoom... + frame.paint(buffer, destPoint, true); + } + } + + @:noCompletion + static final _trianglesSprite = new Sprite(); + + @:noCompletion + static final drawVertices = new DrawData(); + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position, ?blend, repeat = false, smoothing = false, ?transform, ?shader) + { + // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + + final cameraBounds = FlxRect.weak(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); + + if (position == null) + position = FlxPoint.weak(); + + final verticesLength:Int = vertices.length >> 1; + + final bounds = FlxRect.get(); + drawVertices.splice(0, drawVertices.length); + + for (i in 0...verticesLength) + { + final tempX = position.x + vertices[(i << 1) + 0]; + final tempY = position.y + vertices[(i << 1) + 1]; + + drawVertices.push(tempX); + drawVertices.push(tempY); + + if (i == 0) + { + bounds.set(tempX, tempY, 0, 0); + } + else + { + FlxDrawTrianglesItem.inflateBounds(bounds, tempX, tempY); + } + } + + position.putWeak(); + + final overlaps = cameraBounds.overlaps(bounds); + bounds.put(); + + if (!overlaps) + { + drawVertices.splice(drawVertices.length - verticesLength, verticesLength); + return; + } + + _trianglesSprite.graphics.clear(); + _trianglesSprite.graphics.beginBitmapFill(graphic.bitmap, null, repeat, smoothing); + _trianglesSprite.graphics.drawTriangles(drawVertices, indices, uvtData); + _trianglesSprite.graphics.endFill(); + + // TODO: check this block of code for cases, when zoom < 1 (or initial zoom?)... + if (_useBlitMatrix) + _helperMatrix.copyFrom(_blitMatrix); + else + { + _helperMatrix.identity(); + _helperMatrix.translate(-camera.viewMarginLeft, -camera.viewMarginTop); + } + + buffer.draw(_trianglesSprite, _helperMatrix, transform); + + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + { + // TODO: add a drawDebugTriangles method + var gfx:Graphics = FlxSpriteUtil.flashGfx; + gfx.clear(); + gfx.lineStyle(1, FlxColor.BLUE, 0.5); + gfx.drawTriangles(drawVertices, indices); + buffer.draw(FlxSpriteUtil.flashGfxSprite, _helperMatrix); + } + #end + // End of TODO... + } + // ============================================================================= //} endregion RENDERING // ============================================================================= diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index b6052aa847..a081818eb8 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -1,22 +1,6 @@ package flixel.system.render.quad; -import flixel.graphics.FlxGraphic; -import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem; -import flixel.graphics.tile.FlxDrawQuadsItem; -import flixel.graphics.tile.FlxDrawTrianglesItem; -import flixel.math.FlxMatrix; -import flixel.math.FlxPoint; -import flixel.math.FlxRect; -import flixel.system.FlxAssets; import flixel.system.render.FlxRenderer; -import flixel.util.FlxColor; -import flixel.util.FlxDestroyUtil; -import openfl.display.BitmapData; -import openfl.display.BlendMode; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; using flixel.util.FlxColorTransformUtil; #if FLX_OPENGL_AVAILABLE @@ -28,13 +12,6 @@ import lime.graphics.opengl.GL; @:access(flixel.system.render.quad) class FlxQuadRenderer extends FlxTypedRenderer { - var _helperMatrix:FlxMatrix = new FlxMatrix(); - - /** - * Helper rect for `drawTriangles()` visibility checks - */ - var _bounds:FlxRect = FlxRect.get(); - public function new() { super(); @@ -45,60 +22,9 @@ class FlxQuadRenderer extends FlxTypedRenderer maxTextureSize = cast GL.getParameter(GL.MAX_TEXTURE_SIZE); #end } - - override function destroy():Void - { - super.destroy(); - _bounds = FlxDestroyUtil.put(_bounds); - _helperMatrix = null; - } public function createCameraView(camera:FlxCamera) { return new FlxQuadView(camera); } - - public function drawPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader) - { - var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = view.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); - #else - final drawItem:FlxDrawQuadsItem = view.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #end - drawItem.addQuad(frame, matrix, transform); - } - - public function copyPixels(view:FlxQuadView, ?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); - - var isColored = (transform != null && transform.hasRGBMultipliers()); - var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); - - #if FLX_RENDER_TRIANGLE - final drawItem:FlxDrawTrianglesItem = view.startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); - #else - final drawItem:FlxDrawQuadsItem = view.startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); - #end - drawItem.addQuad(frame, _helperMatrix, transform); - } - - public function drawTriangles(view:FlxQuadView, graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) - { - final camera = view.camera; - final cameraBounds = _bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); - - final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); - final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); - - final drawItem = view.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); - drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); - } } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 859365dfb2..56d9d651ad 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -3,19 +3,24 @@ package flixel.system.render.quad; import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; import flixel.graphics.tile.FlxDrawBaseItem; import flixel.graphics.tile.FlxDrawQuadsItem; import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.math.FlxMatrix; import flixel.math.FlxPoint; +import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.display.DisplayObjectContainer; import openfl.display.Graphics; import openfl.display.Sprite; import openfl.geom.ColorTransform; +import openfl.geom.Point; import openfl.geom.Rectangle; using flixel.util.FlxColorTransformUtil; @@ -185,6 +190,57 @@ class FlxQuadView extends FlxCameraView canvas.graphics.endFill(); } + override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, + ?shader) + { + // super.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + + var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + #else + final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #end + drawItem.addQuad(frame, matrix, transform); + } + + @:noCompletion + static final _helperMatrix = new FlxMatrix(); + override function copyPixels(?frame:FlxFrame, ?_:BitmapData, ?_:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend, + smoothing = false, ?shader) + { + // super.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); + + var isColored = (transform != null && transform.hasRGBMultipliers()); + var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); + + #if FLX_RENDER_TRIANGLE + final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); + #else + final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + #end + drawItem.addQuad(frame, _helperMatrix, transform); + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat = false, smoothing = false, ?transform:ColorTransform, ?shader:FlxShader) + { + // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + + final cameraBounds = FlxRect.weak(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight); + + final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers()); + final hasColorOffsets = (transform != null && transform.hasRGBAOffsets()); + + final drawItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); + drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform); + } + // ============================================================================= //} endregion RENDERING // ============================================================================= diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 1d5d8ae30b..725282123e 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -405,7 +405,7 @@ class FlxBitmapText extends FlxSprite matrix.translate(screenPos.x + originX, screenPos.y + originY); final colorTransform = bgColorTransformDrawHelper.reset(); colorTransform.setMultipliers(colorHelper).scaleMultipliers(backgroundColor); - FlxG.renderer.drawPixels(camera.view, FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); + camera.view.drawPixels(FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); } final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); diff --git a/flixel/tile/FlxTilemapBuffer.hx b/flixel/tile/FlxTilemapBuffer.hx index 2f2c16f62e..18078df9d6 100644 --- a/flixel/tile/FlxTilemapBuffer.hx +++ b/flixel/tile/FlxTilemapBuffer.hx @@ -183,14 +183,14 @@ class FlxTilemapBuffer implements IFlxDestroyable if (isPixelPerfectRender(camera) && (scaleX == 1.0 && scaleY == 1.0) && blend == null) { - FlxG.renderer.copyPixels(camera.view, pixels, _flashRect, flashPoint, null, null, true); + camera.view.copyPixels(pixels, _flashRect, flashPoint, null, null, true); } else { _matrix.identity(); _matrix.scale(scaleX, scaleY); _matrix.translate(flashPoint.x, flashPoint.y); - FlxG.renderer.drawPixels(camera.view, pixels, _matrix, null, blend, antialiasing); + camera.view.drawPixels(pixels, _matrix, null, blend, antialiasing); } } diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index 8bc8c47114..7711197b73 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -885,7 +885,7 @@ class FlxBar extends FlxSprite _matrix.ty = Math.floor(_matrix.ty); } - FlxG.renderer.drawPixels(camera.view, _frontFrame, _matrix, colorTransform, blend, antialiasing, shader); + camera.view.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); } } } From 59b4346794842fc742bfbc3955e949c90b4a652e Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 19:42:52 -0500 Subject: [PATCH 58/72] split TrackerProfile from Tracker --- flixel/system/debug/watch/Tracker.hx | 38 ++++--------------- flixel/system/debug/watch/TrackerProfile.hx | 25 ++++++++++++ flixel/system/frontEnds/DebuggerFrontEnd.hx | 10 +++-- .../system/frontEnds/DebuggerFrontEndTest.hx | 3 +- 4 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 flixel/system/debug/watch/TrackerProfile.hx diff --git a/flixel/system/debug/watch/Tracker.hx b/flixel/system/debug/watch/Tracker.hx index 29c86db1e5..26530e991b 100644 --- a/flixel/system/debug/watch/Tracker.hx +++ b/flixel/system/debug/watch/Tracker.hx @@ -1,22 +1,19 @@ package flixel.system.debug.watch; #if FLX_DEBUG -import openfl.display.DisplayObject; -import openfl.geom.Matrix; -import openfl.geom.Point; -import openfl.geom.Rectangle; import flixel.FlxBasic; import flixel.FlxCamera; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.FlxState; +import flixel.animation.FlxAnimationController; import flixel.effects.particles.FlxEmitter.FlxTypedEmitter; -import flixel.group.FlxSpriteGroup; import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.group.FlxSpriteGroup; +import flixel.input.FlxSwipe; import flixel.input.gamepad.FlxGamepad; import flixel.input.mouse.FlxMouse; -import flixel.input.FlxSwipe; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.path.FlxPath; @@ -26,7 +23,10 @@ import flixel.tweens.FlxTween; import flixel.ui.FlxBar; import flixel.ui.FlxButton.FlxTypedButton; import flixel.util.FlxTimer; -import flixel.animation.FlxAnimationController; +import openfl.display.DisplayObject; +import openfl.geom.Matrix; +import openfl.geom.Point; +import openfl.geom.Rectangle; #if FLX_TOUCH import flixel.input.touch.FlxTouch; #end @@ -265,26 +265,4 @@ class Tracker extends Watch add(variable, FIELD(_object, variable)); } #end -} - -class TrackerProfile -{ - public var objectClass:Class; - public var variables:Array; - public var extensions:Array>; - - public function new(ObjectClass:Class, ?Variables:Array, ?Extensions:Array>) - { - objectClass = ObjectClass; - variables = Variables; - extensions = Extensions; - } - - public function toString():String - { - return FlxStringUtil.getDebugString([ - LabelValuePair.weak("variables", variables), - LabelValuePair.weak("extensions", extensions) - ]); - } -} +} \ No newline at end of file diff --git a/flixel/system/debug/watch/TrackerProfile.hx b/flixel/system/debug/watch/TrackerProfile.hx new file mode 100644 index 0000000000..e7498f3b29 --- /dev/null +++ b/flixel/system/debug/watch/TrackerProfile.hx @@ -0,0 +1,25 @@ +package flixel.system.debug.watch; + +import flixel.util.FlxStringUtil; + +class TrackerProfile +{ + public var objectClass:Class; + public var variables:Array; + public var extensions:Array>; + + public function new(ObjectClass:Class, ?Variables:Array, ?Extensions:Array>) + { + objectClass = ObjectClass; + variables = Variables; + extensions = Extensions; + } + + public function toString():String + { + return FlxStringUtil.getDebugString([ + LabelValuePair.weak("variables", variables), + LabelValuePair.weak("extensions", extensions) + ]); + } +} diff --git a/flixel/system/frontEnds/DebuggerFrontEnd.hx b/flixel/system/frontEnds/DebuggerFrontEnd.hx index 2046760228..d6197fd5a6 100644 --- a/flixel/system/frontEnds/DebuggerFrontEnd.hx +++ b/flixel/system/frontEnds/DebuggerFrontEnd.hx @@ -4,9 +4,7 @@ import flixel.FlxG; import flixel.input.keyboard.FlxKey; import flixel.system.debug.FlxDebugger; import flixel.system.debug.Window; -import flixel.system.debug.interaction.Interaction; -import flixel.system.debug.interaction.tools.Tool; -import flixel.system.debug.watch.Tracker; +import flixel.system.debug.watch.TrackerProfile; import flixel.system.ui.FlxSystemButton; import flixel.util.FlxHorizontalAlign; import flixel.util.FlxSignal; @@ -15,6 +13,12 @@ import openfl.display.BitmapData; using flixel.util.FlxArrayUtil; using flixel.util.FlxStringUtil; +#if FLX_DEBUG +import flixel.system.debug.interaction.Interaction; +import flixel.system.debug.interaction.tools.Tool; +import flixel.system.debug.watch.Tracker; +#end + /** * Accessed via `FlxG.debugger`. */ diff --git a/tests/unit/src/flixel/system/frontEnds/DebuggerFrontEndTest.hx b/tests/unit/src/flixel/system/frontEnds/DebuggerFrontEndTest.hx index 514cf90e50..430932f268 100644 --- a/tests/unit/src/flixel/system/frontEnds/DebuggerFrontEndTest.hx +++ b/tests/unit/src/flixel/system/frontEnds/DebuggerFrontEndTest.hx @@ -1,7 +1,8 @@ package flixel.system.frontEnds; import flixel.FlxG; -import flixel.system.debug.watch.Tracker.TrackerProfile; +import flixel.system.debug.watch.Tracker; +import flixel.system.debug.watch.TrackerProfile; import flixel.util.FlxSignal; import massive.munit.Assert; From b19f5938702da7112ad0a8ffc7b94d424d7f209d Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 20:17:31 -0500 Subject: [PATCH 59/72] split copyPixels/drawPixels into copyFrame/drawFrame --- flixel/FlxCamera.hx | 21 ++++++-- flixel/FlxSprite.hx | 10 +++- flixel/system/FlxBGSprite.hx | 2 +- flixel/system/render/FlxCameraView.hx | 66 ++++++++++++++++++------ flixel/system/render/blit/FlxBlitView.hx | 47 ++++++++--------- flixel/system/render/quad/FlxQuadView.hx | 22 +++++--- flixel/text/FlxBitmapText.hx | 2 +- flixel/text/FlxText.hx | 2 +- flixel/ui/FlxBar.hx | 2 +- 9 files changed, 117 insertions(+), 57 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 2481890e3c..43214fb110 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1813,26 +1813,37 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("camera.clearDrawStack() is deprecated, use FlxG.renderer.render() instead.") // 6.2.0 + @:deprecated("camera.clearDrawStack() is deprecated, use camera.viewQuad.render() instead.") // 6.2.0 function clearDrawStack():Void { viewQuad.clearDrawStack(); } @:noCompletion - @:deprecated("camera.drawPixels() is deprecated, use FlxG.renderer.drawPixels() instead.") // 6.2.0 + @:deprecated("camera.drawPixels() is deprecated, use camera.view.drawPixels or drawFrame instead.") // 6.2.0 public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - view.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + if (pixels != null) + view.drawPixels(pixels, matrix, transform, blend, smoothing, shader); + else if (frame != null) + view.drawFrame(frame, matrix, transform, blend, smoothing, shader); + else + FlxG.log.error("camera.drawPixels must have either the frame or pixels arg"); } @:noCompletion - @:deprecated("camera.copyPixels() is deprecated, use camera.view.copyPixels instead.") // 6.2.0 + @:deprecated("camera.copyPixels() is deprecated, use camera.view.copyPixels or copyFrame instead.") // 6.2.0 public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { - view.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + if (pixels != null) + view.copyPixels(pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + else if (frame != null) + view.copyFrame(frame, destPoint, transform, blend, smoothing, shader); + else + FlxG.log.error("camera.copyPixels must have either the frame or pixels arg"); + } @:noCompletion diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 3f8b2e6178..26a4c5d8b7 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -1009,7 +1009,10 @@ class FlxSprite extends FlxObject _point.floor(); _point.copyTo(_flashPoint); - camera.view.copyPixels(_frame, framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); + if (framePixels != null && useFramePixels) + camera.view.copyPixels(framePixels, _flashRect, _flashPoint, colorTransform, blend, antialiasing); + else + camera.view.copyFrame(_frame, _flashPoint, colorTransform, blend, antialiasing); } @:noCompletion @@ -1025,7 +1028,10 @@ class FlxSprite extends FlxObject final matrix = drawComplexMatrix; // TODO: Just use local? prepareComplexMatrix(matrix, frame, camera); - camera.view.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); + if (framePixels != null && useFramePixels) + camera.view.drawPixels(framePixels, matrix, colorTransform, blend, antialiasing, shader); + else + camera.view.drawFrame(frame, matrix, colorTransform, blend, antialiasing, shader); } function prepareComplexMatrix(matrix:FlxMatrix, frame:FlxFrame, camera:FlxCamera) diff --git a/flixel/system/FlxBGSprite.hx b/flixel/system/FlxBGSprite.hx index 29b3edcc38..4cbc91101a 100644 --- a/flixel/system/FlxBGSprite.hx +++ b/flixel/system/FlxBGSprite.hx @@ -32,7 +32,7 @@ class FlxBGSprite extends FlxSprite _matrix.scale(camera.viewWidth + 1, camera.viewHeight + 1); _matrix.translate(camera.viewMarginLeft, camera.viewMarginTop); - camera.view.drawPixels(frame, _matrix, colorTransform); + camera.view.drawFrame(frame, _matrix, colorTransform); #if FLX_DEBUG FlxBasic.visibleCount++; diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 47ce038232..4ae557934a 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -22,6 +22,7 @@ import openfl.geom.Rectangle; /** * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects + * @since 6.2.0 */ @:allow(flixel.FlxCamera) @:access(flixel.FlxCamera) @@ -106,45 +107,76 @@ abstract class FlxCameraView implements IFlxDestroyable } /** - * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * Draws the pixels onto the current render target. * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param matrix The transformation matrix to use. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. + * @param pixels The pixels to draw. + * @param transform The color transform to use. + * @param blend The blend mode to use. * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + * @param shader The shader to use. */ - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, - ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + public function drawPixels(pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) { throw "Not implemented"; // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 } /** - * Draws `frame` or `pixels` (depends on the renderer backend) onto the current render target. + * Draws the pixels onto the current render target. * * Unlike `drawPixels()`, this method does not use a matrix. This means that complex transformations * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. * - * @param frame The frame to draw (used only with the DRAW_TILES renderer). - * @param pixels The pixels to draw (used only with the BLITTING renderer). - * @param sourceRect A rectangle that defines the area of the pixels to use (used only with the BLITTING renderer). + * @param pixels The pixels to draw. + * @param sourceRect A rectangle that defines the area of the pixels to use. * @param destPoint A point representing the top-left position to draw to. - * @param transform The color transform to use, optional. - * @param blend The blend mode to use, optional. + * @param transform The color transform to use. + * @param blend The blend mode to use. * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. - * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). + * @param shader The shader to use. */ - public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, + public function copyPixels(pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) { throw "Not implemented"; // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 } + /** + * Draws the frame onto the current render target. + * + * @param frame The frame to draw. + * @param matrix The transformation matrix to use. + * @param transform The color transform to use. + * @param blend The blend mode to use. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use. + */ + public function drawFrame(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, ?shader:FlxShader) + { + throw "Not implemented"; + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } + + /** + * Draws the frame onto the current render target. + * + * Unlike `drawFrame()`, this method does not use a matrix. This means that complex transformations + * are not supported with this method. The `destPoint` argument is used to determine the position to draw to. + * + * @param frame The frame to draw + * @param destPoint A point representing the top-left position to draw to. + * @param transform The color transform to use. + * @param blend The blend mode to use. + * @param smoothing Whether to use smoothing (anti-aliasing) when drawing. + * @param shader The shader to use + */ + public function copyFrame(frame:FlxFrame, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) + { + throw "Not implemented"; + // Note: Abstract methods with default values are broken on cpp in haxe 4.3. https://github.com/HaxeFoundation/haxe/issues/11666 + } + /** * Draws a set of triangles onto the current render target. * diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index f8d34d2afc..e65a3737f5 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -192,10 +192,9 @@ class FlxBlitView extends FlxCameraView @:noCompletion static final _helperMatrix = new FlxMatrix(); - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing:Bool = false, - ?shader:FlxShader) + override function drawPixels(pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) { - // super.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + // super.drawPixels(pixels, matrix, transform, blend, smoothing, shader); _helperMatrix.copyFrom(matrix); @@ -213,34 +212,36 @@ class FlxBlitView extends FlxCameraView @:noCompletion static final _helperPoint:Point = new Point(); - override function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, - smoothing:Bool = false, ?shader:FlxShader) + override function copyPixels(pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader) { - // super.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + // super.copyPixels(pixels, sourceRect, destPoint, transform, blend, smoothing); - if (pixels != null) + if (_useBlitMatrix) { - if (_useBlitMatrix) - { - _helperMatrix.identity(); - _helperMatrix.translate(destPoint.x, destPoint.y); - _helperMatrix.concat(_blitMatrix); - buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); - } - else - { - _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); - _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); - buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); - } + _helperMatrix.identity(); + _helperMatrix.translate(destPoint.x, destPoint.y); + _helperMatrix.concat(_blitMatrix); + buffer.draw(pixels, _helperMatrix, null, null, null, (smoothing || antialiasing)); } - else if (frame != null) + else { - // TODO: fix this case for zoom less than initial zoom... - frame.paint(buffer, destPoint, true); + _helperPoint.x = destPoint.x - Std.int(camera.viewMarginLeft); + _helperPoint.y = destPoint.y - Std.int(camera.viewMarginTop); + buffer.copyPixels(pixels, sourceRect, _helperPoint, null, null, true); } } + override function drawFrame(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) + { + throw "Not Implemented on blit"; + } + + override function copyFrame(frame:FlxFrame, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) + { + // TODO: fix this case for zoom less than initial zoom... + frame.paint(buffer, destPoint, true); + } + @:noCompletion static final _trianglesSprite = new Sprite(); diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 56d9d651ad..af4e8954c2 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -190,10 +190,21 @@ class FlxQuadView extends FlxCameraView canvas.graphics.endFill(); } - override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, - ?shader) + override function drawPixels(pixels, matrix, ?transform, ?blend, smoothing = false, ?shader) { - // super.drawPixels(frame, pixels, matrix, transform, blend, smoothing, shader); + // super.drawPixels(frame, matrix, transform, blend, smoothing, shader); + throw "Not implemented"; + } + + override function copyPixels(pixels, ?sourceRect, destPoint, ?transform, ?blend, smoothing = false, ?shader) + { + // super.copyPixels(pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + throw "Not implemented"; + } + + override function drawFrame(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader) + { + // super.drawFrame(frame, matrix, transform, blend, smoothing, shader); var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end); var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); @@ -208,10 +219,9 @@ class FlxQuadView extends FlxCameraView @:noCompletion static final _helperMatrix = new FlxMatrix(); - override function copyPixels(?frame:FlxFrame, ?_:BitmapData, ?_:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend, - smoothing = false, ?shader) + override function copyFrame(frame:FlxFrame, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) { - // super.copyPixels(frame, pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + // super.copyFrame(frame, destPoint, transform, blend, smoothing, shader); _helperMatrix.identity(); _helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y); diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 725282123e..8ceca5e933 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -405,7 +405,7 @@ class FlxBitmapText extends FlxSprite matrix.translate(screenPos.x + originX, screenPos.y + originY); final colorTransform = bgColorTransformDrawHelper.reset(); colorTransform.setMultipliers(colorHelper).scaleMultipliers(backgroundColor); - camera.view.drawPixels(FlxG.bitmap.whitePixel, null, matrix, colorTransform, blend, antialiasing); + camera.view.drawFrame(FlxG.bitmap.whitePixel, matrix, colorTransform, blend, antialiasing); } final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index 8cebd3ee04..e105e6534b 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -245,7 +245,7 @@ class FlxText extends FlxSprite allowCollisions = NONE; moves = false; - drawFrame(); + drawFrame(); // TODO: drawFrame(FlxG.renderer.blit); } /** diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index 7711197b73..dbcd8b8d44 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -885,7 +885,7 @@ class FlxBar extends FlxSprite _matrix.ty = Math.floor(_matrix.ty); } - camera.view.drawPixels(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); + camera.view.drawFrame(_frontFrame, _matrix, colorTransform, blend, antialiasing, shader); } } } From e78983ae90cfbab74e9135d118c594292503af2b Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Thu, 12 Mar 2026 20:40:22 -0500 Subject: [PATCH 60/72] change statics to instance vars --- flixel/FlxGame.hx | 4 ++-- flixel/graphics/tile/FlxDrawBaseItem.hx | 10 +++++----- flixel/system/frontEnds/CameraFrontEnd.hx | 4 ++-- flixel/system/render/FlxRenderer.hx | 10 +++++----- flixel/system/render/blit/FlxBlitRenderer.hx | 2 +- flixel/system/render/blit/FlxBlitView.hx | 7 +++++-- flixel/system/render/quad/FlxQuadView.hx | 3 +++ 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index ee3c0f2763..81efba61b9 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -803,7 +803,7 @@ class FlxGame extends Sprite FlxG.signals.preDraw.dispatch(); - FlxRenderer.totalDrawCalls = 0; + FlxG.renderer.totalDrawCalls = 0; FlxG.cameras.clear(); @@ -823,7 +823,7 @@ class FlxGame extends Sprite if (FlxG.renderer.tile) { #if FLX_DEBUG - debugger.stats.drawCalls(FlxRenderer.totalDrawCalls); + debugger.stats.drawCalls(FlxG.renderer.totalDrawCalls); #end } diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index 6127ce907a..3f216571c4 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -2,8 +2,8 @@ package flixel.graphics.tile; import flixel.FlxCamera; import flixel.graphics.frames.FlxFrame; -import flixel.system.render.FlxRenderer; import flixel.math.FlxMatrix; +import flixel.system.render.FlxRenderer; import openfl.display.BlendMode; import openfl.geom.ColorTransform; @@ -15,17 +15,17 @@ class FlxDrawBaseItem /** * Tracks the total number of draw calls made each frame. */ - @:deprecated("drawCalls is deprecated, use FlxRenderer.totalDrawCalls instead") + @:deprecated("drawCalls is deprecated, use FlxG.renderer.totalDrawCalls instead") public static var drawCalls(get, set):Int; static function set_drawCalls(value:Int):Int { - return FlxRenderer.totalDrawCalls = value; + return FlxG.renderer.totalDrawCalls = value; } static function get_drawCalls():Int { - return FlxRenderer.totalDrawCalls; + return FlxG.renderer.totalDrawCalls; } @:noCompletion @@ -75,7 +75,7 @@ class FlxDrawBaseItem public function render(camera:FlxCamera):Void { - FlxRenderer.totalDrawCalls++; + FlxG.renderer.totalDrawCalls++; } public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 9acb834d38..e46b5eb49c 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -344,7 +344,7 @@ class CameraFrontEnd function get_useBufferLocking():Bool { if (FlxG.renderer.blit) - return FlxBlitRenderer.useBufferLocking; + return cast(FlxG.renderer, FlxBlitRenderer).useBufferLocking; return false; } @@ -352,7 +352,7 @@ class CameraFrontEnd function set_useBufferLocking(value:Bool):Bool { if (FlxG.renderer.blit) - return FlxBlitRenderer.useBufferLocking = value; + return cast(FlxG.renderer, FlxBlitRenderer).useBufferLocking = value; return value; } diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index bb24a2bbd1..a30b5b99da 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -31,11 +31,6 @@ typedef FlxRenderer = FlxTypedRenderer; */ abstract class FlxTypedRenderer implements IFlxDestroyable { - /** - * The number of total draw calls in the current frame. - */ - public static var totalDrawCalls:Int = 0; - /** * Creates a renderer instance, based on the used rendering backend. * This function is dynamic, which means that you can change the return value yourself. @@ -54,6 +49,11 @@ abstract class FlxTypedRenderer implements IFlxDestroyable } } + /** + * The number of total draw calls in the current frame. + */ + public var totalDrawCalls:Int = 0; + /** * Returns the current render method as an enum. */ diff --git a/flixel/system/render/blit/FlxBlitRenderer.hx b/flixel/system/render/blit/FlxBlitRenderer.hx index ef7326ae8f..4933e55519 100644 --- a/flixel/system/render/blit/FlxBlitRenderer.hx +++ b/flixel/system/render/blit/FlxBlitRenderer.hx @@ -32,7 +32,7 @@ class FlxBlitRenderer extends FlxTypedRenderer * * This property only has effects when targeting Flash. */ - public static var useBufferLocking:Bool = false; + public var useBufferLocking:Bool = false; public function new() { diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index e65a3737f5..da30f52847 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -106,6 +106,9 @@ class FlxBlitView extends FlxCameraView var _flashOffset:FlxPoint = FlxPoint.get(); + var _renderer(get, never):FlxBlitRenderer; + inline function get__renderer() return cast (FlxG.renderer, FlxBlitRenderer); + @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) { @@ -151,7 +154,7 @@ class FlxBlitView extends FlxCameraView camera.drawFX(); - if (FlxBlitRenderer.useBufferLocking) + if (_renderer.useBufferLocking) { buffer.unlock(); } @@ -165,7 +168,7 @@ class FlxBlitView extends FlxCameraView checkResize(); - if (FlxBlitRenderer.useBufferLocking) + if (_renderer.useBufferLocking) { buffer.lock(); } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index af4e8954c2..fc239c3fdb 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -64,6 +64,9 @@ class FlxQuadView extends FlxCameraView var _flashOffset:FlxPoint = FlxPoint.get(); + var _renderer(get, never):FlxQuadRenderer; + inline function get__renderer() return cast (FlxG.renderer, FlxQuadRenderer); + @:allow(flixel.system.render.FlxCameraView) function new(camera:FlxCamera) { From 5af0840bc5f001550166be83bb510d3c39e96a88 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 13 Mar 2026 15:39:37 -0500 Subject: [PATCH 61/72] add FlxVector2d wrapper for openfl.Vector --- flixel/system/render/FlxCameraView.hx | 2 +- flixel/system/render/FlxVector2d.hx | 47 ++++++++++++++++++++++++ flixel/system/render/blit/FlxBlitView.hx | 19 ++++------ flixel/system/render/quad/FlxQuadView.hx | 2 +- 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 flixel/system/render/FlxVector2d.hx diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 4ae557934a..46b3545004 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -192,7 +192,7 @@ abstract class FlxCameraView implements IFlxDestroyable * @param transform The color transform to use, optional. * @param shader The shader to use, optional (used only with the DRAW_TILES renderer). */ - public function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + public function drawTriangles(graphic:FlxGraphic, vertices:FlxVector2d, indices:FlxVector2d, uvtData:FlxVector2d, ?colors:FlxVector2d, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader) { throw "Not implemented"; diff --git a/flixel/system/render/FlxVector2d.hx b/flixel/system/render/FlxVector2d.hx new file mode 100644 index 0000000000..99459525cc --- /dev/null +++ b/flixel/system/render/FlxVector2d.hx @@ -0,0 +1,47 @@ +package flixel.system.render; + +import openfl.Vector; + +/** + * An `openfl.Vector` disguised as a `openfl.Vector<{ x:T, y:T }>` objects, but without the performance hit + */ +@:multiType(T) +abstract FlxVector2d(Vector) from Vector +{ + // This is needed to get around openfl's complicated Vector class + @:to static function ofInt(_:Vector) { return new FlxIntVector2d(0, false, new Array()); } + @:to static function ofFloat(_:Vector) { return new FlxFloatVector2d(0, false, new Array()); } + @:to static function ofBool(_:Vector) { return new FlxBoolVector2d(0, false, new Array()); } + + // Note: must be inlined + @:to inline function toVector():Vector { return this; } + + public var length(get, never):Int; + inline function get_length() return this.length >> 1; + + public function new(); + + public inline function set(index:Int, x:T, y:T) + { + this[index << 1 + 0] = x; + this[index << 1 + 1] = y; + } + + public inline function getX(index:Int) return this[index << 1 + 0]; + public inline function getY(index:Int) return this[index << 1 + 1]; + + public inline function push(x:T, y:T) + { + this.push(x); + this.push(y); + } + + public inline function clear() + { + this.slice(0, this.length); + } +} + +@:forward @:forward.new abstract FlxIntVector2d(Vector) from Vector to Vector {} +@:forward @:forward.new abstract FlxFloatVector2d(Vector) from Vector to Vector {} +@:forward @:forward.new abstract FlxBoolVector2d(Vector) from Vector to Vector {} \ No newline at end of file diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index da30f52847..fec7e5708c 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -249,8 +249,8 @@ class FlxBlitView extends FlxCameraView static final _trianglesSprite = new Sprite(); @:noCompletion - static final drawVertices = new DrawData(); - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + static final drawVertices = new FlxVector2d(); + override function drawTriangles(graphic:FlxGraphic, vertices:FlxVector2d, indices:FlxVector2d, uvtData:FlxVector2d, ?colors:FlxVector2d, ?position, ?blend, repeat = false, smoothing = false, ?transform, ?shader) { // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); @@ -260,18 +260,15 @@ class FlxBlitView extends FlxCameraView if (position == null) position = FlxPoint.weak(); - final verticesLength:Int = vertices.length >> 1; - final bounds = FlxRect.get(); - drawVertices.splice(0, drawVertices.length); + drawVertices.clear(); - for (i in 0...verticesLength) + for (i in 0...vertices.length) { - final tempX = position.x + vertices[(i << 1) + 0]; - final tempY = position.y + vertices[(i << 1) + 1]; + final tempX = position.x + vertices.getX(i); + final tempY = position.y + vertices.getY(i); - drawVertices.push(tempX); - drawVertices.push(tempY); + drawVertices.push(tempX, tempY); if (i == 0) { @@ -290,7 +287,7 @@ class FlxBlitView extends FlxCameraView if (!overlaps) { - drawVertices.splice(drawVertices.length - verticesLength, verticesLength); + drawVertices.clear(); return; } diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index fc239c3fdb..956040c9ab 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -240,7 +240,7 @@ class FlxQuadView extends FlxCameraView drawItem.addQuad(frame, _helperMatrix, transform); } - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + override function drawTriangles(graphic:FlxGraphic, vertices:FlxVector2d, indices:FlxVector2d, uvtData:FlxVector2d, ?colors:FlxVector2d, ?position:FlxPoint, ?blend:BlendMode, repeat = false, smoothing = false, ?transform:ColorTransform, ?shader:FlxShader) { // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); From a4ab01ffc04bff53b0b21b6cf8423f6c19e487b6 Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Fri, 13 Mar 2026 23:07:56 -0500 Subject: [PATCH 62/72] fix warning --- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index c98efdf407..795c220a99 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -82,7 +82,7 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem view.canvas.graphics.beginShaderFill(shader); #else - view.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); + view.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.view.antialiasing || antialiasing)); #end view.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); From 4fd4035d162063041e88f43277f3b8414856868f Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Tue, 17 Mar 2026 09:46:27 -0500 Subject: [PATCH 63/72] Update flixel/system/debug/stats/Stats.hx Co-authored-by: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> --- flixel/system/debug/stats/Stats.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/debug/stats/Stats.hx b/flixel/system/debug/stats/Stats.hx index 8c4eb88c22..5f88c71d2a 100644 --- a/flixel/system/debug/stats/Stats.hx +++ b/flixel/system/debug/stats/Stats.hx @@ -267,7 +267,7 @@ class Stats extends Window } visibleCount = Std.int(divide(visibleCount, _visibleObjectMarker)); - if (FlxG.renderer.blit) + if (FlxG.renderer.tile) { for (i in 0..._drawCallsMarker) { From 15c7a0027c5bbe377858deca2d54307788075b0d Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Tue, 17 Mar 2026 10:34:33 -0500 Subject: [PATCH 64/72] fix typo --- flixel/system/render/quad/FlxQuadView.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index fc239c3fdb..bfe5916819 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -341,7 +341,7 @@ class FlxQuadView extends FlxCameraView override function set_alpha(value:Float):Float { - canvas.alpha = alpha; + canvas.alpha = value; return super.set_alpha(value); } From 243ac949fc34bbf5969f38f7cfd9ee91c8bae88f Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:07:47 +0100 Subject: [PATCH 65/72] some docs --- flixel/system/render/FlxCameraView.hx | 2 ++ flixel/system/render/FlxRenderer.hx | 18 +++++++++--------- flixel/system/render/quad/FlxQuadRenderer.hx | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 46b3545004..1c89467882 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -22,6 +22,8 @@ import openfl.geom.Rectangle; /** * A `FlxCameraView` is a helper added to cameras, that holds some rendering-related objects + * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. + * * @since 6.2.0 */ @:allow(flixel.FlxCamera) diff --git a/flixel/system/render/FlxRenderer.hx b/flixel/system/render/FlxRenderer.hx index a30b5b99da..a9865a55ad 100644 --- a/flixel/system/render/FlxRenderer.hx +++ b/flixel/system/render/FlxRenderer.hx @@ -13,16 +13,10 @@ import openfl.geom.Point; import openfl.geom.Rectangle; /** - * `FlxRenderer` is the base class for all rendering functionality. + * `FlxRenderer` is a global, base class that handles rendering. * It does not contain any rendering logic by itself, rather it is extended by the various renderer implementations. * * You can access a global renderer instance via `FlxG.renderer`. - * - * The `FlxRenderer` API replaces the previous renderer implementation in `FlxCamera`. - * Because it's not tied to a camera, it also works slightly differently. - * Before any drawing commands are executed, `FlxG.renderer.begin(camera);` is called to use the camera as a render target. - * This is called internally by Flixel during a sprite's draw phase, so you shouldn't worry about calling it yourself unless - * you have a reason to. */ typedef FlxRenderer = FlxTypedRenderer; @@ -59,9 +53,15 @@ abstract class FlxTypedRenderer implements IFlxDestroyable */ public var method(default, null):FlxRenderMethod; + /** + * Convenience shortcut for `FlxG.renderer.method == BLITTING` + */ public var blit(get, never):Bool; inline function get_blit() return method.match(BLITTING); + /** + * Convenience shortcut for `FlxG.renderer.method == DRAW_TILES` + */ public var tile(get, never):Bool; inline function get_tile() return method.match(DRAW_TILES); @@ -101,8 +101,8 @@ abstract class FlxTypedRenderer implements IFlxDestroyable function new() {} /** - * Initializes and global fields that are dependant on the global rendering method. - * Called automatically by `FlxG.init` + * Initializes any global fields that are dependant on the global rendering method. + * Called automatically by `FlxG.init()` */ public function initGlobals() {} diff --git a/flixel/system/render/quad/FlxQuadRenderer.hx b/flixel/system/render/quad/FlxQuadRenderer.hx index a081818eb8..0758335dcf 100644 --- a/flixel/system/render/quad/FlxQuadRenderer.hx +++ b/flixel/system/render/quad/FlxQuadRenderer.hx @@ -7,7 +7,6 @@ using flixel.util.FlxColorTransformUtil; import lime.graphics.opengl.GL; #end - @:access(flixel.FlxCamera) @:access(flixel.system.render.quad) class FlxQuadRenderer extends FlxTypedRenderer From b6748d8c41c4691ea5b5540f94beb3ed5d899ba2 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:12:51 +0100 Subject: [PATCH 66/72] Rename `FlxVertexBuffer` to `FlxCanvas` + add docs Might rename again in the future to something more debug oriented...? --- flixel/FlxCamera.hx | 6 +- flixel/FlxObject.hx | 6 +- flixel/path/FlxBasePath.hx | 6 +- .../debug/interaction/tools/Transform.hx | 6 +- flixel/system/render/FlxCameraView.hx | 2 +- flixel/system/render/FlxCanvas.hx | 90 +++++++++ flixel/system/render/FlxVertexBuffer.hx | 71 ------- flixel/system/render/blit/FlxBlitView.hx | 4 +- flixel/system/render/gl/FlxGLView.hx | 176 ++++++++++++++++++ flixel/system/render/quad/FlxQuadView.hx | 2 +- 10 files changed, 282 insertions(+), 87 deletions(-) create mode 100644 flixel/system/render/FlxCanvas.hx delete mode 100644 flixel/system/render/FlxVertexBuffer.hx create mode 100644 flixel/system/render/gl/FlxGLView.hx diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 43214fb110..cf7690d44b 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -11,7 +11,7 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxShader; import flixel.system.render.FlxCameraView; -import flixel.system.render.FlxVertexBuffer; +import flixel.system.render.FlxCanvas; import flixel.system.render.blit.FlxBlitRenderer; import flixel.system.render.blit.FlxBlitView; import flixel.system.render.quad.FlxQuadRenderer; @@ -1802,7 +1802,7 @@ class FlxCamera extends FlxBasic if (useTargetGraphic) { graphics.overrideBlendMode(null); - final buffer:FlxVertexBuffer = cast graphics; + final buffer:FlxCanvas = cast graphics; // i'm drawing rect with these parameters to avoid light lines at the top and left of the camera, // which could appear while cameras fading buffer.drawFilledRect(camera.viewMarginLeft - 1, camera.viewMarginTop - 1, camera.viewWidth + 2, camera.viewHeight + 2, color); @@ -2272,4 +2272,4 @@ enum FlxCameraFollowStyle * Camera has no deadzone, just tracks the focus object directly and centers it. */ NO_DEAD_ZONE; -} \ No newline at end of file +} diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index 03530287e3..3f4a607fbc 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -6,7 +6,7 @@ import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.path.FlxPath; import flixel.system.render.FlxCameraView; -import flixel.system.render.FlxVertexBuffer; +import flixel.system.render.FlxCanvas; import flixel.tile.FlxBaseTilemap; import flixel.util.FlxAxes; import flixel.util.FlxColor; @@ -1338,7 +1338,7 @@ class FlxObject extends FlxBasic } @:haxe.warning("-WDeprecated") - function drawDebugBoundingBoxTo(buffer:FlxVertexBuffer, rect:FlxRect) + function drawDebugBoundingBoxTo(buffer:FlxCanvas, rect:FlxRect) { drawDebugBoundingBox(buffer, rect, allowCollisions, immovable); } @@ -1362,7 +1362,7 @@ class FlxObject extends FlxBasic @:deprecated("beginDrawDebug(gfx) is deprecated, drawDebugBoundingBoxTo instead") function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) { - final buffer:FlxVertexBuffer = gfx; + final buffer:FlxCanvas = gfx; buffer.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0, color, 1); } diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index d47856b175..c149e4234b 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -5,7 +5,7 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.math.FlxPoint; import flixel.system.render.FlxCameraView; -import flixel.system.render.FlxVertexBuffer; +import flixel.system.render.FlxCanvas; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -387,7 +387,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - inline function drawNode(buffer:FlxVertexBuffer, node:FlxPoint, size:Int, color:FlxColor) + inline function drawNode(buffer:FlxCanvas, node:FlxPoint, size:Int, color:FlxColor) { final offset = Math.floor(size * 0.5); buffer.drawFilledRect(node.x - offset, node.y - offset, size, size, color); @@ -399,7 +399,7 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy drawLink(gfx, node1, node2); } - function drawLink(buffer:FlxVertexBuffer, node1:FlxPoint, node2:FlxPoint) + function drawLink(buffer:FlxCanvas, node1:FlxPoint, node2:FlxPoint) { final lineOffset = debugDrawData.lineSize / 2; buffer.drawLine(node1.x + lineOffset, node1.y + lineOffset, node2.x + lineOffset, node2.y + lineOffset, debugDrawData.lineColor); diff --git a/flixel/system/debug/interaction/tools/Transform.hx b/flixel/system/debug/interaction/tools/Transform.hx index 2e2e1be2df..913a704fed 100644 --- a/flixel/system/debug/interaction/tools/Transform.hx +++ b/flixel/system/debug/interaction/tools/Transform.hx @@ -7,7 +7,7 @@ import flixel.math.FlxRect; import flixel.system.debug.Icon; import flixel.system.debug.Tooltip; import flixel.system.debug.interaction.Interaction; -import flixel.system.render.FlxVertexBuffer; +import flixel.system.render.FlxCanvas; import flixel.util.FlxColor; import flixel.util.FlxSpriteUtil; import openfl.display.BitmapData; @@ -245,7 +245,7 @@ class Transform extends Tool view.endDrawDebug(); } - function drawSelection(buffer:FlxVertexBuffer, camera:FlxCamera) + function drawSelection(buffer:FlxCanvas, camera:FlxCamera) { // draw lines final scroll = camera.scroll; @@ -300,7 +300,7 @@ private class Marker rot.put(); } - public static function draw(buffer:FlxVertexBuffer, screenX:Float, screenY:Float, circle:Bool) + public static function draw(buffer:FlxCanvas, screenX:Float, screenY:Float, circle:Bool) { if (circle) buffer.drawFilledCircle(screenX, screenY, CIRCLE_RADIUS, FlxColor.MAGENTA); diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 1c89467882..834cae2c9f 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -236,7 +236,7 @@ abstract class FlxCameraView implements IFlxDestroyable #if FLX_DEBUG - abstract public function getDebugBuffer():FlxVertexBuffer; + abstract public function getDebugBuffer():FlxCanvas; abstract function worldToDebugX(worldX:Float):Float;//TODO: find out what "debug space" actually is, rename and make public abstract function worldToDebugY(worldY:Float):Float;//TODO: find out what "debug space" actually is, rename and make public diff --git a/flixel/system/render/FlxCanvas.hx b/flixel/system/render/FlxCanvas.hx new file mode 100644 index 0000000000..f3c447c83b --- /dev/null +++ b/flixel/system/render/FlxCanvas.hx @@ -0,0 +1,90 @@ +package flixel.system.render; + +import flixel.util.FlxColor; +import openfl.display.BlendMode; +import openfl.display.Graphics; +import openfl.geom.ColorTransform; +import openfl.geom.Point; +import openfl.geom.Rectangle; + +/** + * Helper for interfacing with a openfl Graphics, in 7.0.0 this will change from + * an abstract to a class wrapping graphic that implements an interface. All + * references to Graphic need to be removed first + */ +@:forward +abstract FlxCanvas(Graphics) from Graphics to Graphics +{ + /** + * Wipes all drawn graphics from teh canvas + */ + public inline function clear():Void + { + this.clear(); + } + + /** + * Draws a hollow axis-aligned rectangle to the canvas. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's outline. + * @param thickness The thickness of the rectangle's outline. + */ + public function drawRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void + { + this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + this.drawRect(x, y, width, height); + } + + /** + * Draws a solid axis-aligned rectangle to the canvas. + * + * @param x The x position of the rectangle. + * @param y The y position of the rectangle. + * @param width The width of the rectangle (in pixels). + * @param height The height of the rectangle (in pixels). + * @param color The color (in 0xAARRGGBB hex format) of the rectangle's fill. + */ + public function drawFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void + { + this.lineStyle(); + this.beginFill(color.rgb, color.alphaFloat); + this.drawRect(x, y, width, height); + this.endFill(); + } + + /** + * Draws a filled circle to the canvas. + * + * @param x The x position of the circle. + * @param y The y position of the circle. + * @param radius The radius of the circle. + * @param color The color (in 0xAARRGGBB hex format) of the circle's fill. + */ + public function drawFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void + { + this.beginFill(color.rgb, color.alphaFloat); + this.drawCircle(x, y, radius); + this.endFill(); + } + + /** + * Draws a line to the canvas. + * + * @param x1 The start x position of the line. + * @param y1 The start y position of the line. + * @param x2 The end x position of the line. + * @param y2 The end y position of the line. + * @param color The color (in 0xAARRGGBB hex format) of the line. + * @param thickness The thickness of the line. + */ + public function drawLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void + { + this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); + this.moveTo(x1, y1); + this.lineTo(x2, y2); + } +} diff --git a/flixel/system/render/FlxVertexBuffer.hx b/flixel/system/render/FlxVertexBuffer.hx deleted file mode 100644 index 4d18d2762f..0000000000 --- a/flixel/system/render/FlxVertexBuffer.hx +++ /dev/null @@ -1,71 +0,0 @@ -package flixel.system.render; - -import flixel.util.FlxColor; -import openfl.display.BlendMode; -import openfl.display.Graphics; -import openfl.geom.ColorTransform; -import openfl.geom.Point; -import openfl.geom.Rectangle; - -/** - * Helper for interfacing with a openfl Graphics, in 7.0.0 this will change from - * an abstract to a class wrapping graphic that implements an interface. All - * references to Graphic need to be removed first - */ -@:forward -abstract FlxVertexBuffer(Graphics) from Graphics to Graphics -{ - /** - * Wipes all drawn vertices from the buffer - */ - public inline function clear():Void - { - this.clear(); - } - - /** - * Draws a hollow axis-aligned rectangle to the buffer - * @param x - * @param y - * @param width - * @param height - * @param color The Color of the outline - * @param thickness The thickness of the outline - */ - public function drawRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness:Float = 1.0):Void - { - this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - this.drawRect(x, y, width, height); - } - - /** - * Draws a solid axis-aligned rectangle to the buffer - */ - public function drawFilledRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor):Void - { - this.lineStyle(); - this.beginFill(color.rgb, color.alphaFloat); - this.drawRect(x, y, width, height); - this.endFill(); - } - - /** - * Draws an antialiased solid circle to the buffer - */ - public function drawFilledCircle(x:Float, y:Float, radius:Float, color:FlxColor):Void - { - this.beginFill(color.rgb, color.alphaFloat); - this.drawCircle(x, y, radius); - this.endFill(); - } - - /** - * Draws an antialiased line to the buffer - */ - public function drawLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness:Float = 1.0):Void - { - this.lineStyle(thickness, color.rgb, color.alphaFloat, false, null, null, MITER, 255); - this.moveTo(x1, y1); - this.lineTo(x2, y2); - } -} \ No newline at end of file diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index fec7e5708c..139e2a7643 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -417,7 +417,7 @@ class FlxBlitView extends FlxCameraView #if FLX_DEBUG - function getDebugBuffer():FlxVertexBuffer + function getDebugBuffer():FlxCanvas { return debugSprite.graphics; } @@ -558,4 +558,4 @@ class FlxBlitView extends FlxCameraView //} endregion GETTERS // ============================================================================= -} \ No newline at end of file +} diff --git a/flixel/system/render/gl/FlxGLView.hx b/flixel/system/render/gl/FlxGLView.hx new file mode 100644 index 0000000000..9a8dc9c97a --- /dev/null +++ b/flixel/system/render/gl/FlxGLView.hx @@ -0,0 +1,176 @@ +package flixel.system.render.gl; + +import lime.graphics.opengl.GL; +import flixel.system.render.gl.FlxBatchElement.FlxQuadBatchElement; +import flixel.util.FlxPool; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxMath; +import flixel.math.FlxMatrix; +import flixel.math.FlxPoint; +import flixel.system.FlxAssets.FlxShader; +import flixel.system.render.quad.FlxDrawTrianglesItem.DrawData; +import flixel.util.FlxColor; +import haxe.Constraints.Function; +import openfl.display.BlendMode; +import openfl.display.DisplayObjectContainer; +import openfl.display.Sprite; +import openfl.geom.ColorTransform; +import openfl.geom.Point; + +class FlxGLView extends FlxCameraView +{ + // TODO: abstract away the camera adding so that we don't need a flash sprite + var dummySprite:Sprite = new Sprite(); + + + var _elements:Array = []; + + var _renderer(get, never):FlxGLRenderer; + inline function get__renderer() return cast (FlxG.renderer, FlxGLRenderer); + + public function new(camera:FlxCamera) + { + super(camera); + + dummySprite.visible = false; + } + + // ============================================================================= + //{ region RENDERING + // ============================================================================= + + override function clear() + { + _renderer.resize(camera.width, camera.height); + } + + override function render() + { + // Submit all the collected sprites to the batcher + for (element in _elements) + _renderer.quadBatcher.add(cast element); + + // Force a flush to draw whatever was left in the buffer + _renderer.quadBatcher.flush(); + + _elements.resize(0); + } + + override function fill(color:FlxColor, blendAlpha:Bool = true) + { + // super.fill(color, blendAlpha); + } + + override function drawPixels(pixels, matrix, ?transform, ?blend, smoothing = false, ?shader) + { + // super.drawPixels(frame, matrix, transform, blend, smoothing, shader); + throw "Not implemented"; + } + + override function copyPixels(pixels, ?sourceRect, destPoint, ?transform, ?blend, smoothing = false, ?shader) + { + // super.copyPixels(pixels, sourceRect, destPoint, transform, blend, smoothing, shader); + throw "Not implemented"; + } + + override function drawFrame(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader) + { + // super.drawFrame(frame, matrix, transform, blend, smoothing, shader); + // _renderer.QuadBatcher.addQuad(frame, matrix,) + + var mat = new FlxMatrix(); + mat.copyFrom(matrix); + + // var quad = quadElementPool.get(); + var quad = new FlxQuadBatchElement(); + quad.frame = frame; + quad.matrix = mat; + quad.colorTransform = transform; + quad.blend = blend; + quad.textureSmoothing = smoothing; + quad.shader = shader; + + _elements.push(quad); + + // _elements[_elementIndex++] = quad; + } + + @:noCompletion + static final _helperMatrix = new FlxMatrix(); + override function copyFrame(frame:FlxFrame, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) + { + // super.copyFrame(frame, destPoint, transform, blend, smoothing, shader); + } + + override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, + ?position:FlxPoint, ?blend:BlendMode, repeat = false, smoothing = false, ?transform:ColorTransform, ?shader:FlxShader) + { + // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); + } + + // ============================================================================= + //} endregion RENDERING + // ============================================================================= + + // ============================================================================= + //{ region DEBUG DRAW + // ============================================================================= + + public function beginDrawDebug():Void {} + + public function endDrawDebug():Void {} + + #if FLX_DEBUG + public function getDebugBuffer():FlxCanvas { return null; } + + function worldToDebugX(worldX:Float):Float + { + //TODO: find out what "debug space" actually is, rename and make public + return worldX; + } + + function worldToDebugY(worldY:Float):Float + { + //TODO: find out what "debug space" actually is, rename and make public + return worldY; + } + #end + + // ============================================================================= + //} endregion DEBUG DRAW + // ============================================================================= + + // ============================================================================= + //{ region HELPERS + // ============================================================================= + + public function offsetView(x:Float, y:Float):Void {} + + function updateInternals():Void {} + + function updateOffset():Void {} + + function updatePosition():Void {} + + function updateScale():Void {} + + function updateScrollRect():Void {} + + // ============================================================================= + //} endregion HELPERS + // ============================================================================= + + // ============================================================================= + //{ region GETTERS + // ============================================================================= + + function get_display():DisplayObjectContainer + { + return dummySprite; + } + + // ============================================================================= + //} endregion GETTERS + // ============================================================================= +} diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index 19da587b20..eb4692d301 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -526,7 +526,7 @@ class FlxQuadView extends FlxCameraView #if FLX_DEBUG - public function getDebugBuffer():FlxVertexBuffer + public function getDebugBuffer():FlxCanvas { return debugLayer.graphics; } From a261bfd186559fe69616c821a5ef7219342d48cb Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:20:19 +0100 Subject: [PATCH 67/72] remove accidental include --- flixel/system/render/gl/FlxGLView.hx | 176 --------------------------- 1 file changed, 176 deletions(-) delete mode 100644 flixel/system/render/gl/FlxGLView.hx diff --git a/flixel/system/render/gl/FlxGLView.hx b/flixel/system/render/gl/FlxGLView.hx deleted file mode 100644 index 9a8dc9c97a..0000000000 --- a/flixel/system/render/gl/FlxGLView.hx +++ /dev/null @@ -1,176 +0,0 @@ -package flixel.system.render.gl; - -import lime.graphics.opengl.GL; -import flixel.system.render.gl.FlxBatchElement.FlxQuadBatchElement; -import flixel.util.FlxPool; -import flixel.graphics.FlxGraphic; -import flixel.graphics.frames.FlxFrame; -import flixel.math.FlxMath; -import flixel.math.FlxMatrix; -import flixel.math.FlxPoint; -import flixel.system.FlxAssets.FlxShader; -import flixel.system.render.quad.FlxDrawTrianglesItem.DrawData; -import flixel.util.FlxColor; -import haxe.Constraints.Function; -import openfl.display.BlendMode; -import openfl.display.DisplayObjectContainer; -import openfl.display.Sprite; -import openfl.geom.ColorTransform; -import openfl.geom.Point; - -class FlxGLView extends FlxCameraView -{ - // TODO: abstract away the camera adding so that we don't need a flash sprite - var dummySprite:Sprite = new Sprite(); - - - var _elements:Array = []; - - var _renderer(get, never):FlxGLRenderer; - inline function get__renderer() return cast (FlxG.renderer, FlxGLRenderer); - - public function new(camera:FlxCamera) - { - super(camera); - - dummySprite.visible = false; - } - - // ============================================================================= - //{ region RENDERING - // ============================================================================= - - override function clear() - { - _renderer.resize(camera.width, camera.height); - } - - override function render() - { - // Submit all the collected sprites to the batcher - for (element in _elements) - _renderer.quadBatcher.add(cast element); - - // Force a flush to draw whatever was left in the buffer - _renderer.quadBatcher.flush(); - - _elements.resize(0); - } - - override function fill(color:FlxColor, blendAlpha:Bool = true) - { - // super.fill(color, blendAlpha); - } - - override function drawPixels(pixels, matrix, ?transform, ?blend, smoothing = false, ?shader) - { - // super.drawPixels(frame, matrix, transform, blend, smoothing, shader); - throw "Not implemented"; - } - - override function copyPixels(pixels, ?sourceRect, destPoint, ?transform, ?blend, smoothing = false, ?shader) - { - // super.copyPixels(pixels, sourceRect, destPoint, transform, blend, smoothing, shader); - throw "Not implemented"; - } - - override function drawFrame(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader) - { - // super.drawFrame(frame, matrix, transform, blend, smoothing, shader); - // _renderer.QuadBatcher.addQuad(frame, matrix,) - - var mat = new FlxMatrix(); - mat.copyFrom(matrix); - - // var quad = quadElementPool.get(); - var quad = new FlxQuadBatchElement(); - quad.frame = frame; - quad.matrix = mat; - quad.colorTransform = transform; - quad.blend = blend; - quad.textureSmoothing = smoothing; - quad.shader = shader; - - _elements.push(quad); - - // _elements[_elementIndex++] = quad; - } - - @:noCompletion - static final _helperMatrix = new FlxMatrix(); - override function copyFrame(frame:FlxFrame, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode, smoothing = false, ?shader:FlxShader) - { - // super.copyFrame(frame, destPoint, transform, blend, smoothing, shader); - } - - override function drawTriangles(graphic:FlxGraphic, vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, - ?position:FlxPoint, ?blend:BlendMode, repeat = false, smoothing = false, ?transform:ColorTransform, ?shader:FlxShader) - { - // super.drawTriangles(graphic, vertices, indices, uvtData, colors, position, blend, repeat, smoothing, transform, shader); - } - - // ============================================================================= - //} endregion RENDERING - // ============================================================================= - - // ============================================================================= - //{ region DEBUG DRAW - // ============================================================================= - - public function beginDrawDebug():Void {} - - public function endDrawDebug():Void {} - - #if FLX_DEBUG - public function getDebugBuffer():FlxCanvas { return null; } - - function worldToDebugX(worldX:Float):Float - { - //TODO: find out what "debug space" actually is, rename and make public - return worldX; - } - - function worldToDebugY(worldY:Float):Float - { - //TODO: find out what "debug space" actually is, rename and make public - return worldY; - } - #end - - // ============================================================================= - //} endregion DEBUG DRAW - // ============================================================================= - - // ============================================================================= - //{ region HELPERS - // ============================================================================= - - public function offsetView(x:Float, y:Float):Void {} - - function updateInternals():Void {} - - function updateOffset():Void {} - - function updatePosition():Void {} - - function updateScale():Void {} - - function updateScrollRect():Void {} - - // ============================================================================= - //} endregion HELPERS - // ============================================================================= - - // ============================================================================= - //{ region GETTERS - // ============================================================================= - - function get_display():DisplayObjectContainer - { - return dummySprite; - } - - // ============================================================================= - //} endregion GETTERS - // ============================================================================= -} From 087e710894fcd0a5c9cbd8733a2d816970ffd51b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:21:55 +0100 Subject: [PATCH 68/72] ooops --- flixel/system/render/FlxCanvas.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/render/FlxCanvas.hx b/flixel/system/render/FlxCanvas.hx index f3c447c83b..30950ce40b 100644 --- a/flixel/system/render/FlxCanvas.hx +++ b/flixel/system/render/FlxCanvas.hx @@ -16,7 +16,7 @@ import openfl.geom.Rectangle; abstract FlxCanvas(Graphics) from Graphics to Graphics { /** - * Wipes all drawn graphics from teh canvas + * Wipes all drawn graphics from the canvas */ public inline function clear():Void { From 74354a08d6c214e7d2b8ee8be71664a51494694e Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Wed, 18 Mar 2026 19:04:05 +0100 Subject: [PATCH 69/72] Deprecate and avoid using batching related functions Was causing crashes with the GL renderer as it doesn't use the FlxDrawItems at all. Seems like there's no functional difference between manually adding quads to a batch and just calling drawFrame() and having it done automatically. --- flixel/FlxCamera.hx | 8 ++++---- flixel/text/FlxBitmapText.hx | 6 +----- flixel/tile/FlxTilemap.hx | 6 +----- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index cf7690d44b..1bbea81fe0 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1765,21 +1765,21 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("camera.startQuadBatch() is deprecated, use view.startQuadBatch() instead.") // 6.2.0 + @:deprecated("camera.startQuadBatch() is deprecated, avoid it and use the draw methods from camera.view instead.") // 6.2.0 public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader) { return viewQuad.startQuadBatch(graphic, colored, hasColorOffsets, blend, smooth, shader); } @:noCompletion - @:deprecated("camera.startTrianglesBatch() is deprecated, use view.startTrianglesBatch() instead.") // 6.2.0 + @:deprecated("camera.startTrianglesBatch() is deprecated, avoid it and use the draw methods from camera.view instead.") // 6.2.0 public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { return viewQuad.startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader); } @:noCompletion - @:deprecated("camera.getNewDrawTrianglesItem() is deprecated, use view.getNewDrawTrianglesItem() instead.") // 6.2.0 + @:deprecated("camera.getNewDrawTrianglesItem() is deprecated, avoid it and use the draw methods from camera.view instead.") // 6.2.0 public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem { return viewQuad.getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader); @@ -1813,7 +1813,7 @@ class FlxCamera extends FlxBasic } @:noCompletion - @:deprecated("camera.clearDrawStack() is deprecated, use camera.viewQuad.render() instead.") // 6.2.0 + @:deprecated("camera.clearDrawStack() is deprecated, use camera.view.clear() instead.") // 6.2.0 function clearDrawStack():Void { viewQuad.clearDrawStack(); diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index 8ceca5e933..de07365b6a 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -408,10 +408,6 @@ class FlxBitmapText extends FlxSprite camera.view.drawFrame(FlxG.bitmap.whitePixel, matrix, colorTransform, blend, antialiasing); } - final hasColorOffsets = (colorTransform != null && colorTransform.hasRGBAOffsets()); - @:privateAccess - final view = camera.viewQuad; // TODO: handle better - final drawItem = view.startQuadBatch(font.parent, true, hasColorOffsets, blend, antialiasing, shader); function addQuad(charCode:Int, x:Float, y:Float, color:ColorTransform) { var frame = font.getCharFrame(charCode); @@ -432,7 +428,7 @@ class FlxBitmapText extends FlxSprite } matrix.translate(screenPos.x + originX, screenPos.y + originY); - drawItem.addQuad(frame, matrix, color); + camera.view.drawFrame(frame, matrix, color, blend, antialiasing, shader); } borderDrawData.forEach(addQuad.bind(_, _, _, borderColorTransform)); diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index b47b0814fc..dd22e2abd6 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -1033,7 +1033,6 @@ class FlxTypedTilemap extends FlxBaseTilemap var drawY:Float = 0; var scaledWidth:Float = 0; var scaledHeight:Float = 0; - var drawItem = null; if (FlxG.renderer.blit) { @@ -1048,9 +1047,6 @@ class FlxTypedTilemap extends FlxBaseTilemap scaledWidth = scaledTileWidth; scaledHeight = scaledTileHeight; - - var hasColorOffsets:Bool = (colorTransform != null && colorTransform.hasRGBAOffsets()); - drawItem = cast (camera.view, FlxQuadView).startQuadBatch(graphic, isColored, hasColorOffsets, blend, antialiasing, shader); } // Copy tile images into the tile buffer @@ -1133,7 +1129,7 @@ class FlxTypedTilemap extends FlxBaseTilemap _matrix.scale(scaleX, scaleY); _matrix.translate(drawX, drawY); - drawItem.addQuad(frame, _matrix, colorTransform); + camera.view.drawFrame(frame, _matrix, colorTransform, blend, antialiasing, shader); } } From f160941910476ced4ce5d6aadbb523339e50b9c3 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Thu, 26 Mar 2026 14:28:28 +0100 Subject: [PATCH 70/72] Add `FLX_RENDER_DRAWQUADS` flag --- flixel/system/macros/FlxDefines.hx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index 4e06969dd1..54c69ac9d1 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -135,6 +135,7 @@ private enum HelperDefine FLX_NO_DEFAULT_SOUND_EXT; /** Enables audio streaming related APIs */ FLX_STREAM_SOUND; + FLX_RENDER_DRAWQUADS; } class FlxDefines @@ -303,6 +304,8 @@ class FlxDefines if (defined(FLX_NO_UNIT_TEST)) define(FLX_OPENGL_AVAILABLE); #end + + define(FLX_RENDER_DRAWQUADS); defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); From e4c7928931bfd876aeab9c4f72effb8ff105f5fc Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Fri, 13 Mar 2026 22:37:20 +0100 Subject: [PATCH 71/72] Move some DRAW_QUADS specific things around --- flixel/FlxCamera.hx | 6 +- flixel/FlxStrip.hx | 2 +- flixel/graphics/tile/FlxDrawBaseItem.hx | 98 +---- flixel/graphics/tile/FlxDrawQuadsItem.hx | 152 +------- flixel/graphics/tile/FlxDrawTrianglesItem.hx | 361 +----------------- flixel/graphics/tile/FlxGraphicsShader.hx | 69 +--- flixel/system/FlxAssets.hx | 2 +- flixel/system/render/FlxCameraView.hx | 2 +- flixel/system/render/blit/FlxBlitView.hx | 2 +- flixel/system/render/quad/FlxDrawBaseItem.hx | 99 +++++ flixel/system/render/quad/FlxDrawQuadsItem.hx | 152 ++++++++ .../render/quad/FlxDrawTrianglesItem.hx | 360 +++++++++++++++++ .../system/render/quad/FlxGraphicsShader.hx | 69 ++++ flixel/system/render/quad/FlxQuadView.hx | 6 +- flixel/text/FlxBitmapText.hx | 2 +- 15 files changed, 701 insertions(+), 681 deletions(-) create mode 100644 flixel/system/render/quad/FlxDrawBaseItem.hx create mode 100644 flixel/system/render/quad/FlxDrawQuadsItem.hx create mode 100644 flixel/system/render/quad/FlxDrawTrianglesItem.hx create mode 100644 flixel/system/render/quad/FlxGraphicsShader.hx diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 1bbea81fe0..2abc1bcc67 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -2,9 +2,9 @@ package flixel; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem; -import flixel.graphics.tile.FlxDrawQuadsItem; -import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.system.render.quad.FlxDrawBaseItem; +import flixel.system.render.quad.FlxDrawQuadsItem; +import flixel.system.render.quad.FlxDrawTrianglesItem; import flixel.math.FlxMath; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; diff --git a/flixel/FlxStrip.hx b/flixel/FlxStrip.hx index 9f34e21b50..5fedcadfc1 100644 --- a/flixel/FlxStrip.hx +++ b/flixel/FlxStrip.hx @@ -1,6 +1,6 @@ package flixel; -import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData; +import flixel.system.render.quad.FlxDrawTrianglesItem.DrawData; /** * A very basic rendering component which uses `drawTriangles()`. diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index 3f216571c4..cf63e498fc 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -1,98 +1,4 @@ package flixel.graphics.tile; -import flixel.FlxCamera; -import flixel.graphics.frames.FlxFrame; -import flixel.math.FlxMatrix; -import flixel.system.render.FlxRenderer; -import openfl.display.BlendMode; -import openfl.geom.ColorTransform; - -/** - * @author Zaphod - */ -class FlxDrawBaseItem -{ - /** - * Tracks the total number of draw calls made each frame. - */ - @:deprecated("drawCalls is deprecated, use FlxG.renderer.totalDrawCalls instead") - public static var drawCalls(get, set):Int; - - static function set_drawCalls(value:Int):Int - { - return FlxG.renderer.totalDrawCalls = value; - } - - static function get_drawCalls():Int - { - return FlxG.renderer.totalDrawCalls; - } - - @:noCompletion - @:deprecated("blendToInt() is deprecated, remove all references to it") - public static function blendToInt(blend:BlendMode):Int - { - return 0; // no blend mode support in drawQuads() - } - - public var nextTyped:T; - - public var next:FlxDrawBaseItem; - - public var graphics:FlxGraphic; - public var antialiasing:Bool = false; - public var colored:Bool = false; - public var hasColorOffsets:Bool = false; - public var blend:BlendMode; - - @:noCompletion - @:deprecated("blending is deprecated, remove all references to it") - public var blending:Int = 0; - - public var type:FlxDrawItemType; - - public var numVertices(get, never):Int; - - public var numTriangles(get, never):Int; - - public function new() {} - - public function reset():Void - { - graphics = null; - antialiasing = false; - nextTyped = null; - next = null; - } - - public function dispose():Void - { - graphics = null; - next = null; - type = null; - nextTyped = null; - } - - public function render(camera:FlxCamera):Void - { - FlxG.renderer.totalDrawCalls++; - } - - public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} - - function get_numVertices():Int - { - return 0; - } - - function get_numTriangles():Int - { - return 0; - } -} - -enum FlxDrawItemType -{ - TILES; - TRIANGLES; -} +@:deprecated("flixel.graphics.tile.FlxDrawBaseItem is deprecated, use flixel.system.render.quad.FlxBaseQuadsItem") +typedef FlxDrawBaseItem = flixel.system.render.quad.FlxDrawBaseItem; diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index b4b4b3573f..38a9da172c 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -1,152 +1,4 @@ package flixel.graphics.tile; -import flixel.FlxCamera; -import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem.FlxDrawItemType; -import flixel.math.FlxMatrix; -import flixel.system.FlxAssets.FlxShader; -import openfl.Vector; -import openfl.display.ShaderParameter; -import openfl.geom.ColorTransform; - -class FlxDrawQuadsItem extends FlxDrawBaseItem -{ - static inline var VERTICES_PER_QUAD = 4; - - public var shader:FlxShader; - - var rects:Vector; - var transforms:Vector; - var alphas:Array; - var colorMultipliers:Array; - var colorOffsets:Array; - - public function new() - { - super(); - type = FlxDrawItemType.TILES; - rects = new Vector(); - transforms = new Vector(); - alphas = []; - } - - override public function reset():Void - { - super.reset(); - rects.length = 0; - transforms.length = 0; - alphas.splice(0, alphas.length); - if (colorMultipliers != null) - colorMultipliers.splice(0, colorMultipliers.length); - if (colorOffsets != null) - colorOffsets.splice(0, colorOffsets.length); - } - - override public function dispose():Void - { - super.dispose(); - rects = null; - transforms = null; - alphas = null; - colorMultipliers = null; - colorOffsets = null; - } - - override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void - { - var rect = frame.frame; - rects.push(rect.x); - rects.push(rect.y); - rects.push(rect.width); - rects.push(rect.height); - - transforms.push(matrix.a); - transforms.push(matrix.b); - transforms.push(matrix.c); - transforms.push(matrix.d); - transforms.push(matrix.tx); - transforms.push(matrix.ty); - - var alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; - for (i in 0...VERTICES_PER_QUAD) - alphas.push(alphaMultiplier); - - if (colored || hasColorOffsets) - { - if (colorMultipliers == null) - colorMultipliers = []; - - if (colorOffsets == null) - colorOffsets = []; - - for (i in 0...VERTICES_PER_QUAD) - { - if (transform != null) - { - colorMultipliers.push(transform.redMultiplier); - colorMultipliers.push(transform.greenMultiplier); - colorMultipliers.push(transform.blueMultiplier); - - colorOffsets.push(transform.redOffset); - colorOffsets.push(transform.greenOffset); - colorOffsets.push(transform.blueOffset); - colorOffsets.push(transform.alphaOffset); - } - else - { - colorMultipliers.push(1); - colorMultipliers.push(1); - colorMultipliers.push(1); - - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - } - - colorMultipliers.push(1); - } - } - } - - #if !flash - override public function render(camera:FlxCamera):Void - { - if (rects.length == 0) - return; - - // TODO: catch this error when the dev actually messes up, not in the draw phase - if (shader == null && graphics.isDestroyed) - throw 'Attempted to render an invalid FlxDrawItem, did you destroy a cached sprite?'; - - final shader = shader != null ? shader : graphics.shader; - shader.bitmap.input = graphics.bitmap; - shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; - shader.alpha.value = alphas; - - if (colored || hasColorOffsets) - { - shader.colorMultiplier.value = colorMultipliers; - shader.colorOffset.value = colorOffsets; - } - - setParameterValue(shader.hasTransform, true); - setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - - @:privateAccess - final view = camera.viewQuad; - view.canvas.graphics.overrideBlendMode(blend); - view.canvas.graphics.beginShaderFill(shader); - view.canvas.graphics.drawQuads(rects, null, transforms); - view.canvas.graphics.endFill(); - super.render(camera); - } - - inline function setParameterValue(parameter:ShaderParameter, value:Bool):Void - { - if (parameter.value == null) - parameter.value = []; - parameter.value[0] = value; - } - #end -} +@:deprecated("flixel.graphics.tile.FlxDrawQuadsItem is deprecated, use flixel.system.render.quad.FlxDrawQuadsItem") +typedef FlxDrawQuadsItem = flixel.system.render.quad.FlxDrawQuadsItem; diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index 795c220a99..75cf97c38f 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -1,360 +1,7 @@ package flixel.graphics.tile; -import flixel.FlxCamera; -import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem.FlxDrawItemType; -import flixel.math.FlxMatrix; -import flixel.math.FlxPoint; -import flixel.math.FlxRect; -import flixel.system.FlxAssets.FlxShader; -import flixel.util.FlxColor; -import openfl.display.Graphics; -import openfl.display.ShaderParameter; -import openfl.display.TriangleCulling; -import openfl.geom.ColorTransform; +@:deprecated("flixel.graphics.tile.FlxDrawTrianglesItem is deprecated, use flixel.system.render.quad.FlxDrawTrianglesItem") +typedef FlxDrawTrianglesItem = flixel.system.render.quad.FlxDrawTrianglesItem; -typedef DrawData = openfl.Vector; - -/** - * @author Zaphod - */ -class FlxDrawTrianglesItem extends FlxDrawBaseItem -{ - static inline final INDICES_PER_QUAD = 6; - static var point:FlxPoint = FlxPoint.get(); - static var rect:FlxRect = FlxRect.get(); - - public var shader:FlxShader; - var alphas:Array; - var colorMultipliers:Array; - var colorOffsets:Array; - - public var vertices:DrawData = new DrawData(); - public var indices:DrawData = new DrawData(); - public var uvtData:DrawData = new DrawData(); - @:deprecated("colors is deprecated, use colorMultipliers and colorOffsets") - public var colors:DrawData = new DrawData(); - - public var verticesPosition:Int = 0; - public var indicesPosition:Int = 0; - @:deprecated("colorsPosition is deprecated") - public var colorsPosition:Int = 0; - - var bounds:FlxRect = FlxRect.get(); - - public function new() - { - super(); - type = FlxDrawItemType.TRIANGLES; - alphas = []; - } - - override public function render(camera:FlxCamera):Void - { - if (numTriangles <= 0) - return; - - @:privateAccess - final view = camera.viewQuad; - - #if !flash - var shader = shader != null ? shader : graphics.shader; - shader.bitmap.input = graphics.bitmap; - shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; - shader.bitmap.wrap = REPEAT; // in order to prevent breaking tiling behaviour in classes that use drawTriangles - shader.alpha.value = alphas; - - if (colored || hasColorOffsets) - { - shader.colorMultiplier.value = colorMultipliers; - shader.colorOffset.value = colorOffsets; - } - else - { - shader.colorMultiplier.value = null; - shader.colorOffset.value = null; - } - - setParameterValue(shader.hasTransform, true); - setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - - view.canvas.graphics.overrideBlendMode(blend); - - view.canvas.graphics.beginShaderFill(shader); - #else - view.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.view.antialiasing || antialiasing)); - #end - - view.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); - view.canvas.graphics.endFill(); - - #if FLX_DEBUG - if (FlxG.debugger.drawDebug) - { - var gfx:Graphics = view.debugLayer.graphics; - gfx.lineStyle(1, FlxColor.BLUE, 0.5); - gfx.drawTriangles(vertices, indices, uvtData); - } - #end - - super.render(camera); - } - - override public function reset():Void - { - super.reset(); - vertices.length = 0; - indices.length = 0; - uvtData.length = 0; - - verticesPosition = 0; - indicesPosition = 0; - alphas.splice(0, alphas.length); - if (colorMultipliers != null) - colorMultipliers.splice(0, colorMultipliers.length); - if (colorOffsets != null) - colorOffsets.splice(0, colorOffsets.length); - } - - override public function dispose():Void - { - super.dispose(); - - vertices = null; - indices = null; - uvtData = null; - bounds = null; - alphas = null; - colorMultipliers = null; - colorOffsets = null; - } - - public function addTriangles(vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, - ?cameraBounds:FlxRect, ?transform:ColorTransform):Void - { - if (position == null) - position = point.zero(); - - if (cameraBounds == null) - cameraBounds = rect.set(0, 0, FlxG.width, FlxG.height); - - var verticesLength:Int = vertices.length; - var prevVerticesLength:Int = this.vertices.length; - var numberOfVertices:Int = Std.int(verticesLength / 2); - var prevIndicesLength:Int = this.indices.length; - var prevUVTDataLength:Int = this.uvtData.length; - var prevNumberOfVertices:Int = this.numVertices; - - var tempX:Float, tempY:Float; - var i:Int = 0; - var currentVertexPosition:Int = prevVerticesLength; - - while (i < verticesLength) - { - tempX = position.x + vertices[i]; - tempY = position.y + vertices[i + 1]; - - this.vertices[currentVertexPosition++] = tempX; - this.vertices[currentVertexPosition++] = tempY; - - if (i == 0) - { - bounds.set(tempX, tempY, 0, 0); - } - else - { - inflateBounds(bounds, tempX, tempY); - } - - i += 2; - } - - var indicesLength:Int = indices.length; - if (!cameraBounds.overlaps(bounds)) - { - this.vertices.splice(this.vertices.length - verticesLength, verticesLength); - } - else - { - var uvtDataLength:Int = uvtData.length; - for (i in 0...uvtDataLength) - { - this.uvtData[prevUVTDataLength + i] = uvtData[i]; - } - - for (i in 0...indicesLength) - { - this.indices[prevIndicesLength + i] = indices[i] + prevNumberOfVertices; - } - - final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; - for (_ in 0...indicesLength) - alphas.push(alphaMultiplier); - - if (colored || hasColorOffsets) - { - if (colorMultipliers == null) - colorMultipliers = []; - - if (colorOffsets == null) - colorOffsets = []; - - for (_ in 0...indicesLength) - { - if (transform != null) - { - colorMultipliers.push(transform.redMultiplier); - colorMultipliers.push(transform.greenMultiplier); - colorMultipliers.push(transform.blueMultiplier); - - colorOffsets.push(transform.redOffset); - colorOffsets.push(transform.greenOffset); - colorOffsets.push(transform.blueOffset); - colorOffsets.push(transform.alphaOffset); - } - else - { - colorMultipliers.push(1); - colorMultipliers.push(1); - colorMultipliers.push(1); - - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - } - - colorMultipliers.push(1); - } - } - - verticesPosition += verticesLength; - indicesPosition += indicesLength; - } - - position.putWeak(); - cameraBounds.putWeak(); - } - - inline function setParameterValue(parameter:ShaderParameter, value:Bool):Void - { - if (parameter.value == null) - parameter.value = []; - parameter.value[0] = value; - } - - public static inline function inflateBounds(bounds:FlxRect, x:Float, y:Float):FlxRect - { - if (x < bounds.x) - { - bounds.width += bounds.x - x; - bounds.x = x; - } - - if (y < bounds.y) - { - bounds.height += bounds.y - y; - bounds.y = y; - } - - if (x > bounds.x + bounds.width) - { - bounds.width = x - bounds.x; - } - - if (y > bounds.y + bounds.height) - { - bounds.height = y - bounds.y; - } - - return bounds; - } - - override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void - { - final prevVerticesPos = verticesPosition; - final prevNumberOfVertices = numVertices; - - final w = frame.frame.width; - final h = frame.frame.height; - vertices[prevVerticesPos + 0] = matrix.transformX(0, 0); // left - vertices[prevVerticesPos + 1] = matrix.transformY(0, 0); // top - vertices[prevVerticesPos + 2] = matrix.transformX(w, 0); // right - vertices[prevVerticesPos + 3] = matrix.transformY(w, 0); // top - vertices[prevVerticesPos + 4] = matrix.transformX(0, h); // left - vertices[prevVerticesPos + 5] = matrix.transformY(0, h); // bottom - vertices[prevVerticesPos + 6] = matrix.transformX(w, h); // right - vertices[prevVerticesPos + 7] = matrix.transformY(w, h); // bottom - - uvtData[prevVerticesPos + 0] = frame.uv.left; - uvtData[prevVerticesPos + 1] = frame.uv.top; - uvtData[prevVerticesPos + 2] = frame.uv.right; - uvtData[prevVerticesPos + 3] = frame.uv.top; - uvtData[prevVerticesPos + 4] = frame.uv.left; - uvtData[prevVerticesPos + 5] = frame.uv.bottom; - uvtData[prevVerticesPos + 6] = frame.uv.right; - uvtData[prevVerticesPos + 7] = frame.uv.bottom; - - final prevIndicesPos = indicesPosition; - indices[prevIndicesPos + 0] = prevNumberOfVertices + 0; // TL - indices[prevIndicesPos + 1] = prevNumberOfVertices + 1; // TR - indices[prevIndicesPos + 2] = prevNumberOfVertices + 2; // BL - indices[prevIndicesPos + 3] = prevNumberOfVertices + 1; // TR - indices[prevIndicesPos + 4] = prevNumberOfVertices + 2; // BL - indices[prevIndicesPos + 5] = prevNumberOfVertices + 3; // BR - - final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; - for (i in 0...INDICES_PER_QUAD) - alphas.push(alphaMultiplier); - - if (colored || hasColorOffsets) - { - if (colorMultipliers == null) - colorMultipliers = []; - - if (colorOffsets == null) - colorOffsets = []; - - for (i in 0...INDICES_PER_QUAD) - { - if (transform != null) - { - colorMultipliers.push(transform.redMultiplier); - colorMultipliers.push(transform.greenMultiplier); - colorMultipliers.push(transform.blueMultiplier); - - colorOffsets.push(transform.redOffset); - colorOffsets.push(transform.greenOffset); - colorOffsets.push(transform.blueOffset); - colorOffsets.push(transform.alphaOffset); - } - else - { - colorMultipliers.push(1); - colorMultipliers.push(1); - colorMultipliers.push(1); - - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - colorOffsets.push(0); - } - - colorMultipliers.push(1); - } - } - - verticesPosition += 8; - indicesPosition += 6; - } - - override function get_numVertices():Int - { - return Std.int(vertices.length / 2); - } - - override function get_numTriangles():Int - { - return Std.int(indices.length / 3); - } -} +@:deprecated("flixel.graphics.tile.FlxDrawTrianglesItem.DrawData is deprecated, use flixel.system.render.quad.FlxDrawTrianglesItem.DrawData") +typedef DrawData = flixel.system.render.quad.FlxDrawTrianglesItem.DrawData; diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index 02a092d1e9..6796164ce9 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -1,69 +1,4 @@ package flixel.graphics.tile; -import openfl.display.GraphicsShader; - -class FlxGraphicsShader extends GraphicsShader -{ - @:glVertexHeader(" - attribute float alpha; - attribute vec4 colorMultiplier; - attribute vec4 colorOffset; - uniform bool hasColorTransform; - ", true) - @:glVertexBody(" - openfl_Alphav = openfl_Alpha * alpha; - - if (hasColorTransform) - { - if (openfl_HasColorTransform) - { - openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0); - openfl_ColorMultiplierv *= colorMultiplier; - } - else - { - openfl_ColorOffsetv = colorOffset / 255.0; - openfl_ColorMultiplierv = colorMultiplier; - } - } - ", true) - @:glFragmentHeader(" - uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes! - uniform bool hasColorTransform; - vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) - { - vec4 color = texture2D(bitmap, coord); - if (!(hasTransform || openfl_HasColorTransform)) - return color; - - if (color.a == 0.0) - return vec4(0.0, 0.0, 0.0, 0.0); - - if (openfl_HasColorTransform || hasColorTransform) - { - color = vec4 (color.rgb / color.a, color.a); - vec4 mult = vec4 (openfl_ColorMultiplierv.rgb, 1.0); - color = clamp (openfl_ColorOffsetv + (color * mult), 0.0, 1.0); - - if (color.a == 0.0) - return vec4 (0.0, 0.0, 0.0, 0.0); - - return vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); - } - - return color * openfl_Alphav; - } - ", true) - @:glFragmentSource(" - #pragma header - - void main(void) - { - gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv); - } - ", true) - public function new() - { - super(); - } -} +@:deprecated("flixel.graphics.tile.FlxGraphicsShader is deprecated, use flixel.system.render.quad.FlxGraphicsShader") +typedef FlxGraphicsShader = flixel.system.render.quad.FlxGraphicsShader; diff --git a/flixel/system/FlxAssets.hx b/flixel/system/FlxAssets.hx index 70d1486415..c83c31af9c 100644 --- a/flixel/system/FlxAssets.hx +++ b/flixel/system/FlxAssets.hx @@ -133,7 +133,7 @@ abstract FlxJsonAsset(OneOfTwo) from T from String } } -typedef FlxShader = #if nme Dynamic #else flixel.graphics.tile.FlxGraphicsShader #end; +typedef FlxShader = #if nme Dynamic #else flixel.system.render.quad.FlxGraphicsShader #end; #end class FlxAssets diff --git a/flixel/system/render/FlxCameraView.hx b/flixel/system/render/FlxCameraView.hx index 834cae2c9f..216f409fa0 100644 --- a/flixel/system/render/FlxCameraView.hx +++ b/flixel/system/render/FlxCameraView.hx @@ -4,7 +4,7 @@ import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.system.render.quad.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; diff --git a/flixel/system/render/blit/FlxBlitView.hx b/flixel/system/render/blit/FlxBlitView.hx index 139e2a7643..251395f162 100644 --- a/flixel/system/render/blit/FlxBlitView.hx +++ b/flixel/system/render/blit/FlxBlitView.hx @@ -4,7 +4,7 @@ import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.system.render.quad.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; diff --git a/flixel/system/render/quad/FlxDrawBaseItem.hx b/flixel/system/render/quad/FlxDrawBaseItem.hx new file mode 100644 index 0000000000..5bede903c7 --- /dev/null +++ b/flixel/system/render/quad/FlxDrawBaseItem.hx @@ -0,0 +1,99 @@ +package flixel.system.render.quad; + +import flixel.FlxCamera; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxFrame; +import flixel.math.FlxMatrix; +import flixel.system.render.FlxRenderer; +import openfl.display.BlendMode; +import openfl.geom.ColorTransform; + +/** + * @author Zaphod + */ +class FlxDrawBaseItem +{ + /** + * Tracks the total number of draw calls made each frame. + */ + @:deprecated("drawCalls is deprecated, use FlxG.renderer.totalDrawCalls instead") + public static var drawCalls(get, set):Int; + + static function set_drawCalls(value:Int):Int + { + return FlxG.renderer.totalDrawCalls = value; + } + + static function get_drawCalls():Int + { + return FlxG.renderer.totalDrawCalls; + } + + @:noCompletion + @:deprecated("blendToInt() is deprecated, remove all references to it") + public static function blendToInt(blend:BlendMode):Int + { + return 0; // no blend mode support in drawQuads() + } + + public var nextTyped:T; + + public var next:FlxDrawBaseItem; + + public var graphics:FlxGraphic; + public var antialiasing:Bool = false; + public var colored:Bool = false; + public var hasColorOffsets:Bool = false; + public var blend:BlendMode; + + @:noCompletion + @:deprecated("blending is deprecated, remove all references to it") + public var blending:Int = 0; + + public var type:FlxDrawItemType; + + public var numVertices(get, never):Int; + + public var numTriangles(get, never):Int; + + public function new() {} + + public function reset():Void + { + graphics = null; + antialiasing = false; + nextTyped = null; + next = null; + } + + public function dispose():Void + { + graphics = null; + next = null; + type = null; + nextTyped = null; + } + + public function render(camera:FlxCamera):Void + { + FlxG.renderer.totalDrawCalls++; + } + + public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} + + function get_numVertices():Int + { + return 0; + } + + function get_numTriangles():Int + { + return 0; + } +} + +enum FlxDrawItemType +{ + TILES; + TRIANGLES; +} diff --git a/flixel/system/render/quad/FlxDrawQuadsItem.hx b/flixel/system/render/quad/FlxDrawQuadsItem.hx new file mode 100644 index 0000000000..c89eca01f3 --- /dev/null +++ b/flixel/system/render/quad/FlxDrawQuadsItem.hx @@ -0,0 +1,152 @@ +package flixel.system.render.quad; + +import flixel.FlxCamera; +import flixel.graphics.frames.FlxFrame; +import flixel.system.render.quad.FlxDrawBaseItem.FlxDrawItemType; +import flixel.math.FlxMatrix; +import flixel.system.FlxAssets.FlxShader; +import openfl.Vector; +import openfl.display.ShaderParameter; +import openfl.geom.ColorTransform; + +class FlxDrawQuadsItem extends FlxDrawBaseItem +{ + static inline var VERTICES_PER_QUAD = 4; + + public var shader:FlxShader; + + var rects:Vector; + var transforms:Vector; + var alphas:Array; + var colorMultipliers:Array; + var colorOffsets:Array; + + public function new() + { + super(); + type = FlxDrawItemType.TILES; + rects = new Vector(); + transforms = new Vector(); + alphas = []; + } + + override public function reset():Void + { + super.reset(); + rects.length = 0; + transforms.length = 0; + alphas.splice(0, alphas.length); + if (colorMultipliers != null) + colorMultipliers.splice(0, colorMultipliers.length); + if (colorOffsets != null) + colorOffsets.splice(0, colorOffsets.length); + } + + override public function dispose():Void + { + super.dispose(); + rects = null; + transforms = null; + alphas = null; + colorMultipliers = null; + colorOffsets = null; + } + + override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void + { + var rect = frame.frame; + rects.push(rect.x); + rects.push(rect.y); + rects.push(rect.width); + rects.push(rect.height); + + transforms.push(matrix.a); + transforms.push(matrix.b); + transforms.push(matrix.c); + transforms.push(matrix.d); + transforms.push(matrix.tx); + transforms.push(matrix.ty); + + var alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; + for (i in 0...VERTICES_PER_QUAD) + alphas.push(alphaMultiplier); + + if (colored || hasColorOffsets) + { + if (colorMultipliers == null) + colorMultipliers = []; + + if (colorOffsets == null) + colorOffsets = []; + + for (i in 0...VERTICES_PER_QUAD) + { + if (transform != null) + { + colorMultipliers.push(transform.redMultiplier); + colorMultipliers.push(transform.greenMultiplier); + colorMultipliers.push(transform.blueMultiplier); + + colorOffsets.push(transform.redOffset); + colorOffsets.push(transform.greenOffset); + colorOffsets.push(transform.blueOffset); + colorOffsets.push(transform.alphaOffset); + } + else + { + colorMultipliers.push(1); + colorMultipliers.push(1); + colorMultipliers.push(1); + + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + } + + colorMultipliers.push(1); + } + } + } + + #if !flash + override public function render(camera:FlxCamera):Void + { + if (rects.length == 0) + return; + + // TODO: catch this error when the dev actually messes up, not in the draw phase + if (shader == null && graphics.isDestroyed) + throw 'Attempted to render an invalid FlxDrawItem, did you destroy a cached sprite?'; + + final shader = shader != null ? shader : graphics.shader; + shader.bitmap.input = graphics.bitmap; + shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; + shader.alpha.value = alphas; + + if (colored || hasColorOffsets) + { + shader.colorMultiplier.value = colorMultipliers; + shader.colorOffset.value = colorOffsets; + } + + setParameterValue(shader.hasTransform, true); + setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); + + @:privateAccess + final view = camera.viewQuad; + view.canvas.graphics.overrideBlendMode(blend); + view.canvas.graphics.beginShaderFill(shader); + view.canvas.graphics.drawQuads(rects, null, transforms); + view.canvas.graphics.endFill(); + super.render(camera); + } + + inline function setParameterValue(parameter:ShaderParameter, value:Bool):Void + { + if (parameter.value == null) + parameter.value = []; + parameter.value[0] = value; + } + #end +} diff --git a/flixel/system/render/quad/FlxDrawTrianglesItem.hx b/flixel/system/render/quad/FlxDrawTrianglesItem.hx new file mode 100644 index 0000000000..afacd5e82b --- /dev/null +++ b/flixel/system/render/quad/FlxDrawTrianglesItem.hx @@ -0,0 +1,360 @@ +package flixel.system.render.quad; + +import flixel.FlxCamera; +import flixel.graphics.frames.FlxFrame; +import flixel.system.render.quad.FlxDrawBaseItem.FlxDrawItemType; +import flixel.math.FlxMatrix; +import flixel.math.FlxPoint; +import flixel.math.FlxRect; +import flixel.system.FlxAssets.FlxShader; +import flixel.util.FlxColor; +import openfl.display.Graphics; +import openfl.display.ShaderParameter; +import openfl.display.TriangleCulling; +import openfl.geom.ColorTransform; + +typedef DrawData = openfl.Vector; + +/** + * @author Zaphod + */ +class FlxDrawTrianglesItem extends FlxDrawBaseItem +{ + static inline final INDICES_PER_QUAD = 6; + static var point:FlxPoint = FlxPoint.get(); + static var rect:FlxRect = FlxRect.get(); + + public var shader:FlxShader; + var alphas:Array; + var colorMultipliers:Array; + var colorOffsets:Array; + + public var vertices:DrawData = new DrawData(); + public var indices:DrawData = new DrawData(); + public var uvtData:DrawData = new DrawData(); + @:deprecated("colors is deprecated, use colorMultipliers and colorOffsets") + public var colors:DrawData = new DrawData(); + + public var verticesPosition:Int = 0; + public var indicesPosition:Int = 0; + @:deprecated("colorsPosition is deprecated") + public var colorsPosition:Int = 0; + + var bounds:FlxRect = FlxRect.get(); + + public function new() + { + super(); + type = FlxDrawItemType.TRIANGLES; + alphas = []; + } + + override public function render(camera:FlxCamera):Void + { + if (numTriangles <= 0) + return; + + @:privateAccess + final view = camera.viewQuad; + + #if !flash + var shader = shader != null ? shader : graphics.shader; + shader.bitmap.input = graphics.bitmap; + shader.bitmap.filter = (camera.view.antialiasing || antialiasing) ? LINEAR : NEAREST; + shader.bitmap.wrap = REPEAT; // in order to prevent breaking tiling behaviour in classes that use drawTriangles + shader.alpha.value = alphas; + + if (colored || hasColorOffsets) + { + shader.colorMultiplier.value = colorMultipliers; + shader.colorOffset.value = colorOffsets; + } + else + { + shader.colorMultiplier.value = null; + shader.colorOffset.value = null; + } + + setParameterValue(shader.hasTransform, true); + setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); + + view.canvas.graphics.overrideBlendMode(blend); + + view.canvas.graphics.beginShaderFill(shader); + #else + view.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing)); + #end + + view.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); + view.canvas.graphics.endFill(); + + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + { + var gfx:Graphics = view.debugLayer.graphics; + gfx.lineStyle(1, FlxColor.BLUE, 0.5); + gfx.drawTriangles(vertices, indices, uvtData); + } + #end + + super.render(camera); + } + + override public function reset():Void + { + super.reset(); + vertices.length = 0; + indices.length = 0; + uvtData.length = 0; + + verticesPosition = 0; + indicesPosition = 0; + alphas.splice(0, alphas.length); + if (colorMultipliers != null) + colorMultipliers.splice(0, colorMultipliers.length); + if (colorOffsets != null) + colorOffsets.splice(0, colorOffsets.length); + } + + override public function dispose():Void + { + super.dispose(); + + vertices = null; + indices = null; + uvtData = null; + bounds = null; + alphas = null; + colorMultipliers = null; + colorOffsets = null; + } + + public function addTriangles(vertices:DrawData, indices:DrawData, uvtData:DrawData, ?colors:DrawData, ?position:FlxPoint, + ?cameraBounds:FlxRect, ?transform:ColorTransform):Void + { + if (position == null) + position = point.zero(); + + if (cameraBounds == null) + cameraBounds = rect.set(0, 0, FlxG.width, FlxG.height); + + var verticesLength:Int = vertices.length; + var prevVerticesLength:Int = this.vertices.length; + var numberOfVertices:Int = Std.int(verticesLength / 2); + var prevIndicesLength:Int = this.indices.length; + var prevUVTDataLength:Int = this.uvtData.length; + var prevNumberOfVertices:Int = this.numVertices; + + var tempX:Float, tempY:Float; + var i:Int = 0; + var currentVertexPosition:Int = prevVerticesLength; + + while (i < verticesLength) + { + tempX = position.x + vertices[i]; + tempY = position.y + vertices[i + 1]; + + this.vertices[currentVertexPosition++] = tempX; + this.vertices[currentVertexPosition++] = tempY; + + if (i == 0) + { + bounds.set(tempX, tempY, 0, 0); + } + else + { + inflateBounds(bounds, tempX, tempY); + } + + i += 2; + } + + var indicesLength:Int = indices.length; + if (!cameraBounds.overlaps(bounds)) + { + this.vertices.splice(this.vertices.length - verticesLength, verticesLength); + } + else + { + var uvtDataLength:Int = uvtData.length; + for (i in 0...uvtDataLength) + { + this.uvtData[prevUVTDataLength + i] = uvtData[i]; + } + + for (i in 0...indicesLength) + { + this.indices[prevIndicesLength + i] = indices[i] + prevNumberOfVertices; + } + + final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; + for (_ in 0...indicesLength) + alphas.push(alphaMultiplier); + + if (colored || hasColorOffsets) + { + if (colorMultipliers == null) + colorMultipliers = []; + + if (colorOffsets == null) + colorOffsets = []; + + for (_ in 0...indicesLength) + { + if (transform != null) + { + colorMultipliers.push(transform.redMultiplier); + colorMultipliers.push(transform.greenMultiplier); + colorMultipliers.push(transform.blueMultiplier); + + colorOffsets.push(transform.redOffset); + colorOffsets.push(transform.greenOffset); + colorOffsets.push(transform.blueOffset); + colorOffsets.push(transform.alphaOffset); + } + else + { + colorMultipliers.push(1); + colorMultipliers.push(1); + colorMultipliers.push(1); + + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + } + + colorMultipliers.push(1); + } + } + + verticesPosition += verticesLength; + indicesPosition += indicesLength; + } + + position.putWeak(); + cameraBounds.putWeak(); + } + + inline function setParameterValue(parameter:ShaderParameter, value:Bool):Void + { + if (parameter.value == null) + parameter.value = []; + parameter.value[0] = value; + } + + public static inline function inflateBounds(bounds:FlxRect, x:Float, y:Float):FlxRect + { + if (x < bounds.x) + { + bounds.width += bounds.x - x; + bounds.x = x; + } + + if (y < bounds.y) + { + bounds.height += bounds.y - y; + bounds.y = y; + } + + if (x > bounds.x + bounds.width) + { + bounds.width = x - bounds.x; + } + + if (y > bounds.y + bounds.height) + { + bounds.height = y - bounds.y; + } + + return bounds; + } + + override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void + { + final prevVerticesPos = verticesPosition; + final prevNumberOfVertices = numVertices; + + final w = frame.frame.width; + final h = frame.frame.height; + vertices[prevVerticesPos + 0] = matrix.transformX(0, 0); // left + vertices[prevVerticesPos + 1] = matrix.transformY(0, 0); // top + vertices[prevVerticesPos + 2] = matrix.transformX(w, 0); // right + vertices[prevVerticesPos + 3] = matrix.transformY(w, 0); // top + vertices[prevVerticesPos + 4] = matrix.transformX(0, h); // left + vertices[prevVerticesPos + 5] = matrix.transformY(0, h); // bottom + vertices[prevVerticesPos + 6] = matrix.transformX(w, h); // right + vertices[prevVerticesPos + 7] = matrix.transformY(w, h); // bottom + + uvtData[prevVerticesPos + 0] = frame.uv.left; + uvtData[prevVerticesPos + 1] = frame.uv.top; + uvtData[prevVerticesPos + 2] = frame.uv.right; + uvtData[prevVerticesPos + 3] = frame.uv.top; + uvtData[prevVerticesPos + 4] = frame.uv.left; + uvtData[prevVerticesPos + 5] = frame.uv.bottom; + uvtData[prevVerticesPos + 6] = frame.uv.right; + uvtData[prevVerticesPos + 7] = frame.uv.bottom; + + final prevIndicesPos = indicesPosition; + indices[prevIndicesPos + 0] = prevNumberOfVertices + 0; // TL + indices[prevIndicesPos + 1] = prevNumberOfVertices + 1; // TR + indices[prevIndicesPos + 2] = prevNumberOfVertices + 2; // BL + indices[prevIndicesPos + 3] = prevNumberOfVertices + 1; // TR + indices[prevIndicesPos + 4] = prevNumberOfVertices + 2; // BL + indices[prevIndicesPos + 5] = prevNumberOfVertices + 3; // BR + + final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; + for (i in 0...INDICES_PER_QUAD) + alphas.push(alphaMultiplier); + + if (colored || hasColorOffsets) + { + if (colorMultipliers == null) + colorMultipliers = []; + + if (colorOffsets == null) + colorOffsets = []; + + for (i in 0...INDICES_PER_QUAD) + { + if (transform != null) + { + colorMultipliers.push(transform.redMultiplier); + colorMultipliers.push(transform.greenMultiplier); + colorMultipliers.push(transform.blueMultiplier); + + colorOffsets.push(transform.redOffset); + colorOffsets.push(transform.greenOffset); + colorOffsets.push(transform.blueOffset); + colorOffsets.push(transform.alphaOffset); + } + else + { + colorMultipliers.push(1); + colorMultipliers.push(1); + colorMultipliers.push(1); + + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + colorOffsets.push(0); + } + + colorMultipliers.push(1); + } + } + + verticesPosition += 8; + indicesPosition += 6; + } + + override function get_numVertices():Int + { + return Std.int(vertices.length / 2); + } + + override function get_numTriangles():Int + { + return Std.int(indices.length / 3); + } +} diff --git a/flixel/system/render/quad/FlxGraphicsShader.hx b/flixel/system/render/quad/FlxGraphicsShader.hx new file mode 100644 index 0000000000..7664d1dea4 --- /dev/null +++ b/flixel/system/render/quad/FlxGraphicsShader.hx @@ -0,0 +1,69 @@ +package flixel.system.render.quad; + +import openfl.display.GraphicsShader; + +class FlxGraphicsShader extends GraphicsShader +{ + @:glVertexHeader(" + attribute float alpha; + attribute vec4 colorMultiplier; + attribute vec4 colorOffset; + uniform bool hasColorTransform; + ", true) + @:glVertexBody(" + openfl_Alphav = openfl_Alpha * alpha; + + if (hasColorTransform) + { + if (openfl_HasColorTransform) + { + openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0); + openfl_ColorMultiplierv *= colorMultiplier; + } + else + { + openfl_ColorOffsetv = colorOffset / 255.0; + openfl_ColorMultiplierv = colorMultiplier; + } + } + ", true) + @:glFragmentHeader(" + uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes! + uniform bool hasColorTransform; + vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) + { + vec4 color = texture2D(bitmap, coord); + if (!(hasTransform || openfl_HasColorTransform)) + return color; + + if (color.a == 0.0) + return vec4(0.0, 0.0, 0.0, 0.0); + + if (openfl_HasColorTransform || hasColorTransform) + { + color = vec4 (color.rgb / color.a, color.a); + vec4 mult = vec4 (openfl_ColorMultiplierv.rgb, 1.0); + color = clamp (openfl_ColorOffsetv + (color * mult), 0.0, 1.0); + + if (color.a == 0.0) + return vec4 (0.0, 0.0, 0.0, 0.0); + + return vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); + } + + return color * openfl_Alphav; + } + ", true) + @:glFragmentSource(" + #pragma header + + void main(void) + { + gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv); + } + ", true) + public function new() + { + super(); + } +} diff --git a/flixel/system/render/quad/FlxQuadView.hx b/flixel/system/render/quad/FlxQuadView.hx index eb4692d301..aaac701754 100644 --- a/flixel/system/render/quad/FlxQuadView.hx +++ b/flixel/system/render/quad/FlxQuadView.hx @@ -4,9 +4,9 @@ import flixel.FlxCamera; import flixel.FlxG; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem; -import flixel.graphics.tile.FlxDrawQuadsItem; -import flixel.graphics.tile.FlxDrawTrianglesItem; +import flixel.system.render.quad.FlxDrawBaseItem; +import flixel.system.render.quad.FlxDrawQuadsItem; +import flixel.system.render.quad.FlxDrawTrianglesItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; diff --git a/flixel/text/FlxBitmapText.hx b/flixel/text/FlxBitmapText.hx index de07365b6a..67b5472c5b 100644 --- a/flixel/text/FlxBitmapText.hx +++ b/flixel/text/FlxBitmapText.hx @@ -5,7 +5,7 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.graphics.frames.FlxBitmapFont; import flixel.graphics.frames.FlxFrame; -import flixel.graphics.tile.FlxDrawBaseItem; +import flixel.system.render.quad.FlxDrawBaseItem; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; From bceadb99ae85efb3bb182958d56e20c73489ec51 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:31:28 +0100 Subject: [PATCH 72/72] typo --- flixel/graphics/tile/FlxDrawBaseItem.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index cf63e498fc..0a35a12fc7 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -1,4 +1,4 @@ package flixel.graphics.tile; -@:deprecated("flixel.graphics.tile.FlxDrawBaseItem is deprecated, use flixel.system.render.quad.FlxBaseQuadsItem") +@:deprecated("flixel.graphics.tile.FlxDrawBaseItem is deprecated, use flixel.system.render.quad.FlxDrawBaseItem") typedef FlxDrawBaseItem = flixel.system.render.quad.FlxDrawBaseItem;