public ElapseProxy Elapse(ElapseProxy ProxyData) { lock (UpdateLock) { try { if (ProxyData == null) { Console.WriteLine(@"DEBUG: The recieved ProxyData was null"); } else if (ProxyData.Data.TotalTime == null) { Console.WriteLine(@"DEBUG: The total time in the recieved ProxyData was invalid"); } else { double time = ProxyData.Data.TotalTime.Milliseconds; Win32VehicleState win32State; win32State.Location = ProxyData.Data.Vehicle.Location; win32State.Speed = (float)ProxyData.Data.Vehicle.Speed.KilometersPerHour; win32State.Time = (int)Math.Floor(time - 2073600000.0 * Math.Floor(time / 2073600000.0)); win32State.BcPressure = (float)ProxyData.Data.Vehicle.BcPressure; win32State.MrPressure = (float)ProxyData.Data.Vehicle.MrPressure; win32State.ErPressure = (float)ProxyData.Data.Vehicle.ErPressure; win32State.BpPressure = (float)ProxyData.Data.Vehicle.BpPressure; win32State.SapPressure = (float)ProxyData.Data.Vehicle.SapPressure; win32State.Current = 0.0f; Win32Handles win32Handles; win32Handles.Brake = ProxyData.Data.Handles.BrakeNotch; win32Handles.Power = ProxyData.Data.Handles.PowerNotch; win32Handles.Reverser = ProxyData.Data.Handles.Reverser; win32Handles.ConstantSpeed = ProxyData.Data.Handles.ConstSpeed ? 1 : 2; Win32Elapse(ref win32Handles.Brake, ref win32State.Location, ref Panel[0], ref Sound[0]); ProxyData.Data.Handles.Reverser = win32Handles.Reverser; ProxyData.Data.Handles.PowerNotch = win32Handles.Power; ProxyData.Data.Handles.BrakeNotch = win32Handles.Brake; switch (win32Handles.ConstantSpeed) { case 0: invalidConstSpeed = false; //Not fitted break; case 1: invalidConstSpeed = false; ProxyData.Data.Handles.ConstSpeed = true; break; case 2: invalidConstSpeed = false; ProxyData.Data.Handles.ConstSpeed = false; break; default: if (invalidConstSpeed == false) { /* * ATS.dll seems to submit an invalid ConstantSpeed value every frame (most likely just reading random memory value?) * so let's just log this once */ Console.WriteLine(@"DEBUG: Invalid ConstantSpeed value recieved from plugin- " + win32Handles.ConstantSpeed); invalidConstSpeed = true; } break; } Array.Copy(Panel, ProxyData.Panel, 256); Array.Copy(Sound, ProxyData.Sound, 256); for (int i = 0; i < 256; i++) { if (Sound[i] == 1) { Sound[i] = 2; } } } } catch (Exception ex) { Callback.ReportError(ex.ToString()); } } return(ProxyData); }
protected override void Elapse(ref ElapseData data) { if (externalCrashed) { //Yuck for (int i = 0; i < Train.Cars[Train.DriverCar].Sounds.Plugin.Length; i++) { if (Train.Cars[Train.DriverCar].Sounds.Plugin[i].IsPlaying) { Train.Cars[Train.DriverCar].Sounds.Plugin[i].Stop(); } } Train.UnloadPlugin(); return; } if (!string.IsNullOrEmpty(lastError)) { //TrainManagercurrentHost.A("ERROR: The proxy plugin " + PluginFile + " generated the following error:"); //Program.FileSystem.AppendToLogFile(pluginProxy.callback.lastError); lastError = string.Empty; } try { ElapseProxy e = new ElapseProxy(data, Panel, Sound); ElapseProxy proxyData = pipeProxy.Elapse(e); Panel = proxyData.Panel; Sound = proxyData.Sound; for (int i = 0; i < Sound.Length; i++) { if (Sound[i] != LastSound[i]) { if (Sound[i] == SoundInstructions.Stop) { if (i < Train.Cars[Train.DriverCar].Sounds.Plugin.Length) { Train.Cars[Train.DriverCar].Sounds.Plugin[i].Stop(); } } else if (Sound[i] > SoundInstructions.Stop & Sound[i] <= SoundInstructions.PlayLooping) { if (i < Train.Cars[Train.DriverCar].Sounds.Plugin.Length) { SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.Plugin[i].Buffer; if (buffer != null) { double volume = (double)(Sound[i] - SoundInstructions.Stop) / (SoundInstructions.PlayLooping - SoundInstructions.Stop); if (Train.Cars[Train.DriverCar].Sounds.Plugin[i].IsPlaying) { Train.Cars[Train.DriverCar].Sounds.Plugin[i].Source.Volume = volume; } else { Train.Cars[Train.DriverCar].Sounds.Plugin[i].Play(1.0, volume, Train.Cars[Train.DriverCar], true); } } } } else if (Sound[i] == SoundInstructions.PlayOnce) { if (i < Train.Cars[Train.DriverCar].Sounds.Plugin.Length) { SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.Plugin[i].Buffer; if (buffer != null) { Train.Cars[Train.DriverCar].Sounds.Plugin[i].Play(1.0, 1.0, Train.Cars[Train.DriverCar], false); } } Sound[i] = SoundInstructions.Continue; } else if (Sound[i] != SoundInstructions.Continue) { PluginValid = false; } LastSound[i] = Sound[i]; } else { if ((Sound[i] < SoundInstructions.Stop | Sound[i] > SoundInstructions.PlayLooping) && Sound[i] != SoundInstructions.PlayOnce & Sound[i] != SoundInstructions.Continue) { PluginValid = false; } } } data = proxyData.Data; } catch { lastError = externalCrashed.ToString(); externalCrashed = true; } }