Skip to content

Commit

Permalink
Reformat and log10 change
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed May 18, 2014
1 parent 915734f commit 9bc6580
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 75 deletions.
84 changes: 53 additions & 31 deletions ModelMultiParticlePersistFX.cs
Expand Up @@ -24,12 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

using System;
using System.Collections.Generic;
using System.Text;

using SmokeScreen;

using UnityEngine;

[EffectDefinition("MODEL_MULTI_PARTICLE_PERSIST")]
Expand Down Expand Up @@ -64,7 +62,6 @@ public class ModelMultiParticlePersistFX : EffectBehaviour
[Persistent]
public Vector3 offsetDirection = Vector3.forward;


[Persistent]
public float fixedScale = 1;

Expand All @@ -85,7 +82,7 @@ public class ModelMultiParticlePersistFX : EffectBehaviour

// How much the particles stick to objects they collide with.
[Persistent]
public double stickiness = 0.5;
public double stickiness = 0.9;

[Persistent]
public double dragCoefficient = 0.1;
Expand All @@ -110,11 +107,17 @@ public class ModelMultiParticlePersistFX : EffectBehaviour
#endregion Persistent fields

public MultiInputCurve emission;

public MultiInputCurve energy;

public MultiInputCurve speed;

public MultiInputCurve grow;

public MultiInputCurve scale;

public MultiInputCurve size;

public MultiInputCurve offset;

// Logarithmic growth applied to to the particle.
Expand Down Expand Up @@ -175,7 +178,6 @@ public ModelMultiParticlePersistFX()
// list.Remove(this);
//}


private void OnDestroy()
{
if (persistentEmitters != null)
Expand Down Expand Up @@ -229,7 +231,7 @@ public override void OnEvent(float power)
}

private bool addedLaunchPadCollider = false;

public static uint physicsPass = 4;

public static uint activePhysicsPass = 0;
Expand Down Expand Up @@ -291,8 +293,10 @@ public void FixedUpdate()
if (SmokeScreenConfig.particleDecimate != 0 && particles.Length > SmokeScreenConfig.decimateFloor)
{
SmokeScreenConfig.particleCounter++;
if ((SmokeScreenConfig.particleDecimate > 0 && (SmokeScreenConfig.particleCounter % SmokeScreenConfig.particleDecimate) == 0)
|| (SmokeScreenConfig.particleDecimate < 0 && (SmokeScreenConfig.particleCounter % SmokeScreenConfig.particleDecimate) != 0))
if ((SmokeScreenConfig.particleDecimate > 0
&& (SmokeScreenConfig.particleCounter % SmokeScreenConfig.particleDecimate) == 0)
|| (SmokeScreenConfig.particleDecimate < 0
&& (SmokeScreenConfig.particleCounter % SmokeScreenConfig.particleDecimate) != 0))
{
particles[j].energy = 0; // energy set to 0 remove the particle, as per Unity doc
}
Expand Down Expand Up @@ -372,14 +376,16 @@ public void FixedUpdate()
}
}

if (physical && !SmokeScreenConfig.Instance.globalPhysicalDisable && (j % physicsPass == activePhysicsPass))
if (physical && !SmokeScreenConfig.Instance.globalPhysicalDisable
&& (j % physicsPass == activePhysicsPass))
{
// There must be a way to keep the actual initial volume,
// but I'm lazy.
pVel = ParticlePhysics(particles[j].size, averageSize, pPos, pVel);
}

