From 3ae2dbae2e18059b89e7ab9572d2767644ac108f Mon Sep 17 00:00:00 2001 From: Sarbian Date: Sun, 16 Aug 2015 11:53:55 +0200 Subject: [PATCH] v2.6.8 - minor performance update --- PersistentKSPParticleEmitter.cs | 41 ++++++++++++++++++--------------- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/PersistentKSPParticleEmitter.cs b/PersistentKSPParticleEmitter.cs index 847773b..46abedc 100644 --- a/PersistentKSPParticleEmitter.cs +++ b/PersistentKSPParticleEmitter.cs @@ -197,6 +197,13 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity) bool coneToggle = true; Vector2 disk = new Vector2 (0,0); + double logGrowConst = TimeWarp.fixedDeltaTime * logarithmicGrow * logarithmicGrowScale; + float linGrowConst = (float)(TimeWarp.fixedDeltaTime * linearGrow * averageSize); + + Transform peTransform = pe.transform; + + Vector3d frameVel = Krakensbane.GetFrameVelocity(); + //Step through all the particles: for (int j = 0; j < particles.Length; j++) { @@ -215,11 +222,12 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity) } } + if (particle.energy > 0) { Vector3d pPos = pe.useWorldSpace ? particle.position - : pe.transform.TransformPoint(particle.position); + : peTransform.TransformPoint(particle.position); //Slight methodology change to avoid duplicating if statements: Vector3d pVel; @@ -250,46 +258,44 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity) lVel = Vector3.Normalize(lVel); lVel *= Vector3.Magnitude(particle.velocity); - pVel = pe.transform.TransformDirection(lVel) - + Krakensbane.GetFrameVelocity(); + pVel = peTransform.TransformDirection(lVel) + frameVel; } else if (!pe.useWorldSpace && particle.energy != particle.startEnergy) { - pVel = pe.transform.TransformDirection(particle.velocity.x * xyForce, + pVel = peTransform.TransformDirection(particle.velocity.x * xyForce, particle.velocity.y * xyForce, particle.velocity.z * zForce) - + Krakensbane.GetFrameVelocity(); + + frameVel; } else { - pVel = pe.transform.TransformDirection(particle.velocity) - + Krakensbane.GetFrameVelocity(); + pVel = peTransform.TransformDirection(particle.velocity) + frameVel; } + // try-finally block to ensure we set the particle velocities correctly in the end. try { // Fixed update is not the best place to update the size but the particles array copy is // slow so doing each frame would be worse - + // No need to waste time doing a division if the result is 0. if (logarithmicGrow != 0.0) { // Euler integration of the derivative of Log(logarithmicGrowth * t + 1) + 1. // This might look weird. - particle.size += - (float) - (((TimeWarp.fixedDeltaTime * logarithmicGrow * logarithmicGrowScale) - / (1 + (particle.startEnergy - particle.energy) * logarithmicGrow)) * averageSize); + + particle.size += (float) ((logGrowConst / (1 + (particle.startEnergy - particle.energy) * logarithmicGrow)) * averageSize); } if (linearGrow != 0.0) { - particle.size += (float)(TimeWarp.fixedDeltaTime * linearGrow * averageSize); + particle.size += linGrowConst; } - + particle.size = Mathf.Min(particle.size, sizeClamp); if (particle.energy == particle.startEnergy) { + if (pe.useWorldSpace) { // Uniformly scatter newly emitted particles along the emitter's trajectory in order to @@ -354,12 +360,11 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity) finally { particle.velocity = (pe.useWorldSpace - ? (Vector3)(pVel - Krakensbane.GetFrameVelocity()) - : pe.transform.InverseTransformDirection( - pVel - Krakensbane.GetFrameVelocity())); + ? (Vector3)(pVel - frameVel) + : peTransform.InverseTransformDirection(pVel - frameVel)); particle.position = pe.useWorldSpace ? (Vector3)pPos - : pe.transform.InverseTransformPoint(pPos); + : peTransform.InverseTransformPoint(pPos); } } particles[j] = particle; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index bccdeec..cf89880 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -34,5 +34,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.6.7.0")] -[assembly: AssemblyFileVersion("2.6.7.0")] +[assembly: AssemblyVersion("2.6.8.0")] +[assembly: AssemblyFileVersion("2.6.8.0")]