From aa9cf60c1c748a479789cd47d5ee067d8cca0429 Mon Sep 17 00:00:00 2001 From: Scott Lee <74874311+RobbinBob@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:52:09 +0000 Subject: [PATCH 1/3] refactored audio kit into its own package --- Audio File.nl2sco | 2 +- Audio Group.nl2sco | 2 +- Button - Master Switch.nl2sco | 2 +- Button - Music Mute Toggle.nl2sco | 2 +- Button - Trigger.nl2sco | 2 +- Cue Trigger - Emergency Stop.nl2sco | 2 +- Cue Trigger - Proximity Cube.nl2sco | 2 +- Cue Trigger - Proximity Sphere.nl2sco | 2 +- Cue Trigger - Station Dispatch.nl2sco | 2 +- Cue Trigger - Station Gate.nl2sco | 2 +- Cue Trigger - Station Platform.nl2sco | 2 +- Cue Trigger - Station Restraint.nl2sco | 59 ++++ Cue Trigger - Time Of Day.nl2sco | 2 +- Cue Trigger - Timer.nl2sco | 2 +- Cue Trigger - Track Trigger.nl2sco | 2 +- Cue Trigger - Weather.nl2sco | 2 +- Emitter - Car.nl2sco | 2 +- Emitter - Cube.nl2sco | 2 +- Emitter - Point.nl2sco | 2 +- Emitter - Sphere.nl2sco | 2 +- scripts/AudioConfig.nlvm | 17 - scripts/AudioController.nlvm | 387 ----------------------- scripts/AudioCue.nlvm | 126 -------- scripts/AudioCueButton.nlvm | 44 --- scripts/AudioCueEStop.nlvm | 49 --- scripts/AudioCueStationDispatch.nlvm | 42 --- scripts/AudioCueStationGate.nlvm | 10 - scripts/AudioCueStationPlatform.nlvm | 10 - scripts/AudioCueStationState.nlvm | 59 ---- scripts/AudioCueTimeOfDay.nlvm | 50 --- scripts/AudioCueTimer.nlvm | 34 -- scripts/AudioCueTrackTrigger.nlvm | 73 ----- scripts/AudioCueVolumeTrigger.nlvm | 55 ---- scripts/AudioCueVolumeTriggerCube.nlvm | 12 - scripts/AudioCueVolumeTriggerSphere.nlvm | 12 - scripts/AudioCueWeather.nlvm | 60 ---- scripts/AudioEmitter.nlvm | 104 ------ scripts/AudioEmitterCar.nlvm | 56 ---- scripts/AudioEmitterCube.nlvm | 12 - scripts/AudioEmitterPoint.nlvm | 11 - scripts/AudioEmitterSphere.nlvm | 13 - scripts/AudioEmitterVolume.nlvm | 66 ---- scripts/AudioFile.nlvm | 72 ----- scripts/AudioToggleMute.nlvm | 70 ---- scripts/AudioToggleShutOff.nlvm | 80 ----- scripts/blocks/BlockSection.nlvm | 88 ------ scripts/blocks/IBlock.nlvm | 12 - scripts/blocks/IState.nlvm | 10 - scripts/blocks/ITrackProcess.nlvm | 14 - scripts/blocks/ITrainPositionQuery.nlvm | 13 - scripts/blocks/LiftSection.nlvm | 84 ----- scripts/blocks/StationSection.nlvm | 12 - scripts/blocks/TrackSection.nlvm | 55 ---- scripts/blocks/TransportSection.nlvm | 98 ------ scripts/math/Matrix4x4.nlvm | 134 +++++--- 55 files changed, 168 insertions(+), 1973 deletions(-) create mode 100644 Cue Trigger - Station Restraint.nl2sco delete mode 100644 scripts/AudioConfig.nlvm delete mode 100644 scripts/AudioController.nlvm delete mode 100644 scripts/AudioCue.nlvm delete mode 100644 scripts/AudioCueButton.nlvm delete mode 100644 scripts/AudioCueEStop.nlvm delete mode 100644 scripts/AudioCueStationDispatch.nlvm delete mode 100644 scripts/AudioCueStationGate.nlvm delete mode 100644 scripts/AudioCueStationPlatform.nlvm delete mode 100644 scripts/AudioCueStationState.nlvm delete mode 100644 scripts/AudioCueTimeOfDay.nlvm delete mode 100644 scripts/AudioCueTimer.nlvm delete mode 100644 scripts/AudioCueTrackTrigger.nlvm delete mode 100644 scripts/AudioCueVolumeTrigger.nlvm delete mode 100644 scripts/AudioCueVolumeTriggerCube.nlvm delete mode 100644 scripts/AudioCueVolumeTriggerSphere.nlvm delete mode 100644 scripts/AudioCueWeather.nlvm delete mode 100644 scripts/AudioEmitter.nlvm delete mode 100644 scripts/AudioEmitterCar.nlvm delete mode 100644 scripts/AudioEmitterCube.nlvm delete mode 100644 scripts/AudioEmitterPoint.nlvm delete mode 100644 scripts/AudioEmitterSphere.nlvm delete mode 100644 scripts/AudioEmitterVolume.nlvm delete mode 100644 scripts/AudioFile.nlvm delete mode 100644 scripts/AudioToggleMute.nlvm delete mode 100644 scripts/AudioToggleShutOff.nlvm delete mode 100644 scripts/blocks/BlockSection.nlvm delete mode 100644 scripts/blocks/IBlock.nlvm delete mode 100644 scripts/blocks/IState.nlvm delete mode 100644 scripts/blocks/ITrackProcess.nlvm delete mode 100644 scripts/blocks/ITrainPositionQuery.nlvm delete mode 100644 scripts/blocks/LiftSection.nlvm delete mode 100644 scripts/blocks/StationSection.nlvm delete mode 100644 scripts/blocks/TrackSection.nlvm delete mode 100644 scripts/blocks/TransportSection.nlvm diff --git a/Audio File.nl2sco b/Audio File.nl2sco index 2c461f3..7ae306a 100644 --- a/Audio File.nl2sco +++ b/Audio File.nl2sco @@ -9,7 +9,7 @@ diff --git a/Audio Group.nl2sco b/Audio Group.nl2sco index 2006148..9fce32a 100644 --- a/Audio Group.nl2sco +++ b/Audio Group.nl2sco @@ -9,7 +9,7 @@ diff --git a/Button - Master Switch.nl2sco b/Button - Master Switch.nl2sco index 8bae953..65087e7 100644 --- a/Button - Master Switch.nl2sco +++ b/Button - Master Switch.nl2sco @@ -26,7 +26,7 @@ diff --git a/Button - Music Mute Toggle.nl2sco b/Button - Music Mute Toggle.nl2sco index a04000f..54643db 100644 --- a/Button - Music Mute Toggle.nl2sco +++ b/Button - Music Mute Toggle.nl2sco @@ -26,7 +26,7 @@ diff --git a/Button - Trigger.nl2sco b/Button - Trigger.nl2sco index fc3d987..b57e336 100644 --- a/Button - Trigger.nl2sco +++ b/Button - Trigger.nl2sco @@ -26,7 +26,7 @@ diff --git a/Cue Trigger - Emergency Stop.nl2sco b/Cue Trigger - Emergency Stop.nl2sco index 80d4ee6..26703d1 100644 --- a/Cue Trigger - Emergency Stop.nl2sco +++ b/Cue Trigger - Emergency Stop.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Proximity Cube.nl2sco b/Cue Trigger - Proximity Cube.nl2sco index ceba74b..27ecdd9 100644 --- a/Cue Trigger - Proximity Cube.nl2sco +++ b/Cue Trigger - Proximity Cube.nl2sco @@ -11,7 +11,7 @@ diff --git a/Cue Trigger - Proximity Sphere.nl2sco b/Cue Trigger - Proximity Sphere.nl2sco index d47bf63..1aa455f 100644 --- a/Cue Trigger - Proximity Sphere.nl2sco +++ b/Cue Trigger - Proximity Sphere.nl2sco @@ -12,7 +12,7 @@ diff --git a/Cue Trigger - Station Dispatch.nl2sco b/Cue Trigger - Station Dispatch.nl2sco index 084e004..70d40a5 100644 --- a/Cue Trigger - Station Dispatch.nl2sco +++ b/Cue Trigger - Station Dispatch.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Station Gate.nl2sco b/Cue Trigger - Station Gate.nl2sco index a3db1c6..81af5a0 100644 --- a/Cue Trigger - Station Gate.nl2sco +++ b/Cue Trigger - Station Gate.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Station Platform.nl2sco b/Cue Trigger - Station Platform.nl2sco index 3621100..f3df5f4 100644 --- a/Cue Trigger - Station Platform.nl2sco +++ b/Cue Trigger - Station Platform.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Station Restraint.nl2sco b/Cue Trigger - Station Restraint.nl2sco new file mode 100644 index 0000000..b3687a7 --- /dev/null +++ b/Cue Trigger - Station Restraint.nl2sco @@ -0,0 +1,59 @@ + + + + + Plays an assigned Audio ID to a Group ID when the Gates are opened or closed. + thumbs/Restraint.png + + + + + + string + + audio_group + Links all emitters/cues to a certain group. + + + + string + + audio_name + Audio id that links to audio file. + + + + blocksection + audio_station + The Station that will trigger this cue upon activation. + + + + int + 0 + Opening,Closing,Both + audio_activation + Sets the type of activation that triggers this cue. + + + + bool + false + audio_mutelower + Sets wether this audio cue will mute lower priority audio cues. Used along-side the audio priority parameter. + + + + int + 3 + audio_priority + Sets the priority of this audio cue which determines what cues will silence others. Used along-side mute lower parameter. + + + thumbs/Restraint.nl2mat + + \ No newline at end of file diff --git a/Cue Trigger - Time Of Day.nl2sco b/Cue Trigger - Time Of Day.nl2sco index 8daea86..c055fc7 100644 --- a/Cue Trigger - Time Of Day.nl2sco +++ b/Cue Trigger - Time Of Day.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Timer.nl2sco b/Cue Trigger - Timer.nl2sco index d3e6156..ade336a 100644 --- a/Cue Trigger - Timer.nl2sco +++ b/Cue Trigger - Timer.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Track Trigger.nl2sco b/Cue Trigger - Track Trigger.nl2sco index bb057bf..e75ca5b 100644 --- a/Cue Trigger - Track Trigger.nl2sco +++ b/Cue Trigger - Track Trigger.nl2sco @@ -9,7 +9,7 @@ diff --git a/Cue Trigger - Weather.nl2sco b/Cue Trigger - Weather.nl2sco index 195191e..f491c5d 100644 --- a/Cue Trigger - Weather.nl2sco +++ b/Cue Trigger - Weather.nl2sco @@ -9,7 +9,7 @@ diff --git a/Emitter - Car.nl2sco b/Emitter - Car.nl2sco index 660a940..5033d24 100644 --- a/Emitter - Car.nl2sco +++ b/Emitter - Car.nl2sco @@ -14,7 +14,7 @@ diff --git a/Emitter - Cube.nl2sco b/Emitter - Cube.nl2sco index ffc1304..90dcf25 100644 --- a/Emitter - Cube.nl2sco +++ b/Emitter - Cube.nl2sco @@ -11,7 +11,7 @@ diff --git a/Emitter - Point.nl2sco b/Emitter - Point.nl2sco index b9a89ab..871e09f 100644 --- a/Emitter - Point.nl2sco +++ b/Emitter - Point.nl2sco @@ -13,7 +13,7 @@ diff --git a/Emitter - Sphere.nl2sco b/Emitter - Sphere.nl2sco index f5dfe11..0314b5b 100644 --- a/Emitter - Sphere.nl2sco +++ b/Emitter - Sphere.nl2sco @@ -13,7 +13,7 @@ diff --git a/scripts/AudioConfig.nlvm b/scripts/AudioConfig.nlvm deleted file mode 100644 index b5ed42c..0000000 --- a/scripts/AudioConfig.nlvm +++ /dev/null @@ -1,17 +0,0 @@ -package scripts; - -public final class AudioConfig extends Object -{ - public String SoundName = ""; - public bool CanMuteLowerPriority = true; - public int Priority = 0; - public AudioFile FileReference; - - public AudioConfig(AudioFile file, int priority, bool canMuteLowerPriority) - { - FileReference = file; - SoundName = file.GetName(); - Priority = priority; - CanMuteLowerPriority = canMuteLowerPriority; - } -} \ No newline at end of file diff --git a/scripts/AudioController.nlvm b/scripts/AudioController.nlvm deleted file mode 100644 index 87549ac..0000000 --- a/scripts/AudioController.nlvm +++ /dev/null @@ -1,387 +0,0 @@ -package scripts; - -//import scripts.math.*; -//import scripts.utilities.*; -import scripts.containers.*; - -public final class AudioController extends Behaviour implements IReferenceable -{ - private SpatialSound m_PrimaryAudioLoop = null; - private AudioFile m_PrimaryAudioFile = null; - - private AudioEmitter[] m_GroupEmitters = null; - private bool m_MutePrimaryTrack = false; - private bool m_IsEnabled = true; - - private Dictionary m_AudioProperties = new Dictionary(); - private String m_GroupName = ""; - - private float m_MuteGain = 0.05f; - - private List m_Queue = new List(); - - // Behaviour - public int GetOrder() { return -25; } - - public bool Awake() - { - m_GroupName = GetStringParameter("group_name", false); - if(m_GroupName.length() == 0) - { - Debug.Warn("Audio Group | No Group Id specified"); - return false; - } - SetName(m_GroupName); - - if(!Debug.IsDebugMode()) - SetIsVisible(false); - return true; - } - public void Start() - { - Registry registry = Registry.GetInstance(); - - // Fetch the main audio loop - String audioName = GetStringParameter("primary_audio_name", false); - if(audioName.length() != 0) - { - m_PrimaryAudioFile = (AudioFile)registry.GetReferenceFromName("scripts.AudioFile", GetStringParameter("primary_audio_name")); - m_PrimaryAudioLoop = (SpatialSound)registry.GetReferenceFromName("scripts.SpatialSound", m_PrimaryAudioFile.GetName()); - if(m_PrimaryAudioLoop == null) - { - Debug.Warn("Audio Group | Unable to find Audio Id '" + GetStringParameter("primary_audio_name") + "'"); - SetIsVisible(true); - } - m_PrimaryAudioLoop.SetGain(0); - } - - m_MuteGain = GetFloatParameter("audio_mute_gain"); - - // Fetch all AudioEmitters with the same group name - IReferenceable[] references = registry.GetReferencesFromName("scripts.AudioEmitter", m_GroupName); - Debug.Print("Audio Group | Found '" + references.length + "' AudioEmitters associated with group '" + m_GroupName + "'"); - m_GroupEmitters = new AudioEmitter[references.length]; - for(int i = 0; i < references.length; ++i) - { - m_GroupEmitters[i] = (AudioEmitter)references[i]; - - if(m_PrimaryAudioLoop != null) - m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - } - - registry.Register(this); - - if(m_MutePrimaryTrack || m_PrimaryAudioLoop == null) - return; - - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - sound.SetGain(m_PrimaryAudioFile.GetDefaultGain()); - sound.SetPitch(m_PrimaryAudioFile.GetDefaultPitch()); - sound.PlaySoundLooped(); - } - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); - } - - private bool m_Debounce = false; - private bool m_EnableDebounce = false; - public void Update(float tick) - { - if(m_IsEnabled == false) - { - if(m_EnableDebounce) - return; - m_EnableDebounce = true; - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound; - if(m_PrimaryAudioLoop != null) - { - sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - sound.SetGain(0); - } - AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0); - - } - IEnumerator enumerator = m_Queue.GetEnumerator(); - while(enumerator.MoveNext()) - { - AudioConfig audio = (AudioConfig)enumerator.Get(); - DequeueSound(audio.SoundName); - Debug.Print("Removing sound '" + audio.SoundName + "' from emitter group '" + m_GroupName + "'"); - } - m_Queue.Clear(); - return; - } - else - m_EnableDebounce = false; - - if(m_Queue.Count() == 0) - { - if(!m_Debounce) - { - if(m_PrimaryAudioLoop != null) - { - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f); - } - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain()); - } - m_Debounce = true; - } - } - else - { - m_Debounce = false; - if(m_GroupEmitters.length == 0) - return; - - // We need to step through the sounds and find any that are completed, remove them from the queue - List toRemove = new List(); - IEnumerator enumerator = m_Queue.GetEnumerator(); - while(enumerator.MoveNext()) - { - AudioConfig audio = (AudioConfig)enumerator.Get(); - SpatialSound sound = m_GroupEmitters[0].SetCurrentSound(audio.SoundName); - if(sound.IsPlaying() == false) - toRemove.Insert(audio); - } - // Purge old sounds and set gain to 0 on emitters - enumerator = toRemove.GetEnumerator(); - while(enumerator.MoveNext()) - { - Debug.Print("Removing completed sound " + ((AudioConfig)enumerator.Get()).SoundName); - m_Queue.Remove((AudioConfig)enumerator.Get()); - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(((AudioConfig)enumerator.Get()).SoundName); - sound.SetGain(0); - } - m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName); - } - - - - - bool isMutingLower = false; - for(int i = m_Queue.Count() - 1; i >= 0; --i) - { - AudioConfig currentAudio = (AudioConfig)m_Queue.At(i); - AudioFile currentFile = currentAudio.FileReference; - - for(int j = 0; j < m_GroupEmitters.length; ++j) - { - SpatialSound sound = m_GroupEmitters[j].SetCurrentSound(currentAudio.SoundName); - sound.SetGain(!isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0); - } - AddOrSetGain(currentAudio.SoundName, !isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0); - if(currentAudio.CanMuteLowerPriority) - isMutingLower = true; - } - - if(m_PrimaryAudioLoop == null) - return; - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - if(m_MutePrimaryTrack) - { - sound.SetGainFaded(0, 0.5f); - AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0); - return; - } - else - { - sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f); - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); - } - - if (isMutingLower) - { - sound.SetGainFaded(m_MuteGain, 0.5f); - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MuteGain); - } - else - { - sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f); - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); - } - } - } - } - - private void AddOrSetGain(String audioId, float gain) - { - if(m_AudioProperties.ContainsKey(audioId)) - m_AudioProperties.Remove(audioId); - m_AudioProperties.Insert(audioId, new Float(gain)); - } - public float GetAudioGain(String audioId) - { - Object val = m_AudioProperties.GetValue(audioId); - if(val == null) - return 0; - return ((Float)val).floatValue(); - } - - - public void EnqueSound(AudioConfig properties) - { - if(!m_IsEnabled) - return; - - // No Audio in queue - if(m_Queue.Count() == 0) - { - m_Queue.Insert(properties); - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); - spatialSound.SetGain(properties.FileReference.GetDefaultGain()); - spatialSound.SetPitch(properties.FileReference.GetDefaultPitch()); - spatialSound.PlaySoundOnce(); - } - // Cache current gain - AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); - return; - } - - IEnumerator enumerator = m_Queue.GetEnumerator(); - int index = 0; - bool success = false; - while(enumerator.MoveNext()) - { - AudioConfig sound = (AudioConfig)enumerator.Get(); - - // If this is already found in the queue, then we just need to restart it from the beginning - if(sound.SoundName.equals(properties.SoundName)) - { - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); - spatialSound.Stop(); - spatialSound.PlaySoundOnce(); - } - // Cache current gain - AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); - return; - } - - // If this was not found in the queue then we need to begin playing it and add it to the queue - if(properties.Priority <= sound.Priority) - { - m_Queue.InsertAt(properties, index); - success = true; - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); - spatialSound.PlaySoundOnce(); - } - // Cache current gain - AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); - - // If they both equal the same property then we need to remove the old audio - while(properties.Priority == ((AudioConfig)enumerator.Get()).Priority) - { - DequeueSound(((AudioConfig)enumerator.Get()).SoundName); - m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName); - if(!enumerator.MoveNext()) - break; - } - - break; - } - } - - // If it was unsuccessful at adding this new audio clip to the queue (usually occurs from an empty queue) - if(!success) - { - m_Queue.Insert(properties); - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); - spatialSound.PlaySoundOnce(); - } - // Cache current gain - AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); - } - } - public void DequeueSound(String soundName) - { - if(m_Queue.Count() == 0) - return; - - IEnumerator enumerator = m_Queue.GetEnumerator(); - int i = 0; - while(enumerator.MoveNext()) - { - AudioConfig sound = (AudioConfig)enumerator.Get(); - if(!sound.SoundName.equals(soundName)) - { - i++; - continue; - } - - Debug.Print("Found sound with name '" + soundName + "' stopping sound and removing it from queue"); - for(int j = 0; j < m_GroupEmitters.length; ++j) - { - SpatialSound spatialSound = m_GroupEmitters[j].SetCurrentSound(sound.SoundName); - spatialSound.Stop(); - } - //DequeueSound(sound.SoundName); - m_Queue.RemoveAt(i); - m_AudioProperties.Remove(sound.SoundName); - break; - } - } - - - public void SetPrimaryTrackMuted(bool isMuted) - { - m_MutePrimaryTrack = isMuted; - if(m_PrimaryAudioLoop == null) - return; - - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - if(m_IsEnabled) - sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f); - } - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain()); - } - public void SetControllerOn(bool isEnabled) - { - m_IsEnabled = isEnabled; - if(m_PrimaryAudioLoop != null) - { - for(int i = 0; i < m_GroupEmitters.length; ++i) - { - SpatialSound sound; - sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); - sound.SetGain(m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0); - } - AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0); - } - - if(m_IsEnabled) - SetPrimaryTrackMuted(m_MutePrimaryTrack); - } - - // IReferenceable - public String GetType() - { - return "scripts.AudioController"; - } - public String GetName() - { - return m_Name; - } - public void SetName(String string) - { - m_Name = string; - } -} \ No newline at end of file diff --git a/scripts/AudioCue.nlvm b/scripts/AudioCue.nlvm deleted file mode 100644 index a6e8ed2..0000000 --- a/scripts/AudioCue.nlvm +++ /dev/null @@ -1,126 +0,0 @@ -package scripts; - -import scripts.utilities.StringUtil; -import scripts.containers.*; - -public abstract class AudioCue extends Behaviour -{ - protected AudioController[] m_AudioControllers = null; - protected String m_AudioName = ""; - protected int m_Priority = 0; - protected bool m_MuteLowerPriority = false; - protected AudioConfig m_SoundConfig = null; - - public int GetOrder() { return -15; } - public bool Awake() - { - String groupId = GetStringParameter("audio_group"); - if(groupId.length() == 0) - { - Debug.Warn("Cue Trigger | No Group Id/s specified"); - return false; - } - String audioId = GetStringParameter("audio_name"); - if(audioId.length() == 0) - { - Debug.Warn("Cue Trigger | No Audio Id specified"); - return false; - } - if(!Debug.IsDebugMode()) - SetIsVisible(false); - return true; - } - - public void Start() - { - String controllerParams = GetStringParameter("audio_group"); - String[] params = StringUtil.SplitString(controllerParams, ','); - if(params.length == 0) - { - Debug.Warn("Cue Trigger | Internal error when parsing Group Id/s, '" + controllerParams + "' is not a valid parameter entry"); - return; - } - List tempControllers = new List(params.length); - for(int i = 0; i < params.length; ++i) - { - IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", params[i]); - if(reference == null) - { - Debug.Warn("Cue Trigger | Unable to find Audio Group with id '" + params[i] + "'"); - continue; - } - tempControllers.Insert(reference); - } - m_AudioControllers = new AudioController[tempControllers.Count()]; - IEnumerator enumerator = tempControllers.GetEnumerator(); - int l = 0; - while(enumerator.MoveNext()) - m_AudioControllers[l++] = (AudioController)enumerator.Get(); - - m_AudioName = GetStringParameter("audio_name"); - m_Priority = GetIntegerParameter("audio_priority"); - m_MuteLowerPriority = GetBoolParameter("audio_mutelower"); - - IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioFile", m_AudioName); - if(reference == null) - { - Debug.Warn("Cue Trigger | Unable to find Audio File with name '" + m_AudioName + "'"); - return; - } - - m_SoundConfig = new AudioConfig( - (AudioFile)reference, - m_Priority, - m_MuteLowerPriority); - } - - protected void BroadcastSoundToAll(AudioConfig config) - { - for(int i = 0; i < m_AudioControllers.length; ++i) - m_AudioControllers[i].EnqueSound(config); - } - protected void BroadcastSoundToWhitelist(AudioConfig config, String[] whitelist) - { - for(int i = 0; i < m_AudioControllers.length; ++i) - { - String audioGroupId = m_AudioControllers[i].GetName(); - bool success = true; - for(int l = 0; l < whitelist.length; ++l) - { - if(whitelist[l].equals(audioGroupId) == false) - { - success = false; - break; - } - } - if(!success) - continue; - m_AudioControllers[i].EnqueSound(config); - } - } - protected void BroadcastSoundToBlacklist(AudioConfig config, String[] blacklist) - { - for(int i = 0; i < m_AudioControllers.length; ++i) - { - String audioGroupId = m_AudioControllers[i].GetName(); - bool success = true; - for(int l = 0; l < blacklist.length; ++l) - { - if(blacklist[l].equals(audioGroupId) == true) - { - success = false; - break; - } - } - if(!success) - continue; - m_AudioControllers[i].EnqueSound(config); - } - } - - protected void CancelSoundToAll(AudioConfig config) - { - for(int i = 0; i < m_AudioControllers.length; ++i) - m_AudioControllers[i].DequeueSound(config.SoundName); - } -} \ No newline at end of file diff --git a/scripts/AudioCueButton.nlvm b/scripts/AudioCueButton.nlvm deleted file mode 100644 index 50faed2..0000000 --- a/scripts/AudioCueButton.nlvm +++ /dev/null @@ -1,44 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public final class AudioQueueButton extends AudioQueue implements InteractionActionListener -{ - private InteractionObject m_Interaction = null; - private Animation m_Animation = null; - private bool m_Debounce = false; - - public void Start() - { - super.Start(); - m_Interaction = InteractionObject.createSimpleButton(); - m_Interaction.setActive(true); - m_Interaction.setEnabled(true); - m_Interaction.setPosition(m_SceneObject.getTranslation()); - m_Interaction.setRadius(0.05f); - m_Interaction.addActionListener(this); - m_Animation = new Animation(m_SceneObject); - m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); - } - public void Update(float deltaTime) - { - if(m_Debounce && !m_Animation.IsPlaying()) - { - m_Debounce = false; - m_Interaction.setEnabled(true); - m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); - } - } - - - public void onInteractionAction(InteractionObject object) - { - if(m_Debounce) - return; - m_Debounce = true; - m_Animation.Play(); - BroadcastSoundToAll(m_SoundConfig); - m_Interaction.setEnabled(false); - m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); - } -} \ No newline at end of file diff --git a/scripts/AudioCueEStop.nlvm b/scripts/AudioCueEStop.nlvm deleted file mode 100644 index dc0de63..0000000 --- a/scripts/AudioCueEStop.nlvm +++ /dev/null @@ -1,49 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public class AudioCueEStop extends AudioCue -{ - private Coaster m_Coaster = null; - private Timer m_IntervalTimer = null; - private bool m_Debounce = false; - - public bool Awake() - { - m_Coaster = GetCoasterParameter("audio_coaster", false); - if(m_Coaster == null) - { - Debug.Warn("Cue Trigger - Emergency Stop | No coaster specified"); - return false; - } - - float interval = GetFloatParameter("audio_interval"); - if(interval < 0.1f) - { - Debug.Warn("Cue Trigger - Emergency Stop | Specified interval '" + interval + "' is outside of bounds, must be >= 0.1"); - return false; - } - m_IntervalTimer = new Timer(GetFloatParameter("audio_interval")); - return super.Awake(); - } - - public void Update(float deltaTime) - { - if(m_Coaster.isEmergencyStop()) - { - if(m_IntervalTimer.IsRunning() && m_IntervalTimer.WaitForComplete()) - return; - - BroadcastSoundToAll(m_SoundConfig); - m_IntervalTimer.StopAndReset(); - m_IntervalTimer.Start(); - m_Debounce = false; - } - else - if(!m_Debounce) - { - m_IntervalTimer.StopAndReset(); - m_Debounce = true; - } - } -} \ No newline at end of file diff --git a/scripts/AudioCueStationDispatch.nlvm b/scripts/AudioCueStationDispatch.nlvm deleted file mode 100644 index 95adcd8..0000000 --- a/scripts/AudioCueStationDispatch.nlvm +++ /dev/null @@ -1,42 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public final class AudioQueueStationDispatch extends AudioQueue -{ - private Section m_Station = null; - private Train m_TrainAtStation = null; - private float m_PreviousTrainSpeed = 0; - - public bool Awake() - { - m_Station = GetSectionParameter("audio_station", false); - if(m_Station == null) - { - Debug.Warn("Cue Trigger - Station Dispatch | No section specified"); - return false; - } - if(m_Station.isStation() == false) - { - Debug.Warn("Cue Trigger - Station Dispatch | The section specified is not a station"); - return false; - } - - m_PreviousTrainSpeed = m_Station.isTrainOnSection() ? 0 : 1; - return super.Awake(); - } - - public void Update(float deltaTime) - { - if(!m_Station.isTrainOnSection()) - return; - - m_TrainAtStation = m_Station.getTrainOnSection(); - float trainSpeed = (float)m_TrainAtStation.getSpeed(); - - if(m_PreviousTrainSpeed == 0 && trainSpeed > 0) - BroadcastSoundToAll(m_SoundConfig); - - m_PreviousTrainSpeed = trainSpeed; - } -} \ No newline at end of file diff --git a/scripts/AudioCueStationGate.nlvm b/scripts/AudioCueStationGate.nlvm deleted file mode 100644 index 9870159..0000000 --- a/scripts/AudioCueStationGate.nlvm +++ /dev/null @@ -1,10 +0,0 @@ -package scripts; - -public final class AudioCueStationGate extends AudioCueStationState -{ - public void Update(float deltaTime) - { - m_Activation = m_Station.getStationGateState(); - super.Update(deltaTime); - } -} \ No newline at end of file diff --git a/scripts/AudioCueStationPlatform.nlvm b/scripts/AudioCueStationPlatform.nlvm deleted file mode 100644 index 04bd7eb..0000000 --- a/scripts/AudioCueStationPlatform.nlvm +++ /dev/null @@ -1,10 +0,0 @@ -package scripts; - -public final class AudioCueStationPlatform extends AudioCueStationState -{ - public void Update(float deltaTime) - { - m_Activation = m_Station.getStationPlatformState(); - super.Update(deltaTime); - } -} \ No newline at end of file diff --git a/scripts/AudioCueStationState.nlvm b/scripts/AudioCueStationState.nlvm deleted file mode 100644 index 0703693..0000000 --- a/scripts/AudioCueStationState.nlvm +++ /dev/null @@ -1,59 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public abstract class AudioCueStationState extends AudioCue -{ - protected Section m_Station = null; - - protected static final int ACTIVATION_OPENING_OR_RAISING = 0; - protected static final int ACTIVATION_CLOSING_OR_LOWERING = 1; - protected static final int ACTIVATION_OPEN_OR_RAISE_AND_CLOSE_OR_LOWER = 2; - protected int m_ActivationType = ACTIVATION_OPENING_OR_RAISING; - protected float m_Activation = 0; - private float m_PreviousActivation = 0; - - public bool Awake() - { - m_Station = GetSectionParameter("audio_station", false); - if(m_Station == null) - { - Debug.Warn("Cue Trigger - Station State (Gate/Platform) | No section specified"); - return false; - } - if (m_Station.isStation() == false) - { - Debug.Warn("Cue Trigger - Station State (Gate/Platform) | Section specified is not a station"); - return false; - } - - m_ActivationType = GetIntegerParameter("audio_activation"); - return super.Awake(); - } - - - public void Update(float deltaTime) - { - float diff = m_Activation - m_PreviousActivation; - if(diff == 0) - return; - - switch(m_ActivationType) - { - case ACTIVATION_OPENING_OR_RAISING: - if(m_PreviousActivation == 0 && m_Activation > 0) - BroadcastSoundToAll(m_SoundConfig); - break; - case ACTIVATION_CLOSING_OR_LOWERING: - if(m_PreviousActivation == 1 && m_Activation < 1) - BroadcastSoundToAll(m_SoundConfig); - break; - case ACTIVATION_OPEN_OR_RAISE_AND_CLOSE_OR_LOWER: - if((m_PreviousActivation == 0 && m_Activation > 0) || (m_PreviousActivation == 1 && m_Activation < 1)) - BroadcastSoundToAll(m_SoundConfig); - break; - } - - m_PreviousActivation = m_Activation; - } -} \ No newline at end of file diff --git a/scripts/AudioCueTimeOfDay.nlvm b/scripts/AudioCueTimeOfDay.nlvm deleted file mode 100644 index 54fb3bf..0000000 --- a/scripts/AudioCueTimeOfDay.nlvm +++ /dev/null @@ -1,50 +0,0 @@ -package scripts; - -import scripts.math.*; - -public final class AudioQueueTimeOfDay extends AudioQueue -{ - private int m_Hour = 0; - private int m_Minute = 0; - private float m_Time = 0; - private bool m_HasPlayed = false; - - public bool Awake() - { - m_Hour = GetIntegerParameter("audio_time_hour"); - if(m_Hour < 0 || m_Hour > 23) - { - Debug.Warn("Cue Trigger - Time of Day | Hour specified is invalid must be >= 0 and < 24"); - return false; - } - m_Minute = GetIntegerParameter("audio_time_minute"); - if(m_Minute < 0 || m_Minute > 59) - { - Debug.Warn("Cue Trigger - Time of Day | Minute specified is invalid must be >= 0 and < 60"); - return false; - } - - float minutes = Mathf.Remap(m_Minute, 0, 60, 0, 1); - m_Time = (float)m_Hour + minutes; - - return super.Awake(); - } - - public void Update(float deltaTime) - { - float currTime = sim.getCurTimeOfDay(); - int hours = (int)currTime; - int minutes = (int)Mathf.Remap(currTime - hours, 0, 1, 0, 60); - - if(hours == m_Hour && minutes == m_Minute) - { - if(m_HasPlayed) - return; - - BroadcastSoundToAll(m_SoundConfig); - m_HasPlayed = true; - } - else if (m_HasPlayed) - m_HasPlayed = false; - } -} \ No newline at end of file diff --git a/scripts/AudioCueTimer.nlvm b/scripts/AudioCueTimer.nlvm deleted file mode 100644 index 7784a8f..0000000 --- a/scripts/AudioCueTimer.nlvm +++ /dev/null @@ -1,34 +0,0 @@ -package scripts; - -public final class AudioQueueTimer extends AudioQueue -{ - private Timer m_IntervalTimer = null; - - public bool Awake() - { - float interval = GetFloatParameter("audio_interval"); - if(interval < 0.1f) - { - Debug.Warn("Cue Trigger - Timer | Time interval specified is invalid, must be > 0.1"); - return false; - } - m_IntervalTimer = new Timer(interval); - return super.Awake(); - } - - public void Start() - { - super.Start(); - m_IntervalTimer.Start(); - } - - public void Update(float tick) - { - if(m_IntervalTimer.WaitForComplete()) - return; - - BroadcastSoundToAll(m_SoundConfig); - m_IntervalTimer.Reset(); - m_IntervalTimer.Start(); - } -} \ No newline at end of file diff --git a/scripts/AudioCueTrackTrigger.nlvm b/scripts/AudioCueTrackTrigger.nlvm deleted file mode 100644 index 2bf93b3..0000000 --- a/scripts/AudioCueTrackTrigger.nlvm +++ /dev/null @@ -1,73 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; -import scripts.utilities.*; - -public final class AudioQueueTrackTrigger extends AudioQueue implements TrackTriggerListener -{ - private TrackTrigger m_TrackTrigger = null; - private TrackTrigger m_StopTrigger = null; - private int[] m_TrainWhitelist = new int[0]; - private Coaster m_Coaster = null; - - public bool Awake() - { - m_TrackTrigger = GetTriggerParameter("audio_trigger", false); - if(m_TrackTrigger == null) - { - Debug.Warn("Cue Trigger - Track Trigger | No track trigger specified"); - return false; - } - m_StopTrigger = GetTriggerParameter("audio_stop_trigger", false); - return super.Awake(); - } - - public void Start() - { - super.Start(); - m_TrackTrigger.addTrackTriggerListener(this); - m_Coaster = m_TrackTrigger.getCoaster(); - - if(m_StopTrigger != null) - m_StopTrigger.addTrackTriggerListener(this); - - String params = GetStringParameter("audio_train_whitelist"); - String[] indices = StringUtil.SplitString(params, ','); - if(indices.length == 0) - { - m_TrainWhitelist = new int[m_Coaster.getTrainCount()]; - for(int i = 0; i < m_TrainWhitelist.length; ++i) - m_TrainWhitelist[i] = i; - return; - } - - m_TrainWhitelist = new int[indices.length]; - for (int i = 0; i < indices.length; ++i) - m_TrainWhitelist[i] = Integer.parseInt(indices[i]); - } - - public void onTrainEntering(TrackTrigger trigger, Train train) - { - bool success = false; - for(int i = 0; i < m_TrainWhitelist.length; ++i) - { - if(m_Coaster.getTrainAt(m_TrainWhitelist[i]) == train) - { - success = true; - break; - } - } - if(!success) - return; - - if(trigger == m_TrackTrigger) - BroadcastSoundToAll(m_SoundConfig); - if(m_StopTrigger != null) - { - if(trigger != m_StopTrigger) - return; - CancelSoundToAll(m_SoundConfig); - } - } - public void onTrainLeaving(TrackTrigger trigger, Train train) { } -} \ No newline at end of file diff --git a/scripts/AudioCueVolumeTrigger.nlvm b/scripts/AudioCueVolumeTrigger.nlvm deleted file mode 100644 index 5c758ff..0000000 --- a/scripts/AudioCueVolumeTrigger.nlvm +++ /dev/null @@ -1,55 +0,0 @@ -package scripts; - -import scripts.math.*; - -public abstract class AudioCueVolumeTrigger extends AudioCue -{ - protected Volume m_TriggerVolume = null; - private static final float MAX_DIST_CALCULATIONS = 2; - - private bool m_IsViewerInside = false; - private bool m_IsViewerInsidePrevious = false; - - private static final int PLAY_ON_ENTRY = 0; - private static final int PLAY_ON_EXIT = 1; - private int m_PlayState = PLAY_ON_ENTRY; - - public void Start() - { - super.Start(); - m_PlayState = GetIntegerParameter("audio_play_state"); - } - - public void Update(float tick) - { - m_IsViewerInsidePrevious = m_IsViewerInside; - Vector3 viewPos = GetViewerPosition(); - if(Vector3.Distance(m_TriggerVolume.GetMatrix().GetPosition(), viewPos) > m_TriggerVolume.GetScale().Length() * MAX_DIST_CALCULATIONS) - { - m_IsViewerInside = false; - CheckTriggerStateAndFire(); - return; - } - - m_IsViewerInside = m_TriggerVolume.IsPointWithinVolume(viewPos); - CheckTriggerStateAndFire(); - } - - private void CheckTriggerStateAndFire() - { - // Gaurd clause to ignore states where no updates have happened - if(m_IsViewerInside == m_IsViewerInsidePrevious) - return; - - if(m_IsViewerInside) - { - if(m_PlayState == PLAY_ON_ENTRY) - BroadcastSoundToAll(m_SoundConfig); - } - else - { - if(m_PlayState == PLAY_ON_EXIT) - BroadcastSoundToAll(m_SoundConfig); - } - } -} \ No newline at end of file diff --git a/scripts/AudioCueVolumeTriggerCube.nlvm b/scripts/AudioCueVolumeTriggerCube.nlvm deleted file mode 100644 index b86ccf3..0000000 --- a/scripts/AudioCueVolumeTriggerCube.nlvm +++ /dev/null @@ -1,12 +0,0 @@ -package scripts; - -import scripts.math.*; - -public final class AudioCueVolumeTriggerCube extends AudioCueVolumeTrigger -{ - public void Start() - { - super.Start(); - m_TriggerVolume = new Cube(GetMatrix(), GetScale()); - } -} \ No newline at end of file diff --git a/scripts/AudioCueVolumeTriggerSphere.nlvm b/scripts/AudioCueVolumeTriggerSphere.nlvm deleted file mode 100644 index f213e50..0000000 --- a/scripts/AudioCueVolumeTriggerSphere.nlvm +++ /dev/null @@ -1,12 +0,0 @@ -package scripts; - -import scripts.math.*; - -public final class AudioCueVolumeTriggerSphere extends AudioCueVolumeTrigger -{ - public void Start() - { - super.Start(); - m_TriggerVolume = new Sphere(GetMatrix(), GetScale().X); - } -} \ No newline at end of file diff --git a/scripts/AudioCueWeather.nlvm b/scripts/AudioCueWeather.nlvm deleted file mode 100644 index 93bf670..0000000 --- a/scripts/AudioCueWeather.nlvm +++ /dev/null @@ -1,60 +0,0 @@ -package scripts; - -public final class AudioQueueWeather extends AudioQueue -{ - private float m_WeatherThreshold = 0; - private bool m_HasPlayed = false; - private int m_WeatherType = 0; - - public void Start() - { - super.Start(); - m_WeatherType = GetIntegerParameter("weather_type"); - m_WeatherThreshold = GetFloatParameter("weather_threshold"); - m_SoundConfig.CanMuteLowerPriority = true; - } - - - public void Update(float tick) - { - float currentWeatherState = 0; - switch(m_WeatherType) - { - // Rain - case 0: - currentWeatherState = sim.getRainIntensity(); - break; - // Snow - case 1: - currentWeatherState = sim.getSnowIntensity(); - break; - // Wind - case 2: - currentWeatherState = sim.getWindIntensity(); - break; - // Thunder - case 3: - currentWeatherState = sim.getThunderIntensity(); - break; - } - - if(m_HasPlayed) - { - // If weather is still above threshold skip - if(currentWeatherState >= m_WeatherThreshold) - return; - - m_HasPlayed = false; - } - else - { - // If weather is below threshold skip - if(currentWeatherState < m_WeatherThreshold) - return; - - m_HasPlayed = true; - BroadcastSoundToAll(m_SoundConfig); - } - } - -} \ No newline at end of file diff --git a/scripts/AudioEmitter.nlvm b/scripts/AudioEmitter.nlvm deleted file mode 100644 index 64481c3..0000000 --- a/scripts/AudioEmitter.nlvm +++ /dev/null @@ -1,104 +0,0 @@ -package scripts; - -import scripts.containers.*; - -public abstract class AudioEmitter extends Behaviour implements IReferenceable -{ - protected List m_AudioClips = new List(); - protected SpatialSound m_ActiveSound = null; - private AudioController m_AudioGroup = null; - - protected float m_FallOff = 1; - protected float m_Distance = 1; - - public int GetOrder() { return -30; } - public bool Awake() - { - String groupId = GetStringParameter("group_name"); - if(groupId.length() == 0) - { - Debug.Warn("Audio Emitter | No Group Id specified"); - return false; - } - SetName(groupId); - - if(!Debug.IsDebugMode()) - SetIsVisible(false); - return true; - } - public void Start() - { - m_FallOff = GetFloatParameter("audio_falloff"); - m_Distance = GetFloatParameter("audio_distance"); - Registry.GetInstance().Register(this); - } - - public final SpatialSound GetCurrentSound() - { - return m_ActiveSound; - } - public SpatialSound SetCurrentSound(String name) - { - //Debug.Print("Setting sound " + name); - // Try find the sound in the current emitter cache - m_ActiveSound = null; - IEnumerator enumerator = m_AudioClips.GetEnumerator(); - while(enumerator.MoveNext()) - { - if(((SpatialSound)enumerator.Get()).GetName().equals(name)) - { - m_ActiveSound = (SpatialSound)enumerator.Get(); - break; - } - } - - // Not in cache, we need to load it in - if(m_ActiveSound == null) - { - Debug.Print("Audio Emitter | Unable to find sound with name " + name + " in cache"); - IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.SpatialSound", name); - if(reference == null) - Exception.Throw("Audio Emitter | Unable to load SpatialSound file from registry with name '" + name + "'"); - - SpatialSound sound = (SpatialSound)((SpatialSound)reference).Instantiate(); - m_AudioClips.Insert(sound); - m_ActiveSound = sound; - } - - //m_ActiveSound.SetPosition(GetPosition()); - m_ActiveSound.SetConstantDistance(m_Distance); - m_ActiveSound.SetFalloffFactor(m_FallOff); - //m_ActiveSound.SetPosition(GetPosition()); - //m_ActiveSound.SetShouldUseDoppler(false); - - return m_ActiveSound; - } - - public List GetAllSounds() - { - return m_AudioClips; - } - - public AudioController GetAudioController() - { - if(m_AudioGroup == null) - m_AudioGroup = (AudioController)Registry.GetInstance().GetReferenceFromName("scripts.AudioController", GetStringParameter("group_name")); - return m_AudioGroup; - } - - - - // IReferenceable - public String GetType() - { - return "scripts.AudioEmitter"; - } - public final String GetName() - { - return m_Name; - } - public final void SetName(String name) - { - m_Name = name; - } -} \ No newline at end of file diff --git a/scripts/AudioEmitterCar.nlvm b/scripts/AudioEmitterCar.nlvm deleted file mode 100644 index ddc2f35..0000000 --- a/scripts/AudioEmitterCar.nlvm +++ /dev/null @@ -1,56 +0,0 @@ -package scripts; - -import scripts.math.*; -import scripts.containers.*; - -import com.nolimitscoaster.*; -import nlvm.math3d.*; - -public final class AudioEmitterCar extends AudioEmitter -{ - private Coaster m_Coaster = null; - private Train m_Train = null; - private int m_CarIndex = 0; - private Vector3f m_CarPos = new Vector3f(); - - public bool Awake() - { - m_Coaster = GetCoasterParameter("audio_coaster", false); - if(m_Coaster == null) - { - Debug.Warn("Emitter - Car | No specified coaster found"); - return false; - } - if(m_Coaster.getTrainCount() == 0) - { - Debug.Warn("Emitter - Car | Coaster '" + m_Coaster.getName() + "' has no trains"); - return false; - } - - m_Train = m_Coaster.findNearestTrain(m_SceneObject.getTranslation(), 15.0f); - if(m_Train == null) - { - Debug.Warn("Emitter - Car | Could not find train on coaster '" + m_Coaster.getName() + "' within 15m"); - return false; - } - m_CarIndex = GetIntegerParameter("audio_car"); - if(m_CarIndex < 0 || m_CarIndex > m_Train.getCarCount()) - { - Debug.Warn("Emitter - Car | The car index '" + m_CarIndex + "' is invalid for coaster '" + m_Coaster.getName() + "', must be <= " + m_Train.getCarCount()); - return false; - } - return super.Awake(); - } - - public void Update(float tick) - { - m_Train.getCarOrientationAndPosition(m_CarIndex, null, null, null, m_CarPos); - Vector3 carPos = Vector3.FromNative(m_CarPos); - IEnumerator enumerator = m_AudioClips.GetEnumerator(); - while(enumerator.MoveNext()) - { - SpatialSound sound = (SpatialSound)enumerator.Get(); - sound.SetPosition(carPos); - } - } -} \ No newline at end of file diff --git a/scripts/AudioEmitterCube.nlvm b/scripts/AudioEmitterCube.nlvm deleted file mode 100644 index ad7664b..0000000 --- a/scripts/AudioEmitterCube.nlvm +++ /dev/null @@ -1,12 +0,0 @@ -package scripts; - -import scripts.math.*; - -public final class AudioEmitterCube extends AudioEmitterVolume -{ - public void Start() - { - super.Start(); - m_EmitterWorldVolume = new Cube(GetMatrix(), GetScale()); - } -} \ No newline at end of file diff --git a/scripts/AudioEmitterPoint.nlvm b/scripts/AudioEmitterPoint.nlvm deleted file mode 100644 index 35baea8..0000000 --- a/scripts/AudioEmitterPoint.nlvm +++ /dev/null @@ -1,11 +0,0 @@ -package scripts; - -public class AudioEmitterPoint extends AudioEmitter -{ - public SpatialSound SetCurrentSound(String name) - { - SpatialSound sound = super.SetCurrentSound(name); - m_ActiveSound.SetPosition(GetPosition()); - return sound; - } -} \ No newline at end of file diff --git a/scripts/AudioEmitterSphere.nlvm b/scripts/AudioEmitterSphere.nlvm deleted file mode 100644 index 552f03c..0000000 --- a/scripts/AudioEmitterSphere.nlvm +++ /dev/null @@ -1,13 +0,0 @@ -package scripts; - -import scripts.math.*; - -public final class AudioEmitterSphere extends AudioEmitterVolume -{ - public void Start() - { - super.Start(); - Vector3 scale = GetScale(); - m_EmitterWorldVolume = new Sphere(GetMatrix(), Mathf.Min(scale.X, Mathf.Min(scale.Y, scale.Z))); - } -} \ No newline at end of file diff --git a/scripts/AudioEmitterVolume.nlvm b/scripts/AudioEmitterVolume.nlvm deleted file mode 100644 index bd10c0c..0000000 --- a/scripts/AudioEmitterVolume.nlvm +++ /dev/null @@ -1,66 +0,0 @@ -package scripts; - -import scripts.containers.*; -import scripts.math.*; - -public abstract class AudioEmitterVolume extends AudioEmitter implements IReferenceable -{ - protected Volume m_EmitterWorldVolume = null; - private static final float MAX_DIST_CALCULATIONS = 2; - - private bool m_FadeOutDebounce = false; - private bool m_FadeInDebounce = false; - - private Color[] colors = new Color[] - { - Color.Red, - Color.Yellow, - Color.Green, - Color.Cyan, - Color.Blue, - Color.Magenta - }; - - public void LateUpdate(float tick) - { - Vector3 viewPos = GetViewerPosition(); - if(Vector3.Distance(m_EmitterWorldVolume.GetMatrix().GetPosition(), viewPos) > m_EmitterWorldVolume.GetScale().Length() * MAX_DIST_CALCULATIONS) - return; - - Vector3 soundPosition = viewPos; - if(m_EmitterWorldVolume.IsPointWithinVolume(viewPos)) - { - m_FadeOutDebounce = false; - if(!m_FadeInDebounce) - { - m_FadeInDebounce = true; - IEnumerator enumerator = m_AudioClips.GetEnumerator(); - while(enumerator.MoveNext()) - { - // Needs to check the gain level of the audio - SpatialSound sound = ((SpatialSound)enumerator.Get()); - String audioId = sound.GetName(); - //Debug.Print("AUDIO EMITTER AUDIO ID '" + audioId + "'"); - ((SpatialSound)enumerator.Get()).SetGainFaded(GetAudioController().GetAudioGain(audioId), 0.05f); - } - } - - IEnumerator enumerator = m_AudioClips.GetEnumerator(); - int index = 0; - while(enumerator.MoveNext()) - { - SpatialSound sound = (SpatialSound)enumerator.Get(); - sound.SetPosition(soundPosition); - } - - } - else - { - m_FadeInDebounce = false; - m_FadeOutDebounce = true; - IEnumerator enumerator = m_AudioClips.GetEnumerator(); - while(enumerator.MoveNext()) - ((SpatialSound)enumerator.Get()).SetGainFaded(0, 0.05f); - } - } -} \ No newline at end of file diff --git a/scripts/AudioFile.nlvm b/scripts/AudioFile.nlvm deleted file mode 100644 index 42141f2..0000000 --- a/scripts/AudioFile.nlvm +++ /dev/null @@ -1,72 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public final class AudioFile extends Behaviour implements IReferenceable -{ - private Sound m_Sound = null; - private String m_Name = ""; - private float m_DefaultGain = 0; - private float m_DefaultPitch = 0; - - public bool Awake() - { - ResourcePath resource = GetResourcePathParameter("audio_file", false); - if(resource == null) - { - Debug.Warn("Audio File | No sound file specified"); - return false; - } - - int audioFlags = Sound.AUDIO_FLAG_SOUND | (GetBoolParameter("audio_flag_mono") ? Sound.AUDIO_FLAG_MONO : 0) | (GetBoolParameter("audio_flag_shared") ? Sound.AUDIO_FLAG_SHARED : 0); - bool isMusic = GetBoolParameter("audio_is_music"); - if(isMusic) - audioFlags |= Sound.AUDIO_FLAG_MUSIC; - m_Sound = new SpatialSound(resource, audioFlags, Sound.ENVIRONMENT_WORLD); - - m_Name = GetStringParameter("audio_name", false); - if(m_Name == null || m_Name.length() == 0) - { - Debug.Warn("Audio File | No Audio Id specified"); - return false; - } - - m_DefaultGain = GetFloatParameter("audio_gain"); - m_DefaultPitch = GetFloatParameter("audio_pitch"); - - m_Sound.SetGain(0); - m_Sound.SetPitch(m_DefaultPitch); - m_Sound.SetShouldUseDoppler(false); - m_Sound.SetName(m_Name); - - Registry.GetInstance().Register(this); - - if(!Debug.IsDebugMode()) - SetIsVisible(false); - - return false; - } - - public float GetDefaultGain() - { - return m_DefaultGain; - } - public float GetDefaultPitch() - { - return m_DefaultPitch; - } - - public String GetName() - { - return m_Name; - } - public void SetName(String name) - { - m_Name = name; - m_Sound.SetName(name); - } - public String GetType() - { - return "scripts.AudioFile"; - } -} \ No newline at end of file diff --git a/scripts/AudioToggleMute.nlvm b/scripts/AudioToggleMute.nlvm deleted file mode 100644 index 56ef1e7..0000000 --- a/scripts/AudioToggleMute.nlvm +++ /dev/null @@ -1,70 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public final class AudioToggleMute extends Behaviour implements InteractionActionListener -{ - private AudioController m_AudioController = null; - private InteractionObject m_Interaction = null; - private Animation m_Animation = null; - private bool m_IsToggled = false; - private bool m_Debounce = false; - - public int GetOrder() { return -15; } - public bool Awake() - { - String groupId = GetStringParameter("audio_group"); - if(groupId.length() == 0) - { - Debug.Warn("Button - Music Mute Toggle | No Group Id specified"); - return false; - } - return true; - } - - public void Start() - { - String groupId = GetStringParameter("audio_group"); - IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", groupId); - if(reference == null) - { - Debug.Warn("Button - Music Mute Toggle | Could not find Audio Group with Group Id '" + groupId + "'"); - return; - } - m_AudioController = (AudioController)reference; - m_Interaction = InteractionObject.createSimpleButton(); - m_Interaction.setActive(true); - m_Interaction.setEnabled(true); - m_Interaction.setPosition(m_SceneObject.getTranslation()); - m_Interaction.setRadius(0.05f); - m_Interaction.addActionListener(this); - m_Animation = new Animation(m_SceneObject); - m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); - } - - public void Update(float deltaTime) - { - if(m_Debounce && !m_Animation.IsPlaying()) - { - m_Debounce = false; - m_Interaction.setEnabled(true); - if(!m_IsToggled) - m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); - } - } - - public void onInteractionAction(InteractionObject object) - { - if(m_Debounce) - return; - m_Debounce = true; - m_Animation.Play(); - m_Interaction.setEnabled(false); - - m_IsToggled = !m_IsToggled; - m_AudioController.SetPrimaryTrackMuted(m_IsToggled); - - if(m_IsToggled) - m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); - } -} \ No newline at end of file diff --git a/scripts/AudioToggleShutOff.nlvm b/scripts/AudioToggleShutOff.nlvm deleted file mode 100644 index fabb205..0000000 --- a/scripts/AudioToggleShutOff.nlvm +++ /dev/null @@ -1,80 +0,0 @@ -package scripts; - -import com.nolimitscoaster.*; - -public final class AudioToggleShutOff extends Behaviour implements InteractionActionListener -{ - private AudioController m_AudioController = null; - private InteractionObject m_Interaction = null; - private Animation m_Animation = null; - private bool m_IsToggled = false; - private bool m_Debounce = false; - - public int GetOrder() { return -15; } - public bool Awake() - { - String groupId = GetStringParameter("audio_group"); - if(groupId.length() == 0) - { - Debug.Warn("Button - Master Switch | No Group Id specified"); - return false; - } - return true; - } - - public void Start() - { - String groupId = GetStringParameter("audio_group"); - IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", groupId); - if(reference == null) - { - Debug.Warn("Button - Master Switch | Could not find Audio Group with Group Id '" + groupId + "'"); - return; - } - m_AudioController = (AudioController)reference; - m_Interaction = InteractionObject.createSimpleButton(); - m_Interaction.setActive(true); - m_Interaction.setEnabled(true); - m_Interaction.setPosition(m_SceneObject.getTranslation()); - m_Interaction.setRadius(0.05f); - m_Interaction.addActionListener(this); - m_Animation = new Animation(m_SceneObject); - - m_IsToggled = true; - m_Animation.Play(0, 10); - m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); - - m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); - } - - public void Update(float deltaTime) - { - if(m_Debounce && !m_Animation.IsPlaying()) - { - m_Debounce = false; - m_Interaction.setEnabled(true); - if(!m_IsToggled) - m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); - } - } - - public void onInteractionAction(InteractionObject object) - { - if(m_Debounce) - return; - m_Debounce = true; - m_Interaction.setEnabled(false); - - if(m_IsToggled) - { - m_Animation.Play(10, 20); - } - else - { - m_Animation.Play(0, 10); - m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); - } - m_IsToggled = !m_IsToggled; - m_AudioController.SetControllerOn(m_IsToggled); - } -} \ No newline at end of file diff --git a/scripts/blocks/BlockSection.nlvm b/scripts/blocks/BlockSection.nlvm deleted file mode 100644 index baa1854..0000000 --- a/scripts/blocks/BlockSection.nlvm +++ /dev/null @@ -1,88 +0,0 @@ -package scripts.blocks; - -import com.nolimitscoaster.Block; -import com.nolimitscoaster.Section; - -/// -/// . -public class BlockSection extends TransportSection, IState, IBlock, ITrainPositionQuery -{ - protected Block m_Block = null; - - public static final int E_BRAKE_OFF = 0; - public static final int E_BRAKE_ON = 1; - public static final int E_BRAKE_TRIM = 2; - private int m_BrakeState = E_TRANSPORT_OFF; - - public BlockSection(Block block) - { - super(block.getSection()); - m_Block = block; - } - public BlockSection(Section section) - { - super(section); - m_Block = section.getBlock(); - } - - - - public void SetBrakeState(int brakeState) - { - if (brakeState < 0 || brakeState > 2) - return; - - switch (brakeState) - { - case E_BRAKE_OFF: - m_Section.setBrakesOff(); - break; - case E_BRAKE_ON: - m_Section.setBrakesOn(); - break; - case E_BRAKE_TRIM: - m_Section.setBrakesTrim(); - break; - } - - m_BrakeState = brakeState; - } - public int GetBrakeState() - { - return m_BrakeState; - } - - - public bool IsTrainBeforeTrigger() - { - return m_Section.isTrainBeforeBrakeTrigger(); - } - public bool IsTrainBehindTrigger() - { - return m_Section.isTrainBehindBrakeTrigger(); - } - - - public int GetState() - { - if(block.getState() == Block.STATE_ERROR_OPERATION_MODE) - return block.getNormalModeState(Block.PROTOCOL_V1); - return block.getState(); - } - public void SetState(int state) - { - m_Block.setState(state); - } - - - public String GetName() - { - return m_Block.getName(); - } - - public Block GetBlock() - { - return m_Block; - } -} -/// \ No newline at end of file diff --git a/scripts/blocks/IBlock.nlvm b/scripts/blocks/IBlock.nlvm deleted file mode 100644 index 5d20712..0000000 --- a/scripts/blocks/IBlock.nlvm +++ /dev/null @@ -1,12 +0,0 @@ -package scripts.blocks; - -/// -/// . -public interface IBlock -{ - /// - /// Gets the underlying block. - /// - public Block GetBlock(); -} -/// \ No newline at end of file diff --git a/scripts/blocks/IState.nlvm b/scripts/blocks/IState.nlvm deleted file mode 100644 index 2a9ffdc..0000000 --- a/scripts/blocks/IState.nlvm +++ /dev/null @@ -1,10 +0,0 @@ -package scripts.blocks; - -/// -/// . -public interface IState -{ - public void SetState(int state); - public int GetState(); -} -/// \ No newline at end of file diff --git a/scripts/blocks/ITrackProcess.nlvm b/scripts/blocks/ITrackProcess.nlvm deleted file mode 100644 index e9c761b..0000000 --- a/scripts/blocks/ITrackProcess.nlvm +++ /dev/null @@ -1,14 +0,0 @@ -package scripts.core.blocks; - -import com.nolimitscoaster.Section; - -/// -/// . -public interface ITrackProcess -{ - public Coaster GetCoaster(); - public Section GetSection(); - - public void Process(); -} -/// \ No newline at end of file diff --git a/scripts/blocks/ITrainPositionQuery.nlvm b/scripts/blocks/ITrainPositionQuery.nlvm deleted file mode 100644 index dbdcd8d..0000000 --- a/scripts/blocks/ITrainPositionQuery.nlvm +++ /dev/null @@ -1,13 +0,0 @@ -package scripts.blocks; - -public interface ITrainPositionQuery -{ - public bool IsTrainBeforeCenterOfSection(); - public bool IsTrainBehindCenterOfSection(); - - public bool IsTrainBeforeTrigger(); - public bool IsTrainBehindTrigger(); - - public bool IsTrainBeforeStartOfSection(float offset); - public bool IsTrainBehindEndOfSection(float offset); -} \ No newline at end of file diff --git a/scripts/blocks/LiftSection.nlvm b/scripts/blocks/LiftSection.nlvm deleted file mode 100644 index 6acb810..0000000 --- a/scripts/blocks/LiftSection.nlvm +++ /dev/null @@ -1,84 +0,0 @@ -package scripts.core.blocks; - -import com.nolimitscoaster.Block; -import com.nolimitscoaster.Section; - -/// -/// . -public class LiftSection extends TrackSection implements IState, IBlock, ITrainPositionQuery -{ - protected Block m_Block = null; - - public static final int E_LIFT_OFF = 0; - public static final int E_LIFT_FWD = 1; - public static final int E_LIFT_IDLE = 2; - public static final int E_LIFT_BWD = -1; - private int m_LiftState = E_LIFT_OFF; - - public LiftSection(Block block) - { - super(block.getSection()); - m_Block = block; - } - public LiftSection(Section section) - { - super(section); - m_Block = section.getBlock(); - } - - - public void SetLiftState(int liftState) - { - if (liftState < -1 || liftState > 2) - return; - - switch (liftState) - { - case E_LIFT_OFF: - m_Section.setLiftOff(); - break; - case E_LIFT_FWD: - m_Section.setLiftFwdOn(); - break; - case E_LIFT_BWD: - m_Section.setLiftBwdOn(); - break; - case E_LIFT_IDLE: - m_Section.setLiftFwdIdleOn(); - break; - } - - m_LiftState = liftState; - } - public int GetLiftState() - { - return m_LiftState; - } - - public bool IsTrainBehindTrigger() - { - return m_Section.isTrainBehindLiftTrigger(); - } - public bool IsTrainBeforeTrigger() - { - return m_Section.isTrainBeforeLiftTrigger(); - } - - public int GetState() - { - if(block.getState() == Block.STATE_ERROR_OPERATION_MODE) - return block.getNormalModeState(Block.PROTOCOL_V1); - return block.getState(); - } - public void SetState(int state) - { - m_Block.setState(state); - } - - - public float GetDeviceSpeed() - { - return m_Section.getLiftCurrentSpeed(); - } -} -/// \ No newline at end of file diff --git a/scripts/blocks/StationSection.nlvm b/scripts/blocks/StationSection.nlvm deleted file mode 100644 index 117a3ec..0000000 --- a/scripts/blocks/StationSection.nlvm +++ /dev/null @@ -1,12 +0,0 @@ -package scripts.core.blocks; - -import com.nolimitscoaster.Block; -import com.nolimitscoaster.Section; - -/// -/// . -public class StationSection extends BlockSection implements IState, IBlock, ITrainPositionQuery -{ - -} -/// \ No newline at end of file diff --git a/scripts/blocks/TrackSection.nlvm b/scripts/blocks/TrackSection.nlvm deleted file mode 100644 index 2b37830..0000000 --- a/scripts/blocks/TrackSection.nlvm +++ /dev/null @@ -1,55 +0,0 @@ -package scripts.blocks; - -import com.nolimitscoaster.Section; -import scripts.containers.*; - -/// -/// . -public abstract class TrackSection extends Object implements ITrainPositionQuery -{ - protected Section m_Section = null; - - public TrackSection(Section section) - { - m_Section = section; - } - - - public bool IsTrainBeforeCenterOfSection() - { - return m_Section.isTrainBeforeCenterOfSection(); - } - public bool IsTrainBehindCenterOfSection() - { - return m_Section.isTrainBehindCenterOfSection(); - } - - public abstract bool IsTrainBeforeTrigger(); - public abstract bool IsTrainBehindTrigger(); - - public bool IsTrainBeforeStartOfSection(float offset) - { - return m_Section.isTrainBeforeStartOfSection(offset); - } - public bool IsTrainBehindEndOfSection(float offset) - { - return m_Section.isTrainBehindEndOfSection(offset); - } - - - - public bool IsTrainOnTrackSection() - { - return m_Section.isTrainOnSection(); - } - - public final Coaster GetCoaster() - { - m_Section.getCoaster(); - } - public final Section GetSection() - { - return m_Section; - } -} -/// \ No newline at end of file diff --git a/scripts/blocks/TransportSection.nlvm b/scripts/blocks/TransportSection.nlvm deleted file mode 100644 index a8de124..0000000 --- a/scripts/blocks/TransportSection.nlvm +++ /dev/null @@ -1,98 +0,0 @@ -package scripts.blocks; - -import com.nolimitscoaster.Section; - -/// -/// . -public class TransportSection extends TrackSection implements ITrainPositionQuery -{ - /// - /// Transports off (Read Only). - /// - public static final int E_TRANSPORT_OFF = 0; - /// - /// Transports forward (Read Only). - /// - public static final int E_TRANSPORT_FWD = 1; - /// - /// Transports forward launched (Read Only). - /// - public static final int E_TRANSPORT_FWD_LAUNCH = 2; - /// - /// Transports backward (Read Only). - /// - public static final int E_TRANSPORT_BWD = -1; - /// - /// Transports backward launched (Read Only). - /// - public static final int E_TRANSPORT_BWD_LAUNCH = -2; - private int m_TransportState = E_TRANSPORT_OFF; - - /// - public TransportSection(Section section) - { - super(section); - } - /// - - - public bool IsTrainBeforeTrigger() - { - return false; - } - public bool IsTrainBehindTrigger() - { - return false; - } - - - /// - /// Sets the current transports state. - /// The transport state to use. - /// - public void SetTransportState(int transportState) - { - if(transportState < -2 || transportState > 2) - return; - - switch(transportState) - { - case E_TRANSPORT_OFF: - m_Section.setTransportsOff(); - break; - case E_TRANSPORT_FWD: - m_Section.setTransportsStandardFwdOn(); - break; - case E_TRANSPORT_BWD: - m_Section.setTransportsStandardBwdOn(); - break; - case E_TRANSPORT_FWD_LAUNCH: - m_Section.setTransportsLaunchFwdOn(); - break; - case E_TRANSPORT_BWD_LAUNCH: - m_Section.setTransportsLaunchBwdOn(); - break; - } - - m_TransportState = transportState; - } - /// - /// Gets the current transport state currently active. - /// The current transport state. - /// - public int GetTransportState() - { - return m_TransportState; - } - /// - /// Gets the current transport device speed. - /// The current device speed(meters/s). - /// - public float GetDeviceSpeed() - { - return m_Section.getTransportCurrentSpeed(); - } - - public void Process() { } -} -/// diff --git a/scripts/math/Matrix4x4.nlvm b/scripts/math/Matrix4x4.nlvm index 0cca2f3..66ad18d 100644 --- a/scripts/math/Matrix4x4.nlvm +++ b/scripts/math/Matrix4x4.nlvm @@ -7,7 +7,6 @@ import com.nolimitscoaster.Tools; /// Immutable Matrix4x4 type. public final class Matrix4x4 extends Object { - private Matrix4x4f m_NativeMatrix = null; private float[] m_NativeComponents = null; /// @@ -90,9 +89,7 @@ public final class Matrix4x4 extends Object /// public Matrix4x4() { - m_NativeMatrix = new Matrix4x4f(); - m_NativeMatrix.initIdentity(); - m_NativeComponents = m_NativeMatrix.elems(); + InitialiseIdentity(); } /// /// Creates a new Matrix4x4 instance as a copy. @@ -100,8 +97,7 @@ public final class Matrix4x4 extends Object /// public Matrix4x4(Matrix4x4 copy) { - m_NativeMatrix = new Matrix4x4f(); - m_NativeComponents = m_NativeMatrix.elems(); + InitialiseIdentity(); float[] copyComponents = copy.m_NativeComponents; for(int i = 0; i < copyComponents.length; ++i) m_NativeComponents[i] = copyComponents[i]; @@ -111,8 +107,7 @@ public final class Matrix4x4 extends Object /// public Matrix4x4(float a1, float a2, float a3, float a4, float b1, float b2, float b3, float b4, float c1, float c2, float c3, float c4, float d1, float d2, float d3, float d4) { - m_NativeMatrix = new Matrix4x4f(); - m_NativeComponents = m_NativeMatrix.elems(); + InitialiseIdentity(); m_NativeComponents[A1] = a1; m_NativeComponents[A2] = a2; m_NativeComponents[A3] = a3; @@ -143,10 +138,8 @@ public final class Matrix4x4 extends Object /// public Matrix4x4(Vector4 right, Vector4 up, Vector4 forward, Vector4 position) { - m_NativeMatrix = new Matrix4x4f(); - m_NativeMatrix.initIdentity(); - m_NativeComponents = m_NativeMatrix.elems(); - SetColumns(new Vector3(right), new Vector3(up), new Vector3(forward), new Vector3(position)); + InitialiseIdentity(); + m_NativeComponents = SetColumns(new Vector3(right), new Vector3(up), new Vector3(forward), new Vector3(position)).m_NativeComponents; m_NativeComponents[D4] = position.W; } /// @@ -158,13 +151,22 @@ public final class Matrix4x4 extends Object /// public Matrix4x4(Vector3 right, Vector3 up, Vector3 forward, Vector3 position) { - m_NativeMatrix = new Matrix4x4f(); - m_NativeMatrix.initIdentity(); - m_NativeComponents = m_NativeMatrix.elems(); - SetColumns(right, up, forward, position); + InitialiseIdentity(); + m_NativeComponents = SetColumns(right, up, forward, position).m_NativeComponents; } + private void InitialiseIdentity() + { + m_NativeComponents = new float[] + { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + } + /// /// Creates a translation Matrix4x4. @@ -173,7 +175,9 @@ public final class Matrix4x4 extends Object public static Matrix4x4 AsTranslation(float x, float y, float z) { Matrix4x4 matrix = new Matrix4x4(); - matrix.m_NativeMatrix.initTrans(x, y, z); + matrix.m_NativeComponents[A4] = x; + matrix.m_NativeComponents[B4] = y; + matrix.m_NativeComponents[C4] = z; return matrix; } /// @@ -192,24 +196,32 @@ public final class Matrix4x4 extends Object public static Matrix4x4 AsRotation(float x, float y, float z) { Matrix4x4 matrix = new Matrix4x4(); + Matrix4x4f rotation = new Matrix4x4f(); + Matrix4x4f cumulativeRotation = new Matrix4x4f(); + cumulativeRotation.initIdentity(); + if(x != 0) { rotation.initXRot(x); - matrix.m_NativeMatrix.multRight(rotation); + cumulativeRotation.multRight(rotation); } if(y != 0) { - matrix.m_NativeMatrix.multRight(rotation); rotation.initYRot(y); + cumulativeRotation.multRight(rotation); } if(z != 0) { rotation.initZRot(z); - matrix.m_NativeMatrix.multRight(rotation); + cumulativeRotation.multRight(rotation); } + float[] elems = cumulativeRotation.elems(); + for(int i = 0; i < 16; ++i) + matrix.m_NativeComponents[i] = elems[i]; + return matrix; } /// @@ -228,7 +240,13 @@ public final class Matrix4x4 extends Object public static Matrix4x4 AsScale(float x, float y, float z) { Matrix4x4 matrix = new Matrix4x4(); - matrix.m_NativeMatrix.initScal(x, y, z); + Matrix4x4f temp = new Matrix4x4f(); + temp.initScal(x, y, z); + + float[] elems = temp.elems(); + for(int i = 0; i < 16; ++i) + matrix.m_NativeComponents[i] = elems[i]; + return matrix; } /// @@ -306,7 +324,11 @@ public final class Matrix4x4 extends Object public Matrix4x4 LeftMultiply(Matrix4x4 left) { Matrix4x4 copy = new Matrix4x4(this); - copy.m_NativeMatrix.multLeft(left.m_NativeMatrix); + Matrix4x4f copyNative = GetNative(); + copyNative.multLeft(left.GetNative()); + float[] elems = copyNative.elems(); + for(int i = 0; i < 16; ++i) + copy.m_NativeComponents[i] = elems[i]; return copy; } /// @@ -316,14 +338,20 @@ public final class Matrix4x4 extends Object public Matrix4x4 RightMultiply(Matrix4x4 right) { Matrix4x4 copy = new Matrix4x4(this); - copy.m_NativeMatrix.multRight(right.m_NativeMatrix); + Matrix4x4f copyNative = GetNative(); + copyNative.multRight(right.GetNative()); + float[] elems = copyNative.elems(); + for(int i = 0; i < 16; ++i) + copy.m_NativeComponents[i] = elems[i]; return copy; } + public Vector3 Multiply3x3(Vector3 vector) { Vector3f nativeVector = new Vector3f(vector.X, vector.Y, vector.Z); - m_NativeMatrix.multVector3x3(nativeVector, nativeVector); + Matrix4x4f nativeMatrix = GetNative(); + nativeMatrix.multVector3x3(nativeVector, nativeVector); return Vector3.FromNative(nativeVector); } @@ -333,9 +361,10 @@ public final class Matrix4x4 extends Object /// public Vector3 TransformVector3Zero(Vector3 vector) { - Vector4f v = new Vector4f(vector.X, vector.Y, vector.Z, 0); - m_NativeMatrix.multVector(v, v); - return new Vector3(v.x, v.y, v.z); + Vector4f nativeVector = new Vector4f(vector.X, vector.Y, vector.Z, 0); + Matrix4x4f nativeMatrix = GetNative(); + nativeMatrix.multVector(nativeVector, nativeVector); + return new Vector3(nativeVector.x, nativeVector.y, nativeVector.z); } /// /// Transforms the vector by the matrix with the virtual 4th component being 1. @@ -343,9 +372,10 @@ public final class Matrix4x4 extends Object /// public Vector3 TransformVector3One(Vector3 vector) { - Vector4f v = new Vector4f(vector.X, vector.Y, vector.Z, 1); - m_NativeMatrix.multVector(v, v); - return new Vector3(v.x, v.y, v.z); + Vector4f nativeVector = new Vector4f(vector.X, vector.Y, vector.Z, 1); + Matrix4x4f nativeMatrix = GetNative(); + nativeMatrix.multVector(nativeVector, nativeVector); + return new Vector3(nativeVector.x, nativeVector.y, nativeVector.z); } /// @@ -355,7 +385,11 @@ public final class Matrix4x4 extends Object public Matrix4x4 Invert() { Matrix4x4 copy = new Matrix4x4(this); - copy.m_NativeMatrix.invert(); + Matrix4x4f invert = GetNative(); + invert.invert(); + float[] elems = invert.elems(); + for(int i = 0; i < 16; ++i) + copy.m_NativeComponents[i] = elems[i]; return copy; } @@ -464,16 +498,35 @@ public final class Matrix4x4 extends Object } + public float GetDeterminant() + { + float[] m = m_NativeComponents; + return + m[A1] * (m[B2] * (m[C3] * m[D4] - m[C4] * m[D3]) + - m[B3] * (m[C2] * m[D4] - m[C4] * m[D2]) + + m[B4] * (m[C2] * m[D3] - m[C3] * m[D2])) + - m[A2] * (m[B1] * (m[C3] * m[D4] - m[C4] * m[D3]) + - m[B3] * (m[C1] * m[D4] - m[C4] * m[D1]) + + m[B4] * (m[C1] * m[D3] - m[C3] * m[D1])) + + m[A3] * (m[B1] * (m[C2] * m[D4] - m[C4] * m[D2]) + - m[B2] * (m[C1] * m[D4] - m[C4] * m[D1]) + + m[B4] * (m[C1] * m[D2] - m[C2] * m[D1])) + - m[A4] * (m[B1] * (m[C2] * m[D3] - m[C3] * m[D2]) + - m[B2] * (m[C1] * m[D3] - m[C3] * m[D1]) + + m[B3] * (m[C1] * m[D2] - m[C2] * m[D1])); + + } + /// /// Interpolate between two matrices. /// public static Matrix4x4 Lerp(float t, Matrix4x4 in, Matrix4x4 out) { - float[] inComp = in.m_NativeMatrix.elems(); - float[] outComp = out.m_NativeMatrix.elems(); + float[] inComp = in.m_NativeComponents; + float[] outComp = out.m_NativeComponents; Matrix4x4 matrix = new Matrix4x4(); - float[] comp = matrix.m_NativeMatrix.elems(); + float[] comp = matrix.m_NativeComponents; for(int i = 0; i < 16; ++i) comp[i] = Tools.lerp(t, inComp[i], outComp[i]); @@ -487,11 +540,9 @@ public final class Matrix4x4 extends Object public static Matrix4x4 FromNative(Matrix4x4f nativeMatrix) { Matrix4x4 matrix = new Matrix4x4(); - float[] inComp = matrix.m_NativeMatrix.elems(); float[] copyComp = nativeMatrix.elems(); - for(int i = 0; i < 16; ++i) - inComp[i] = copyComp[i]; + matrix.m_NativeComponents[i] = copyComp[i]; return matrix; } @@ -502,10 +553,8 @@ public final class Matrix4x4 extends Object public void GetNative(Matrix4x4f outMatrix) { float[] outComp = outMatrix.elems(); - float[] copyComp = m_NativeMatrix.elems(); - for(int i = 0; i < 16; ++i) - outComp[i] = copyComp[i]; + outComp[i] = m_NativeComponents[i]; } /// /// Gets the underlying Matrix4x4f type. @@ -514,12 +563,9 @@ public final class Matrix4x4 extends Object public Matrix4x4f GetNative() { Matrix4x4f outMatrix = new Matrix4x4f(); - float[] outComp = outMatrix.elems(); - float[] copyComp = m_NativeMatrix.elems(); - for(int i = 0; i < 16; ++i) - outComp[i] = copyComp[i]; + outComp[i] = m_NativeComponents[i]; return outMatrix; } From fe8c3714ee02a24ddadc8e476f038afd49fc388e Mon Sep 17 00:00:00 2001 From: Scott Lee <74874311+RobbinBob@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:52:54 +0000 Subject: [PATCH 2/3] Refactor --- scripts/BlockLogic.nlvm | 63 +++ scripts/BlockLogicManager.nlvm | 46 +++ scripts/BlockSection.nlvm | 95 +++++ scripts/Elevator.nlvm | 21 + scripts/IBlock.nlvm | 18 + scripts/IInputable.nlvm | 10 + scripts/IInputableButton.nlvm | 6 + scripts/IState.nlvm | 10 + scripts/ITrackProcess.nlvm | 14 + scripts/ITrainPositionQuery.nlvm | 16 + scripts/LiftSection.nlvm | 98 +++++ scripts/StandardBlockLogic.nlvm | 67 +++ scripts/StationSection.nlvm | 40 ++ scripts/TrackSection.nlvm | 76 ++++ scripts/TransportSection.nlvm | 101 +++++ scripts/audiokit/AudioConfig.nlvm | 17 + scripts/audiokit/AudioController.nlvm | 387 ++++++++++++++++++ scripts/audiokit/AudioCue.nlvm | 126 ++++++ scripts/audiokit/AudioCueButton.nlvm | 45 ++ scripts/audiokit/AudioCueEStop.nlvm | 49 +++ scripts/audiokit/AudioCueStationDispatch.nlvm | 42 ++ scripts/audiokit/AudioCueStationGate.nlvm | 10 + scripts/audiokit/AudioCueStationPlatform.nlvm | 10 + .../audiokit/AudioCueStationRestraint.nlvm | 11 + scripts/audiokit/AudioCueStationState.nlvm | 59 +++ scripts/audiokit/AudioCueTimeOfDay.nlvm | 50 +++ scripts/audiokit/AudioCueTimer.nlvm | 34 ++ scripts/audiokit/AudioCueTrackTrigger.nlvm | 73 ++++ scripts/audiokit/AudioCueVolumeTrigger.nlvm | 55 +++ .../audiokit/AudioCueVolumeTriggerCube.nlvm | 12 + .../audiokit/AudioCueVolumeTriggerSphere.nlvm | 12 + scripts/audiokit/AudioCueWeather.nlvm | 60 +++ scripts/audiokit/AudioEmitter.nlvm | 104 +++++ scripts/audiokit/AudioEmitterCar.nlvm | 56 +++ scripts/audiokit/AudioEmitterCube.nlvm | 12 + scripts/audiokit/AudioEmitterPoint.nlvm | 11 + scripts/audiokit/AudioEmitterSphere.nlvm | 13 + scripts/audiokit/AudioEmitterVolume.nlvm | 68 +++ scripts/audiokit/AudioFile.nlvm | 72 ++++ scripts/audiokit/AudioToggleMute.nlvm | 89 ++++ scripts/audiokit/AudioToggleShutOff.nlvm | 98 +++++ 41 files changed, 2256 insertions(+) create mode 100644 scripts/BlockLogic.nlvm create mode 100644 scripts/BlockLogicManager.nlvm create mode 100644 scripts/BlockSection.nlvm create mode 100644 scripts/Elevator.nlvm create mode 100644 scripts/IBlock.nlvm create mode 100644 scripts/IInputable.nlvm create mode 100644 scripts/IInputableButton.nlvm create mode 100644 scripts/IState.nlvm create mode 100644 scripts/ITrackProcess.nlvm create mode 100644 scripts/ITrainPositionQuery.nlvm create mode 100644 scripts/LiftSection.nlvm create mode 100644 scripts/StandardBlockLogic.nlvm create mode 100644 scripts/StationSection.nlvm create mode 100644 scripts/TrackSection.nlvm create mode 100644 scripts/TransportSection.nlvm create mode 100644 scripts/audiokit/AudioConfig.nlvm create mode 100644 scripts/audiokit/AudioController.nlvm create mode 100644 scripts/audiokit/AudioCue.nlvm create mode 100644 scripts/audiokit/AudioCueButton.nlvm create mode 100644 scripts/audiokit/AudioCueEStop.nlvm create mode 100644 scripts/audiokit/AudioCueStationDispatch.nlvm create mode 100644 scripts/audiokit/AudioCueStationGate.nlvm create mode 100644 scripts/audiokit/AudioCueStationPlatform.nlvm create mode 100644 scripts/audiokit/AudioCueStationRestraint.nlvm create mode 100644 scripts/audiokit/AudioCueStationState.nlvm create mode 100644 scripts/audiokit/AudioCueTimeOfDay.nlvm create mode 100644 scripts/audiokit/AudioCueTimer.nlvm create mode 100644 scripts/audiokit/AudioCueTrackTrigger.nlvm create mode 100644 scripts/audiokit/AudioCueVolumeTrigger.nlvm create mode 100644 scripts/audiokit/AudioCueVolumeTriggerCube.nlvm create mode 100644 scripts/audiokit/AudioCueVolumeTriggerSphere.nlvm create mode 100644 scripts/audiokit/AudioCueWeather.nlvm create mode 100644 scripts/audiokit/AudioEmitter.nlvm create mode 100644 scripts/audiokit/AudioEmitterCar.nlvm create mode 100644 scripts/audiokit/AudioEmitterCube.nlvm create mode 100644 scripts/audiokit/AudioEmitterPoint.nlvm create mode 100644 scripts/audiokit/AudioEmitterSphere.nlvm create mode 100644 scripts/audiokit/AudioEmitterVolume.nlvm create mode 100644 scripts/audiokit/AudioFile.nlvm create mode 100644 scripts/audiokit/AudioToggleMute.nlvm create mode 100644 scripts/audiokit/AudioToggleShutOff.nlvm diff --git a/scripts/BlockLogic.nlvm b/scripts/BlockLogic.nlvm new file mode 100644 index 0000000..8c8f1cd --- /dev/null +++ b/scripts/BlockLogic.nlvm @@ -0,0 +1,63 @@ +package scripts; + +import com.nolimitscoaster.*; + +public abstract class BlockLogic extends Behaviour implements ITrackProcess +{ + public final int GetOrder() { return 25; } + public bool Awake() { return true; } + + protected Coaster m_Coaster = null; + protected IBlock m_ControlledBlock = null; + + public static final int STATE_EMPTY = 0; + public static final int STATE_APPROACH = 1; + public static final int STATE_PROCESS = 2; + public static final int STATE_LEAVING = 3; + + public void Start() + { + Block block = GetBlockParameter("controlled_block", true); + m_ControlledBlock = GetIBlockFromInternalType(block); + + + BlockLogicManager.GetInstance().Register(this); + } + + protected IBlock GetIBlockFromInternalType(Block block) + { + String blockId = block.getName(); + if(block.isStation()) + { + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.StationSection", blockId); + if(reference == null) + Exception.Throw("Unable to find type 'scripts.StationSection' with name '" + blockId + "'"); + return (IBlock)reference; + } + else if(block.isLift()) + { + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.LiftSection", blockId); + if(reference == null) + Exception.Throw("Unable to find type 'scripts.LiftSection' with name '" + blockId + "'"); + return (IBlock)reference; + } + else + { + IReferenceable reference = Register.GetInstance().GetReferenceFromName("scripts.BlockSection", blockId); + if(reference == null) + Exception.Throw("Unable to find type 'scripts.BlockSection' with name '" + blockId + "'"); + return (IBlock)reference; + } + } + + public final Coaster GetCoaster() + { + return m_ControlledBlock.GetBlock().getCoaster(); + } + public final Section GetSection() + { + return m_ControlledBlock.GetBlock().getSection(); + } + + public abstract void Process(); +} \ No newline at end of file diff --git a/scripts/BlockLogicManager.nlvm b/scripts/BlockLogicManager.nlvm new file mode 100644 index 0000000..eb092a0 --- /dev/null +++ b/scripts/BlockLogicManager.nlvm @@ -0,0 +1,46 @@ +package scripts; + +import scripts.containers.*; + +public final class BlockLogicManager extends UpdateableObject +{ + private static BlockLogicManager m_Instance = null; + private List m_RegisteredTrackProcesses = new List(); + + private BlockLogicManager() + { + SetShouldUpdate(true); + } + + public static BlockLogicManager GetInstance() + { + if(m_Instance == null) + m_Instance = new BlockLogicManager(); + + return m_Instance; + } + + + public void RegisterProcess(ITrackProcess process) + { + if(m_RegisteredTrackProcesses.Contains(process)) + return; + + m_RegisteredTrackProcesses.Insert(process); + } + public void UnregisterProcess(ITrackProcess process) + { + if(m_RegisteredTrackProcesses.Contains(process)) + m_RegisteredTrackProcesses.Remove(process); + } + + public void Update(float tick) + { + IEnumerator enumerator = m_RegisteredTrackProcesses.GetEnumerator(); + while(enumerator.MoveNext()) + ((ITrackProcess)enumerator.Get()).Process(); + } + + public void LateUpdate(float tick) { } + public void LateUnblockedUpdate() { } +} \ No newline at end of file diff --git a/scripts/BlockSection.nlvm b/scripts/BlockSection.nlvm new file mode 100644 index 0000000..14656d6 --- /dev/null +++ b/scripts/BlockSection.nlvm @@ -0,0 +1,95 @@ +package scripts; + +import com.nolimitscoaster.Block; +import com.nolimitscoaster.Section; + +/// +/// . +public class BlockSection extends TransportSection, IState, IBlock, ITrainPositionQuery, IReferenceable +{ + protected Block m_Block = null; + + public static final int E_BRAKE_OFF = 0; + public static final int E_BRAKE_ON = 1; + public static final int E_BRAKE_TRIM = 2; + private int m_BrakeState = E_TRANSPORT_OFF; + + public BlockSection(Block block) + { + super(block.getSection()); + m_Block = block; + } + public BlockSection(Section section) + { + super(section); + m_Block = section.getBlock(); + } + + + + public void SetBrakeState(int brakeState) + { + if (brakeState < 0 || brakeState > 2) + return; + + switch (brakeState) + { + case E_BRAKE_OFF: + m_Section.setBrakesOff(); + break; + case E_BRAKE_ON: + m_Section.setBrakesOn(); + break; + case E_BRAKE_TRIM: + m_Section.setBrakesTrim(); + break; + } + + m_BrakeState = brakeState; + } + public int GetBrakeState() + { + return m_BrakeState; + } + + + public bool IsTrainBeforeTrigger() + { + return m_Section.isTrainBeforeBrakeTrigger(); + } + public bool IsTrainBehindTrigger() + { + return m_Section.isTrainBehindBrakeTrigger(); + } + + + public int GetState() + { + if(block.getState() == Block.STATE_ERROR_OPERATION_MODE) + return block.getNormalModeState(Block.PROTOCOL_V1); + return block.getState(); + } + public void SetState(int state) + { + m_Block.setState(state); + } + + public Block GetBlock() + { + return m_Block; + } + public TrackSection GetTrackSection() + { + return this; + } + public int GetNumberOfTrainsOnBlock() + { + return m_Block.getNumberOfTrainsOnBlock(); + } + + public String GetType() + { + return "scripts.BlockSection"; + } +} +/// \ No newline at end of file diff --git a/scripts/Elevator.nlvm b/scripts/Elevator.nlvm new file mode 100644 index 0000000..bfabbd7 --- /dev/null +++ b/scripts/Elevator.nlvm @@ -0,0 +1,21 @@ +package scripts; + +import scripts.containers.*; + +public class Elevator extends Behaviour +{ + private Dictionary m_ElevatorInternalDoors = new Dictionary(); + + public int GetOrder() { return 20; } + + public bool Awake() { return true; } + public void Start() + { + Json data = Json.Parse(Tools.loadTextFileFromResource(GetResourcePathParameter("elevator_data", true))); + } + + public void Update(float delta) + { + + } +} \ No newline at end of file diff --git a/scripts/IBlock.nlvm b/scripts/IBlock.nlvm new file mode 100644 index 0000000..78aec9e --- /dev/null +++ b/scripts/IBlock.nlvm @@ -0,0 +1,18 @@ +package scripts; + +/// +/// . +public interface IBlock extends IState +{ + /// + /// Gets the underlying block. + /// + public Block GetBlock(); + + public TrackSection GetTrackSection(); + + public int GetNumberOfTrainsOnBlock(); + + +} +/// \ No newline at end of file diff --git a/scripts/IInputable.nlvm b/scripts/IInputable.nlvm new file mode 100644 index 0000000..3b08511 --- /dev/null +++ b/scripts/IInputable.nlvm @@ -0,0 +1,10 @@ +package scripts; +import scripts.delegates.*; + +public interface IInputable extends IReferenceable +{ + public void SetIsInputEnabled(bool isEnableInput); + public bool GetIsInputEnabled(); + + public Delegate1 OnInputTriggered(); +} \ No newline at end of file diff --git a/scripts/IInputableButton.nlvm b/scripts/IInputableButton.nlvm new file mode 100644 index 0000000..08c5e30 --- /dev/null +++ b/scripts/IInputableButton.nlvm @@ -0,0 +1,6 @@ +package scripts; + +public interface IInputableButton extends IInputable +{ + +} \ No newline at end of file diff --git a/scripts/IState.nlvm b/scripts/IState.nlvm new file mode 100644 index 0000000..62421f3 --- /dev/null +++ b/scripts/IState.nlvm @@ -0,0 +1,10 @@ +package scripts; + +/// +/// . +public interface IState +{ + public void SetState(int state); + public int GetState(); +} +/// \ No newline at end of file diff --git a/scripts/ITrackProcess.nlvm b/scripts/ITrackProcess.nlvm new file mode 100644 index 0000000..e42ba9f --- /dev/null +++ b/scripts/ITrackProcess.nlvm @@ -0,0 +1,14 @@ +package scripts; + +import com.nolimitscoaster.Section; + +/// +/// . +public interface ITrackProcess +{ + public Coaster GetCoaster(); + public Section GetSection(); + + public void Process(); +} +/// \ No newline at end of file diff --git a/scripts/ITrainPositionQuery.nlvm b/scripts/ITrainPositionQuery.nlvm new file mode 100644 index 0000000..0c2ec05 --- /dev/null +++ b/scripts/ITrainPositionQuery.nlvm @@ -0,0 +1,16 @@ +package scripts; + +public interface ITrainPositionQuery +{ + public bool IsTrainBeforeCenterOfSection(); + public bool IsTrainBehindCenterOfSection(); + + public bool IsTrainBeforeTrigger(); + public bool IsTrainBehindTrigger(); + + public bool IsTrainBeforeStartOfSection(float offset); + public bool IsTrainBehindEndOfSection(float offset); + + public bool IsTrainOnTrackSection(); + public Train GetTrainOnSection(); +} \ No newline at end of file diff --git a/scripts/LiftSection.nlvm b/scripts/LiftSection.nlvm new file mode 100644 index 0000000..2bf0a08 --- /dev/null +++ b/scripts/LiftSection.nlvm @@ -0,0 +1,98 @@ +package scripts; + +import com.nolimitscoaster.Block; +import com.nolimitscoaster.Section; + +/// +/// . +public class LiftSection extends TrackSection implements IState, IBlock, ITrainPositionQuery, IReferenceable +{ + protected Block m_Block = null; + + public static final int E_LIFT_OFF = 0; + public static final int E_LIFT_FWD = 1; + public static final int E_LIFT_IDLE = 2; + public static final int E_LIFT_BWD = -1; + private int m_LiftState = E_LIFT_OFF; + + public LiftSection(Block block) + { + super(block.getSection()); + m_Block = block; + } + public LiftSection(Section section) + { + super(section); + m_Block = section.getBlock(); + } + + + public void SetLiftState(int liftState) + { + if (liftState < -1 || liftState > 2) + return; + + switch (liftState) + { + case E_LIFT_OFF: + m_Section.setLiftOff(); + break; + case E_LIFT_FWD: + m_Section.setLiftFwdOn(); + break; + case E_LIFT_BWD: + m_Section.setLiftBwdOn(); + break; + case E_LIFT_IDLE: + m_Section.setLiftFwdIdleOn(); + break; + } + + m_LiftState = liftState; + } + public int GetLiftState() + { + return m_LiftState; + } + + public bool IsTrainBehindTrigger() + { + return m_Section.isTrainBehindLiftTrigger(); + } + public bool IsTrainBeforeTrigger() + { + return m_Section.isTrainBeforeLiftTrigger(); + } + + public int GetState() + { + if(block.getState() == Block.STATE_ERROR_OPERATION_MODE) + return block.getNormalModeState(Block.PROTOCOL_V1); + return block.getState(); + } + public void SetState(int state) + { + m_Block.setState(state); + } + + + public TrackSection GetTrackSection() + { + return this; + } + public int GetNumberOfTrainsOnBlock() + { + return m_Block.getNumberOfTrainsOnBlock(); + } + + public float GetDeviceSpeed() + { + return m_Section.getLiftCurrentSpeed(); + } + + public String GetType() + { + return "scripts.LiftSection"; + } +} +/// \ No newline at end of file diff --git a/scripts/StandardBlockLogic.nlvm b/scripts/StandardBlockLogic.nlvm new file mode 100644 index 0000000..b7b8a68 --- /dev/null +++ b/scripts/StandardBlockLogic.nlvm @@ -0,0 +1,67 @@ +package scripts; + +public class StandardBlockLogic extends BlockLogic +{ + public void Start() + { + super.Start(); + + } + + public void Process() + { + int blockState = m_ControlledBlock.GetState(); + switch(blockState) + { + case BlockLogic.STATE_EMPTY: + if(m_ControlledBlock instanceof LiftSection) + { + LiftSection lift = (LiftSection)m_ControlledBlock; + lift.SetLiftState(LiftSection.E_LIFT_IDLE); + } + else if(m_ControlledBlock instanceof BlockSection || m_ControlledBlock instanceof StationSection) + { + BlockSection block = (BlockSection)m_ControlledBlock; + block.SetBrakeState(BlockSection.E_BRAKE_ON); + block.SetTransportState(TransportSection.E_TRANSPORT_OFF); + } + break; + case BlockLogic.STATE_APPROACH: + if(m_ControlledBlock instanceof LiftSection) + { + LiftSection lift = (LiftSection)m_ControlledBlock; + lift.SetLiftState(LiftSection.E_LIFT_FWD); + } + else if(m_ControlledBlock instanceof BlockSection || m_ControlledBlock instanceof StationSection) + { + BlockSection block = (BlockSection)m_ControlledBlock; + block.SetBrakeState(BlockSection.E_BRAKE_OFF); + } + break; + case BlockLogic.STATE_PROCESS: + + break; + case BlockLogic.STATE_LEAVING: + TrackSection trackSection = m_ControlledBlock.GetTrackSection(); + bool isTrainOnSection = trackSection.IsTrainOnTrackSection(); + int numTrainOnSection = m_ControlledBlock.GetNumberOfTrainsOnBlock(); + bool isBlockCleared = !isTrainOnSection && numTrainOnSection < 1; + + if(m_ControlledBlock instanceof LiftSection) + { + LiftSection lift = (LiftSection)m_ControlledBlock; + lift.SetLiftState(LiftSection.E_LIFT_FWD); + } + else if(m_ControlledBlock instanceof BlockSection || m_ControlledBlock instanceof StationSection) + { + BlockSection block = (BlockSection)m_ControlledBlock; + block.SetTransportState(TransportSection.E_TRANSPORT_FWD); + block.SetBrakeState(BlockSection.E_BRAKE_OFF); + } + + if(isBlockCleared) + m_ControlledBlock.SetState(BlockLogic.STATE_EMPTY); + break; + } + } +} \ No newline at end of file diff --git a/scripts/StationSection.nlvm b/scripts/StationSection.nlvm new file mode 100644 index 0000000..ff40a1d --- /dev/null +++ b/scripts/StationSection.nlvm @@ -0,0 +1,40 @@ +package scripts; + +import com.nolimitscoaster.Block; +import com.nolimitscoaster.Section; + +/// +/// . +public class StationSection extends BlockSection implements IState, IBlock, ITrainPositionQuery, IReferenceable +{ + public static final int STATION_IDLE = 0; + public static final int STATION_OPEN_RESTRAINT = 1; + public static final int STATION_CLOSE_RESTRAINT = 2; + public static final int STATION_OPEN_GATE = 3; + public static final int STATION_CLOSE_GATE = 4; + public static final int STATION_CHECK_CLEAR = 5; + + public StationSection(Block block) + { + super(block); + } + public StationSection(Section section) + { + super(section); + } + + public void SetStationEnter() + { + m_Block.setStationEntering(); + } + public void SetStationLeave() + { + m_Block.setStationLeaving(); + } + + public String GetType() + { + return "scripts.StationSection"; + } +} +/// \ No newline at end of file diff --git a/scripts/TrackSection.nlvm b/scripts/TrackSection.nlvm new file mode 100644 index 0000000..c3453ac --- /dev/null +++ b/scripts/TrackSection.nlvm @@ -0,0 +1,76 @@ +package scripts; + +import com.nolimitscoaster.Section; +import scripts.containers.*; + +/// +/// . +public abstract class TrackSection extends Object implements ITrainPositionQuery, IReferenceable +{ + protected Section m_Section = null; + + public TrackSection(Section section) + { + m_Section = section; + Registry.GetInstance().Register(this); + } + + + public bool IsTrainBeforeCenterOfSection() + { + return m_Section.isTrainBeforeCenterOfSection(); + } + public bool IsTrainBehindCenterOfSection() + { + return m_Section.isTrainBehindCenterOfSection(); + } + + public abstract bool IsTrainBeforeTrigger(); + public abstract bool IsTrainBehindTrigger(); + + public bool IsTrainBeforeStartOfSection(float offset) + { + return m_Section.isTrainBeforeStartOfSection(offset); + } + public bool IsTrainBehindEndOfSection(float offset) + { + return m_Section.isTrainBehindEndOfSection(offset); + } + + + + public bool IsTrainOnTrackSection() + { + return m_Section.isTrainOnSection(); + } + public Train GetTrainOnSection() + { + return m_Section.getTrainOnSection(); + } + + + public final Coaster GetCoaster() + { + m_Section.getCoaster(); + } + public final Section GetSection() + { + return m_Section; + } + + + public final String GetName() + { + return m_Section.getName(); + } + public final void SetName(String name) + { + Exception.Throw("Cannot modify name of type 'scripts.TrackSection'"); + } + + public String GetType() + { + return "scripts.TrackSection"; + } +} +/// \ No newline at end of file diff --git a/scripts/TransportSection.nlvm b/scripts/TransportSection.nlvm new file mode 100644 index 0000000..2d09231 --- /dev/null +++ b/scripts/TransportSection.nlvm @@ -0,0 +1,101 @@ +package scripts; + +import com.nolimitscoaster.Section; + +/// +/// . +public class TransportSection extends TrackSection implements ITrainPositionQuery +{ + /// + /// Transports off (Read Only). + /// + public static final int E_TRANSPORT_OFF = 0; + /// + /// Transports forward (Read Only). + /// + public static final int E_TRANSPORT_FWD = 1; + /// + /// Transports forward launched (Read Only). + /// + public static final int E_TRANSPORT_FWD_LAUNCH = 2; + /// + /// Transports backward (Read Only). + /// + public static final int E_TRANSPORT_BWD = -1; + /// + /// Transports backward launched (Read Only). + /// + public static final int E_TRANSPORT_BWD_LAUNCH = -2; + private int m_TransportState = E_TRANSPORT_OFF; + + /// + public TransportSection(Section section) + { + super(section); + } + /// + + + public bool IsTrainBeforeTrigger() + { + return false; + } + public bool IsTrainBehindTrigger() + { + return false; + } + + + /// + /// Sets the current transports state. + /// The transport state to use. + /// + public void SetTransportState(int transportState) + { + if(transportState < -2 || transportState > 2) + return; + + switch(transportState) + { + case E_TRANSPORT_OFF: + m_Section.setTransportsOff(); + break; + case E_TRANSPORT_FWD: + m_Section.setTransportsStandardFwdOn(); + break; + case E_TRANSPORT_BWD: + m_Section.setTransportsStandardBwdOn(); + break; + case E_TRANSPORT_FWD_LAUNCH: + m_Section.setTransportsLaunchFwdOn(); + break; + case E_TRANSPORT_BWD_LAUNCH: + m_Section.setTransportsLaunchBwdOn(); + break; + } + + m_TransportState = transportState; + } + /// + /// Gets the current transport state currently active. + /// The current transport state. + /// + public int GetTransportState() + { + return m_TransportState; + } + /// + /// Gets the current transport device speed. + /// The current device speed(meters/s). + /// + public float GetDeviceSpeed() + { + return m_Section.getTransportCurrentSpeed(); + } + + public String GetType() + { + return "scripts.TransportSection"; + } +} +/// diff --git a/scripts/audiokit/AudioConfig.nlvm b/scripts/audiokit/AudioConfig.nlvm new file mode 100644 index 0000000..174e618 --- /dev/null +++ b/scripts/audiokit/AudioConfig.nlvm @@ -0,0 +1,17 @@ +package scripts.audiokit; + +public final class AudioConfig extends Object +{ + public String SoundName = ""; + public bool CanMuteLowerPriority = true; + public int Priority = 0; + public AudioFile FileReference; + + public AudioConfig(AudioFile file, int priority, bool canMuteLowerPriority) + { + FileReference = file; + SoundName = file.GetName(); + Priority = priority; + CanMuteLowerPriority = canMuteLowerPriority; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioController.nlvm b/scripts/audiokit/AudioController.nlvm new file mode 100644 index 0000000..c457895 --- /dev/null +++ b/scripts/audiokit/AudioController.nlvm @@ -0,0 +1,387 @@ +package scripts.audiokit; + +//import scripts.math.*; +//import scripts.utilities.*; +import scripts.containers.*; + +public final class AudioController extends Behaviour implements IReferenceable +{ + private SpatialSound m_PrimaryAudioLoop = null; + private AudioFile m_PrimaryAudioFile = null; + + private AudioEmitter[] m_GroupEmitters = null; + private bool m_MutePrimaryTrack = false; + private bool m_IsEnabled = true; + + private Dictionary m_AudioProperties = new Dictionary(); + private String m_GroupName = ""; + + private float m_MuteGain = 0.05f; + + private List m_Queue = new List(); + + // Behaviour + public int GetOrder() { return -25; } + + public bool Awake() + { + m_GroupName = GetStringParameter("group_name", false); + if(m_GroupName.length() == 0) + { + Debug.Warn("Audio Group | No Group Id specified"); + return false; + } + SetName(m_GroupName); + + if(!Debug.IsDebugMode()) + SetIsVisible(false); + return true; + } + public void Start() + { + Registry registry = Registry.GetInstance(); + + // Fetch the main audio loop + String audioName = GetStringParameter("primary_audio_name", false); + if(audioName.length() != 0) + { + m_PrimaryAudioFile = (AudioFile)registry.GetReferenceFromName("scripts.AudioFile", GetStringParameter("primary_audio_name")); + m_PrimaryAudioLoop = (SpatialSound)registry.GetReferenceFromName("scripts.SpatialSound", m_PrimaryAudioFile.GetName()); + if(m_PrimaryAudioLoop == null) + { + Debug.Warn("Audio Group | Unable to find Audio Id '" + GetStringParameter("primary_audio_name") + "'"); + SetIsVisible(true); + } + m_PrimaryAudioLoop.SetGain(0); + } + + m_MuteGain = GetFloatParameter("audio_mute_gain"); + + // Fetch all AudioEmitters with the same group name + IReferenceable[] references = registry.GetReferencesFromName("scripts.AudioEmitter", m_GroupName); + Debug.Print("Audio Group | Found '" + references.length + "' AudioEmitters associated with group '" + m_GroupName + "'"); + m_GroupEmitters = new AudioEmitter[references.length]; + for(int i = 0; i < references.length; ++i) + { + m_GroupEmitters[i] = (AudioEmitter)references[i]; + + if(m_PrimaryAudioLoop != null) + m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + } + + registry.Register(this); + + if(m_MutePrimaryTrack || m_PrimaryAudioLoop == null) + return; + + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + sound.SetGain(m_PrimaryAudioFile.GetDefaultGain()); + sound.SetPitch(m_PrimaryAudioFile.GetDefaultPitch()); + sound.PlaySoundLooped(); + } + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); + } + + private bool m_Debounce = false; + private bool m_EnableDebounce = false; + public void Update(float tick) + { + if(m_IsEnabled == false) + { + if(m_EnableDebounce) + return; + m_EnableDebounce = true; + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound; + if(m_PrimaryAudioLoop != null) + { + sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + sound.SetGain(0); + AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0); + } + + } + IEnumerator enumerator = m_Queue.GetEnumerator(); + while(enumerator.MoveNext()) + { + AudioConfig audio = (AudioConfig)enumerator.Get(); + DequeueSound(audio.SoundName); + Debug.Print("Removing sound '" + audio.SoundName + "' from emitter group '" + m_GroupName + "'"); + } + m_Queue.Clear(); + return; + } + else + m_EnableDebounce = false; + + if(m_Queue.Count() == 0) + { + if(!m_Debounce) + { + if(m_PrimaryAudioLoop != null) + { + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f); + } + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain()); + } + m_Debounce = true; + } + } + else + { + m_Debounce = false; + if(m_GroupEmitters.length == 0) + return; + + // We need to step through the sounds and find any that are completed, remove them from the queue + List toRemove = new List(); + IEnumerator enumerator = m_Queue.GetEnumerator(); + while(enumerator.MoveNext()) + { + AudioConfig audio = (AudioConfig)enumerator.Get(); + SpatialSound sound = m_GroupEmitters[0].SetCurrentSound(audio.SoundName); + if(sound.IsPlaying() == false) + toRemove.Insert(audio); + } + // Purge old sounds and set gain to 0 on emitters + enumerator = toRemove.GetEnumerator(); + while(enumerator.MoveNext()) + { + Debug.Print("Removing completed sound " + ((AudioConfig)enumerator.Get()).SoundName); + m_Queue.Remove((AudioConfig)enumerator.Get()); + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(((AudioConfig)enumerator.Get()).SoundName); + sound.SetGain(0); + } + m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName); + } + + + + + bool isMutingLower = false; + for(int i = m_Queue.Count() - 1; i >= 0; --i) + { + AudioConfig currentAudio = (AudioConfig)m_Queue.At(i); + AudioFile currentFile = currentAudio.FileReference; + + for(int j = 0; j < m_GroupEmitters.length; ++j) + { + SpatialSound sound = m_GroupEmitters[j].SetCurrentSound(currentAudio.SoundName); + sound.SetGain(!isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0); + } + AddOrSetGain(currentAudio.SoundName, !isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0); + if(currentAudio.CanMuteLowerPriority) + isMutingLower = true; + } + + if(m_PrimaryAudioLoop == null) + return; + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + if(m_MutePrimaryTrack) + { + sound.SetGainFaded(0, 0.5f); + AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0); + return; + } + else + { + sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f); + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); + } + + if (isMutingLower) + { + sound.SetGainFaded(m_MuteGain, 0.5f); + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MuteGain); + } + else + { + sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f); + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain()); + } + } + } + } + + private void AddOrSetGain(String audioId, float gain) + { + if(m_AudioProperties.ContainsKey(audioId)) + m_AudioProperties.Remove(audioId); + m_AudioProperties.Insert(audioId, new Float(gain)); + } + public float GetAudioGain(String audioId) + { + Object val = m_AudioProperties.GetValue(audioId); + if(val == null) + return 0; + return ((Float)val).floatValue(); + } + + + public void EnqueSound(AudioConfig properties) + { + if(!m_IsEnabled) + return; + + // No Audio in queue + if(m_Queue.Count() == 0) + { + m_Queue.Insert(properties); + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); + spatialSound.SetGain(properties.FileReference.GetDefaultGain()); + spatialSound.SetPitch(properties.FileReference.GetDefaultPitch()); + spatialSound.PlaySoundOnce(); + } + // Cache current gain + AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); + return; + } + + IEnumerator enumerator = m_Queue.GetEnumerator(); + int index = 0; + bool success = false; + while(enumerator.MoveNext()) + { + AudioConfig sound = (AudioConfig)enumerator.Get(); + + // If this is already found in the queue, then we just need to restart it from the beginning + if(sound.SoundName.equals(properties.SoundName)) + { + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); + spatialSound.Stop(); + spatialSound.PlaySoundOnce(); + } + // Cache current gain + AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); + return; + } + + // If this was not found in the queue then we need to begin playing it and add it to the queue + if(properties.Priority <= sound.Priority) + { + m_Queue.InsertAt(properties, index); + success = true; + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); + spatialSound.PlaySoundOnce(); + } + // Cache current gain + AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); + + // If they both equal the same property then we need to remove the old audio + while(properties.Priority == ((AudioConfig)enumerator.Get()).Priority) + { + DequeueSound(((AudioConfig)enumerator.Get()).SoundName); + m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName); + if(!enumerator.MoveNext()) + break; + } + + break; + } + } + + // If it was unsuccessful at adding this new audio clip to the queue (usually occurs from an empty queue) + if(!success) + { + m_Queue.Insert(properties); + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName); + spatialSound.PlaySoundOnce(); + } + // Cache current gain + AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain()); + } + } + public void DequeueSound(String soundName) + { + if(m_Queue.Count() == 0) + return; + + IEnumerator enumerator = m_Queue.GetEnumerator(); + int i = 0; + while(enumerator.MoveNext()) + { + AudioConfig sound = (AudioConfig)enumerator.Get(); + if(!sound.SoundName.equals(soundName)) + { + i++; + continue; + } + + Debug.Print("Found sound with name '" + soundName + "' stopping sound and removing it from queue"); + for(int j = 0; j < m_GroupEmitters.length; ++j) + { + SpatialSound spatialSound = m_GroupEmitters[j].SetCurrentSound(sound.SoundName); + spatialSound.Stop(); + } + //DequeueSound(sound.SoundName); + m_Queue.RemoveAt(i); + m_AudioProperties.Remove(sound.SoundName); + break; + } + } + + + public void SetPrimaryTrackMuted(bool isMuted) + { + m_MutePrimaryTrack = isMuted; + if(m_PrimaryAudioLoop == null) + return; + + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + if(m_IsEnabled) + sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f); + } + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain()); + } + public void SetControllerOn(bool isEnabled) + { + m_IsEnabled = isEnabled; + if(m_PrimaryAudioLoop != null) + { + for(int i = 0; i < m_GroupEmitters.length; ++i) + { + SpatialSound sound; + sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName()); + sound.SetGain(m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0); + } + AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0); + } + + if(m_IsEnabled) + SetPrimaryTrackMuted(m_MutePrimaryTrack); + } + + // IReferenceable + public String GetType() + { + return "scripts.AudioController"; + } + public String GetName() + { + return m_Name; + } + public void SetName(String string) + { + m_Name = string; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCue.nlvm b/scripts/audiokit/AudioCue.nlvm new file mode 100644 index 0000000..5089025 --- /dev/null +++ b/scripts/audiokit/AudioCue.nlvm @@ -0,0 +1,126 @@ +package scripts.audiokit; + +import scripts.utilities.StringUtil; +import scripts.containers.*; + +public abstract class AudioCue extends Behaviour +{ + protected AudioController[] m_AudioControllers = null; + protected String m_AudioName = ""; + protected int m_Priority = 0; + protected bool m_MuteLowerPriority = false; + protected AudioConfig m_SoundConfig = null; + + public int GetOrder() { return -15; } + public bool Awake() + { + String groupId = GetStringParameter("audio_group"); + if(groupId.length() == 0) + { + Debug.Warn("Cue Trigger | No Group Id/s specified"); + return false; + } + String audioId = GetStringParameter("audio_name"); + if(audioId.length() == 0) + { + Debug.Warn("Cue Trigger | No Audio Id specified"); + return false; + } + if(!Debug.IsDebugMode()) + SetIsVisible(false); + return true; + } + + public void Start() + { + String controllerParams = GetStringParameter("audio_group"); + String[] params = StringUtil.SplitString(controllerParams, ','); + if(params.length == 0) + { + Debug.Warn("Cue Trigger | Internal error when parsing Group Id/s, '" + controllerParams + "' is not a valid parameter entry"); + return; + } + List tempControllers = new List(params.length); + for(int i = 0; i < params.length; ++i) + { + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", params[i]); + if(reference == null) + { + Debug.Warn("Cue Trigger | Unable to find Audio Group with id '" + params[i] + "'"); + continue; + } + tempControllers.Insert(reference); + } + m_AudioControllers = new AudioController[tempControllers.Count()]; + IEnumerator enumerator = tempControllers.GetEnumerator(); + int l = 0; + while(enumerator.MoveNext()) + m_AudioControllers[l++] = (AudioController)enumerator.Get(); + + m_AudioName = GetStringParameter("audio_name"); + m_Priority = GetIntegerParameter("audio_priority"); + m_MuteLowerPriority = GetBoolParameter("audio_mutelower"); + + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioFile", m_AudioName); + if(reference == null) + { + Debug.Warn("Cue Trigger | Unable to find Audio File with name '" + m_AudioName + "'"); + return; + } + + m_SoundConfig = new AudioConfig( + (AudioFile)reference, + m_Priority, + m_MuteLowerPriority); + } + + protected void BroadcastSoundToAll(AudioConfig config) + { + for(int i = 0; i < m_AudioControllers.length; ++i) + m_AudioControllers[i].EnqueSound(config); + } + protected void BroadcastSoundToWhitelist(AudioConfig config, String[] whitelist) + { + for(int i = 0; i < m_AudioControllers.length; ++i) + { + String audioGroupId = m_AudioControllers[i].GetName(); + bool success = true; + for(int l = 0; l < whitelist.length; ++l) + { + if(whitelist[l].equals(audioGroupId) == false) + { + success = false; + break; + } + } + if(!success) + continue; + m_AudioControllers[i].EnqueSound(config); + } + } + protected void BroadcastSoundToBlacklist(AudioConfig config, String[] blacklist) + { + for(int i = 0; i < m_AudioControllers.length; ++i) + { + String audioGroupId = m_AudioControllers[i].GetName(); + bool success = true; + for(int l = 0; l < blacklist.length; ++l) + { + if(blacklist[l].equals(audioGroupId) == true) + { + success = false; + break; + } + } + if(!success) + continue; + m_AudioControllers[i].EnqueSound(config); + } + } + + protected void CancelSoundToAll(AudioConfig config) + { + for(int i = 0; i < m_AudioControllers.length; ++i) + m_AudioControllers[i].DequeueSound(config.SoundName); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueButton.nlvm b/scripts/audiokit/AudioCueButton.nlvm new file mode 100644 index 0000000..675cc42 --- /dev/null +++ b/scripts/audiokit/AudioCueButton.nlvm @@ -0,0 +1,45 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; + +public final class AudioCueButton extends AudioCue implements InteractionActionListener +{ + private InteractionObject m_Interaction = null; + private Animation m_Animation = null; + private bool m_Debounce = false; + + public void Start() + { + super.Start(); + m_Interaction = InteractionObject.createSimpleButton(); + m_Interaction.setActive(true); + m_Interaction.setEnabled(true); + m_Interaction.setPosition(m_SceneObject.getTranslation()); + m_Interaction.setRadius(0.05f); + m_Interaction.addActionListener(this); + m_Animation = new Animation(m_SceneObject); + m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); + SetIsVisible(true); + } + public void Update(float deltaTime) + { + if(m_Debounce && !m_Animation.IsPlaying()) + { + m_Debounce = false; + m_Interaction.setEnabled(true); + m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); + } + } + + + public void onInteractionAction(InteractionObject object) + { + if(m_Debounce) + return; + m_Debounce = true; + m_Animation.Play(); + BroadcastSoundToAll(m_SoundConfig); + m_Interaction.setEnabled(false); + m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueEStop.nlvm b/scripts/audiokit/AudioCueEStop.nlvm new file mode 100644 index 0000000..396e1a6 --- /dev/null +++ b/scripts/audiokit/AudioCueEStop.nlvm @@ -0,0 +1,49 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; + +public class AudioCueEStop extends AudioCue +{ + private Coaster m_Coaster = null; + private Timer m_IntervalTimer = null; + private bool m_Debounce = false; + + public bool Awake() + { + m_Coaster = GetCoasterParameter("audio_coaster", false); + if(m_Coaster == null) + { + Debug.Warn("Cue Trigger - Emergency Stop | No coaster specified"); + return false; + } + + float interval = GetFloatParameter("audio_interval"); + if(interval < 0.1f) + { + Debug.Warn("Cue Trigger - Emergency Stop | Specified interval '" + interval + "' is outside of bounds, must be >= 0.1"); + return false; + } + m_IntervalTimer = new Timer(GetFloatParameter("audio_interval")); + return super.Awake(); + } + + public void Update(float deltaTime) + { + if(m_Coaster.isEmergencyStop()) + { + if(m_IntervalTimer.IsRunning() && m_IntervalTimer.WaitForComplete()) + return; + + BroadcastSoundToAll(m_SoundConfig); + m_IntervalTimer.StopAndReset(); + m_IntervalTimer.Start(); + m_Debounce = false; + } + else + if(!m_Debounce) + { + m_IntervalTimer.StopAndReset(); + m_Debounce = true; + } + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueStationDispatch.nlvm b/scripts/audiokit/AudioCueStationDispatch.nlvm new file mode 100644 index 0000000..df5b6cc --- /dev/null +++ b/scripts/audiokit/AudioCueStationDispatch.nlvm @@ -0,0 +1,42 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; + +public final class AudioCueStationDispatch extends AudioCue +{ + private Section m_Station = null; + private Train m_TrainAtStation = null; + private float m_PreviousTrainSpeed = 0; + + public bool Awake() + { + m_Station = GetSectionParameter("audio_station", false); + if(m_Station == null) + { + Debug.Warn("Cue Trigger - Station Dispatch | No section specified"); + return false; + } + if(m_Station.isStation() == false) + { + Debug.Warn("Cue Trigger - Station Dispatch | The section specified is not a station"); + return false; + } + + m_PreviousTrainSpeed = m_Station.isTrainOnSection() ? 0 : 1; + return super.Awake(); + } + + public void Update(float deltaTime) + { + if(!m_Station.isTrainOnSection()) + return; + + m_TrainAtStation = m_Station.getTrainOnSection(); + float trainSpeed = (float)m_TrainAtStation.getSpeed(); + + if(m_PreviousTrainSpeed == 0 && trainSpeed > 0) + BroadcastSoundToAll(m_SoundConfig); + + m_PreviousTrainSpeed = trainSpeed; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueStationGate.nlvm b/scripts/audiokit/AudioCueStationGate.nlvm new file mode 100644 index 0000000..7e830ac --- /dev/null +++ b/scripts/audiokit/AudioCueStationGate.nlvm @@ -0,0 +1,10 @@ +package scripts.audiokit; + +public final class AudioCueStationGate extends AudioCueStationState +{ + public void Update(float deltaTime) + { + m_Activation = m_Station.getStationGateState(); + super.Update(deltaTime); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueStationPlatform.nlvm b/scripts/audiokit/AudioCueStationPlatform.nlvm new file mode 100644 index 0000000..b1be654 --- /dev/null +++ b/scripts/audiokit/AudioCueStationPlatform.nlvm @@ -0,0 +1,10 @@ +package scripts.audiokit; + +public final class AudioCueStationPlatform extends AudioCueStationState +{ + public void Update(float deltaTime) + { + m_Activation = m_Station.getStationPlatformState(); + super.Update(deltaTime); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueStationRestraint.nlvm b/scripts/audiokit/AudioCueStationRestraint.nlvm new file mode 100644 index 0000000..383ea99 --- /dev/null +++ b/scripts/audiokit/AudioCueStationRestraint.nlvm @@ -0,0 +1,11 @@ +package scripts.audiokit; + +public final class AudioCueStationRestraint extends AudioCueStationState +{ + public void Update(float deltaTime) + { + if(m_Station.isTrainOnSection()) + m_Activation = m_Station.getTrainOnSection().getHarnessState(); + super.Update(deltaTime); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueStationState.nlvm b/scripts/audiokit/AudioCueStationState.nlvm new file mode 100644 index 0000000..e874c6e --- /dev/null +++ b/scripts/audiokit/AudioCueStationState.nlvm @@ -0,0 +1,59 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; + +public abstract class AudioCueStationState extends AudioCue +{ + protected Section m_Station = null; + + protected static final int ACTIVATION_OPENING_OR_RAISING = 0; + protected static final int ACTIVATION_CLOSING_OR_LOWERING = 1; + protected static final int ACTIVATION_OPEN_OR_RAISE_AND_CLOSE_OR_LOWER = 2; + protected int m_ActivationType = ACTIVATION_OPENING_OR_RAISING; + protected float m_Activation = 0; + private float m_PreviousActivation = 0; + + public bool Awake() + { + m_Station = GetSectionParameter("audio_station", false); + if(m_Station == null) + { + Debug.Warn("Cue Trigger - Station State (Gate/Platform) | No section specified"); + return false; + } + if (m_Station.isStation() == false) + { + Debug.Warn("Cue Trigger - Station State (Gate/Platform) | Section specified is not a station"); + return false; + } + + m_ActivationType = GetIntegerParameter("audio_activation"); + return super.Awake(); + } + + + public void Update(float deltaTime) + { + float diff = m_Activation - m_PreviousActivation; + if(diff == 0) + return; + + switch(m_ActivationType) + { + case ACTIVATION_OPENING_OR_RAISING: + if(m_PreviousActivation == 0 && m_Activation > 0) + BroadcastSoundToAll(m_SoundConfig); + break; + case ACTIVATION_CLOSING_OR_LOWERING: + if(m_PreviousActivation == 1 && m_Activation < 1) + BroadcastSoundToAll(m_SoundConfig); + break; + case ACTIVATION_OPEN_OR_RAISE_AND_CLOSE_OR_LOWER: + if((m_PreviousActivation == 0 && m_Activation > 0) || (m_PreviousActivation == 1 && m_Activation < 1)) + BroadcastSoundToAll(m_SoundConfig); + break; + } + + m_PreviousActivation = m_Activation; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueTimeOfDay.nlvm b/scripts/audiokit/AudioCueTimeOfDay.nlvm new file mode 100644 index 0000000..63a2dd0 --- /dev/null +++ b/scripts/audiokit/AudioCueTimeOfDay.nlvm @@ -0,0 +1,50 @@ +package scripts.audiokit; + +import scripts.math.*; + +public final class AudioCueTimeOfDay extends AudioCue +{ + private int m_Hour = 0; + private int m_Minute = 0; + private float m_Time = 0; + private bool m_HasPlayed = false; + + public bool Awake() + { + m_Hour = GetIntegerParameter("audio_time_hour"); + if(m_Hour < 0 || m_Hour > 23) + { + Debug.Warn("Cue Trigger - Time of Day | Hour specified is invalid must be >= 0 and < 24"); + return false; + } + m_Minute = GetIntegerParameter("audio_time_minute"); + if(m_Minute < 0 || m_Minute > 59) + { + Debug.Warn("Cue Trigger - Time of Day | Minute specified is invalid must be >= 0 and < 60"); + return false; + } + + float minutes = Mathf.Remap(m_Minute, 0, 60, 0, 1); + m_Time = (float)m_Hour + minutes; + + return super.Awake(); + } + + public void Update(float deltaTime) + { + float currTime = sim.getCurTimeOfDay(); + int hours = (int)currTime; + int minutes = (int)Mathf.Remap(currTime - hours, 0, 1, 0, 60); + + if(hours == m_Hour && minutes == m_Minute) + { + if(m_HasPlayed) + return; + + BroadcastSoundToAll(m_SoundConfig); + m_HasPlayed = true; + } + else if (m_HasPlayed) + m_HasPlayed = false; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueTimer.nlvm b/scripts/audiokit/AudioCueTimer.nlvm new file mode 100644 index 0000000..95d973e --- /dev/null +++ b/scripts/audiokit/AudioCueTimer.nlvm @@ -0,0 +1,34 @@ +package scripts.audiokit; + +public final class AudioCueTimer extends AudioCue +{ + private Timer m_IntervalTimer = null; + + public bool Awake() + { + float interval = GetFloatParameter("audio_interval"); + if(interval < 0.1f) + { + Debug.Warn("Cue Trigger - Timer | Time interval specified is invalid, must be > 0.1"); + return false; + } + m_IntervalTimer = new Timer(interval); + return super.Awake(); + } + + public void Start() + { + super.Start(); + m_IntervalTimer.Start(); + } + + public void Update(float tick) + { + if(m_IntervalTimer.WaitForComplete()) + return; + + BroadcastSoundToAll(m_SoundConfig); + m_IntervalTimer.Reset(); + m_IntervalTimer.Start(); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueTrackTrigger.nlvm b/scripts/audiokit/AudioCueTrackTrigger.nlvm new file mode 100644 index 0000000..29e2a75 --- /dev/null +++ b/scripts/audiokit/AudioCueTrackTrigger.nlvm @@ -0,0 +1,73 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; +import scripts.utilities.*; + +public final class AudioCueTrackTrigger extends AudioCue implements TrackTriggerListener +{ + private TrackTrigger m_TrackTrigger = null; + private TrackTrigger m_StopTrigger = null; + private int[] m_TrainWhitelist = new int[0]; + private Coaster m_Coaster = null; + + public bool Awake() + { + m_TrackTrigger = GetTriggerParameter("audio_trigger", false); + if(m_TrackTrigger == null) + { + Debug.Warn("Cue Trigger - Track Trigger | No track trigger specified"); + return false; + } + m_StopTrigger = GetTriggerParameter("audio_stop_trigger", false); + return super.Awake(); + } + + public void Start() + { + super.Start(); + m_TrackTrigger.addTrackTriggerListener(this); + m_Coaster = m_TrackTrigger.getCoaster(); + + if(m_StopTrigger != null) + m_StopTrigger.addTrackTriggerListener(this); + + String params = GetStringParameter("audio_train_whitelist"); + String[] indices = StringUtil.SplitString(params, ','); + if(indices.length == 0) + { + m_TrainWhitelist = new int[m_Coaster.getTrainCount()]; + for(int i = 0; i < m_TrainWhitelist.length; ++i) + m_TrainWhitelist[i] = i; + return; + } + + m_TrainWhitelist = new int[indices.length]; + for (int i = 0; i < indices.length; ++i) + m_TrainWhitelist[i] = Integer.parseInt(indices[i]); + } + + public void onTrainEntering(TrackTrigger trigger, Train train) + { + bool success = false; + for(int i = 0; i < m_TrainWhitelist.length; ++i) + { + if(m_Coaster.getTrainAt(m_TrainWhitelist[i]) == train) + { + success = true; + break; + } + } + if(!success) + return; + + if(trigger == m_TrackTrigger) + BroadcastSoundToAll(m_SoundConfig); + if(m_StopTrigger != null) + { + if(trigger != m_StopTrigger) + return; + CancelSoundToAll(m_SoundConfig); + } + } + public void onTrainLeaving(TrackTrigger trigger, Train train) { } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueVolumeTrigger.nlvm b/scripts/audiokit/AudioCueVolumeTrigger.nlvm new file mode 100644 index 0000000..0384b07 --- /dev/null +++ b/scripts/audiokit/AudioCueVolumeTrigger.nlvm @@ -0,0 +1,55 @@ +package scripts.audiokit; + +import scripts.math.*; + +public abstract class AudioCueVolumeTrigger extends AudioCue +{ + protected Volume m_TriggerVolume = null; + private static final float MAX_DIST_CALCULATIONS = 2; + + private bool m_IsViewerInside = false; + private bool m_IsViewerInsidePrevious = false; + + private static final int PLAY_ON_ENTRY = 0; + private static final int PLAY_ON_EXIT = 1; + private int m_PlayState = PLAY_ON_ENTRY; + + public void Start() + { + super.Start(); + m_PlayState = GetIntegerParameter("audio_play_state"); + } + + public void Update(float tick) + { + m_IsViewerInsidePrevious = m_IsViewerInside; + Vector3 viewPos = GetViewerPosition(); + if(Vector3.Distance(m_TriggerVolume.GetMatrix().GetPosition(), viewPos) > m_TriggerVolume.GetScale().Length() * MAX_DIST_CALCULATIONS) + { + m_IsViewerInside = false; + CheckTriggerStateAndFire(); + return; + } + + m_IsViewerInside = m_TriggerVolume.IsPointWithinVolume(viewPos); + CheckTriggerStateAndFire(); + } + + private void CheckTriggerStateAndFire() + { + // Gaurd clause to ignore states where no updates have happened + if(m_IsViewerInside == m_IsViewerInsidePrevious) + return; + + if(m_IsViewerInside) + { + if(m_PlayState == PLAY_ON_ENTRY) + BroadcastSoundToAll(m_SoundConfig); + } + else + { + if(m_PlayState == PLAY_ON_EXIT) + BroadcastSoundToAll(m_SoundConfig); + } + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueVolumeTriggerCube.nlvm b/scripts/audiokit/AudioCueVolumeTriggerCube.nlvm new file mode 100644 index 0000000..5abd2d7 --- /dev/null +++ b/scripts/audiokit/AudioCueVolumeTriggerCube.nlvm @@ -0,0 +1,12 @@ +package scripts.audiokit; + +import scripts.math.*; + +public final class AudioCueVolumeTriggerCube extends AudioCueVolumeTrigger +{ + public void Start() + { + super.Start(); + m_TriggerVolume = new Cube(GetMatrix(), GetScale()); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueVolumeTriggerSphere.nlvm b/scripts/audiokit/AudioCueVolumeTriggerSphere.nlvm new file mode 100644 index 0000000..fb1306c --- /dev/null +++ b/scripts/audiokit/AudioCueVolumeTriggerSphere.nlvm @@ -0,0 +1,12 @@ +package scripts.audiokit; + +import scripts.math.*; + +public final class AudioCueVolumeTriggerSphere extends AudioCueVolumeTrigger +{ + public void Start() + { + super.Start(); + m_TriggerVolume = new Sphere(GetMatrix(), GetScale().X); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioCueWeather.nlvm b/scripts/audiokit/AudioCueWeather.nlvm new file mode 100644 index 0000000..6756293 --- /dev/null +++ b/scripts/audiokit/AudioCueWeather.nlvm @@ -0,0 +1,60 @@ +package scripts.audiokit; + +public final class AudioCueWeather extends AudioCue +{ + private float m_WeatherThreshold = 0; + private bool m_HasPlayed = false; + private int m_WeatherType = 0; + + public void Start() + { + super.Start(); + m_WeatherType = GetIntegerParameter("weather_type"); + m_WeatherThreshold = GetFloatParameter("weather_threshold"); + m_SoundConfig.CanMuteLowerPriority = true; + } + + + public void Update(float tick) + { + float currentWeatherState = 0; + switch(m_WeatherType) + { + // Rain + case 0: + currentWeatherState = sim.getRainIntensity(); + break; + // Snow + case 1: + currentWeatherState = sim.getSnowIntensity(); + break; + // Wind + case 2: + currentWeatherState = sim.getWindIntensity(); + break; + // Thunder + case 3: + currentWeatherState = sim.getThunderIntensity(); + break; + } + + if(m_HasPlayed) + { + // If weather is still above threshold skip + if(currentWeatherState >= m_WeatherThreshold) + return; + + m_HasPlayed = false; + } + else + { + // If weather is below threshold skip + if(currentWeatherState < m_WeatherThreshold) + return; + + m_HasPlayed = true; + BroadcastSoundToAll(m_SoundConfig); + } + } + +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitter.nlvm b/scripts/audiokit/AudioEmitter.nlvm new file mode 100644 index 0000000..cdb1845 --- /dev/null +++ b/scripts/audiokit/AudioEmitter.nlvm @@ -0,0 +1,104 @@ +package scripts.audiokit; + +import scripts.containers.*; + +public abstract class AudioEmitter extends Behaviour implements IReferenceable +{ + protected List m_AudioClips = new List(); + protected SpatialSound m_ActiveSound = null; + private AudioController m_AudioGroup = null; + + protected float m_FallOff = 1; + protected float m_Distance = 1; + + public int GetOrder() { return -30; } + public bool Awake() + { + String groupId = GetStringParameter("group_name"); + if(groupId.length() == 0) + { + Debug.Warn("Audio Emitter | No Group Id specified"); + return false; + } + SetName(groupId); + + if(!Debug.IsDebugMode()) + SetIsVisible(false); + return true; + } + public void Start() + { + m_FallOff = GetFloatParameter("audio_falloff"); + m_Distance = GetFloatParameter("audio_distance"); + Registry.GetInstance().Register(this); + } + + public final SpatialSound GetCurrentSound() + { + return m_ActiveSound; + } + public SpatialSound SetCurrentSound(String name) + { + //Debug.Print("Setting sound " + name); + // Try find the sound in the current emitter cache + m_ActiveSound = null; + IEnumerator enumerator = m_AudioClips.GetEnumerator(); + while(enumerator.MoveNext()) + { + if(((SpatialSound)enumerator.Get()).GetName().equals(name)) + { + m_ActiveSound = (SpatialSound)enumerator.Get(); + break; + } + } + + // Not in cache, we need to load it in + if(m_ActiveSound == null) + { + Debug.Print("Audio Emitter | Unable to find sound with name " + name + " in cache"); + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.SpatialSound", name); + if(reference == null) + Exception.Throw("Audio Emitter | Unable to load SpatialSound file from registry with name '" + name + "'"); + + SpatialSound sound = (SpatialSound)((SpatialSound)reference).Instantiate(); + m_AudioClips.Insert(sound); + m_ActiveSound = sound; + } + + //m_ActiveSound.SetPosition(GetPosition()); + m_ActiveSound.SetConstantDistance(m_Distance); + m_ActiveSound.SetFalloffFactor(m_FallOff); + //m_ActiveSound.SetPosition(GetPosition()); + //m_ActiveSound.SetShouldUseDoppler(false); + + return m_ActiveSound; + } + + public List GetAllSounds() + { + return m_AudioClips; + } + + public AudioController GetAudioController() + { + if(m_AudioGroup == null) + m_AudioGroup = (AudioController)Registry.GetInstance().GetReferenceFromName("scripts.AudioController", GetStringParameter("group_name")); + return m_AudioGroup; + } + + + + // IReferenceable + public String GetType() + { + return "scripts.AudioEmitter"; + } + public final String GetName() + { + return m_Name; + } + public final void SetName(String name) + { + m_Name = name; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitterCar.nlvm b/scripts/audiokit/AudioEmitterCar.nlvm new file mode 100644 index 0000000..a32cea1 --- /dev/null +++ b/scripts/audiokit/AudioEmitterCar.nlvm @@ -0,0 +1,56 @@ +package scripts.audiokit; + +import scripts.math.*; +import scripts.containers.*; + +import com.nolimitscoaster.*; +import nlvm.math3d.*; + +public final class AudioEmitterCar extends AudioEmitter +{ + private Coaster m_Coaster = null; + private Train m_Train = null; + private int m_CarIndex = 0; + private Vector3f m_CarPos = new Vector3f(); + + public bool Awake() + { + m_Coaster = GetCoasterParameter("audio_coaster", false); + if(m_Coaster == null) + { + Debug.Warn("Emitter - Car | No specified coaster found"); + return false; + } + if(m_Coaster.getTrainCount() == 0) + { + Debug.Warn("Emitter - Car | Coaster '" + m_Coaster.getName() + "' has no trains"); + return false; + } + + m_Train = m_Coaster.findNearestTrain(m_SceneObject.getTranslation(), 15.0f); + if(m_Train == null) + { + Debug.Warn("Emitter - Car | Could not find train on coaster '" + m_Coaster.getName() + "' within 15m"); + return false; + } + m_CarIndex = GetIntegerParameter("audio_car"); + if(m_CarIndex < 0 || m_CarIndex > m_Train.getCarCount()) + { + Debug.Warn("Emitter - Car | The car index '" + m_CarIndex + "' is invalid for coaster '" + m_Coaster.getName() + "', must be <= " + m_Train.getCarCount()); + return false; + } + return super.Awake(); + } + + public void Update(float tick) + { + m_Train.getCarOrientationAndPosition(m_CarIndex, null, null, null, m_CarPos); + Vector3 carPos = Vector3.FromNative(m_CarPos); + IEnumerator enumerator = m_AudioClips.GetEnumerator(); + while(enumerator.MoveNext()) + { + SpatialSound sound = (SpatialSound)enumerator.Get(); + sound.SetPosition(carPos); + } + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitterCube.nlvm b/scripts/audiokit/AudioEmitterCube.nlvm new file mode 100644 index 0000000..7debe99 --- /dev/null +++ b/scripts/audiokit/AudioEmitterCube.nlvm @@ -0,0 +1,12 @@ +package scripts.audiokit; + +import scripts.math.*; + +public final class AudioEmitterCube extends AudioEmitterVolume +{ + public void Start() + { + super.Start(); + m_EmitterWorldVolume = new Cube(GetMatrix(), GetScale()); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitterPoint.nlvm b/scripts/audiokit/AudioEmitterPoint.nlvm new file mode 100644 index 0000000..7b4ef60 --- /dev/null +++ b/scripts/audiokit/AudioEmitterPoint.nlvm @@ -0,0 +1,11 @@ +package scripts.audiokit; + +public class AudioEmitterPoint extends AudioEmitter +{ + public SpatialSound SetCurrentSound(String name) + { + SpatialSound sound = super.SetCurrentSound(name); + m_ActiveSound.SetPosition(GetPosition()); + return sound; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitterSphere.nlvm b/scripts/audiokit/AudioEmitterSphere.nlvm new file mode 100644 index 0000000..1f125e2 --- /dev/null +++ b/scripts/audiokit/AudioEmitterSphere.nlvm @@ -0,0 +1,13 @@ +package scripts.audiokit; + +import scripts.math.*; + +public final class AudioEmitterSphere extends AudioEmitterVolume +{ + public void Start() + { + super.Start(); + Vector3 scale = GetScale(); + m_EmitterWorldVolume = new Sphere(GetMatrix(), Mathf.Min(scale.X, Mathf.Min(scale.Y, scale.Z))); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioEmitterVolume.nlvm b/scripts/audiokit/AudioEmitterVolume.nlvm new file mode 100644 index 0000000..7152302 --- /dev/null +++ b/scripts/audiokit/AudioEmitterVolume.nlvm @@ -0,0 +1,68 @@ +package scripts.audiokit; + +import scripts.containers.*; +import scripts.math.*; + +public abstract class AudioEmitterVolume extends AudioEmitter implements IReferenceable +{ + protected Volume m_EmitterWorldVolume = null; + private static final float MAX_DIST_CALCULATIONS = 2; + + private bool m_FadeOutDebounce = false; + private bool m_FadeInDebounce = false; + + private Color[] colors = new Color[] + { + Color.Red, + Color.Yellow, + Color.Green, + Color.Cyan, + Color.Blue, + Color.Magenta + }; + + public void LateUpdate(float tick) + { + Vector3 viewPos = GetViewerPosition(); + if(Vector3.Distance(m_EmitterWorldVolume.GetMatrix().GetPosition(), viewPos) > m_EmitterWorldVolume.GetScale().Length() * MAX_DIST_CALCULATIONS) + return; + + Vector3 soundPosition = viewPos; + if(m_EmitterWorldVolume.IsPointWithinVolume(viewPos)) + { + m_FadeOutDebounce = false; + if(!m_FadeInDebounce) + { + m_FadeInDebounce = true; + IEnumerator enumerator = m_AudioClips.GetEnumerator(); + while(enumerator.MoveNext()) + { + // Needs to check the gain level of the audio + SpatialSound sound = ((SpatialSound)enumerator.Get()); + String audioId = sound.GetName(); + //Debug.Print("AUDIO EMITTER AUDIO ID '" + audioId + "'"); + ((SpatialSound)enumerator.Get()).SetGainFaded(GetAudioController().GetAudioGain(audioId), 0.05f); + } + } + + IEnumerator enumerator = m_AudioClips.GetEnumerator(); + int index = 0; + while(enumerator.MoveNext()) + { + SpatialSound sound = (SpatialSound)enumerator.Get(); + sound.SetPosition(soundPosition); + sound.SetConstantDistance(100); + sound.SetFalloffFactor(0); + } + + } + else + { + m_FadeInDebounce = false; + m_FadeOutDebounce = true; + IEnumerator enumerator = m_AudioClips.GetEnumerator(); + while(enumerator.MoveNext()) + ((SpatialSound)enumerator.Get()).SetGainFaded(0, 0.05f); + } + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioFile.nlvm b/scripts/audiokit/AudioFile.nlvm new file mode 100644 index 0000000..e675d13 --- /dev/null +++ b/scripts/audiokit/AudioFile.nlvm @@ -0,0 +1,72 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; + +public final class AudioFile extends Behaviour implements IReferenceable +{ + private Sound m_Sound = null; + private String m_Name = ""; + private float m_DefaultGain = 0; + private float m_DefaultPitch = 0; + + public bool Awake() + { + ResourcePath resource = GetResourcePathParameter("audio_file", false); + if(resource == null) + { + Debug.Warn("Audio File | No sound file specified"); + return false; + } + + int audioFlags = Sound.AUDIO_FLAG_SOUND | (GetBoolParameter("audio_flag_mono") ? Sound.AUDIO_FLAG_MONO : 0) | (GetBoolParameter("audio_flag_shared") ? Sound.AUDIO_FLAG_SHARED : 0); + bool isMusic = GetBoolParameter("audio_is_music"); + if(isMusic) + audioFlags |= Sound.AUDIO_FLAG_MUSIC; + m_Sound = new SpatialSound(resource, audioFlags, Sound.ENVIRONMENT_WORLD); + + m_Name = GetStringParameter("audio_name", false); + if(m_Name == null || m_Name.length() == 0) + { + Debug.Warn("Audio File | No Audio Id specified"); + return false; + } + + m_DefaultGain = GetFloatParameter("audio_gain"); + m_DefaultPitch = GetFloatParameter("audio_pitch"); + + m_Sound.SetGain(0); + m_Sound.SetPitch(m_DefaultPitch); + m_Sound.SetShouldUseDoppler(false); + m_Sound.SetName(m_Name); + + Registry.GetInstance().Register(this); + + if(!Debug.IsDebugMode()) + SetIsVisible(false); + + return false; + } + + public float GetDefaultGain() + { + return m_DefaultGain; + } + public float GetDefaultPitch() + { + return m_DefaultPitch; + } + + public String GetName() + { + return m_Name; + } + public void SetName(String name) + { + m_Name = name; + m_Sound.SetName(name); + } + public String GetType() + { + return "scripts.AudioFile"; + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioToggleMute.nlvm b/scripts/audiokit/AudioToggleMute.nlvm new file mode 100644 index 0000000..bcf3f1c --- /dev/null +++ b/scripts/audiokit/AudioToggleMute.nlvm @@ -0,0 +1,89 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; +import scripts.containers.*; +import scripts.utilities.StringUtil; + +public final class AudioToggleMute extends Behaviour implements InteractionActionListener +{ + private AudioController[] m_AudioControllers = null; + private InteractionObject m_Interaction = null; + private Animation m_Animation = null; + private bool m_IsToggled = false; + private bool m_Debounce = false; + + public int GetOrder() { return -15; } + public bool Awake() + { + String groupId = GetStringParameter("audio_group"); + if(groupId.length() == 0) + { + Debug.Warn("Button - Music Mute Toggle | No Group Id specified"); + return false; + } + return true; + } + + public void Start() + { + String controllerParams = GetStringParameter("audio_group"); + String[] params = StringUtil.SplitString(controllerParams, ','); + if(params.length == 0) + { + Debug.Warn("Cue Trigger | Internal error when parsing Group Id/s, '" + controllerParams + "' is not a valid parameter entry"); + return; + } + List tempControllers = new List(params.length); + for(int i = 0; i < params.length; ++i) + { + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", params[i]); + if(reference == null) + { + Debug.Warn("Cue Trigger | Unable to find Audio Group with id '" + params[i] + "'"); + continue; + } + tempControllers.Insert(reference); + } + m_AudioControllers = new AudioController[tempControllers.Count()]; + IEnumerator enumerator = tempControllers.GetEnumerator(); + int l = 0; + while(enumerator.MoveNext()) + m_AudioControllers[l++] = (AudioController)enumerator.Get(); + + m_Interaction = InteractionObject.createSimpleButton(); + m_Interaction.setActive(true); + m_Interaction.setEnabled(true); + m_Interaction.setPosition(m_SceneObject.getTranslation()); + m_Interaction.setRadius(0.05f); + m_Interaction.addActionListener(this); + m_Animation = new Animation(m_SceneObject); + m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); + } + + public void Update(float deltaTime) + { + if(m_Debounce && !m_Animation.IsPlaying()) + { + m_Debounce = false; + m_Interaction.setEnabled(true); + if(!m_IsToggled) + m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); + } + } + + public void onInteractionAction(InteractionObject object) + { + if(m_Debounce) + return; + m_Debounce = true; + m_Animation.Play(); + m_Interaction.setEnabled(false); + + m_IsToggled = !m_IsToggled; + for(int i = 0; i < m_AudioControllers.length; ++i) + m_AudioControllers[i].SetPrimaryTrackMuted(m_IsToggled); + + if(m_IsToggled) + m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); + } +} \ No newline at end of file diff --git a/scripts/audiokit/AudioToggleShutOff.nlvm b/scripts/audiokit/AudioToggleShutOff.nlvm new file mode 100644 index 0000000..553eea0 --- /dev/null +++ b/scripts/audiokit/AudioToggleShutOff.nlvm @@ -0,0 +1,98 @@ +package scripts.audiokit; + +import com.nolimitscoaster.*; +import scripts.containers.*; +import scripts.utilities.StringUtil; + +public final class AudioToggleShutOff extends Behaviour implements InteractionActionListener +{ + private AudioController[] m_AudioControllers = null; + private InteractionObject m_Interaction = null; + private Animation m_Animation = null; + private bool m_IsToggled = false; + private bool m_Debounce = false; + + public int GetOrder() { return -15; } + public bool Awake() + { + String groupId = GetStringParameter("audio_group"); + if(groupId.length() == 0) + { + Debug.Warn("Button - Master Switch | No Group Id specified"); + return false; + } + return true; + } + + public void Start() + { + String controllerParams = GetStringParameter("audio_group"); + String[] params = StringUtil.SplitString(controllerParams, ','); + if(params.length == 0) + { + Debug.Warn("Cue Trigger | Internal error when parsing Group Id/s, '" + controllerParams + "' is not a valid parameter entry"); + return; + } + List tempControllers = new List(params.length); + for(int i = 0; i < params.length; ++i) + { + IReferenceable reference = Registry.GetInstance().GetReferenceFromName("scripts.AudioController", params[i]); + if(reference == null) + { + Debug.Warn("Cue Trigger | Unable to find Audio Group with id '" + params[i] + "'"); + continue; + } + tempControllers.Insert(reference); + } + m_AudioControllers = new AudioController[tempControllers.Count()]; + IEnumerator enumerator = tempControllers.GetEnumerator(); + int l = 0; + while(enumerator.MoveNext()) + m_AudioControllers[l++] = (AudioController)enumerator.Get(); + + m_Interaction = InteractionObject.createSimpleButton(); + m_Interaction.setActive(true); + m_Interaction.setEnabled(true); + m_Interaction.setPosition(m_SceneObject.getTranslation()); + m_Interaction.setRadius(0.05f); + m_Interaction.addActionListener(this); + m_Animation = new Animation(m_SceneObject); + + m_IsToggled = true; + m_Animation.Play(0, 10); + m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); + m_SceneObject.getElementForName("Plaque").setVisible(!GetBoolParameter("hide_plaque")); + } + + public void Update(float deltaTime) + { + if(m_Debounce && !m_Animation.IsPlaying()) + { + m_Debounce = false; + m_Interaction.setEnabled(true); + if(!m_IsToggled) + m_SceneObject.getElementAt(1).setTextureAnimationIndex(0); + } + } + + public void onInteractionAction(InteractionObject object) + { + if(m_Debounce) + return; + m_Debounce = true; + m_Interaction.setEnabled(false); + + if(m_IsToggled) + { + m_Animation.Play(10, 20); + } + else + { + m_Animation.Play(0, 10); + m_SceneObject.getElementAt(1).setTextureAnimationIndex(1); + } + m_IsToggled = !m_IsToggled; + for(int i = 0; i < m_AudioControllers.length; ++i) + m_AudioControllers[i].SetControllerOn(m_IsToggled); + } +} \ No newline at end of file From a073424cfc460a07285365ccdf7a40826db0c4bf Mon Sep 17 00:00:00 2001 From: Scott Lee <74874311+RobbinBob@users.noreply.github.com> Date: Sat, 3 Jan 2026 18:56:03 +0000 Subject: [PATCH 3/3] removal of nl2mat --- New.nl2mat | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 New.nl2mat diff --git a/New.nl2mat b/New.nl2mat deleted file mode 100644 index dcd699b..0000000 --- a/New.nl2mat +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file