if (collide && !SmokeScreenConfig.Instance.globalCollideDisable && particles[j].energy != particles[j].startEnergy
if (collide && !SmokeScreenConfig.Instance.globalCollideDisable
&& particles[j].energy != particles[j].startEnergy
// Do not collide newly created particles (they collide with the emitter and things look bad).
&& (j % physicsPass == activePhysicsPass))
{
Expand Down Expand Up @@ -546,7 +552,9 @@ private void AddLaunchPadColliders(RaycastHit hit)
private void UpdateInputs(float power)
{
if (overRideInputs)
{
return;
}

float atmDensity = 1;
float surfaceVelMach = 1;
Expand Down Expand Up @@ -578,7 +586,10 @@ private void UpdateInputs(float power)
externalTemp = FlightGlobals.getExternalTemperature(hostPart.transform.position);
const double magicNumberFromFAR = 1.4 * 8.3145 * 1000 / 28.96;
double speedOfSound = Math.Sqrt((externalTemp + 273.15) * magicNumberFromFAR);
surfaceVelMach = (float)((hostPart.vel - FlightGlobals.currentMainBody.getRFrmVel(hostPart.transform.position)).magnitude / speedOfSound);
surfaceVelMach =
(float)
((hostPart.vel - FlightGlobals.currentMainBody.getRFrmVel(hostPart.transform.position)).magnitude
/ speedOfSound);
}
}

Expand Down Expand Up @@ -621,7 +632,10 @@ public void UpdateEmitters(float power)

logarithmicGrow = logGrow.Value(inputs);

pkpe.go.transform.localPosition = localPosition + offsetDirection.normalized * offset.Value(inputs) * fixedScale;
pkpe.go.transform.localPosition = localPosition
+ offsetDirection.normalized * offset.Value(inputs) * fixedScale;

pkpe.go.transform.localRotation = Quaternion.Euler(localRotation);

////print(atmDensity.ToString("F2") + " " + offset.Value(power).ToString("F2") + " " + offsetFromDensity.Value(atmDensity).ToString("F2") + " " + offsetFromMach.Value(surfaceVelMach).ToString("F2"));
}
Expand All @@ -648,15 +662,15 @@ public void Update()
}
}



public override void OnInitialize()
{
// Restore the Curve config from the node content backup
// Done because I could not get the serialization of MultiInputCurve to work
if (node_backup != string.Empty) Restore();
if (node_backup != string.Empty)
{
Restore();
}


// The shader loading require proper testing
// Unity doc says that "Creating materials this way supports only simple shaders (fixed function ones).
// If you need a surface shader, or vertex/pixel shaders, you'll need to create shader asset in the editor and use that."
Expand Down Expand Up @@ -721,7 +735,7 @@ public override void OnInitialize()
emitterGameObject,
childKSPParticleEmitter,
templateKspParticleEmitter);

try
{
childKSPParticleEmitter.particleRenderMode =
Expand All @@ -745,7 +759,7 @@ public override void OnInitialize()

list.Add(this);
}

public void Backup(ConfigNode node)
{
node_backup = SmokeScreenUtil.WriteRootNode(node);
Expand Down Expand Up @@ -810,19 +824,20 @@ private static void print(String s)
MonoBehaviour.print("[ModelMultiParticlePersistFX] " + s);
}


// TODO : move the whole UI stuff to a dedicated class - this is getting way to big

private Rect winPos = new Rect(50, 50, 400, 100);

private static int baseWinID = 512100;

private static int winID = baseWinID;

private string nodeText = "";

private bool nodeEdit = false;

private Vector2 scrollPosition = new Vector2();

private void OnGUI()
{
if (!HighLogic.LoadedSceneIsFlight)
Expand All @@ -831,7 +846,12 @@ private void OnGUI()
}
if (showUI)
{
winPos = GUILayout.Window(winID, winPos, windowGUI, hostPart.name + " " + this.effectName + " " + this.instanceName, GUILayout.MinWidth(300));
winPos = GUILayout.Window(
winID,
winPos,
windowGUI,
hostPart.name + " " + this.effectName + " " + this.instanceName,
GUILayout.MinWidth(300));
}
}

Expand Down Expand Up @@ -864,15 +884,14 @@ private void windowGUI(int ID)
GUILayout.Space(10);

nodeEdit = GUILayout.Toggle(nodeEdit, "Open Config Editor");

