瀏覽代碼

[fx] Restored old api, deprecated setTime in favor of Seek and Update functions

Clément Espeute 1 月之前
父節點
當前提交
196c7b69f3
共有 5 個文件被更改,包括 30 次插入12 次删除
  1. 1 1
      hide/tools/ThumbnailGenerator.hx
  2. 1 1
      hide/view/FXEditor.hx
  3. 1 1
      hide/view/shadereditor/ShaderEditor.hx
  4. 0 5
      hrt/prefab/fx/Emitter.hx
  5. 27 4
      hrt/prefab/fx/FX.hx

+ 1 - 1
hide/tools/ThumbnailGenerator.hx

@@ -280,7 +280,7 @@ class ThumbnailGenerator {
 						// Forward the animations a little bit to show something more usefull
 						if (fxAnim != null) {
 							var duration = fxAnim.duration;
-							fxAnim.setTime(duration * 0.25, 0, true, true);
+							fxAnim.setTimeInternal(duration * 0.25, 0, true, true);
 						}
 					}
 				}

+ 1 - 1
hide/view/FXEditor.hx

@@ -1766,7 +1766,7 @@ class FXEditor extends hide.view.FileView {
 						fx.reset();
 					}
 				}
-				@:privateAccess fx.setTime(nextTime, localDt, hasJumped);
+				@:privateAccess fx.setTimeInternal(nextTime, localDt, hasJumped);
 
 				currentTime = fx.localTime;
 				lastTime = currentTime;

+ 1 - 1
hide/view/shadereditor/ShaderEditor.hx

@@ -1470,7 +1470,7 @@ class ShaderEditor extends hide.view.FileView implements GraphInterface.IGraphEd
 		var anims = meshPreviewRoot3d.findAll((f) -> Std.downcast(f, hrt.prefab.fx.FX.FXAnimation));
 		for (anim in anims) {
 			if (@:privateAccess anim.parentFX != null) {
-				@:privateAccess anim.setTime(meshPreviewScene.s3d.renderer.ctx.time % anim.duration, meshPreviewScene.s3d.renderer.ctx.elapsedTime, false);
+				@:privateAccess anim.setTimeInternal(meshPreviewScene.s3d.renderer.ctx.time % anim.duration, meshPreviewScene.s3d.renderer.ctx.elapsedTime, false);
 			}
 		}
 	}

+ 0 - 5
hrt/prefab/fx/Emitter.hx

@@ -789,7 +789,6 @@ class EmitterObject extends h3d.scene.Object {
 
 
 	public function softReset() {
-		trace("softReset");
 		totalBurstCount = 0;
 		enable = true;
 	}
@@ -1226,9 +1225,6 @@ class EmitterObject extends h3d.scene.Object {
 				case Burst:
 					if( burstDelay > 0 ) {
 						var burstTarget = hxd.Math.min(burstCount, 1 + hxd.Math.floor(curTime / burstDelay));
-						if (burstTarget > totalBurstCount) {
-							trace("bc:", burstCount, "curTime", curTime, "bt:", burstTarget);
-						}
 						while( totalBurstCount < burstTarget ) {
 							var delta = hxd.Math.ceil(hxd.Math.min(maxCount - numInstances, Std.int(evaluator.getFloat(burstParticleCount, curTime))));
 							doEmit(delta);
@@ -1496,7 +1492,6 @@ class EmitterObject extends h3d.scene.Object {
 		}
 		else if (!seek) {
 			if (parentTime < lastParentTime) {
-				trace("softReset", parentTime, localTime, curTime);
 				softReset();
 				curTime = localTime;
 			}

+ 27 - 4
hrt/prefab/fx/FX.hx

@@ -250,7 +250,7 @@ class FXAnimation extends h3d.scene.Object {
 			// so we restore FX in correct state when unculled
 			if (parentFX == null) {
 				var dt = ctx.elapsedTime * playSpeed;
-				setTime(curTime + dt, dt, false, fullSync);
+				setTimeInternal(curTime + dt, dt, false, fullSync);
 			}
 		}
 
@@ -279,12 +279,35 @@ class FXAnimation extends h3d.scene.Object {
 
 	static var closest : Map<h3d.scene.Object, {instance: EventInstance, distance: Float, jumpTo: Float}> = [];
 
+
+	/**
+		Jump or rewind in time instantly in the current fx
+	**/
+	public function seek(newTime: Float, fullsync: Bool = true) {
+		setTimeInternal(newTime, 0, true, fullsync);
+	}
+
+	/**
+		Increase the current playtime of the animation by a small ammount
+	**/
+	public function update(dt: Float, fullsync: Bool) {
+		setTimeInternal(localTime + dt, dt, false, fullsync);
+	}
+
+	/**
+		Prefer using seek or update depending on the context
+	**/
+	@:deprecated
+	public function setTime(newTime: Float, fullsync: Bool = true) {
+		seek(newTime, fullsync);
+	}
+
 	/**
 		newTime is the new time to set, relative to the "parent" timeline
 		dt is the relative delta of time since the last "parent" update
 		Depending on how the parent loops, `newTime != lastTime + dt`, that's why the two arguments exists
 	**/
-	public function setTime(newTimeParent:Float, dt: Float, isSeek: Bool, fullSync: Bool = true) {
+	public function setTimeInternal(newTimeParent:Float, dt: Float, isSeek: Bool, fullSync: Bool = true) {
 
 		var oldLocalTime = localTime;
 		localTime = newTimeParent - startDelay;
@@ -324,7 +347,7 @@ class FXAnimation extends h3d.scene.Object {
 		}
 
 		for (subFX in subFXs) {
-			subFX.setTime(localTime, dt, isSeek, fullSync);
+			subFX.setTimeInternal(localTime, dt, isSeek, fullSync);
 		}
 
 		if (fullSync) {
@@ -546,7 +569,7 @@ class FXAnimation extends h3d.scene.Object {
 		this.onEnd = onEnd;
 		playState = End;
 		if (instant == true) {
-			setTime(duration, 0, true, true);
+			setTimeInternal(duration, 0, true, true);
 		} else {
 			stopTime = localTime;
 		}