Ver Fonte

added dispose()

ncannasse há 10 anos atrás
pai
commit
34cfcb7510

+ 1 - 1
hxd/fmt/pak/FileSystem.hx

@@ -148,7 +148,7 @@ class FileSystem implements hxd.fs.FileSystem {
 		files.push(s);
 	}
 
-	public function close() {
+	public function dispose() {
 		for( f in files )
 			f.close();
 		files = [];

+ 3 - 0
hxd/fs/BytesFileSystem.hx

@@ -85,4 +85,7 @@ class BytesFileSystem implements FileSystem {
 		return new BytesFileEntry(path,bytes);
 	}
 
+	public function dispose() {
+	}
+
 }

+ 3 - 0
hxd/fs/EmbedFileSystem.hx

@@ -269,4 +269,7 @@ class EmbedFileSystem #if !macro implements FileSystem #end {
 		return macro { $types; @:privateAccess new hxd.fs.EmbedFileSystem(haxe.Unserializer.run($v { sdata } )); };
 	}
 
+	public function dispose() {
+	}
+
 }

+ 1 - 0
hxd/fs/FileSystem.hx

@@ -4,4 +4,5 @@ interface FileSystem {
 	public function getRoot() : FileEntry;
 	public function get( path : String ) : FileEntry;
 	public function exists( path : String ) : Bool;
+	public function dispose() : Void;
 }

+ 8 - 0
hxd/fs/LocalFileSystem.hx

@@ -405,6 +405,10 @@ class LocalFileSystem implements FileSystem {
 		#end
 	}
 
+	public function dispose() {
+		fileCache = new Map();
+	}
+
 }
 
 #else
@@ -432,6 +436,10 @@ class LocalFileSystem implements FileSystem {
 	public function getRoot() : FileEntry {
 		return null;
 	}
+
+	public function dispose() {
+	}
+
 }
 
 #end

+ 5 - 0
hxd/fs/MultiFileSystem.hx

@@ -101,4 +101,9 @@ class MultiFileSystem implements FileSystem {
 		return false;
 	}
 
+	public function dispose() {
+		for( f in fs )
+			f.dispose();
+	}
+
 }

+ 11 - 0
hxd/res/Loader.hx

@@ -2,6 +2,12 @@ package hxd.res;
 
 class Loader {
 
+	/**
+		Set when initializing hxd.Res, or manually.
+		Allows code to resolve resources without compiling hxd.Res
+	*/
+	public static var currentInstance : Loader;
+
 	public var fs(default,null) : hxd.fs.FileSystem;
 	var cache : Map<String,Dynamic>;
 
@@ -67,4 +73,9 @@ class Loader {
 		return new TiledMap(fs.get(path));
 	}
 
+	public function dispose() {
+		cache = new Map();
+		fs.dispose();
+	}
+
 }