Parcourir la source

Allow cache file to show loading progress

TothBenoit il y a 2 semaines
Parent
commit
a7d2e3e1be
2 fichiers modifiés avec 13 ajouts et 6 suppressions
  1. 11 4
      hxsl/CacheFile.hx
  2. 2 2
      hxsl/CacheFileBuilder.hx

+ 11 - 4
hxsl/CacheFile.hx

@@ -41,13 +41,13 @@ class CacheFile extends Cache {
 
 	public var allowSave = #if usesys false #else true #end;
 
-	public function new( allowCompile, recompileRT = false ) {
+	public function new( allowCompile, recompileRT = false, showProgress = false ) {
 		super();
 		this.allowCompile = allowCompile;
 		this.recompileRT = recompileRT || allowCompile;
 		this.file = FILENAME;
 		sourceFile = this.file + "." + getPlatformTag();
-		load();
+		load(showProgress);
 	}
 
 	function getPlatformTag() {
@@ -120,7 +120,7 @@ class CacheFile extends Cache {
 			for( r in wait ) {
 				if (showProgress && (waitCount % 5 == 0 || waitCount <= 1)) {
 					var progress = Std.int((1 - (waitCount / fullCount)) * 1000) / 10;
-					Sys.print('$progress%  \t(${fullCount - waitCount}/$fullCount)  \r');
+					log('$progress%  \t(${fullCount - waitCount}/$fullCount)  \r');
 				}
 
 				addNewShader(r);
@@ -135,7 +135,14 @@ class CacheFile extends Cache {
 			}
 			#else
 			haxe.Timer.delay(function() {
-				for( r in wait ) {
+				var shaderCount = wait.length;
+				if ( showProgress )
+					log('Compiling ${shaderCount} shaders');
+				for( i => r in wait ) {
+					if ( showProgress && i % 5 == 0 ) {
+						var progress = Std.int((i / shaderCount) * 1000) / 10;
+						log('$progress%  \t($i/$shaderCount)  \r');
+					}
 					addNewShader(r);
 					hxd.System.timeoutTick();
 				}

+ 2 - 2
hxsl/CacheFileBuilder.hx

@@ -18,10 +18,10 @@ private class CustomCacheFile extends CacheFile {
 
 	public function new(build) {
 		this.build = build;
-		super(true, true);
+		super(true, true, true);
 	}
 
-	override function load(showProgress=true) {
+	override function load(showProgress) {
 		allowSave = true;
 		super.load(showProgress);
 	}