Pārlūkot izejas kodu

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

Clément Espeute 1 mēnesi atpakaļ
vecāks
revīzija
196c7b69f3

+ 1 - 1
hide/tools/ThumbnailGenerator.hx

@@ -280,7 +280,7 @@ class ThumbnailGenerator {
 						// Forward the animations a little bit to show something more usefull
 						// Forward the animations a little bit to show something more usefull
 						if (fxAnim != null) {
 						if (fxAnim != null) {
 							var duration = fxAnim.duration;
 							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();
 						fx.reset();
 					}
 					}
 				}
 				}
-				@:privateAccess fx.setTime(nextTime, localDt, hasJumped);
+				@:privateAccess fx.setTimeInternal(nextTime, localDt, hasJumped);
 
 
 				currentTime = fx.localTime;
 				currentTime = fx.localTime;
 				lastTime = currentTime;
 				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));
 		var anims = meshPreviewRoot3d.findAll((f) -> Std.downcast(f, hrt.prefab.fx.FX.FXAnimation));
 		for (anim in anims) {
 		for (anim in anims) {
 			if (@:privateAccess anim.parentFX != null) {
 			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() {
 	public function softReset() {
-		trace("softReset");
 		totalBurstCount = 0;
 		totalBurstCount = 0;
 		enable = true;
 		enable = true;
 	}
 	}
@@ -1226,9 +1225,6 @@ class EmitterObject extends h3d.scene.Object {
 				case Burst:
 				case Burst:
 					if( burstDelay > 0 ) {
 					if( burstDelay > 0 ) {
 						var burstTarget = hxd.Math.min(burstCount, 1 + hxd.Math.floor(curTime / burstDelay));
 						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 ) {
 						while( totalBurstCount < burstTarget ) {
 							var delta = hxd.Math.ceil(hxd.Math.min(maxCount - numInstances, Std.int(evaluator.getFloat(burstParticleCount, curTime))));
 							var delta = hxd.Math.ceil(hxd.Math.min(maxCount - numInstances, Std.int(evaluator.getFloat(burstParticleCount, curTime))));
 							doEmit(delta);
 							doEmit(delta);
@@ -1496,7 +1492,6 @@ class EmitterObject extends h3d.scene.Object {
 		}
 		}
 		else if (!seek) {
 		else if (!seek) {
 			if (parentTime < lastParentTime) {
 			if (parentTime < lastParentTime) {
-				trace("softReset", parentTime, localTime, curTime);
 				softReset();
 				softReset();
 				curTime = localTime;
 				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
 			// so we restore FX in correct state when unculled
 			if (parentFX == null) {
 			if (parentFX == null) {
 				var dt = ctx.elapsedTime * playSpeed;
 				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}> = [];
 	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
 		newTime is the new time to set, relative to the "parent" timeline
 		dt is the relative delta of time since the last "parent" update
 		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
 		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;
 		var oldLocalTime = localTime;
 		localTime = newTimeParent - startDelay;
 		localTime = newTimeParent - startDelay;
@@ -324,7 +347,7 @@ class FXAnimation extends h3d.scene.Object {
 		}
 		}
 
 
 		for (subFX in subFXs) {
 		for (subFX in subFXs) {
-			subFX.setTime(localTime, dt, isSeek, fullSync);
+			subFX.setTimeInternal(localTime, dt, isSeek, fullSync);
 		}
 		}
 
 
 		if (fullSync) {
 		if (fullSync) {
@@ -546,7 +569,7 @@ class FXAnimation extends h3d.scene.Object {
 		this.onEnd = onEnd;
 		this.onEnd = onEnd;
 		playState = End;
 		playState = End;
 		if (instant == true) {
 		if (instant == true) {
-			setTime(duration, 0, true, true);
+			setTimeInternal(duration, 0, true, true);
 		} else {
 		} else {
 			stopTime = localTime;
 			stopTime = localTime;
 		}
 		}