diff --git a/source/Cache.hx b/source/Cache.hx index 9a4a3767..cbc502fe 100644 --- a/source/Cache.hx +++ b/source/Cache.hx @@ -1,9 +1,19 @@ package; import flixel.graphics.frames.FlxFramesCollection; - +import flixel.FlxG; +import LuaClass; class Cache { public static var offsetData = new Map(); public static var animData = new Map(); public static var charFrames = new Map(); public static var xmlData = new Map(); + + public static function Clear(){ + offsetData.clear(); + animData.clear(); + charFrames.clear(); + xmlData.clear(); + LuaStorage.objectProperties.clear(); + trace("CLEARED CACHE!"); + } } diff --git a/source/Character.hx b/source/Character.hx index fe2c3f5e..93302240 100644 --- a/source/Character.hx +++ b/source/Character.hx @@ -427,7 +427,7 @@ class Character extends FlxSprite playAnim("idle"); default: var xmlData:String = ''; - if(Cache.xmlData[curCharacter]!=null){ + /*if(Cache.xmlData[curCharacter]!=null){ xmlData=Cache.xmlData[curCharacter]; }else{ xmlData=File.getContent("assets/shared/images/characters/"+curCharacter+".xml"); @@ -439,9 +439,19 @@ class Character extends FlxSprite }else{ bitmapData = BitmapData.fromFile("assets/shared/images/characters/"+curCharacter+".png"); FlxG.bitmap.add(bitmapData,true,curCharacter+"CharFrames"); + }*/ + + if(Cache.charFrames[curCharacter]!=null){ + frames=Cache.charFrames[curCharacter]; + }else{ + frames = FlxAtlasFrames.fromSparrow(BitmapData.fromFile("assets/shared/images/characters/"+curCharacter+".png"),File.getContent("assets/shared/images/characters/"+curCharacter+".xml")); + Cache.charFrames[curCharacter]=frames; } + FlxG.bitmap.dumpCache(); + + + - frames = FlxAtlasFrames.fromSparrow(bitmapData,xmlData); loadAnimations(); loadOffsets(); diff --git a/source/LoadingState.hx b/source/LoadingState.hx index 23bce2e6..bd2f21c9 100644 --- a/source/LoadingState.hx +++ b/source/LoadingState.hx @@ -18,22 +18,22 @@ import haxe.io.Path; class LoadingState extends MusicBeatState { inline static var MIN_TIME = 1.0; - + var target:FlxState; var stopMusic = false; var callbacks:MultiCallback; - + var logo:FlxSprite; var gfDance:FlxSprite; var danceLeft = false; - + function new(target:FlxState, stopMusic:Bool) { super(); this.target = target; this.stopMusic = stopMusic; } - + override function create() { logo = new FlxSprite(-150, -100); @@ -52,7 +52,7 @@ class LoadingState extends MusicBeatState gfDance.antialiasing = true; add(gfDance); add(logo); - + initSongsManifest().onComplete ( function (lib) @@ -67,14 +67,14 @@ class LoadingState extends MusicBeatState checkLibrary("week" + PlayState.storyWeek); else checkLibrary("tutorial"); - + var fadeTime = 0.5; FlxG.camera.fade(FlxG.camera.bgColor, fadeTime, true); new FlxTimer().start(fadeTime + MIN_TIME, function(_) introComplete()); } ); } - + function checkLoadSong(path:String) { if (!Assets.cache.hasSound(path)) @@ -89,7 +89,7 @@ class LoadingState extends MusicBeatState Assets.loadSound(path).onComplete(function (_) { callback(); }); } } - + function checkLibrary(library:String) { trace(Assets.hasLibrary(library)); @@ -98,25 +98,25 @@ class LoadingState extends MusicBeatState @:privateAccess if (!LimeAssets.libraryPaths.exists(library)) throw "Missing library: " + library; - + var callback = callbacks.add("library:" + library); Assets.loadLibrary(library).onComplete(function (_) { callback(); }); } } - + override function beatHit() { super.beatHit(); - + logo.animation.play('bump'); danceLeft = !danceLeft; - + if (danceLeft) gfDance.animation.play('danceRight'); else gfDance.animation.play('danceLeft'); } - + override function update(elapsed:Float) { super.update(elapsed); @@ -125,30 +125,31 @@ class LoadingState extends MusicBeatState trace('fired: ' + callbacks.getFired() + " unfired:" + callbacks.getUnfired()); #end } - + function onLoad() { if (stopMusic && FlxG.sound.music != null) FlxG.sound.music.stop(); - + FlxG.switchState(target); } - + static function getSongPath() { return Paths.inst(PlayState.SONG.song); } - + static function getVocalPath() { return Paths.voices(PlayState.SONG.song); } - + inline static public function loadAndSwitchState(target:FlxState, stopMusic = false) { + Cache.Clear(); FlxG.switchState(getNextState(target, stopMusic)); } - + static function getNextState(target:FlxState, stopMusic = false):FlxState { Paths.setCurrentLevel("week" + PlayState.storyWeek); @@ -156,35 +157,35 @@ class LoadingState extends MusicBeatState var loaded = isSoundLoaded(getSongPath()) && (!PlayState.SONG.needsVoices || isSoundLoaded(getVocalPath())) && isLibraryLoaded("shared"); - + if (!loaded) return new LoadingState(target, stopMusic); #end if (stopMusic && FlxG.sound.music != null) FlxG.sound.music.stop(); - + return target; } - + #if NO_PRELOAD_ALL static function isSoundLoaded(path:String):Bool { return Assets.cache.hasSound(path); } - + static function isLibraryLoaded(library:String):Bool { return Assets.getLibrary(library) != null; } #end - + override function destroy() { super.destroy(); - + callbacks = null; } - + static function initSongsManifest() { var id = "songs"; @@ -258,16 +259,16 @@ class MultiCallback public var logId:String = null; public var length(default, null) = 0; public var numRemaining(default, null) = 0; - + var unfired = new MapVoid>(); var fired = new Array(); - + public function new (callback:Void->Void, logId:String = null) { this.callback = callback; this.logId = logId; } - + public function add(id = "untitled") { id = '$length:$id'; @@ -281,10 +282,10 @@ class MultiCallback unfired.remove(id); fired.push(id); numRemaining--; - + if (logId != null) log('fired $id, $numRemaining remaining'); - + if (numRemaining == 0) { if (logId != null) @@ -298,13 +299,13 @@ class MultiCallback unfired[id] = func; return func; } - + inline function log(msg):Void { if (logId != null) trace('$logId: $msg'); } - + public function getFired() return fired.copy(); public function getUnfired() return [for (id in unfired.keys()) id]; -} \ No newline at end of file +} diff --git a/source/LuaClass.hx b/source/LuaClass.hx index d7b584fc..ce4b5966 100644 --- a/source/LuaClass.hx +++ b/source/LuaClass.hx @@ -21,17 +21,20 @@ typedef LuaProperty = { var setter:State->Int; } +class LuaStorage { + public static var objectProperties:Map> = []; +} + class LuaClass { public var properties:Map = []; public var methods:MapInt> > = []; public var className:String = "BaseClass"; - private static var objectProperties:Map> = []; private static var state:State; public var addToGlobal:Bool=true; public function Register(l:State){ Lua.newtable(l); state=l; - objectProperties[className]=this.properties; + LuaStorage.objectProperties[className]=this.properties; var classIdx = Lua.gettop(l); Lua.pushvalue(l,classIdx); @@ -83,8 +86,8 @@ class LuaClass { Lua.pushstring(l,"_CLASSNAME"); Lua.rawget(l,mtIdx); var clName = Lua.tostring(l,-1); - if(objectProperties[clName]!=null && objectProperties[clName][index]!=null){ - return objectProperties[clName][index].getter(l,data); + if(LuaStorage.objectProperties[clName]!=null && LuaStorage.objectProperties[clName][index]!=null){ + return LuaStorage.objectProperties[clName][index].getter(l,data); } }; }else{ @@ -105,9 +108,9 @@ class LuaClass { Lua.pushstring(l,"_CLASSNAME"); Lua.rawget(l,mtIdx); var clName = Lua.tostring(l,-1); - if(objectProperties[clName]!=null && objectProperties[clName][index]!=null){ + if(LuaStorage.objectProperties[clName]!=null && LuaStorage.objectProperties[clName][index]!=null){ Lua.pop(l,2); - return objectProperties[clName][index].setter(l); + return LuaStorage.objectProperties[clName][index].setter(l); } }; }else{ diff --git a/source/Note.hx b/source/Note.hx index e230056e..5983c028 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -153,8 +153,8 @@ class Note extends FlxSprite //off -= width / 2; //x -= width / 2; - if (PlayState.curStage.startsWith('school')) - off += 30; + // if (PlayState.curStage.startsWith('school')) + //off += 30; offset.x = off; diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index 2e36eda0..be83e4a7 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -109,6 +109,7 @@ class PauseSubState extends MusicBeatSubstate FlxG.resetState(); case "Exit to menu": FlxG.switchState(new MainMenuState()); + Cache.Clear(); } } diff --git a/source/PlayState.hx b/source/PlayState.hx index 9d9ff5c7..3090b16f 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -98,8 +98,8 @@ class PlayState extends MusicBeatState private var opponentStrumLines:FlxTypedGroup; public var luaSprites:Map; public var luaObjects:Map; - var unnamedLuaSprites:Int=0; - var unnamedLuaObjects:Int=0; + public var unnamedLuaSprites:Int=0; + public var unnamedLuaObjects:Int=0; public var dadLua:LuaCharacter; public var gfLua:LuaCharacter; public var bfLua:LuaCharacter; @@ -217,6 +217,7 @@ class PlayState extends MusicBeatState override public function create() { + Cache.Clear(); FlxG.sound.music.looped=false; unnamedLuaSprites=0; unnamedLuaObjects=0; @@ -1771,6 +1772,7 @@ class PlayState extends MusicBeatState { // gitaroo man easter egg FlxG.switchState(new GitarooPause()); + Cache.Clear(); } else openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); @@ -1792,6 +1794,7 @@ class PlayState extends MusicBeatState } #end FlxG.switchState(new ChartingState()); + Cache.Clear(); #if desktop DiscordClient.changePresence("Chart Editor", null, null, true); @@ -1835,6 +1838,7 @@ class PlayState extends MusicBeatState if (FlxG.keys.justPressed.EIGHT){ FlxG.switchState(new AnimationDebug(SONG.player2)); + Cache.Clear(); #if windows if(lua!=null){ lua.destroy(); @@ -1844,6 +1848,7 @@ class PlayState extends MusicBeatState } if (FlxG.keys.justPressed.NINE){ FlxG.switchState(new AnimationDebug(SONG.player1)); + Cache.Clear(); #if windows if(lua!=null){ lua.destroy(); @@ -2309,6 +2314,7 @@ class PlayState extends MusicBeatState transOut = FlxTransitionableState.defaultTransOut; FlxG.switchState(new StoryMenuState()); + Cache.Clear(); // if () StoryMenuState.weekUnlocked[Std.int(Math.min(storyWeek + 1, StoryMenuState.weekUnlocked.length - 1))] = true; @@ -2354,12 +2360,14 @@ class PlayState extends MusicBeatState FlxG.sound.music.stop(); LoadingState.loadAndSwitchState(new PlayState()); + Cache.Clear(); } } else { trace('WENT BACK TO FREEPLAY??'); FlxG.switchState(new FreeplayState()); + Cache.Clear(); } }