فهرست منبع

FX: minor alloc optim, reset() also resets sub FX

trethaller 2 سال پیش
والد
کامیت
41b45dd7a7
2فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 6 2
      hrt/prefab/fx/BaseFX.hx
  2. 7 0
      hrt/prefab/fx/FX.hx

+ 6 - 2
hrt/prefab/fx/BaseFX.hx

@@ -116,7 +116,7 @@ class BaseFX extends hrt.prefab.Library {
 		if(shaderDef == null)
 			return null;
 
-		var ret : ShaderParams = [];
+		var ret : ShaderParams = null;
 
 		var paramCount = 0;
 		for(v in shaderDef.data.vars) {
@@ -137,6 +137,7 @@ class BaseFX extends hrt.prefab.Library {
 				case TVec(_, VFloat) :
 					var isColor = v.name.toLowerCase().indexOf("color") >= 0;
 					var val = isColor ? Curve.getColorValue(curves) : Curve.getVectorValue(curves);
+					if(ret == null) ret = [];
 					ret.push({
 						idx: paramCount - 1,
 						def: v,
@@ -151,6 +152,7 @@ class BaseFX extends hrt.prefab.Library {
 					var val = Value.VConst(base);
 					if(curve != null)
 						val = Value.VCurveScale(curve, base);
+					if(ret == null) ret = [];
 					ret.push({
 						idx: paramCount - 1,
 						def: v,
@@ -175,9 +177,11 @@ class BaseFX extends hrt.prefab.Library {
 
 		for(shCtx in ctx.shared.getContexts(elt)) {
 			if(shCtx.custom == null) continue;
+			var params = makeShaderParams(ctx, shader);
+			if(params == null) continue;
 			var anim = Std.isOfType(shCtx.custom,hxsl.DynamicShader) ? new ShaderDynAnimation() : new ShaderAnimation();
 			anim.shader = shCtx.custom;
-			anim.params = makeShaderParams(ctx, shader);
+			anim.params = params;
 			anims.push(anim);
 		}
 	}

+ 7 - 0
hrt/prefab/fx/FX.hx

@@ -49,6 +49,7 @@ class FXAnimation extends h3d.scene.Object {
 		initObjAnimations(ctx, root);
 		initEmitters(ctx, root);
 		BaseFX.getShaderAnims(ctx, root, shaderAnims);
+		if(shaderAnims.length == 0) shaderAnims = null;
 		events = initEvents(root, ctx);
 		var root = def.getFXRoot(ctx, def);
 		initConstraints(ctx, root != null ? root : def);
@@ -58,6 +59,12 @@ class FXAnimation extends h3d.scene.Object {
 		firstSync = true;
 		prevTime = -1.0;
 		localTime = 0;
+		if(parentFX == null) {
+			for(c in findAll(o -> Std.downcast(o, FXAnimation))) {
+				if(c != this)
+					c.reset();
+			}
+		}
 	}
 
 	public function setRandSeed(seed: Int) {