瀏覽代碼

added immediate loading of possible files, added queue for other files

ncannasse 6 年之前
父節點
當前提交
7786c971e9
共有 1 個文件被更改,包括 18 次插入1 次删除
  1. 18 1
      hide/comp/Scene.hx

+ 18 - 1
hide/comp/Scene.hx

@@ -183,8 +183,11 @@ class Scene extends Component implements h3d.IDrawable {
 		engine.render(this);
 	}
 
+	var loadQueue : Array<Void->Void> = [];
+	var pendingCount : Int = 0;
+
 	function loadTextureData( img : hxd.res.Image, onReady : h3d.mat.Texture -> Void, ?target : h3d.mat.Texture ) {
-		if( img.entry.extension == "tga" ) {
+		if( !img.getFormat().useAsyncDecode ) {
 			// immediate read
 			var pix = img.getPixels();
 			if( target == null )
@@ -198,6 +201,20 @@ class Scene extends Component implements h3d.IDrawable {
 			}
 			return;
 		}
+		if( pendingCount < 10 ) {
+			pendingCount++;
+			_loadTextureData(img,function(t) {
+				pendingCount--;
+				var f = loadQueue.shift();
+				if( f != null ) f();
+				onReady(t);
+			}, target);
+		} else {
+			loadQueue.push(loadTextureData.bind(img,onReady,target));
+		}
+	}
+
+	function _loadTextureData( img : hxd.res.Image, onReady : h3d.mat.Texture -> Void, ?target : h3d.mat.Texture ) {
 		var path = ide.getPath(img.entry.path);
 		var img = new Element('<img src="file://$path" crossorigin="anonymous"/>');
 		function onLoaded() {