Explorar el Código

delayed source recompilation

ncannasse hace 6 años
padre
commit
b332ee953b
Se han modificado 1 ficheros con 13 adiciones y 10 borrados
  1. 13 10
      hxsl/CacheFile.hx

+ 13 - 10
hxsl/CacheFile.hx

@@ -81,6 +81,7 @@ class CacheFile extends Cache {
 	function load() {
 	function load() {
 		isLoading = true;
 		isLoading = true;
 		var t0 = haxe.Timer.stamp();
 		var t0 = haxe.Timer.stamp();
+		var wait = [];
 		if( sys.FileSystem.exists(file) ) {
 		if( sys.FileSystem.exists(file) ) {
 			loadShaders();
 			loadShaders();
 			if( sys.FileSystem.exists(sourceFile) )
 			if( sys.FileSystem.exists(sourceFile) )
@@ -90,14 +91,9 @@ class CacheFile extends Cache {
 
 
 			if( allowCompile ) {
 			if( allowCompile ) {
 				// update missing shader sources (after platform switch)
 				// update missing shader sources (after platform switch)
-				var change = false;
-				for( r in runtimeShaders ) {
-					if( r.vertex.code == null || r.fragment.code == null ) {
-						change = true;
-						addSource(r);
-					}
-				}
-				if( change ) save();
+				for( r in runtimeShaders )
+					if( r.vertex.code == null || r.fragment.code == null )
+						wait.push(addSource.bind(r));
 			}
 			}
 
 
 			log(runtimeShaders.length+" shaders loaded in "+hxd.Math.fmt(haxe.Timer.stamp() - t0)+"s");
 			log(runtimeShaders.length+" shaders loaded in "+hxd.Math.fmt(haxe.Timer.stamp() - t0)+"s");
@@ -109,12 +105,19 @@ class CacheFile extends Cache {
 			if( rt.vertex.code == null || rt.fragment.code == null ) {
 			if( rt.vertex.code == null || rt.fragment.code == null ) {
 				if( !allowCompile ) throw "Missing default shader code";
 				if( !allowCompile ) throw "Missing default shader code";
 				waitCount++;
 				waitCount++;
-				haxe.Timer.delay(function() {
+				wait.push(function() {
 					h3d.Engine.getCurrent().selectShader(rt);
 					h3d.Engine.getCurrent().selectShader(rt);
 					addNewShader(rt);
 					addNewShader(rt);
-				}, 1000);
+				});
 			}
 			}
 		}
 		}
+		if( wait.length > 0 ) {
+			haxe.Timer.delay(function() {
+				for( w in wait )
+					w();
+				save();
+			},1000); // wait until engine correctly initialized
+		}
 		isLoading = false;
 		isLoading = false;
 	}
 	}