From f94f1d1d98de652745fa34941f64466f3614fd80 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 6 Sep 2021 15:30:19 -0400 Subject: [PATCH] FlxAnimate drawing optimizations --- source/animate/FlxAnimate.hx | 55 ++++++++++++++++++++++++++-------- source/animate/ParseAnimate.hx | 23 ++++++-------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/source/animate/FlxAnimate.hx b/source/animate/FlxAnimate.hx index 8cd6ae864..e34130986 100644 --- a/source/animate/FlxAnimate.hx +++ b/source/animate/FlxAnimate.hx @@ -10,6 +10,7 @@ import flixel.FlxSprite; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxFrame.FlxFrameAngle; +import flixel.group.FlxGroup; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; @@ -25,10 +26,14 @@ class FlxAnimate extends FlxSymbol // var animBitmap:BitmapData; var jsonAnim:AnimJson; + var sprGrp:FlxTypedGroup; + public function new(x:Float, y:Float) { super(x, y); + sprGrp = new FlxTypedGroup(); + var folder:String = "tightestBars"; frames = FlxAnimate.fromAnimate(Paths.file('images/' + folder + "/spritemap1.png"), Paths.file('images/$folder/spritemap1.json')); @@ -36,8 +41,11 @@ class FlxAnimate extends FlxSymbol jsonAnim = cast CoolUtil.coolJSON(Assets.getText(Paths.file('images/$folder/Animation.json'))); ParseAnimate.generateSymbolmap(jsonAnim.SD.S); ParseAnimate.resetFrameList(); + ParseAnimate.parseTimeline(jsonAnim.AN.TL, 0, 0); + generateSpriteShit(); + /* var folder:String = 'tightestBars'; coolParse = cast Json.parse(Assets.getText(Paths.file('images/' + folder + '/Animation.json'))); @@ -62,23 +70,23 @@ class FlxAnimate extends FlxSymbol actualFrameRender(); } - // fix render order of ALL layers! - // seperate frameList into layers - // go thru animate file to see how it should all be ordered - // per frame symbol stuff to fix lip sync (in ParseAnimate?) - // definitely need to dig through Animate.json stuff - // something with TRP stuff, look through tighterBars (GF scene) - // redo map stuff incase there's multiple assets - // ONE CENTRAL THING FOR THIS DUMBASS BULLSHIT - // sorted framelist put it all in there, then make i actually mean something - - function actualFrameRender() + function generateSpriteShit() { for (frameSorted in ParseAnimate.frameList) { + if (FlxG.keys.justPressed.I) + { + trace("\n\n\n\n"); + trace('NEW LAYER TYPE SHIT'); + trace(frameSorted.length); + // trace(i.depthString); + // trace("random lol: " + i.randomLol); + } + for (i in frameSorted) { - var spr:FlxSymbol = new FlxSymbol(0, 0); // redo this to recycle from a list later + // instead of making them every frame, regenerate when needed? + var spr:FlxSymbol = sprGrp.recycle(FlxSymbol); // redo this to recycle from a list later spr.frames = frames; spr.frame = spr.frames.getByName(i.frameName); // this one is fine @@ -99,8 +107,10 @@ class FlxAnimate extends FlxSymbol // spr.alpha = 0.3; spr.origin.set(); spr.antialiasing = true; + sprGrp.add(spr); + // trace(sprGrp); + // trace(spr); // spr.alpha = 0.5; - spr.draw(); /* if (i == "0225") { @@ -116,6 +126,23 @@ class FlxAnimate extends FlxSymbol }*/ } } + + // trace(sprGrp.length); + } + + // fix render order of ALL layers! + // seperate frameList into layers + // go thru animate file to see how it should all be ordered + // per frame symbol stuff to fix lip sync (in ParseAnimate?) + // definitely need to dig through Animate.json stuff + // something with TRP stuff, look through tighterBars (GF scene) + // redo map stuff incase there's multiple assets + // ONE CENTRAL THING FOR THIS DUMBASS BULLSHIT + // sorted framelist put it all in there, then make i actually mean something + + function actualFrameRender() + { + sprGrp.draw(); } // notes to self @@ -153,6 +180,8 @@ class FlxAnimate extends FlxSymbol ParseAnimate.resetFrameList(); ParseAnimate.parseTimeline(jsonAnim.AN.TL, 0, daFrame); + + generateSpriteShit(); } if (FlxG.keys.justPressed.LEFT) changeFrame(-1); diff --git a/source/animate/ParseAnimate.hx b/source/animate/ParseAnimate.hx index beb1e72a8..4fb51eb59 100644 --- a/source/animate/ParseAnimate.hx +++ b/source/animate/ParseAnimate.hx @@ -95,10 +95,10 @@ class ParseAnimate */ public static var depthTypeBeat:String = ""; + /** + * Array of bullshit that will eventually be RENDERED by whoever wanna use it! + */ public static var frameList:Array> = []; - public static var matrixMap:Map>> = new Map(); - public static var trpMap:Map>> = new Map(); - public static var theRoots:Map = new Map(); // for loop stuf @@ -113,15 +113,14 @@ class ParseAnimate public static var loopedFrameShit:Int = 0; + // clean up all the crazy ass arrays + public static function resetFrameList() { frameList = []; frameList.push([]); matrixHelp = []; matrixHelp.push([]); - matrixMap.clear(); - theRoots.clear(); - trpMap.clear(); } public static function parseTimeline(TL:Timeline, tabbed:Int = 0, ?frameInput:Int) @@ -185,25 +184,20 @@ class ParseAnimate if (Reflect.hasField(element, "ASI")) { matrixHelp[matrixHelp.length - 1].push(element.ASI.M3D); - // matrixMap.set(element.ASI.N, matrixHelp); frameList[frameList.length - 1].push({ frameName: element.ASI.N, M3D: element.ASI.M3D, depthString: depthTypeBeat, - matrixArray: matrixHelp[matrixHelp.length - 1] + matrixArray: matrixHelp[matrixHelp.length - 1], + trpArray: trpHelpIDK }); - trpMap.set(element.ASI.N, trpHelpIDK); - // flips the matrix once?? I cant remember exactly why it needs to be flipped - // matrixMap[matrixHelp.length - 1].reverse(); // matrixHelp[matrixHelp.length - 1].reverse(); trpHelpIDK = []; - theRoots.set(element.ASI.N, depthTypeBeat); - depthTypeBeat = ""; curLoopType = ""; loopedFrameShit = 0; @@ -248,7 +242,8 @@ typedef VALIDFRAME = frameName:String, M3D:Array, depthString:String, - matrixArray:Array> + matrixArray:Array>, + trpArray:Array> } typedef AnimJson =