/// <inheritdoc/> public override void Update(AbstractTrain NearestTrain, double TimeElapsed, bool ForceUpdate, bool CurrentlyVisible) { if (CurrentlyVisible | ForceUpdate) { if (TimeElapsed > 0.05) { return; } if (this.TrackFollowerFunction != null) { double delta = this.TrackFollowerFunction.Perform(NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, this.Position, this.Follower.TrackPosition, 0, false, TimeElapsed, 0); this.Follower.UpdateRelative(this.currentTrackPosition + delta, true, true); this.Follower.UpdateWorldCoordinates(false); } if (this.VolumeFunction != null) { this.currentVolume = this.VolumeFunction.Perform(NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, this.Position, this.Follower.TrackPosition, 0, false, TimeElapsed, 0); } if (this.PitchFunction != null) { this.currentPitch = this.PitchFunction.Perform(NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, this.Position, this.Follower.TrackPosition, 0, false, TimeElapsed, 0); } if (this.Source != null) { this.Source.Pitch = this.currentPitch; this.Source.Volume = this.currentVolume; } //Buffer should never be null, but check it anyways if (!currentHost.SoundIsPlaying(Source) && Buffer != null) { Source = currentHost.PlaySound(Buffer, 1.0, 1.0, Follower.WorldPosition + Position, this, true); } } else { if (currentHost.SoundIsPlaying(Source)) { currentHost.StopSound(Source); } } }
/// <inheritdoc/> public override void Update(AbstractTrain NearestTrain, double TimeElapsed, bool ForceUpdate, bool CurrentlyVisible) { if (CurrentlyVisible | ForceUpdate) { if (Object.SecondsSinceLastUpdate >= Object.RefreshRate | ForceUpdate) { double timeDelta = Object.SecondsSinceLastUpdate + TimeElapsed; Object.SecondsSinceLastUpdate = 0.0; Object.Update(false, NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, SectionIndex, TrackPosition, Position, Direction, Up, Side, true, true, timeDelta, true); if (this.Object.CurrentState != this.lastState && currentHost.SimulationSetup) { if (this.SingleBuffer && this.Buffers[0] != null) { switch (this.Object.CurrentState) { case -1: if (this.PlayOnHide) { Source = currentHost.PlaySound(Buffers[0], currentPitch, currentVolume, Position, null, false); } break; case 0: if (this.PlayOnShow || this.lastState != -1) { Source = currentHost.PlaySound(Buffers[0], currentPitch, currentVolume, Position, null, false); } break; default: Source = currentHost.PlaySound(Buffers[0], currentPitch, currentVolume, Position, null, false); break; } } else { int bufferIndex = this.Object.CurrentState; switch (bufferIndex) { case -1: //Do not play sound when completely hiding the object from view break; default: if (this.Buffers.Length >= bufferIndex && this.Buffers[bufferIndex] != null) { Source = currentHost.PlaySound(Buffers[bufferIndex], currentPitch, currentVolume, Position, null, false); } break; } } } } else { Object.SecondsSinceLastUpdate += TimeElapsed; } if (!base.Visible) { currentHost.ShowObject(Object.internalObject, ObjectType.Dynamic); base.Visible = true; } } else { Object.SecondsSinceLastUpdate += TimeElapsed; if (base.Visible) { currentHost.HideObject(Object.internalObject); base.Visible = false; } } this.lastState = this.Object.CurrentState; }