diff --git a/src/AudioManager.hx b/src/AudioManager.hx index a7f932db..cacc1a16 100644 --- a/src/AudioManager.hx +++ b/src/AudioManager.hx @@ -8,12 +8,15 @@ import h3d.Vector; import hxd.res.Sound; import src.Settings; import hxd.snd.ChannelGroup; +import src.Resource; class AudioManager { static var manager:hxd.snd.Manager; static var soundGroup:hxd.snd.SoundGroup; static var musicGroup:hxd.snd.SoundGroup; + static var currentMusicResource:Resource; + public static function init() { AudioManager.manager = hxd.snd.Manager.get(); AudioManager.soundGroup = new SoundGroup("sound"); @@ -50,10 +53,14 @@ class AudioManager { public static function playShell() { AudioManager.manager.stopByName("music"); - var snd = ResourceLoader.getAudio("data/sound/shell.ogg"); - if (snd == null) + var sndres = ResourceLoader.getAudio("data/sound/shell.ogg"); + if (sndres == null) return; - var ch = AudioManager.manager.play(snd, null, musicGroup); + sndres.acquire(); + if (currentMusicResource != null) + currentMusicResource.release(); + currentMusicResource = sndres; + var ch = AudioManager.manager.play(sndres.resource, null, musicGroup); ch.loop = true; } diff --git a/src/DifBuilder.hx b/src/DifBuilder.hx index 0a5ce142..9226122d 100644 --- a/src/DifBuilder.hx +++ b/src/DifBuilder.hx @@ -79,7 +79,9 @@ class DifBuilder { ]; public static function loadDif(path:String, itr:InteriorObject, ?so:Int = -1) { - var dif = ResourceLoader.loadInterior(path); + var difresource = ResourceLoader.loadInterior(path); + difresource.acquire(); + var dif = difresource.resource; var geo = so == -1 ? dif.interiors[0] : dif.subObjects[so]; @@ -374,5 +376,7 @@ class DifBuilder { var mesh = new Mesh(prim, material, itr); } + + difresource.release(); } } diff --git a/src/DtsObject.hx b/src/DtsObject.hx index f7806015..0a929336 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -1,5 +1,6 @@ package src; +import hxd.res.Sound; import h3d.col.Bounds; import src.TimeState; import shaders.Billboard; @@ -30,6 +31,7 @@ import src.ResourceLoader; import dts.DtsFile; import h3d.Matrix; import src.Util; +import src.Resource; var DROP_TEXTURE_FOR_ENV_MAP = ['shapes/items/superjump.dts', 'shapes/items/antigravity.dts']; @@ -72,6 +74,7 @@ class DtsObject extends GameObject { var dtsPath:String; var directoryPath:String; var dts:DtsFile; + var dtsResource:Resource; var level:MarbleWorld; @@ -110,7 +113,10 @@ class DtsObject extends GameObject { } public function init(level:MarbleWorld) { - this.dts = ResourceLoader.loadDts(this.dtsPath); + this.dtsResource = ResourceLoader.loadDts(this.dtsPath); + this.dtsResource.acquire(); + this.dts = this.dtsResource.resource; + this.directoryPath = Path.directory(this.dtsPath); if (level != null) this.level = level; @@ -300,7 +306,7 @@ class DtsObject extends GameObject { var completion = 0 / (iflSequence[0].duration); var keyframe = Math.floor(completion * info.length) % info.length; var currentFile = info[keyframe]; - var texture = ResourceLoader.getTexture(this.directoryPath + '/' + currentFile); + var texture = ResourceLoader.getResource(this.directoryPath + '/' + currentFile, ResourceLoader.getTexture, this.textureResources); var flags = this.dts.matFlags[i]; if (flags & 1 > 0 || flags & 2 > 0) @@ -363,7 +369,7 @@ class DtsObject extends GameObject { this.materialInfos.set(material, keyframes); iflMaterial = true; } else { - var texture:Texture = ResourceLoader.getTexture(fullName); + var texture = ResourceLoader.getResource(fullName, ResourceLoader.getTexture, this.textureResources); texture.wrap = Wrap.Repeat; material.texture = texture; // if (this.useInstancing) { @@ -393,7 +399,7 @@ class DtsObject extends GameObject { #end // Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem #if js - var texture:Texture = ResourceLoader.getTexture("data/interiors/parts/white.jpg"); + var texture:Texture = ResourceLoader.getResource("data/interiors/parts/white.jpg", ResourceLoader.getTexture, this.textureResources); texture.wrap = Wrap.Repeat; #end material.texture = texture; @@ -855,7 +861,7 @@ class DtsObject extends GameObject { var completion = timeState.timeSinceLoad / (iflSequence[0].duration); var keyframe = Math.floor(completion * info.length) % info.length; var currentFile = info[keyframe]; - var texture = ResourceLoader.getTexture(this.directoryPath + '/' + currentFile); + var texture = ResourceLoader.getResource(this.directoryPath + '/' + currentFile, ResourceLoader.getTexture, this.textureResources); var flags = this.dts.matFlags[i]; if (flags & 1 > 0 || flags & 2 > 0) @@ -938,4 +944,9 @@ class DtsObject extends GameObject { public function setCollisionEnabled(flag:Bool) { this.isCollideable = flag; } + + public override function dispose() { + super.dispose(); + this.dtsResource.release(); + } } diff --git a/src/GameObject.hx b/src/GameObject.hx index f2e222c4..1013ac89 100644 --- a/src/GameObject.hx +++ b/src/GameObject.hx @@ -3,6 +3,9 @@ package src; import src.TimeState; import collision.CollisionInfo; import h3d.scene.Object; +import src.Resource; +import h3d.mat.Texture; +import hxd.res.Sound; class GameObject extends Object { public var identifier:String; @@ -10,6 +13,9 @@ class GameObject extends Object { public var isCollideable:Bool = false; public var isBoundingBoxCollideable:Bool = true; + var textureResources:Array> = []; + var soundResources:Array> = []; + public function onMarbleContact(time:TimeState, ?contact:CollisionInfo) {} public function onMarbleInside(time:TimeState) {} @@ -21,4 +27,13 @@ class GameObject extends Object { public function onLevelStart() {} public function reset() {} + + public function dispose() { + for (textureResource in textureResources) { + textureResource.release(); + } + for (audioResource in soundResources) { + audioResource.release(); + } + } } diff --git a/src/Main.hx b/src/Main.hx index 64e77854..69c63288 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -17,6 +17,7 @@ class Main extends hxd.App { var marbleGame:MarbleGame; // var fpsCounter:Text; + var debugProfiler:h3d.impl.Benchmark; var loaded:Bool = false; override function init() { @@ -39,6 +40,8 @@ class Main extends hxd.App { // world.init(); // world.start(); + // debugProfiler = new h3d.impl.Benchmark(s2d); + // debugProfiler.y = 40; // fpsCounter = new Text(DefaultFont.get(), s2d); // fpsCounter.y = 40; @@ -59,8 +62,12 @@ class Main extends hxd.App { override function render(e:h3d.Engine) { // this.world.render(e); - if (loaded) + if (loaded) { + // debugProfiler.begin(); + // debugProfiler.measure("marbleGame"); marbleGame.render(e); + // debugProfiler.end(); + } super.render(e); } diff --git a/src/Marble.hx b/src/Marble.hx index e124a900..6e7e7529 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -42,6 +42,8 @@ import h3d.prim.Sphere; import h3d.scene.Object; import src.MarbleGame; import src.CameraController; +import src.Resource; +import h3d.mat.Texture; class Move { public var d:Vector; @@ -200,21 +202,26 @@ class Marble extends GameObject { this.bounceEmitterData = new ParticleData(); this.bounceEmitterData.identifier = "MarbleBounceParticle"; - this.bounceEmitterData.texture = ResourceLoader.getTexture("data/particles/star.png"); + this.bounceEmitterData.texture = ResourceLoader.getResource("data/particles/star.png", ResourceLoader.getTexture, this.textureResources); this.trailEmitterData = new ParticleData(); this.trailEmitterData.identifier = "MarbleTrailParticle"; - this.trailEmitterData.texture = ResourceLoader.getTexture("data/particles/smoke.png"); + this.trailEmitterData.texture = ResourceLoader.getResource("data/particles/smoke.png", ResourceLoader.getTexture, this.textureResources); - this.rollSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/rolling_hard.wav"), this.getAbsPos().getPosition(), true); - this.slipSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/sliding.wav"), this.getAbsPos().getPosition(), true); + this.rollSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/rolling_hard.wav", ResourceLoader.getAudio, this.soundResources), + this.getAbsPos().getPosition(), true); + this.slipSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/sliding.wav", ResourceLoader.getAudio, this.soundResources), + this.getAbsPos().getPosition(), true); this.rollSound.volume = 0; this.slipSound.volume = 0; - this.shockabsorberSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/superbounceactive.wav"), null, true); + this.shockabsorberSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/superbounceactive.wav", ResourceLoader.getAudio, + this.soundResources), null, true); this.shockabsorberSound.pause = true; - this.superbounceSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/forcefield.wav"), null, true); + this.superbounceSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/forcefield.wav", ResourceLoader.getAudio, this.soundResources), + null, true); this.superbounceSound.pause = true; - this.helicopterSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/use_gyrocopter.wav"), null, true); + this.helicopterSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/use_gyrocopter.wav", ResourceLoader.getAudio, + this.soundResources), null, true); this.helicopterSound.pause = true; } @@ -291,13 +298,13 @@ class Marble extends GameObject { if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) { if (contact.otherObject is RoundBumper) { if (!playedSounds.contains("data/sound/bumperding1.wav")) { - AudioManager.playSound(ResourceLoader.getAudio("data/sound/bumperding1.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources)); playedSounds.push("data/sound/bumperding1.wav"); } } if (contact.otherObject is TriangleBumper) { if (!playedSounds.contains("data/sound/bumper1.wav")) { - AudioManager.playSound(ResourceLoader.getAudio("data/sound/bumper1.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/bumper1.wav", ResourceLoader.getAudio, this.soundResources)); playedSounds.push("data/sound/bumper1.wav"); } } @@ -545,7 +552,7 @@ class Marble extends GameObject { if (sv < this._jumpImpulse) { this.velocity = this.velocity.add(bestContact.normal.multiply((this._jumpImpulse - sv))); if (!playedSounds.contains("data/sound/jump.wav")) { - AudioManager.playSound(ResourceLoader.getAudio("data/sound/jump.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/jump.wav", ResourceLoader.getAudio, this.soundResources)); playedSounds.push("data/sound/jump.wav"); } } @@ -658,7 +665,7 @@ class Marble extends GameObject { "data/sound/bouncehard3.wav", "data/sound/bouncehard4.wav" ]; - var snd = ResourceLoader.getAudio(sndList[bounceSoundNum]); + var snd = ResourceLoader.getResource(sndList[bounceSoundNum], ResourceLoader.getAudio, this.soundResources); var gain = bounceMinGain; gain = Util.clamp(Math.pow(contactVel / 12, 1.5), 0, 1); diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 0f41cdb5..3e963e92 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -69,6 +69,7 @@ import src.InteriorObject; import h3d.scene.Scene; import collision.CollisionWorld; import src.Marble; +import src.Resource; class MarbleWorld extends Scheduler { public var collisionWorld:CollisionWorld; @@ -131,6 +132,9 @@ class MarbleWorld extends Scheduler { var _loadingLength:Int = 0; + var textureResources:Array> = []; + var soundResources:Array> = []; + public function new(scene:Scene, scene2d:h2d.Scene, mission:Mission) { this.scene = scene; this.scene2d = scene2d; @@ -175,7 +179,7 @@ class MarbleWorld extends Scheduler { 'data/sound/classic vibe.ogg', 'data/sound/beach party.ogg' ][(mission.index + 1) % 3]; - AudioManager.playMusic(ResourceLoader.getAudio(musicFileName)); + AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources)); }); this.resourceLoadFuncs.push(() -> { this.addSimGroup(this.mission.root); @@ -296,22 +300,22 @@ class MarbleWorld extends Scheduler { this.newOrientationQuat = new Quat(); this.deselectPowerUp(); - AudioManager.playSound(ResourceLoader.getAudio('data/sound/spawn.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/spawn.wav', ResourceLoader.getAudio, this.soundResources)); this.clearSchedule(); this.schedule(0.5, () -> { // setCenterText('ready'); - AudioManager.playSound(ResourceLoader.getAudio('data/sound/ready.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/ready.wav', ResourceLoader.getAudio, this.soundResources)); return 0; }); this.schedule(2, () -> { // setCenterText('set'); - AudioManager.playSound(ResourceLoader.getAudio('data/sound/set.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/set.wav', ResourceLoader.getAudio, this.soundResources)); return 0; }); this.schedule(3.5, () -> { // setCenterText('go'); - AudioManager.playSound(ResourceLoader.getAudio('data/sound/go.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/go.wav', ResourceLoader.getAudio, this.soundResources)); return 0; }); @@ -760,7 +764,7 @@ class MarbleWorld extends Scheduler { this.bonusTime = 0; } if (timeTravelSound == null) { - var ttsnd = ResourceLoader.getAudio("data/sound/timetravelactive.wav"); + var ttsnd = ResourceLoader.getResource("data/sound/timetravelactive.wav", ResourceLoader.getAudio, this.soundResources); timeTravelSound = AudioManager.playSound(ttsnd, null, true); } } else { @@ -847,7 +851,7 @@ class MarbleWorld extends Scheduler { if (this.gemCount == this.totalGems) { string = "You have all the gems, head for the finish!"; // if (!this.rewinding) - AudioManager.playSound(ResourceLoader.getAudio('data/sound/gotallgems.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/gotallgems.wav', ResourceLoader.getAudio, this.soundResources)); // Some levels with this package end immediately upon collection of all gems // if (this.mission.misFile.activatedPackages.includes('endWithTheGems')) { @@ -866,7 +870,7 @@ class MarbleWorld extends Scheduler { } // if (!this.rewinding) - AudioManager.playSound(ResourceLoader.getAudio('data/sound/gotgem.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/gotgem.wav', ResourceLoader.getAudio, this.soundResources)); } displayAlert(string); @@ -959,7 +963,7 @@ class MarbleWorld extends Scheduler { return; if (this.gemCount < this.totalGems) { - AudioManager.playSound(ResourceLoader.getAudio('data/sound/missinggems.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/missinggems.wav', ResourceLoader.getAudio, this.soundResources)); displayAlert("You can't finish without all the gems!!"); } else { this.endPad.spawnFirework(this.timeState); @@ -1077,7 +1081,7 @@ class MarbleWorld extends Scheduler { // sky.follow = null; // this.oobCameraPosition = camera.position.clone(); playGui.setCenterText('outofbounds'); - AudioManager.playSound(ResourceLoader.getAudio('data/sound/whoosh.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/whoosh.wav', ResourceLoader.getAudio, this.soundResources)); // if (this.replay.mode != = 'playback') this.schedule(this.timeState.currentAttemptTime + 2, () -> this.restart()); } @@ -1096,6 +1100,31 @@ class MarbleWorld extends Scheduler { public function dispose() { this.playGui.dispose(); scene.removeChildren(); + + for (interior in this.interiors) { + interior.dispose(); + } + for (pathedInteriors in this.pathedInteriors) { + pathedInteriors.dispose(); + } + for (marble in this.marbles) { + marble.dispose(); + } + for (dtsObject in this.dtsObjects) { + dtsObject.dispose(); + } + for (trigger in this.triggers) { + trigger.dispose(); + } + for (soundResource in this.soundResources) { + soundResource.release(); + } + for (textureResource in this.textureResources) { + textureResource.release(); + } + + sky.dispose(); + this._disposed = true; AudioManager.stopAllSounds(); AudioManager.playShell(); diff --git a/src/Mission.hx b/src/Mission.hx index b81f93a5..4dc8474d 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -9,6 +9,8 @@ import mis.MissionElement.MissionElementType; import mis.MisFile; import mis.MissionElement.MissionElementSimGroup; import src.ResourceLoader; +import hxd.res.Image; +import src.Resource; class Mission { public var root:MissionElementSimGroup; @@ -25,6 +27,8 @@ class Mission { public var id:Int; public var isClaMission:Bool; + var imageResources:Array> = []; + public function new() {} public function load() { @@ -33,6 +37,12 @@ class Mission { root = contents.root; } + public function dispose() { + for (imageResource in imageResources) { + imageResource.release(); + } + } + public static function fromMissionInfo(path:String, mInfo:MissionElementScriptObject) { var mission = new Mission(); mission.path = path; @@ -57,10 +67,10 @@ class Mission { if (!this.isClaMission) { var basename = haxe.io.Path.withoutExtension(this.path); if (ResourceLoader.fileSystem.exists(basename + ".png")) { - return ResourceLoader.getImage(basename + ".png").toTile(); + return ResourceLoader.getResource(basename + ".png", ResourceLoader.getImage, this.imageResources).toTile(); } if (ResourceLoader.fileSystem.exists(basename + ".jpg")) { - return ResourceLoader.getImage(basename + ".jpg").toTile(); + return ResourceLoader.getResource(basename + ".jpg", ResourceLoader.getImage, this.imageResources).toTile(); } var img = new BitmapData(1, 1); img.setPixel(0, 0, 0); diff --git a/src/PathedInterior.hx b/src/PathedInterior.hx index 2cd4e55a..09482b8d 100644 --- a/src/PathedInterior.hx +++ b/src/PathedInterior.hx @@ -19,6 +19,7 @@ import h3d.Vector; import src.Util; import src.PathedInteriorMarker; import src.InteriorObject; +import src.Resource; typedef PIState = { var currentTime:Float; @@ -131,7 +132,8 @@ class PathedInterior extends InteriorObject { } if (this.element.datablock.toLowerCase() == "pathedmovingblock") { - this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/movingblockloop.wav"), new Vector(), true); + this.soundChannel = AudioManager.playSound(ResourceLoader.getResource("data/sound/movingblockloop.wav", ResourceLoader.getAudio, + this.soundResources), new Vector(), true); } this.reset(); diff --git a/src/Resource.hx b/src/Resource.hx new file mode 100644 index 00000000..dedc6237 --- /dev/null +++ b/src/Resource.hx @@ -0,0 +1,31 @@ +package src; + +class Resource { + public var resource:T; + public var identifier:String; + + var referenceCount:Int = 0; + var resourceMap:Map>; + var disposeFunc:T->Void; + + public function new(resource:T, identifier:String, resList:Map>, disposeFunc:T->Void) { + this.resource = resource; + this.resourceMap = resList; + this.disposeFunc = disposeFunc; + this.identifier = identifier; + } + + public function acquire() { + this.referenceCount++; + trace('Acquiring Resource ${this.identifier}: ${this.referenceCount}'); + } + + public function release() { + this.referenceCount--; + if (this.referenceCount == 0) { + disposeFunc(this.resource); + this.resourceMap.remove(this.identifier); + trace('Releasing Resource ${this.identifier}'); + } + } +} diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index d7ad2d09..f5f07e15 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -13,6 +13,7 @@ import hxd.fs.LocalFileSystem; import hxd.fs.FileSystem; import hxd.res.Loader; import fs.ManifestProgress; +import src.Resource; class ResourceLoader { #if hl @@ -27,11 +28,11 @@ class ResourceLoader { #if js public static var loader:Loader = null; #end - static var interiorResources:Map = new Map(); - static var dtsResources:Map = new Map(); - static var textureCache:Map = new Map(); - static var imageCache:Map = new Map(); - static var audioCache:Map = new Map(); + static var interiorResources:Map> = new Map(); + static var dtsResources:Map> = new Map(); + static var textureCache:Map> = new Map(); + static var imageCache:Map> = new Map(); + static var audioCache:Map> = new Map(); // static var threadPool:FixedThreadPool = new FixedThreadPool(4); @@ -63,11 +64,12 @@ class ResourceLoader { // var lock = new Lock(); // threadPool.run(() -> { itr = Dif.LoadFromBuffer(fileSystem.get(path).getBytes()); - interiorResources.set(path, itr); + var itrresource = new Resource(itr, path, interiorResources, dif -> {}); + interiorResources.set(path, itrresource); // lock.release(); // }); // lock.wait(); - return itr; + return itrresource; } } @@ -82,11 +84,12 @@ class ResourceLoader { // var lock = new Lock(); // threadPool.run(() -> { dts.read(path); - dtsResources.set(path, dts); + var dtsresource = new Resource(dts, path, dtsResources, dtsFile -> {}); + dtsResources.set(path, dtsresource); // lock.release(); // }); // lock.wait(); - return dts; + return dtsresource; } } @@ -104,9 +107,10 @@ class ResourceLoader { var tex = img.toTexture(); tex.mipMap = Nearest; // tex.filter = Nearest; - textureCache.set(path, tex); + var textureresource = new Resource(tex, path, textureCache, tex -> tex.dispose()); + textureCache.set(path, textureresource); - return tex; + return textureresource; } return null; } @@ -119,8 +123,9 @@ class ResourceLoader { return imageCache.get(path); if (fileSystem.exists(path)) { var tex = loader.load(path).toImage(); - imageCache.set(path, tex); - return tex; + var imageresource = new Resource(tex, path, imageCache, img -> {}); + imageCache.set(path, imageresource); + return imageresource; } return null; } @@ -133,8 +138,21 @@ class ResourceLoader { return audioCache.get(path); if (fileSystem.exists(path)) { var snd = loader.load(path).toSound(); - audioCache.set(path, snd); - return snd; + var audioresource = new Resource(snd, path, audioCache, snd -> snd.dispose()); + audioCache.set(path, audioresource); + return audioresource; + } + return null; + } + + public static function getResource(path:String, resourceAcquirerer:String->Null>, resourceCollector:Array>) { + var res = resourceAcquirerer(path); + if (res != null) { + if (!resourceCollector.contains(res)) { + res.acquire(); + resourceCollector.push(res); + } + return res.resource; } return null; } diff --git a/src/Sky.hx b/src/Sky.hx index 5d01a55c..7af18bbc 100644 --- a/src/Sky.hx +++ b/src/Sky.hx @@ -12,10 +12,14 @@ import h3d.mat.Texture; import haxe.io.Path; import src.ResourceLoader; import h3d.scene.Object; +import src.Resource; +import hxd.res.Image; class Sky extends Object { public var dmlPath:String; + var imageResources:Array> = []; + public function new() { super(); } @@ -47,6 +51,12 @@ class Sky extends Object { // skyMesh.material.shadows = false; } + public function dispose() { + for (imageResource in imageResources) { + imageResource.release(); + } + } + function createSkyboxCubeTextured(dmlPath:String) { #if js dmlPath = StringTools.replace(dmlPath, "data/", ""); @@ -67,7 +77,7 @@ class Sky extends Object { if (filenames.length == 0) { skyboxImages.push(new BitmapData(128, 128)); } else { - var image = ResourceLoader.getImage(filenames[0]).toBitmap(); + var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap(); skyboxImages.push(image); } } diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index c9728c92..a012a8c2 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -25,13 +25,13 @@ class EndGameGui extends GuiControl { this.mission = mission; function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } - var pg = new GuiImage(ResourceLoader.getImage("data/ui/play/playgui.png").toTile()); + var pg = new GuiImage(ResourceLoader.getResource("data/ui/play/playgui.png", ResourceLoader.getImage, this.imageResources).toTile()); pg.horizSizing = Center; pg.vertSizing = Center; pg.position = new Vector(77, 9); diff --git a/src/gui/EnterNameDlg.hx b/src/gui/EnterNameDlg.hx index c0bd1017..7babdffa 100644 --- a/src/gui/EnterNameDlg.hx +++ b/src/gui/EnterNameDlg.hx @@ -15,9 +15,9 @@ class EnterNameDlg extends GuiControl { this.vertSizing = Height; function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } @@ -50,7 +50,7 @@ class EnterNameDlg extends GuiControl { } } - var dlg = new GuiImage(ResourceLoader.getImage("data/ui/common/dialog.png").toTile()); + var dlg = new GuiImage(ResourceLoader.getResource("data/ui/common/dialog.png", ResourceLoader.getImage, this.imageResources).toTile()); dlg.horizSizing = Center; dlg.vertSizing = Center; dlg.position = new Vector(112, 111); @@ -72,7 +72,7 @@ class EnterNameDlg extends GuiControl { } dlg.addChild(okbutton); - var wnd = new GuiImage(ResourceLoader.getImage("data/ui/common/window.png").toTile()); + var wnd = new GuiImage(ResourceLoader.getResource("data/ui/common/window.png", ResourceLoader.getImage, this.imageResources).toTile()); wnd.position = new Vector(58, 124); wnd.extent = new Vector(295, 55); dlg.addChild(wnd); diff --git a/src/gui/ExitGameDlg.hx b/src/gui/ExitGameDlg.hx index d79743fd..1f2bf9f5 100644 --- a/src/gui/ExitGameDlg.hx +++ b/src/gui/ExitGameDlg.hx @@ -14,13 +14,13 @@ class ExitGameDlg extends GuiControl { this.extent = new Vector(640, 480); function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } - var dialogImg = new GuiImage(ResourceLoader.getImage("data/ui/common/dialog.png").toTile()); + var dialogImg = new GuiImage(ResourceLoader.getResource("data/ui/common/dialog.png", ResourceLoader.getImage, this.imageResources).toTile()); dialogImg.horizSizing = Center; dialogImg.vertSizing = Center; dialogImg.position = new Vector(134, 148); diff --git a/src/gui/GuiButton.hx b/src/gui/GuiButton.hx index 8a079ba2..c656d0be 100644 --- a/src/gui/GuiButton.hx +++ b/src/gui/GuiButton.hx @@ -35,7 +35,7 @@ class GuiButton extends GuiAnim { var renderRect = getRenderRectangle(); if (renderRect.inRect(mouseState.position) && !disabled) { if (buttonSounds && Key.isPressed(Key.MOUSE_LEFT)) { - AudioManager.playSound(ResourceLoader.getAudio("data/sound/buttonpress.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources)); } } if (buttonType == Normal) { @@ -87,7 +87,7 @@ class GuiButton extends GuiAnim { super.onMouseEnter(mouseState); if (buttonSounds) { - AudioManager.playSound(ResourceLoader.getAudio("data/sound/buttonover.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonover.wav", ResourceLoader.getAudio, this.soundResources)); } } } diff --git a/src/gui/GuiControl.hx b/src/gui/GuiControl.hx index 3ba4885d..bdd931c1 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -1,11 +1,15 @@ package gui; +import hxd.res.Image; import h2d.Graphics; import hxd.Key; import h2d.Scene; import h2d.col.Bounds; import hxd.Window; import h3d.Vector; +import src.Resource; +import hxd.res.Sound; +import h3d.mat.Texture; enum HorizSizing { Right; @@ -43,6 +47,10 @@ class GuiControl { var _entered:Bool = false; var _skipNextEvent:Bool = false; + var imageResources:Array> = []; + var textureResources:Array> = []; + var soundResources:Array> = []; + public function new() {} public function render(scene2d:Scene) { @@ -191,6 +199,16 @@ class GuiControl { c.dispose(); } this.children = []; + + for (textureResource in textureResources) { + textureResource.release(); + } + for (imageResource in imageResources) { + imageResource.release(); + } + for (audioResource in soundResources) { + audioResource.release(); + } } public function onMouseDown(mouseState:MouseState) {} diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index 0cdd74cd..94f65faa 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -34,13 +34,14 @@ class HelpCreditsGui extends GuiImage { var superBounceCtrl:GuiObjectShow; public function new() { - super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); + var img = ResourceLoader.getImage("data/ui/background.jpg"); + super(img.resource.toTile()); this.position = new Vector(); this.extent = new Vector(640, 480); this.horizSizing = Width; this.vertSizing = Height; - var helpGui = new GuiImage(ResourceLoader.getImage("data/ui/help/help_gui.png").toTile()); + var helpGui = new GuiImage(ResourceLoader.getResource("data/ui/help/help_gui.png", ResourceLoader.getImage, this.imageResources).toTile()); helpGui.horizSizing = Center; helpGui.vertSizing = Center; helpGui.position = new Vector(15, 10); @@ -48,9 +49,9 @@ class HelpCreditsGui extends GuiImage { this.addChild(helpGui); function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } @@ -74,7 +75,7 @@ class HelpCreditsGui extends GuiImage { } helpGui.addChild(homeButton); - var helpWindow = new GuiImage(ResourceLoader.getImage("data/ui/help/help_window.png").toTile()); + var helpWindow = new GuiImage(ResourceLoader.getResource("data/ui/help/help_window.png", ResourceLoader.getImage, this.imageResources).toTile()); helpWindow.position = new Vector(30, 31); helpWindow.extent = new Vector(549, 338); helpGui.addChild(helpWindow); diff --git a/src/gui/LoadingGui.hx b/src/gui/LoadingGui.hx index ab9a1a2b..17de5dcd 100644 --- a/src/gui/LoadingGui.hx +++ b/src/gui/LoadingGui.hx @@ -9,22 +9,23 @@ class LoadingGui extends GuiImage { public var setProgress:Float->Void; public function new(missionName:String) { - super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); + var img = ResourceLoader.getImage("data/ui/background.jpg"); + super(img.resource.toTile()); this.horizSizing = Width; this.vertSizing = Height; this.extent = new Vector(640, 480); this.position = new Vector(); - var loadingGui = new GuiImage(ResourceLoader.getImage("data/ui/loading/loadinggui.png").toTile()); + var loadingGui = new GuiImage(ResourceLoader.getResource("data/ui/loading/loadinggui.png", ResourceLoader.getImage, this.imageResources).toTile()); loadingGui.horizSizing = Center; loadingGui.vertSizing = Center; loadingGui.position = new Vector(86, 77); loadingGui.extent = new Vector(468, 325); function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } @@ -56,7 +57,7 @@ class LoadingGui extends GuiImage { MarbleGame.instance.quitMission(); } - var overlay = new GuiImage(ResourceLoader.getImage("data/ui/loading/overlay.png").toTile()); + var overlay = new GuiImage(ResourceLoader.getResource("data/ui/loading/overlay.png", ResourceLoader.getImage, this.imageResources).toTile()); overlay.position = new Vector(151, 131); overlay.extent = new Vector(278, 86); diff --git a/src/gui/MainMenuGui.hx b/src/gui/MainMenuGui.hx index b4545dd9..1eddf05f 100644 --- a/src/gui/MainMenuGui.hx +++ b/src/gui/MainMenuGui.hx @@ -8,7 +8,8 @@ import src.ResourceLoader; class MainMenuGui extends GuiImage { public function new() { - super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); + var img = ResourceLoader.getImage("data/ui/background.jpg"); + super(img.resource.toTile()); var fontdata = ResourceLoader.getFileEntry("data/font/DomCasual32px.fnt"); var bfont = new BitmapFont(fontdata.entry); @:privateAccess bfont.loader = ResourceLoader.loader; @@ -26,7 +27,7 @@ class MainMenuGui extends GuiImage { versionText.text.text = "1.0.0"; this.addChild(versionText); - var homebase = new GuiImage(ResourceLoader.getImage("data/ui/home/homegui.png").toTile()); + var homebase = new GuiImage(ResourceLoader.getResource("data/ui/home/homegui.png", ResourceLoader.getImage, this.imageResources).toTile()); homebase.horizSizing = Center; homebase.vertSizing = Center; homebase.extent = new Vector(349, 477); @@ -34,9 +35,9 @@ class MainMenuGui extends GuiImage { this.addChild(homebase); function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } diff --git a/src/gui/MessageBoxYesNoDlg.hx b/src/gui/MessageBoxYesNoDlg.hx index 64e8015d..5c7b3499 100644 --- a/src/gui/MessageBoxYesNoDlg.hx +++ b/src/gui/MessageBoxYesNoDlg.hx @@ -18,13 +18,13 @@ class MessageBoxYesNoDlg extends GuiControl { @:privateAccess domcasual24.loader = ResourceLoader.loader; function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } - var yesNoFrame = new GuiImage(ResourceLoader.getImage("data/ui/common/dialog.png").toTile()); + var yesNoFrame = new GuiImage(ResourceLoader.getResource("data/ui/common/dialog.png", ResourceLoader.getImage, this.imageResources).toTile()); yesNoFrame.horizSizing = Center; yesNoFrame.vertSizing = Center; yesNoFrame.position = new Vector(187, 156); diff --git a/src/gui/OptionsDlg.hx b/src/gui/OptionsDlg.hx index a78902fd..7b9c1c31 100644 --- a/src/gui/OptionsDlg.hx +++ b/src/gui/OptionsDlg.hx @@ -16,7 +16,8 @@ class OptionsDlg extends GuiImage { var musicSliderFunc:(dt:Float, mouseState:MouseState) -> Void; public function new() { - super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); + var img = ResourceLoader.getImage("data/ui/background.jpg"); + super(img.resource.toTile()); this.horizSizing = Width; this.vertSizing = Height; this.position = new Vector(); @@ -27,9 +28,9 @@ class OptionsDlg extends GuiImage { @:privateAccess arial14.loader = ResourceLoader.loader; function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } @@ -42,21 +43,21 @@ class OptionsDlg extends GuiImage { var setTab:String->Void = null; - var graphicsTab = new GuiImage(ResourceLoader.getImage("data/ui/options/graf_tab.png").toTile()); + var graphicsTab = new GuiImage(ResourceLoader.getResource("data/ui/options/graf_tab.png", ResourceLoader.getImage, this.imageResources).toTile()); graphicsTab.position = new Vector(58, 44); graphicsTab.extent = new Vector(149, 86); - var controlsTab = new GuiImage(ResourceLoader.getImage("data/ui/options/cntr_tab.png").toTile()); + var controlsTab = new GuiImage(ResourceLoader.getResource("data/ui/options/cntr_tab.png", ResourceLoader.getImage, this.imageResources).toTile()); controlsTab.position = new Vector(315, 15); controlsTab.extent = new Vector(149, 65); - var boxFrame = new GuiImage(ResourceLoader.getImage("data/ui/options/options_base.png").toTile()); + var boxFrame = new GuiImage(ResourceLoader.getResource("data/ui/options/options_base.png", ResourceLoader.getImage, this.imageResources).toTile()); boxFrame.position = new Vector(25, 14); boxFrame.extent = new Vector(470, 422); boxFrame.horizSizing = Center; boxFrame.vertSizing = Center; - var audioTab = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_tab.png").toTile()); + var audioTab = new GuiImage(ResourceLoader.getResource("data/ui/options/aud_tab.png", ResourceLoader.getImage, this.imageResources).toTile()); audioTab.position = new Vector(204, 33); audioTab.extent = new Vector(114, 75); @@ -125,7 +126,7 @@ class OptionsDlg extends GuiImage { graphicsPane.addChild(gfxFull); windowBoxes.push(gfxFull); - var gfxText = new GuiImage(ResourceLoader.getImage("data/ui/options/graf_txt.png").toTile()); + var gfxText = new GuiImage(ResourceLoader.getResource("data/ui/options/graf_txt.png", ResourceLoader.getImage, this.imageResources).toTile()); gfxText.horizSizing = Right; gfxText.vertSizing = Bottom; gfxText.position = new Vector(12, 12); @@ -269,17 +270,17 @@ class OptionsDlg extends GuiImage { audioPane.extent = new Vector(425, 281); // mainPane.addChild(audioPane); - var audSndSlide = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_snd_slide.png").toTile()); + var audSndSlide = new GuiImage(ResourceLoader.getResource("data/ui/options/aud_snd_slide.png", ResourceLoader.getImage, this.imageResources).toTile()); audSndSlide.position = new Vector(14, 92); audSndSlide.extent = new Vector(388, 34); audioPane.addChild(audSndSlide); - var audMusSlide = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_mus_slide.png").toTile()); + var audMusSlide = new GuiImage(ResourceLoader.getResource("data/ui/options/aud_mus_slide.png", ResourceLoader.getImage, this.imageResources).toTile()); audMusSlide.position = new Vector(17, 32); audMusSlide.extent = new Vector(381, 40); audioPane.addChild(audMusSlide); - var audMusKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_mus_knb.png").toTile()); + var audMusKnob = new GuiSlider(ResourceLoader.getResource("data/ui/options/aud_mus_knb.png", ResourceLoader.getImage, this.imageResources).toTile()); audMusKnob.position = new Vector(137, 37); audMusKnob.extent = new Vector(250, 34); audMusKnob.sliderValue = Settings.optionsSettings.musicVolume; @@ -288,11 +289,12 @@ class OptionsDlg extends GuiImage { } audioPane.addChild(audMusKnob); - var audSndKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_snd_knb.png").toTile()); + var audSndKnob = new GuiSlider(ResourceLoader.getResource("data/ui/options/aud_snd_knb.png", ResourceLoader.getImage, this.imageResources).toTile()); audSndKnob.position = new Vector(137, 95); audSndKnob.extent = new Vector(254, 37); audSndKnob.sliderValue = Settings.optionsSettings.soundVolume; - var testingSnd = AudioManager.playSound(ResourceLoader.getAudio("data/sound/testing.wav"), null, true); + var testingSnd = AudioManager.playSound(ResourceLoader.getResource("data/sound/testing.wav", ResourceLoader.getAudio, this.soundResources), null, + true); testingSnd.pause = true; audSndKnob.slidingSound = testingSnd; audSndKnob.pressedAction = (sender) -> { @@ -315,7 +317,7 @@ class OptionsDlg extends GuiImage { } } - var audTxtWndo = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_txt_wndo.png").toTile()); + var audTxtWndo = new GuiImage(ResourceLoader.getResource("data/ui/options/aud_txt_wndo.png", ResourceLoader.getImage, this.imageResources).toTile()); audTxtWndo.position = new Vector(26, 130); audTxtWndo.extent = new Vector(396, 132); audioPane.addChild(audTxtWndo); @@ -368,7 +370,8 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3"; controlsPane.position = new Vector(44, 58); controlsPane.extent = new Vector(459, 339); // MARBLE PANEL - var marbleControlsPane = new GuiImage(ResourceLoader.getImage("data/ui/options/cntrl_marb_bse.png").toTile()); + var marbleControlsPane = new GuiImage(ResourceLoader.getResource("data/ui/options/cntrl_marb_bse.png", ResourceLoader.getImage, this.imageResources) + .toTile()); marbleControlsPane.position = new Vector(0, 5); marbleControlsPane.extent = new Vector(438, 320); controlsPane.addChild(marbleControlsPane); @@ -503,7 +506,8 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3"; marbleControlsPane.addChild(marbleToMouseButton); // CAMERA PANEL - cameraControlsPane = new GuiImage(ResourceLoader.getImage("data/ui/options/cntrl_cam_bse.png").toTile()); + cameraControlsPane = new GuiImage(ResourceLoader.getResource("data/ui/options/cntrl_cam_bse.png", ResourceLoader.getImage, this.imageResources) + .toTile()); cameraControlsPane.position = new Vector(0, 5); cameraControlsPane.extent = new Vector(438, 320); @@ -565,7 +569,8 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3"; // MOUSE CONTROLS - mouseControlsPane = new GuiImage(ResourceLoader.getImage("data/ui/options/cntrl_mous_base.png").toTile()); + mouseControlsPane = new GuiImage(ResourceLoader.getResource("data/ui/options/cntrl_mous_base.png", ResourceLoader.getImage, this.imageResources) + .toTile()); mouseControlsPane.position = new Vector(-17, -47); mouseControlsPane.extent = new Vector(470, 425); @@ -619,7 +624,8 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3"; } mouseControlsPane.addChild(alwaysFreelook); - var mouseSensitivity = new GuiSlider(ResourceLoader.getImage("data/ui/options/cntrl_mous_knb.png").toTile()); + var mouseSensitivity = new GuiSlider(ResourceLoader.getResource("data/ui/options/cntrl_mous_knb.png", ResourceLoader.getImage, this.imageResources) + .toTile()); mouseSensitivity.position = new Vector(147, 148); mouseSensitivity.extent = new Vector(254, 34); mouseSensitivity.sliderValue = (Settings.controlsSettings.cameraSensitivity - 0.2) / (3 - 0.2); diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx index e2fbc2ee..cc4b83d2 100644 --- a/src/gui/PlayGui.hx +++ b/src/gui/PlayGui.hx @@ -1,5 +1,6 @@ package gui; +import hxd.res.Image; import hxd.Window; import h3d.shader.AlphaMult; import h3d.shader.ColorKey; @@ -22,6 +23,9 @@ import h2d.Anim; import h2d.Bitmap; import src.ResourceLoader; import src.MarbleGame; +import src.Resource; +import hxd.res.Sound; +import h3d.mat.Texture; class PlayGui { var scene2d:h2d.Scene; @@ -52,6 +56,10 @@ class PlayGui { var alertTextForeground:GuiText; var alertTextBackground:GuiText; + var imageResources:Array> = []; + var textureResources:Array> = []; + var soundResources:Array> = []; + var playGuiCtrl:GuiControl; var resizeEv:Void->Void; @@ -68,6 +76,17 @@ class PlayGui { powerupImageSceneTarget.dispose(); powerupImageSceneTargetBitmap.remove(); RSGOCenterText.remove(); + + for (textureResource in textureResources) { + textureResource.release(); + } + for (imageResource in imageResources) { + imageResource.release(); + } + for (audioResource in soundResources) { + audioResource.release(); + } + Window.getInstance().removeResizeEvent(resizeEv); } } @@ -84,7 +103,7 @@ class PlayGui { var numberTiles = []; for (i in 0...10) { - var tile = ResourceLoader.getImage('data/ui/game/numbers/${i}.png').toTile(); + var tile = ResourceLoader.getResource('data/ui/game/numbers/${i}.png', ResourceLoader.getImage, this.imageResources).toTile(); numberTiles.push(tile); } @@ -97,13 +116,13 @@ class PlayGui { } var rsgo = []; - rsgo.push(ResourceLoader.getImage("data/ui/game/ready.png").toTile()); - rsgo.push(ResourceLoader.getImage("data/ui/game/set.png").toTile()); - rsgo.push(ResourceLoader.getImage("data/ui/game/go.png").toTile()); - rsgo.push(ResourceLoader.getImage("data/ui/game/outofbounds.png").toTile()); + rsgo.push(ResourceLoader.getResource("data/ui/game/ready.png", ResourceLoader.getImage, this.imageResources).toTile()); + rsgo.push(ResourceLoader.getResource("data/ui/game/set.png", ResourceLoader.getImage, this.imageResources).toTile()); + rsgo.push(ResourceLoader.getResource("data/ui/game/go.png", ResourceLoader.getImage, this.imageResources).toTile()); + rsgo.push(ResourceLoader.getResource("data/ui/game/outofbounds.png", ResourceLoader.getImage, this.imageResources).toTile()); RSGOCenterText = new Anim(rsgo, 0, scene2d); - powerupBox = new GuiImage(ResourceLoader.getImage('data/ui/game/powerup.png').toTile()); + powerupBox = new GuiImage(ResourceLoader.getResource('data/ui/game/powerup.png', ResourceLoader.getImage, this.imageResources).toTile()); initTimer(); initGemCounter(); initCenterText(); @@ -133,7 +152,7 @@ class PlayGui { timerNumbers[1].position = new Vector(47, 0); timerNumbers[1].extent = new Vector(43, 55); - timerColon = new GuiImage(ResourceLoader.getImage('data/ui/game/numbers/colon.png').toTile()); + timerColon = new GuiImage(ResourceLoader.getResource('data/ui/game/numbers/colon.png', ResourceLoader.getImage, this.imageResources).toTile()); timerColon.position = new Vector(67, 0); timerColon.extent = new Vector(43, 55); @@ -143,7 +162,7 @@ class PlayGui { timerNumbers[3].position = new Vector(107, 0); timerNumbers[3].extent = new Vector(43, 55); - timerPoint = new GuiImage(ResourceLoader.getImage('data/ui/game/numbers/point.png').toTile()); + timerPoint = new GuiImage(ResourceLoader.getResource('data/ui/game/numbers/point.png', ResourceLoader.getImage, this.imageResources).toTile()); timerPoint.position = new Vector(127, 0); timerPoint.extent = new Vector(43, 55); @@ -203,7 +222,7 @@ class PlayGui { gemCountNumbers[1].position = new Vector(54, 0); gemCountNumbers[1].extent = new Vector(43, 55); - gemCountSlash = new GuiImage(ResourceLoader.getImage('data/ui/game/numbers/slash.png').toTile()); + gemCountSlash = new GuiImage(ResourceLoader.getResource('data/ui/game/numbers/slash.png', ResourceLoader.getImage, this.imageResources).toTile()); gemCountSlash.position = new Vector(75, 0); gemCountSlash.extent = new Vector(43, 55); diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index 1a4b21ae..514ef559 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -45,7 +45,8 @@ class PlayMissionGui extends GuiImage { currentSelection = PlayMissionGui.currentSelectionStatic; currentCategory = PlayMissionGui.currentCategoryStatic; - super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); + var img = ResourceLoader.getImage("data/ui/background.jpg"); + super(img.resource.toTile()); this.horizSizing = Width; this.vertSizing = Height; @@ -60,14 +61,14 @@ class PlayMissionGui extends GuiImage { this.addChild(localContainer); function loadButtonImages(path:String) { - var normal = ResourceLoader.getImage('${path}_n.png').toTile(); - var hover = ResourceLoader.getImage('${path}_h.png').toTile(); - var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); - var disabled = ResourceLoader.getImage('${path}_i.png').toTile(); + var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); + var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); + var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); + var disabled = ResourceLoader.getResource('${path}_i.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed, disabled]; } - var tabAdvanced = new GuiImage(ResourceLoader.getImage("data/ui/play/tab_adv.png").toTile()); + var tabAdvanced = new GuiImage(ResourceLoader.getResource("data/ui/play/tab_adv.png", ResourceLoader.getImage, this.imageResources).toTile()); tabAdvanced.position = new Vector(410, 21); tabAdvanced.extent = new Vector(166, 43); tabAdvanced.pressedAction = (sender) -> { @@ -77,7 +78,7 @@ class PlayMissionGui extends GuiImage { } localContainer.addChild(tabAdvanced); - var tabIntermediate = new GuiImage(ResourceLoader.getImage("data/ui/play/tab_inter.png").toTile()); + var tabIntermediate = new GuiImage(ResourceLoader.getResource("data/ui/play/tab_inter.png", ResourceLoader.getImage, this.imageResources).toTile()); tabIntermediate.position = new Vector(213, 6); tabIntermediate.extent = new Vector(205, 58); tabIntermediate.pressedAction = (sender) -> { @@ -87,7 +88,7 @@ class PlayMissionGui extends GuiImage { } localContainer.addChild(tabIntermediate); - var tabCustom = new GuiImage(ResourceLoader.getImage("data/ui/play/cust_tab.png").toTile()); + var tabCustom = new GuiImage(ResourceLoader.getResource("data/ui/play/cust_tab.png", ResourceLoader.getImage, this.imageResources).toTile()); tabCustom.position = new Vector(589, 91); tabCustom.extent = new Vector(52, 198); tabCustom.pressedAction = (sender) -> { @@ -97,28 +98,29 @@ class PlayMissionGui extends GuiImage { } localContainer.addChild(tabCustom); - var pmBox = new GuiImage(ResourceLoader.getImage("data/ui/play/playgui.png").toTile()); + var pmBox = new GuiImage(ResourceLoader.getResource("data/ui/play/playgui.png", ResourceLoader.getImage, this.imageResources).toTile()); pmBox.position = new Vector(0, 42); pmBox.extent = new Vector(610, 351); pmBox.horizSizing = Width; pmBox.vertSizing = Height; localContainer.addChild(pmBox); - var textWnd = new GuiImage(ResourceLoader.getImage("data/ui/play/text_window.png").toTile()); + var textWnd = new GuiImage(ResourceLoader.getResource("data/ui/play/text_window.png", ResourceLoader.getImage, this.imageResources).toTile()); textWnd.horizSizing = Width; textWnd.vertSizing = Height; textWnd.position = new Vector(31, 29); textWnd.extent = new Vector(276, 229); pmBox.addChild(textWnd); - var pmPreview = new GuiImage(ResourceLoader.getImage("data/missions/beginner/superspeed.jpg").toTile()); + var pmPreview = new GuiImage(ResourceLoader.getResource("data/missions/beginner/superspeed.jpg", ResourceLoader.getImage, this.imageResources) + .toTile()); pmPreview.position = new Vector(312, 42); pmPreview.extent = new Vector(258, 193); pmBox.addChild(pmPreview); var filt = new ColorMatrix(Matrix.I()); pmPreview.bmp.filter = filt; - var levelWnd = new GuiImage(ResourceLoader.getImage("data/ui/play/level_window.png").toTile()); + var levelWnd = new GuiImage(ResourceLoader.getResource("data/ui/play/level_window.png", ResourceLoader.getImage, this.imageResources).toTile()); levelWnd.position = new Vector(); levelWnd.extent = new Vector(258, 194); pmPreview.addChild(levelWnd); @@ -289,7 +291,7 @@ class PlayMissionGui extends GuiImage { pmDescriptionOther.text.text = descText2; pmBox.addChild(pmDescriptionOther); - var tabBeginner = new GuiImage(ResourceLoader.getImage("data/ui/play/tab_begin.png").toTile()); + var tabBeginner = new GuiImage(ResourceLoader.getResource("data/ui/play/tab_begin.png", ResourceLoader.getImage, this.imageResources).toTile()); tabBeginner.position = new Vector(29, 2); tabBeginner.extent = new Vector(184, 55); tabBeginner.pressedAction = (sender) -> { @@ -309,7 +311,7 @@ class PlayMissionGui extends GuiImage { localContainer.removeChild(tabCustom); localContainer.removeChild(pmBox); if (doRender) - AudioManager.playSound(ResourceLoader.getAudio("data/sound/buttonpress.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources)); if (category == "beginner") { localContainer.addChild(tabIntermediate); localContainer.addChild(tabAdvanced); @@ -376,7 +378,7 @@ class PlayMissionGui extends GuiImage { return splits.join('\n'); } - var goldBadge = ResourceLoader.getImage("data/ui/play/goldscore.png").toTile(); + var goldBadge = ResourceLoader.getResource("data/ui/play/goldscore.png", ResourceLoader.getImage, this.imageResources).toTile(); goldBadge.dy = 2.5; goldBadge.dx = 8; diff --git a/src/gui/RemapDlg.hx b/src/gui/RemapDlg.hx index a3f45a71..e8e333a1 100644 --- a/src/gui/RemapDlg.hx +++ b/src/gui/RemapDlg.hx @@ -16,7 +16,7 @@ class RemapDlg extends GuiControl { this.position = new Vector(); this.extent = new Vector(640, 480); - var remapDlg = new GuiImage(ResourceLoader.getImage("data/ui/common/dialog.png").toTile()); + var remapDlg = new GuiImage(ResourceLoader.getResource("data/ui/common/dialog.png", ResourceLoader.getImage, this.imageResources).toTile()); remapDlg.horizSizing = Center; remapDlg.vertSizing = Center; remapDlg.position = new Vector(170, 159); diff --git a/src/shapes/AntiGravity.hx b/src/shapes/AntiGravity.hx index 4d582195..46a05ed0 100644 --- a/src/shapes/AntiGravity.hx +++ b/src/shapes/AntiGravity.hx @@ -15,7 +15,7 @@ class AntiGravity extends PowerUp { this.identifier = "AntiGravity"; this.pickUpName = "Gravity Modifier"; this.autoUse = true; - this.pickupSound = ResourceLoader.getAudio("data/sound/gravitychange.wav"); + this.pickupSound = ResourceLoader.getResource("data/sound/gravitychange.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { diff --git a/src/shapes/DuctFan.hx b/src/shapes/DuctFan.hx index 069cfd87..96ed4708 100644 --- a/src/shapes/DuctFan.hx +++ b/src/shapes/DuctFan.hx @@ -31,7 +31,8 @@ class DuctFan extends ForceObject { public override function init(level:src.MarbleWorld) { super.init(level); - this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/fan_loop.wav"), new Vector(1e8, 1e8, 1e8), true); + this.soundChannel = AudioManager.playSound(ResourceLoader.getResource("data/sound/fan_loop.wav", ResourceLoader.getAudio, this.soundResources), + new Vector(1e8, 1e8, 1e8), true); } public override function update(timeState:src.TimeState) { diff --git a/src/shapes/EndPad.hx b/src/shapes/EndPad.hx index 7a098e26..f03e809b 100644 --- a/src/shapes/EndPad.hx +++ b/src/shapes/EndPad.hx @@ -19,6 +19,8 @@ import src.MarbleWorld.Scheduler; import src.ParticleSystem.ParticleEmitter; import src.ParticleSystem.ParticleEmitterOptions; import h3d.Vector; +import src.Resource; +import h3d.mat.Texture; class EndPad extends DtsObject { var fireworks:Array = []; @@ -45,7 +47,8 @@ class EndPad extends DtsObject { function spawnFirework(time:TimeState) { var firework = new Firework(this.getAbsPos().getPosition(), time.timeSinceLoad, this.level); this.fireworks.push(firework); - AudioManager.playSound(ResourceLoader.getAudio("data/sound/firewrks.wav"), this.getAbsPos().getPosition()); + AudioManager.playSound(ResourceLoader.getResource("data/sound/firewrks.wav", ResourceLoader.getAudio, this.soundResources), + this.getAbsPos().getPosition()); // AudioManager.play(this.sounds[0], 1, AudioManager.soundGain, this.worldPosition); } @@ -245,6 +248,8 @@ class Firework extends Scheduler { var fireworkRedSparkData:ParticleData; var fireworkBlueSparkData:ParticleData; + var textureResources:Array> = []; + public function new(pos:Vector, spawnTime:Float, level:MarbleWorld) { this.pos = pos; this.spawnTime = spawnTime; @@ -252,23 +257,43 @@ class Firework extends Scheduler { fireworkSmokeData = new ParticleData(); fireworkSmokeData.identifier = "fireworkSmoke"; - fireworkSmokeData.texture = ResourceLoader.getTexture("data/particles/saturn.png"); + var res1 = ResourceLoader.getTexture("data/particles/saturn.png"); + res1.acquire(); + if (!this.textureResources.contains(res1)) + this.textureResources.push(res1); + fireworkSmokeData.texture = res1.resource; fireworkRedTrailData = new ParticleData(); fireworkRedTrailData.identifier = "fireworkRedTrail"; - fireworkRedTrailData.texture = ResourceLoader.getTexture("data/particles/spark.png"); + var res2 = ResourceLoader.getTexture("data/particles/spark.png"); + res2.acquire(); + if (!this.textureResources.contains(res2)) + this.textureResources.push(res2); + fireworkRedTrailData.texture = res2.resource; fireworkBlueTrailData = new ParticleData(); fireworkBlueTrailData.identifier = "fireworkBlueTrail"; - fireworkBlueTrailData.texture = ResourceLoader.getTexture("data/particles/spark.png"); + var res3 = ResourceLoader.getTexture("data/particles/spark.png"); + res3.acquire(); + if (!this.textureResources.contains(res3)) + this.textureResources.push(res3); + fireworkBlueTrailData.texture = res3.resource; fireworkRedSparkData = new ParticleData(); fireworkRedSparkData.identifier = "fireworkRedSpark"; - fireworkRedSparkData.texture = ResourceLoader.getTexture("data/particles/star.png"); + var res4 = ResourceLoader.getTexture("data/particles/star.png"); + res4.acquire(); + if (!this.textureResources.contains(res4)) + this.textureResources.push(res4); + fireworkRedSparkData.texture = res4.resource; fireworkBlueSparkData = new ParticleData(); fireworkBlueSparkData.identifier = "fireworkBlueSpark"; - fireworkBlueSparkData.texture = ResourceLoader.getTexture("data/particles/bubble.png"); + var res5 = ResourceLoader.getTexture("data/particles/bubble.png"); + res5.acquire(); + if (!this.textureResources.contains(res5)) + this.textureResources.push(res5); + fireworkBlueSparkData.texture = res5.resource; level.particleManager.createEmitter(fireworkSmoke, fireworkSmokeData, this.pos); // Start the smoke this.doWave(this.spawnTime); // Start the first wave @@ -335,4 +360,10 @@ class Firework extends Scheduler { }; this.trails.push(trail); } + + function dispose() { + for (textureResource in this.textureResources) { + textureResource.release(); + } + } } diff --git a/src/shapes/Helicopter.hx b/src/shapes/Helicopter.hx index 4f9dccc0..753838d7 100644 --- a/src/shapes/Helicopter.hx +++ b/src/shapes/Helicopter.hx @@ -15,7 +15,7 @@ class Helicopter extends PowerUp { this.showSequences = false; this.identifier = "Helicopter"; this.pickUpName = "Gyrocopter PowerUp"; - this.pickupSound = ResourceLoader.getAudio("data/sound/pugyrocoptervoice.wav"); + this.pickupSound = ResourceLoader.getResource("data/sound/pugyrocoptervoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { diff --git a/src/shapes/LandMine.hx b/src/shapes/LandMine.hx index 133f965f..476420cd 100644 --- a/src/shapes/LandMine.hx +++ b/src/shapes/LandMine.hx @@ -103,15 +103,15 @@ class LandMine extends DtsObject { landMineParticleData = new ParticleData(); landMineParticleData.identifier = "landMineParticle"; - landMineParticleData.texture = ResourceLoader.getTexture("data/particles/smoke.png"); + landMineParticleData.texture = ResourceLoader.getResource("data/particles/smoke.png", ResourceLoader.getTexture, this.textureResources); landMineSmokeParticleData = new ParticleData(); landMineSmokeParticleData.identifier = "landMineSmokeParticle"; - landMineSmokeParticleData.texture = ResourceLoader.getTexture("data/particles/smoke.png"); + landMineSmokeParticleData.texture = ResourceLoader.getResource("data/particles/smoke.png", ResourceLoader.getTexture, this.textureResources); landMineSparkParticleData = new ParticleData(); landMineSparkParticleData.identifier = "landMineSparkParticle"; - landMineSparkParticleData.texture = ResourceLoader.getTexture("data/particles/spark.png"); + landMineSparkParticleData.texture = ResourceLoader.getResource("data/particles/spark.png", ResourceLoader.getTexture, this.textureResources); } override function onMarbleContact(timeState:TimeState, ?contact:CollisionInfo) { @@ -121,7 +121,7 @@ class LandMine extends DtsObject { this.setCollisionEnabled(false); // if (!this.level.rewinding) - AudioManager.playSound(ResourceLoader.getAudio("data/sound/explode1.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/explode1.wav", ResourceLoader.getAudio, this.soundResources)); this.level.particleManager.createEmitter(landMineParticle, landMineParticleData, this.getAbsPos().getPosition()); this.level.particleManager.createEmitter(landMineSmokeParticle, landMineSmokeParticleData, this.getAbsPos().getPosition()); this.level.particleManager.createEmitter(landMineSparksParticle, landMineSparkParticleData, this.getAbsPos().getPosition()); diff --git a/src/shapes/ShockAbsorber.hx b/src/shapes/ShockAbsorber.hx index 0fba3b12..6441e385 100644 --- a/src/shapes/ShockAbsorber.hx +++ b/src/shapes/ShockAbsorber.hx @@ -13,7 +13,7 @@ class ShockAbsorber extends PowerUp { this.isTSStatic = false; this.identifier = "ShockAbsorber"; this.pickUpName = "Shock Absorber PowerUp"; - this.pickupSound = ResourceLoader.getAudio("data/sound/pushockabsorbervoice.wav"); + this.pickupSound = ResourceLoader.getResource("data/sound/pushockabsorbervoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { diff --git a/src/shapes/SmallDuctFan.hx b/src/shapes/SmallDuctFan.hx index f2ffd128..baf7ebb8 100644 --- a/src/shapes/SmallDuctFan.hx +++ b/src/shapes/SmallDuctFan.hx @@ -31,7 +31,8 @@ class SmallDuctFan extends ForceObject { public override function init(level:src.MarbleWorld) { super.init(level); - this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/fan_loop.wav"), new Vector(1e8, 1e8, 1e8), true); + this.soundChannel = AudioManager.playSound(ResourceLoader.getResource("data/sound/fan_loop.wav", ResourceLoader.getAudio, this.soundResources), + new Vector(1e8, 1e8, 1e8), true); } public override function update(timeState:src.TimeState) { diff --git a/src/shapes/SuperBounce.hx b/src/shapes/SuperBounce.hx index a3d2b05d..1636ddce 100644 --- a/src/shapes/SuperBounce.hx +++ b/src/shapes/SuperBounce.hx @@ -13,7 +13,7 @@ class SuperBounce extends PowerUp { this.isTSStatic = false; this.identifier = "SuperBounce"; this.pickUpName = "Super Bounce PowerUp"; - this.pickupSound = ResourceLoader.getAudio("data/sound/pusuperbouncevoice.wav"); + this.pickupSound = ResourceLoader.getResource("data/sound/pusuperbouncevoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { diff --git a/src/shapes/SuperJump.hx b/src/shapes/SuperJump.hx index 08d668f1..11468fb3 100644 --- a/src/shapes/SuperJump.hx +++ b/src/shapes/SuperJump.hx @@ -44,8 +44,8 @@ class SuperJump extends PowerUp { this.pickUpName = "Super Jump PowerUp"; sjEmitterParticleData = new ParticleData(); sjEmitterParticleData.identifier = "superJumpParticle"; - sjEmitterParticleData.texture = ResourceLoader.getTexture("data/particles/twirl.png"); - this.pickupSound = ResourceLoader.getAudio("data/sound/pusuperjumpvoice.wav"); + sjEmitterParticleData.texture = ResourceLoader.getResource("data/particles/twirl.png", ResourceLoader.getTexture, this.textureResources); + this.pickupSound = ResourceLoader.getResource("data/sound/pusuperjumpvoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { @@ -58,7 +58,7 @@ class SuperJump extends PowerUp { this.level.particleManager.createEmitter(superJumpParticleOptions, this.sjEmitterParticleData, null, () -> marble.getAbsPos().getPosition()); // marble.body.addLinearVelocity(this.level.currentUp.scale(20)); // Simply add to vertical velocity // if (!this.level.rewinding) - AudioManager.playSound(ResourceLoader.getAudio("data/sound/dosuperjump.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/dosuperjump.wav", ResourceLoader.getAudio, this.soundResources)); // this.level.particles.createEmitter(superJumpParticleOptions, null, () => Util.vecOimoToThree(marble.body.getPosition())); this.level.deselectPowerUp(); } diff --git a/src/shapes/SuperSpeed.hx b/src/shapes/SuperSpeed.hx index ceb0ac3f..26ea6d77 100644 --- a/src/shapes/SuperSpeed.hx +++ b/src/shapes/SuperSpeed.hx @@ -50,8 +50,8 @@ class SuperSpeed extends PowerUp { this.useInstancing = true; ssEmitterParticleData = new ParticleData(); ssEmitterParticleData.identifier = "superSpeedParticle"; - ssEmitterParticleData.texture = ResourceLoader.getTexture("data/particles/spark.png"); - this.pickupSound = ResourceLoader.getAudio("data/sound/pusuperspeedvoice.wav"); + ssEmitterParticleData.texture = ResourceLoader.getResource("data/particles/spark.png", ResourceLoader.getTexture, this.textureResources); + this.pickupSound = ResourceLoader.getResource("data/sound/pusuperspeedvoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { @@ -76,7 +76,7 @@ class SuperSpeed extends PowerUp { // marble.body.addLinearVelocity(Util.vecThreeToOimo(movementVector).scale(24.7)); // Whirligig's determined value // marble.body.addLinearVelocity(this.level.currentUp.scale(20)); // Simply add to vertical velocity // if (!this.level.rewinding) - AudioManager.playSound(ResourceLoader.getAudio("data/sound/dosuperspeed.wav")); + AudioManager.playSound(ResourceLoader.getResource("data/sound/dosuperspeed.wav", ResourceLoader.getAudio, this.soundResources)); this.level.particleManager.createEmitter(superSpeedParticleOptions, this.ssEmitterParticleData, null, () -> marble.getAbsPos().getPosition()); this.level.deselectPowerUp(); } diff --git a/src/shapes/TimeTravel.hx b/src/shapes/TimeTravel.hx index ee93e31f..4946aa7e 100644 --- a/src/shapes/TimeTravel.hx +++ b/src/shapes/TimeTravel.hx @@ -23,7 +23,7 @@ class TimeTravel extends PowerUp { this.cooldownDuration = 1e8; this.useInstancing = true; this.autoUse = true; - this.pickupSound = ResourceLoader.getAudio("data/sound/putimetravelvoice.wav"); + this.pickupSound = ResourceLoader.getResource("data/sound/putimetravelvoice.wav", ResourceLoader.getAudio, this.soundResources); } public function pickUp():Bool { diff --git a/src/shapes/Tornado.hx b/src/shapes/Tornado.hx index 225dfa86..ff0e4f63 100644 --- a/src/shapes/Tornado.hx +++ b/src/shapes/Tornado.hx @@ -46,7 +46,8 @@ class Tornado extends ForceObject { public override function init(level:src.MarbleWorld) { super.init(level); - this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/tornado.wav"), new Vector(1e8, 1e8, 1e8), true); + this.soundChannel = AudioManager.playSound(ResourceLoader.getResource("data/sound/tornado.wav", ResourceLoader.getAudio, this.soundResources), + new Vector(1e8, 1e8, 1e8), true); for (material in this.materials) { material.blendMode = Alpha; material.mainPass.culling = h3d.mat.Data.Face.None; diff --git a/src/shapes/Trapdoor.hx b/src/shapes/Trapdoor.hx index ac2072fc..bc9b7346 100644 --- a/src/shapes/Trapdoor.hx +++ b/src/shapes/Trapdoor.hx @@ -40,7 +40,8 @@ class Trapdoor extends DtsObject { direction = -1; if (direction != 0 && direction != this.lastDirection) { // If the direction has changed, play the sound - var ch = AudioManager.playSound(ResourceLoader.getAudio("data/sound/trapdooropen.wav"), this.getAbsPos().getPosition()); + var ch = AudioManager.playSound(ResourceLoader.getResource("data/sound/trapdooropen.wav", ResourceLoader.getAudio, this.soundResources), + this.getAbsPos().getPosition()); } this.lastCompletion = currentCompletion; diff --git a/src/triggers/HelpTrigger.hx b/src/triggers/HelpTrigger.hx index 3731e0f7..2e4d2939 100644 --- a/src/triggers/HelpTrigger.hx +++ b/src/triggers/HelpTrigger.hx @@ -6,7 +6,7 @@ import src.AudioManager; class HelpTrigger extends Trigger { override function onMarbleEnter(timeState:TimeState) { - AudioManager.playSound(ResourceLoader.getAudio('data/sound/infotutorial.wav')); + AudioManager.playSound(ResourceLoader.getResource('data/sound/infotutorial.wav', ResourceLoader.getAudio, this.soundResources)); this.level.displayHelp(this.element.text); // this.level.replay.recordMarbleEnter(this); }