Skip to content

Commit

Permalink
v2.6.8 - minor performance update
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Aug 16, 2015
1 parent 25ba6b1 commit 3ae2dba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions PersistentKSPParticleEmitter.cs
Expand Up @@ -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++)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Expand Up @@ -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")]

0 comments on commit 3ae2dba

Please sign in to comment.