if (nodeEdit)
{
GUILayout.BeginHorizontal();

// Set the node with what was in the .cfg
if (GUILayout.Button("Import"))
{

nodeText = string.Copy(node_backup);
//print("Displaying node \n " + nodeText.Replace("\n", "\n" + "ModelMultiParticlePersistFX "));
}
Expand Down Expand Up @@ -900,7 +919,7 @@ private void windowGUI(int ID)
nodeText = GUILayout.TextArea(nodeText, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.EndScrollView();
}

GUILayout.EndVertical();

GUI.DragWindow();
Expand All @@ -910,12 +929,11 @@ private void windowGUI(int ID)

private void GUIInput(int id, string text)
{

float min = minInput(id);
float max = maxInput(id);

GUILayout.Label(text + " Val=" + inputs[id].ToString("F3") + " Min=" + min.ToString("F2") + " Max=" + max.ToString("F2"));

GUILayout.Label(
text + " Val=" + inputs[id].ToString("F3") + " Min=" + min.ToString("F2") + " Max=" + max.ToString("F2"));

if (overRideInputs)
{
Expand All @@ -930,7 +948,11 @@ private void GUIInput(int id, string text)
}
else
{
inputs[id] = GUILayout.HorizontalSlider(inputs[id], minInput(id), maxInput(id), GUILayout.ExpandWidth(true));
inputs[id] = GUILayout.HorizontalSlider(
inputs[id],
minInput(id),
maxInput(id),
GUILayout.ExpandWidth(true));
}

GUILayout.EndHorizontal();
Expand All @@ -947,7 +969,7 @@ private float minInput(int id)
min = Mathf.Min(min, size.minInput[id]);
min = Mathf.Min(min, offset.minInput[id]);
min = Mathf.Min(min, logGrow.minInput[id]);

return min;
}

Expand All @@ -961,7 +983,7 @@ private float maxInput(int id)
max = Mathf.Max(max, size.maxInput[id]);
max = Mathf.Max(max, offset.maxInput[id]);
max = Mathf.Max(max, logGrow.maxInput[id]);

return max;
}
}
11 changes: 3 additions & 8 deletions MultiInputCurve.cs
Expand Up @@ -24,15 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using SmokeScreen;
using UnityEngine;


// This class Serialization DOES NOT WORK in Unity
// Life would be so easier if it did.
[Serializable]
Expand Down Expand Up @@ -202,8 +197,8 @@ public float Value(float[] inputs)
if (logCurves[i] != null)
{
result = additive
? result + logCurves[i].Value(Mathf.Log(input))
: result * logCurves[i].Value(Mathf.Log(input));
? result + logCurves[i].Value(Mathf.Log10(input))
: result * logCurves[i].Value(Mathf.Log10(input));
}
}
return result;
Expand Down
20 changes: 12 additions & 8 deletions PersistentKSPParticleEmitter.cs
Expand Up @@ -25,38 +25,43 @@
*
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;


// TODO : handle the relation with PersistentEmitterManager inside the class
public class PersistentKSPParticleEmitter
{
public GameObject go;

public KSPParticleEmitter pe;

public bool fixedEmit = false;

public float timer = 0;

public readonly float minEmissionBase;

public readonly float maxEmissionBase;

public readonly float minEnergyBase;

public readonly float maxEnergyBase;

public readonly float minSizeBase;

public readonly float maxSizeBase;

public readonly float scale1DBase;

public readonly Vector2 scale2DBase;

public readonly Vector3 scale3DBase;

readonly public Vector3 localVelocityBase;
public readonly Vector3 localVelocityBase;

public PersistentKSPParticleEmitter(GameObject go, KSPParticleEmitter pe, KSPParticleEmitter templateKspParticleEmitter)
public PersistentKSPParticleEmitter(
GameObject go,
KSPParticleEmitter pe,
KSPParticleEmitter templateKspParticleEmitter)
{
this.go = go;
this.pe = pe;
Expand Down Expand Up @@ -94,5 +99,4 @@ public void EmissionStop()
fixedEmit = false;
pe.emit = false;
}

}

0 comments on commit 9bc6580

Please sign in to comment.