Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions Source/RocketSoundEnhancement/AudioUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,6 @@ public static class AudioUtility
public static AnimationCurve SmoothControl = AnimationCurve.EaseInOut(0f, 0.04f, 1f, 1f);
public static string RSETag = "RSE";

public static ConfigNode GetConfigNode(string partInfoName, string moduleName, string moduleID = "")
{
var configs = GameDatabase.Instance.GetConfigs("PART");

foreach (var configNode in configs)
{
if (configNode.name.Replace("_", ".") == partInfoName)
{
if (moduleID == "")
{
return Array.FindAll(configNode.config.GetNodes("MODULE"), x => x.GetValue("name") == moduleName).FirstOrDefault();
}
else
{
return Array.FindAll(configNode.config.GetNodes("MODULE"), x => x.GetValue("name") == moduleName && x.GetValue("moduleID") == moduleID).FirstOrDefault();
}
}
}
return null;
}

public static List<SoundLayer> CreateSoundLayerGroup(ConfigNode[] groupNodes)
{
var group = new List<SoundLayer>();
Expand Down
8 changes: 6 additions & 2 deletions Source/RocketSoundEnhancement/PartModules/RSE_Coupler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ public class RSE_Coupler : RSE_Module
private bool isDecoupler;
private bool hasDecoupled;

public RSE_Coupler()
{
EnableLowpassFilter = true;
EnableDistortionFilter = true;
}

public override void OnStart(StartState state)
{
if (state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
EnableDistortionFilter = true;
base.OnStart(state);

if(part.GetComponent<ModuleDecouplerBase>()) {
Expand Down
12 changes: 8 additions & 4 deletions Source/RocketSoundEnhancement/PartModules/RSE_Engines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ public class RSE_Engines : RSE_Module
public Dictionary<string, int> sharedSoundLayers = new Dictionary<string, int>();
private List<ModuleEngines> engineModules = new List<ModuleEngines>();

public override void OnStart(StartState state)
public RSE_Engines()
{
if(state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
EnableCombFilter = true;
EnableDistortionFilter = true;
}

public override void OnStart(StartState state)
{
if (state == StartState.Editor || state == StartState.None)
return;

base.OnStart(state);

var soundLayersCache = new HashSet<string>();
Expand Down
6 changes: 5 additions & 1 deletion Source/RocketSoundEnhancement/PartModules/RSE_KerbalEVA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ namespace RocketSoundEnhancement.PartModules
{
public class RSE_KerbalEVA : RSE_Module
{
public RSE_KerbalEVA()
{
EnableLowpassFilter = true;
}

public override void OnStart(StartState state)
{
if (state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
base.OnStart(state);

Initialized = true;
Expand Down
107 changes: 63 additions & 44 deletions Source/RocketSoundEnhancement/PartModules/RSE_Module.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using RocketSoundEnhancement.AudioFilters;
using RocketSoundEnhancement.Unity;
using UnityEngine;
Expand All @@ -17,7 +18,6 @@ public class RSE_Module : PartModule

public GameObject AudioParent { get; protected set; }

public ConfigNode PartConfigNode;
public bool PrepareSoundLayers = true;
public bool Initialized;
public bool GamePaused;
Expand Down Expand Up @@ -53,51 +53,9 @@ public override void OnStart(StartState state)
{
string partParentName = part.name + "_" + this.moduleName;
AudioParent = AudioUtility.CreateAudioParent(part, partParentName);
PartConfigNode = AudioUtility.GetConfigNode(part.partInfo.name, this.moduleName);

if (!float.TryParse(PartConfigNode.GetValue("volume"), out Volume)) Volume = 1;
if (!float.TryParse(PartConfigNode.GetValue("DopplerFactor"), out DopplerFactor)) DopplerFactor = 0.5f;

if (PartConfigNode.HasNode("AIRSIMULATION"))
{
var node = PartConfigNode.GetNode("AIRSIMULATION");

if (node.HasValue("EnableCombFilter")) bool.TryParse(node.GetValue("EnableCombFilter"), out EnableCombFilter);
if (node.HasValue("EnableLowpassFilter")) bool.TryParse(node.GetValue("EnableLowpassFilter"), out EnableLowpassFilter);
if (node.HasValue("EnableDistortionFilter")) bool.TryParse(node.GetValue("EnableDistortionFilter"), out EnableDistortionFilter);

if (node.HasValue("UpdateMode")) node.TryGetEnum("UpdateMode", ref AirSimUpdateMode, AirSimulationUpdate.Full);

if (node.HasValue("FarLowpass")) FarLowpass = float.Parse(node.GetValue("FarLowpass"));
if (node.HasValue("MaxCombDelay")) MaxCombDelay = float.Parse(node.GetValue("MaxCombDelay"));
if (node.HasValue("MaxCombMix")) MaxCombMix = float.Parse(node.GetValue("MaxCombMix"));
if (node.HasValue("MaxDistortion")) MaxDistortion = float.Parse(node.GetValue("MaxDistortion"));
if (node.HasValue("AngleHighpass")) AngleHighpass = float.Parse(node.GetValue("AngleHighpass"));
}

UseAirSimulation = !(!EnableLowpassFilter && !EnableCombFilter && !EnableDistortionFilter);

if (PrepareSoundLayers)
{
foreach (var node in PartConfigNode.GetNodes())
{
var soundLayers = AudioUtility.CreateSoundLayerGroup(node.GetNodes("SOUNDLAYER"));
if (soundLayers.Count == 0) continue;

var groupName = node.name;

if(node.name == "SOUNDLAYERGROUP")
{
groupName = node.GetValue("name");
}

if (SoundLayerGroups.ContainsKey(groupName)) { SoundLayerGroups[groupName].AddRange(soundLayers); continue; }

SoundLayerGroups.Add(groupName, soundLayers);
}

SoundLayers = AudioUtility.CreateSoundLayerGroup(PartConfigNode.GetNodes("SOUNDLAYER"));

if (SoundLayerGroups.Count > 0)
{
foreach (var soundLayerGroup in SoundLayerGroups)
Expand Down Expand Up @@ -263,7 +221,7 @@ public void PlaySoundLayer(SoundLayer soundLayer, float control, float volume, b

if (source.isPlaying && soundLayer.loop)
source.volume = 0;

return;
}

Expand Down Expand Up @@ -338,5 +296,66 @@ public virtual void OnDestroy()
}
Destroy(AudioParent);
}

public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

// This likely doesn't work correctly with B9PS which can call OnLoad at unexpected times
if (part?.partInfo?.partPrefab != null)
{
int moduleIndex = part.Modules.IndexOf(this);
var prefab = part.partInfo.partPrefab.modules[moduleIndex] as RSE_Module;

SoundLayerGroups = prefab.SoundLayerGroups;
SoundLayers = prefab.SoundLayers;
return;
}

// Do the actual parsing during part compilation.

node.TryGetValue("volume", ref Volume);
node.TryGetValue("DopplerFactor", ref DopplerFactor);

ConfigNode sim = null;
if (node.TryGetNode("AIRSIMULATION", ref sim))
{
sim.TryGetValue("EnableCombFilter", ref EnableCombFilter);
sim.TryGetValue("EnableLowpassFilter", ref EnableLowpassFilter);
sim.TryGetValue("EnableDistortionFilter", ref EnableDistortionFilter);

sim.TryGetEnum("UpdateMode", ref AirSimUpdateMode, AirSimulationUpdate.Full);

sim.TryGetValue("FarLowpass", ref FarLowpass);
sim.TryGetValue("MaxCombDelay", ref MaxCombDelay);
sim.TryGetValue("MaxCombMix", ref MaxCombMix);
sim.TryGetValue("MaxDistortion", ref MaxDistortion);
sim.TryGetValue("AngleHighpass", ref AngleHighpass);
}

UseAirSimulation = !(!EnableLowpassFilter && !EnableCombFilter && !EnableDistortionFilter);

if (PrepareSoundLayers)
{
foreach (var lnode in node.GetNodes())
{
var soundLayers = AudioUtility.CreateSoundLayerGroup(lnode.GetNodes("SOUNDLAYER"));
if (soundLayers.Count == 0) continue;

var groupName = lnode.name;

if (lnode.name == "SOUNDLAYERGROUP")
{
groupName = lnode.GetValue("name");
}

if (SoundLayerGroups.ContainsKey(groupName)) { SoundLayerGroups[groupName].AddRange(soundLayers); continue; }

SoundLayerGroups.Add(groupName, soundLayers);
}

SoundLayers = AudioUtility.CreateSoundLayerGroup(node.GetNodes("SOUNDLAYER"));
}
}
}
}
7 changes: 6 additions & 1 deletion Source/RocketSoundEnhancement/PartModules/RSE_RCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ public class RSE_RCS : RSE_Module
{
private ModuleRCSFX moduleRCSFX;

public RSE_RCS()
{
EnableLowpassFilter = true;
}


public override void OnStart(StartState state)
{
if (state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
base.OnStart(state);

moduleRCSFX = part.Modules.GetModule<ModuleRCSFX>();
Expand Down
14 changes: 9 additions & 5 deletions Source/RocketSoundEnhancement/PartModules/RSE_RotorEngines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ public class RSE_RotorEngines : RSE_Module
private ModuleResourceIntake resourceIntake;
private int childPartsCount = 0;

public RSE_RotorEngines()
{
EnableLowpassFilter = true;
EnableCombFilter = true;
EnableDistortionFilter = true;
}

public override void OnStart(StartState state)
{
if(state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
EnableCombFilter = true;
EnableDistortionFilter = true;
base.OnStart(state);

rotorModule = part.GetComponent<ModuleRoboticServoRotor>();
Expand All @@ -58,8 +62,8 @@ public void SetupBlades()
childPartsCount = childParts.Count;
foreach (var childPart in childParts)
{
var configNode = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(x => x.name.Replace("_", ".") == childPart.partInfo.name);
var propConfig = configNode.config.GetNode("RSE_Propellers");
var configNode = childPart.partInfo.partConfig;
var propConfig = configNode.GetNode("RSE_Propellers");

if (propConfig != null)
{
Expand Down
64 changes: 42 additions & 22 deletions Source/RocketSoundEnhancement/PartModules/RSE_Wheels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,18 @@ public class RSE_Wheels : RSE_Module
private float wheelSpeed = 0;
private float slipDisplacement = 0;

public RSE_Wheels()
{
EnableLowpassFilter = true;
}

public override void OnStart(StartState state)
{
if (state == StartState.Editor || state == StartState.None)
return;

EnableLowpassFilter = true;
base.OnStart(state);

if (PartConfigNode.HasNode("Motor"))
{
ConfigNode offLoadVolumeScaleNode;
if ((offLoadVolumeScaleNode = PartConfigNode.GetNode("Motor").GetNode("offLoadVolumeScale")) != null && offLoadVolumeScaleNode.HasValues())
{
foreach (ConfigNode.Value node in offLoadVolumeScaleNode.values)
{
string soundLayerName = node.name;
float value = float.Parse(node.value);

if (offLoadVolumeScale.ContainsKey(soundLayerName))
{
offLoadVolumeScale[soundLayerName] = value;
continue;
}

offLoadVolumeScale.Add(soundLayerName, value);
}
}
}

moduleWheel = part.GetComponent<ModuleWheelBase>();
moduleMotor = part.GetComponent<ModuleWheelMotor>();
moduleDeploy = part.GetComponent<ModuleWheelDeployment>();
Expand Down Expand Up @@ -188,5 +171,42 @@ public override void FixedUpdate()

slipDisplacement = Mathf.Sqrt(x * x + y * y);
}

public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

if (part?.partInfo?.partPrefab != null)
{
int moduleIndex = part.modules.IndexOf(this);
var prefab = part.partInfo.partPrefab.modules[moduleIndex] as RSE_Wheels;
offLoadVolumeScale = prefab.offLoadVolumeScale;
return;
}

ConfigNode motor = null;
if (node.TryGetNode("Motor", ref motor))
{
ConfigNode offLoadVolumeScaleNode = motor.GetNode("offLoadVolumeScale");

if (offLoadVolumeScaleNode != null && offLoadVolumeScaleNode.HasValue())
{
foreach (ConfigNode.Value vnode in offLoadVolumeScaleNode.values)
{
string soundLayerName = vnode.name;
float value = float.Parse(vnode.value);

if (offLoadVolumeScale.ContainsKey(soundLayerName))
{
offLoadVolumeScale[soundLayerName] = value;
continue;
}

offLoadVolumeScale.Add(soundLayerName, value);
}
}
}
}

}
}
Loading
Loading