Browse Source

Scene: cache resolution of paths

trethaller 7 years ago
parent
commit
ccff551e89
1 changed files with 12 additions and 1 deletions
  1. 12 1
      hide/comp/Scene.hx

+ 12 - 1
hide/comp/Scene.hx

@@ -59,6 +59,7 @@ class Scene extends Component implements h3d.IDrawable {
 	var canvas : js.html.CanvasElement;
 	var hmdCache = new Map<String, hxd.fmt.hmd.Library>();
 	var texCache = new Map<String, h3d.mat.Texture>();
+	var pathsMap = new Map<String, String>();
 	var cleanup = new Array<Void->Void>();
 	var defaultCamera : h3d.Camera;
 	public var props : hide.ui.Props;
@@ -293,7 +294,7 @@ class Scene extends Component implements h3d.IDrawable {
 		return lib.loadAnimation();
 	}
 
-	function resolvePath( modelPath : String, filePath : String ) {
+	function resolvePathImpl( modelPath : String, filePath : String ) {
 		inline function exists(path) return sys.FileSystem.exists(path);
 		var fullPath = ide.getPath(filePath);
 		if( exists(fullPath) )
@@ -321,6 +322,16 @@ class Scene extends Component implements h3d.IDrawable {
 		return null;
 	}
 
+	function resolvePath(modelPath : String, filePath : String) {
+		var key = modelPath + ":" + filePath;
+		var p = pathsMap.get(key);
+		if(p != null)
+			return p;
+		p = resolvePathImpl(modelPath, filePath);
+		pathsMap.set(key, p);
+		return p;
+	}
+
 	public function loadTextureDotPath( path : String, ?onReady ) {
 		var path = path.split(".").join("/");
 		var t = resolvePath(null, path + ".png");