forked from FunkinCrew/Funkin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,830 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,16 @@ | ||
{ | ||
"disableFormatting": false, | ||
|
||
"indentation": { | ||
"character": " ", | ||
"tabWidth": 1, | ||
"indentCaseLabels": true | ||
}, | ||
"lineEnds": { | ||
"anonFunctionCurly": { | ||
"emptyCurly": "break", | ||
"leftCurly": "after", | ||
"rightCurly": "both" | ||
}, | ||
"leftCurly": "both", | ||
"rightCurly": "both" | ||
}, | ||
|
||
"sameLine": { | ||
"ifBody": "same", | ||
"ifElse": "next", | ||
"doWhile": "next", | ||
"tryBody": "next", | ||
"tryCatch": "next" | ||
}, | ||
|
||
"whitespace": { | ||
"switchPolicy": "around" | ||
} | ||
"lineEnds": { | ||
"leftCurly": "both", | ||
"rightCurly": "both", | ||
"emptyCurly": "break", | ||
"objectLiteralCurly": { | ||
"leftCurly": "after" | ||
} | ||
}, | ||
"sameLine": { | ||
"ifElse": "next", | ||
"doWhile": "next", | ||
"tryBody": "next", | ||
"tryCatch": "next" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package flixel.graphics.tile; | ||
|
||
import openfl.display.ShaderParameter; | ||
import flixel.FlxCamera; | ||
import flixel.graphics.frames.FlxFrame; | ||
import flixel.math.FlxMatrix; | ||
import openfl.display.BlendMode; | ||
import openfl.geom.ColorTransform; | ||
|
||
/** | ||
* @author Zaphod | ||
*/ | ||
class FlxDrawBaseItem<T> | ||
{ | ||
/** | ||
* Tracks the total number of draw calls made each frame. | ||
*/ | ||
public static var drawCalls:Int = 0; | ||
|
||
public static inline function blendToInt(blend:BlendMode):Int | ||
{ | ||
return 0; // no blend mode support in drawQuads() | ||
} | ||
|
||
public var nextTyped:T; | ||
|
||
public var next:FlxDrawBaseItem<T>; | ||
|
||
public var graphics:FlxGraphic; | ||
public var antialiasing:Bool = false; | ||
public var colored(default, set):Bool = false; | ||
public var hasColorOffsets:Bool = false; | ||
public var blending:Int = 0; | ||
public var blend:BlendMode; | ||
|
||
public var type:Null<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 | ||
{ | ||
drawCalls++; | ||
} | ||
|
||
function set_colored(value:Bool) return colored = value; | ||
|
||
public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void {} | ||
|
||
function get_numVertices():Int | ||
{ | ||
return 0; | ||
} | ||
|
||
function get_numTriangles():Int | ||
{ | ||
return 0; | ||
} | ||
|
||
inline function setParameterValue(parameter:ShaderParameter<Bool>, value:Bool):Void | ||
{ | ||
if (parameter.value == null) | ||
parameter.value = []; | ||
parameter.value[0] = value; | ||
} | ||
} | ||
|
||
enum abstract FlxDrawItemType(Bool) { | ||
var TILES = false; | ||
var TRIANGLES = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package flixel.graphics.tile; | ||
|
||
import openfl.display.GraphicsShader; | ||
import openfl.display.Graphics; | ||
import flixel.FlxCamera; | ||
import flixel.graphics.frames.FlxFrame; | ||
import flixel.graphics.tile.FlxDrawBaseItem.FlxDrawItemType; | ||
import flixel.system.FlxAssets.FlxShader; | ||
import flixel.math.FlxMatrix; | ||
import openfl.geom.ColorTransform; | ||
import openfl.geom.Rectangle; | ||
import openfl.Vector; | ||
|
||
class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem> | ||
{ | ||
static inline var VERTICES_PER_QUAD = 4; | ||
|
||
public var shader:FlxShader; | ||
|
||
var rects:Vector<Float>; | ||
var transforms:Vector<Float>; | ||
var alphas:Array<Float>; | ||
var colorMultipliers:Array<Float>; | ||
var colorOffsets:Array<Float>; | ||
|
||
public function new() | ||
{ | ||
super(); | ||
type = FlxDrawItemType.TILES; | ||
rects = new Vector<Float>(); | ||
transforms = new Vector<Float>(); | ||
alphas = []; | ||
} | ||
|
||
override public function reset():Void | ||
{ | ||
super.reset(); | ||
rects.length = 0; | ||
transforms.length = 0; | ||
alphas.resize(0); | ||
if (colored) | ||
{ | ||
colorMultipliers.resize(0); | ||
colorOffsets.resize(0); | ||
} | ||
} | ||
|
||
override public function dispose():Void | ||
{ | ||
super.dispose(); | ||
rects = null; | ||
transforms = null; | ||
alphas = null; | ||
colorMultipliers = null; | ||
colorOffsets = null; | ||
} | ||
|
||
override inline function set_colored(value:Bool) { | ||
if (value) if (colorMultipliers == null) { | ||
colorMultipliers = []; | ||
colorOffsets = []; | ||
} | ||
return colored = value; | ||
} | ||
|
||
override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void | ||
{ | ||
rects.push(frame.frame.x); | ||
rects.push(frame.frame.y); | ||
rects.push(frame.frame.width); | ||
rects.push(frame.frame.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); | ||
|
||
final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0; | ||
for (i in 0...VERTICES_PER_QUAD) | ||
alphas.push(alphaMultiplier); | ||
|
||
if (colored) | ||
{ | ||
for (i in 0...VERTICES_PER_QUAD) | ||
{ | ||
colorMultipliers.push(transform.redMultiplier); | ||
colorMultipliers.push(transform.greenMultiplier); | ||
colorMultipliers.push(transform.blueMultiplier); | ||
colorMultipliers.push(1); | ||
|
||
colorOffsets.push(transform.redOffset); | ||
colorOffsets.push(transform.greenOffset); | ||
colorOffsets.push(transform.blueOffset); | ||
colorOffsets.push(transform.alphaOffset); | ||
} | ||
} | ||
} | ||
|
||
#if !flash | ||
override public function render(camera:FlxCamera):Void | ||
{ | ||
if (#if cpp untyped __cpp__('this->rects->_hx___array->length == 0') #else rects.length == 0 #end) | ||
return; | ||
|
||
if (shader == null) | ||
{ | ||
shader = graphics.shader; | ||
if (shader == null) | ||
return; | ||
} | ||
|
||
shader.bitmap.input = graphics.bitmap; | ||
shader.alpha.value = alphas; | ||
|
||
shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST; | ||
|
||
if (colored) | ||
{ | ||
shader.colorMultiplier.value = colorMultipliers; | ||
shader.colorOffset.value = colorOffsets; | ||
} | ||
|
||
setParameterValue(shader.hasColorTransform, colored); | ||
drawFlxQuad(camera.canvas.graphics, shader, rects, transforms); | ||
|
||
#if FLX_DEBUG | ||
FlxDrawBaseItem.drawCalls++; | ||
#end | ||
} | ||
|
||
// Copy pasted from openfl Graphics, made SPECIFICALLY to work with funkin draw quads | ||
|
||
private static final bounds:Rectangle = new Rectangle(0, 0, 1280, 720); | ||
|
||
function drawFlxQuad(graphics:Graphics, shader:GraphicsShader, rects:Vector<Float>, transforms:Vector<Float>):Void @:privateAccess | ||
{ | ||
// Override blend mode | ||
if (blend == null) blend = NORMAL; | ||
graphics.__commands.overrideBlendMode(blend); | ||
|
||
// Begin shader fill | ||
final shaderBuffer = graphics.__shaderBufferPool.get(); | ||
graphics.__usedShaderBuffers.add(shaderBuffer); | ||
shaderBuffer.update(shader); | ||
graphics.__commands.beginShaderFill(shaderBuffer); | ||
|
||
// Draw the quad | ||
if (graphics.__bounds == null) | ||
{ | ||
graphics.__bounds = bounds; | ||
graphics.__transformDirty = true; | ||
} | ||
|
||
graphics.__commands.drawQuads(rects, null, transforms); | ||
|
||
graphics.__dirty = true; | ||
graphics.__visible = true; | ||
} | ||
#end | ||
|
||
override inline function get_numVertices():Int | ||
{ | ||
return VERTICES_PER_QUAD; | ||
} | ||
|
||
override inline function get_numTriangles():Int | ||
{ | ||
return 2; | ||
} | ||
} |
Oops, something went wrong.