diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 33039c793d..ff57e7bb7f 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -11,6 +11,7 @@ import openfl.geom.Rectangle; 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.FlxMath; import flixel.math.FlxMatrix; @@ -27,8 +28,6 @@ import openfl.filters.BitmapFilter; using flixel.util.FlxColorTransformUtil; -private typedef FlxDrawItem = flixel.graphics.tile.FlxDrawQuadsItem; - /** * 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. @@ -537,7 +536,7 @@ class FlxCamera extends FlxBasic /** * Last draw tiles item */ - var _headTiles:FlxDrawItem; + var _headTiles:FlxDrawQuadsItem; /** * Last draw triangles item @@ -547,7 +546,7 @@ class FlxCamera extends FlxBasic /** * Draw tiles stack items that can be reused */ - static var _storageTilesHead:FlxDrawItem; + static var _storageTilesHead:FlxDrawQuadsItem; /** * Draw triangles stack items that can be reused @@ -601,7 +600,7 @@ class FlxCamera extends FlxBasic } else { - itemToReturn = new FlxDrawItem(); + itemToReturn = new FlxDrawQuadsItem(); } // TODO: catch this error when the dev actually messes up, not in the draw phase @@ -765,9 +764,9 @@ class FlxCamera extends FlxBasic var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); #if FLX_RENDER_TRIANGLE - var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend); + final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader); #else - var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); + final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader); #end drawItem.addQuad(frame, matrix, transform); } @@ -808,10 +807,10 @@ class FlxCamera extends FlxBasic 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); } diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index b9cffcbb4e..da34d8dd6b 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -20,6 +20,7 @@ typedef DrawData = openfl.Vector; */ class FlxDrawTrianglesItem extends FlxDrawBaseItem { + static inline final INDICES_PER_QUAD = 6; static var point:FlxPoint = FlxPoint.get(); static var rect:FlxRect = FlxRect.get(); @@ -31,10 +32,12 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem 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(); @@ -100,11 +103,9 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem vertices.length = 0; indices.length = 0; uvtData.length = 0; - colors.length = 0; verticesPosition = 0; indicesPosition = 0; - colorsPosition = 0; alphas.splice(0, alphas.length); if (colorMultipliers != null) colorMultipliers.splice(0, colorMultipliers.length); @@ -119,7 +120,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem vertices = null; indices = null; uvtData = null; - colors = null; bounds = null; alphas = null; colorMultipliers = null; @@ -140,7 +140,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem var numberOfVertices:Int = Std.int(verticesLength / 2); var prevIndicesLength:Int = this.indices.length; var prevUVTDataLength:Int = this.uvtData.length; - var prevColorsLength:Int = this.colors.length; var prevNumberOfVertices:Int = this.numVertices; var tempX:Float, tempY:Float; @@ -184,16 +183,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem { this.indices[prevIndicesLength + i] = indices[i] + prevNumberOfVertices; } - - if (colored) - { - for (i in 0...numberOfVertices) - { - this.colors[prevColorsLength + i] = colors[i]; - } - - colorsPosition += numberOfVertices; - } final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; for (_ in 0...indicesLength) @@ -280,82 +269,76 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void { - var prevVerticesPos:Int = verticesPosition; - var prevIndicesPos:Int = indicesPosition; - var prevColorsPos:Int = colorsPosition; - var prevNumberOfVertices:Int = numVertices; - - var point = FlxPoint.get(); - point.transform(matrix); - - vertices[prevVerticesPos] = point.x; - vertices[prevVerticesPos + 1] = point.y; - - uvtData[prevVerticesPos] = frame.uv.left; + 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; - - point.set(frame.frame.width, 0); - point.transform(matrix); - - vertices[prevVerticesPos + 2] = point.x; - vertices[prevVerticesPos + 3] = point.y; - uvtData[prevVerticesPos + 2] = frame.uv.right; uvtData[prevVerticesPos + 3] = frame.uv.top; - - point.set(frame.frame.width, frame.frame.height); - point.transform(matrix); - - vertices[prevVerticesPos + 4] = point.x; - vertices[prevVerticesPos + 5] = point.y; - - uvtData[prevVerticesPos + 4] = frame.uv.right; + uvtData[prevVerticesPos + 4] = frame.uv.left; uvtData[prevVerticesPos + 5] = frame.uv.bottom; - - point.set(0, frame.frame.height); - point.transform(matrix); - - vertices[prevVerticesPos + 6] = point.x; - vertices[prevVerticesPos + 7] = point.y; - - point.put(); - - uvtData[prevVerticesPos + 6] = frame.uv.left; + uvtData[prevVerticesPos + 6] = frame.uv.right; uvtData[prevVerticesPos + 7] = frame.uv.bottom; - - indices[prevIndicesPos] = prevNumberOfVertices; - indices[prevIndicesPos + 1] = prevNumberOfVertices + 1; - indices[prevIndicesPos + 2] = prevNumberOfVertices + 2; - indices[prevIndicesPos + 3] = prevNumberOfVertices + 2; - indices[prevIndicesPos + 4] = prevNumberOfVertices + 3; - indices[prevIndicesPos + 5] = prevNumberOfVertices; - - if (colored) + + 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) { - var red = 1.0; - var green = 1.0; - var blue = 1.0; - var alpha = 1.0; - - if (transform != null) + if (colorMultipliers == null) + colorMultipliers = []; + + if (colorOffsets == null) + colorOffsets = []; + + for (i in 0...INDICES_PER_QUAD) { - red = transform.redMultiplier; - green = transform.greenMultiplier; - blue = transform.blueMultiplier; - - #if !neko - alpha = transform.alphaMultiplier; - #end + 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); } - - var color = FlxColor.fromRGBFloat(red, green, blue, alpha); - - colors[prevColorsPos] = color; - colors[prevColorsPos + 1] = color; - colors[prevColorsPos + 2] = color; - colors[prevColorsPos + 3] = color; - - colorsPosition += 4; } verticesPosition += 8;