private void StopPlaying() { playing = false; airplaneModel.KillEngine(); startTime = -1; if (binaryReader != null) { binaryReader.Close(); binaryReader = null; } if (file != null) { file.Close(); file.Dispose(); file = null; } if (airplaneModel != null) { airplaneModel.Dispose(); airplaneModel = null; } previousState = null; nextState = null; if (Stopped != null) { Stopped(this, EventArgs.Empty); } }
/// <summary> /// Clean up. /// </summary> public void Dispose() { Bonsai.Utils.Settings.SettingsChanged -= new Bonsai.Utils.Settings.SettingsEventHandler(Settings_SettingsChanged); if (iFlightModel != null) { iFlightModel.Dispose(); iFlightModel = null; } if (modelApi != null) { modelApi.Dispose(); modelApi = null; } if (smoke != null) { smoke.Dispose(); smoke = null; } if (airplane != null) { airplane.Dispose(); airplane = null; } if (variometer != null) { variometer.Dispose(); variometer = null; } if (towLine != null) { towLine.Dispose(); towLine = null; } if (windVector != null) { windVector.Dispose(); windVector = null; } if (ripples != null) { ripples.Dispose(); ripples = null; } if (reflection != null) { reflection.Dispose(); reflection = null; } }
/// <summary> /// Clean up. /// </summary> public void Dispose() { if (smoke != null) { smoke.Dispose(); smoke = null; } if (airplaneModel != null) { airplaneModel.Dispose(); airplaneModel = null; } if (ripples != null) { ripples.Dispose(); ripples = null; } }
private void StartPlaying() { if (!string.IsNullOrEmpty(fileName)) { if (playing) { StopPlaying(); } file = File.OpenRead(fileName); binaryReader = new BinaryReader(file); aircraftParameters = new AircraftParameters(); aircraftParameters.ReadParameters(binaryReader.ReadString()); if (airplaneModel == null) { airplaneModel = new AirplaneModel(this); } playing = true; startTime = -1; relativeTime = 0; previousState = new AirplaneState(); nextState = new AirplaneState(); nextTime = binaryReader.ReadDouble(); nextState.Read(binaryReader); currentState.Gear = nextState.Gear; currentState.Flaps = nextState.Flaps; if (currentState.Gear) { Gear = 1.0; } if (currentState.Flaps) { Flaps = 1.0; } airplaneModel.StartEngine(); } }
public void LoadModel(string fileName) { // First clean up if (iFlightModel != null) { iFlightModel.Dispose(); iFlightModel = null; } if (modelApi != null) { modelApi.Dispose(); modelApi = null; } if (airplane != null) { airplane.Dispose(); airplane = null; } if (variometer != null) { variometer.Dispose(); variometer = null; } // Now load the actual model //model = new FlightModelWind(); AircraftParameters parameters = new RCSim.DataClasses.AircraftParameters(); parameters.File = fileName; if (!string.IsNullOrEmpty(Bonsai.Utils.Settings.GetValue("ApiFlightModel"))) { try { string assemblyInfo = Bonsai.Utils.Settings.GetValue("ApiFlightModel"); string[] assemblyParts = assemblyInfo.Split(',', ';'); Assembly assembly = Assembly.LoadFrom(assemblyParts[0]); RCDeskPilot.API.FlightModelSimple flightModelSimple = assembly.CreateInstance(assemblyParts[1]) as RCDeskPilot.API.FlightModelSimple; modelApi = new FlightModelApi(); modelApi.ApiModel = flightModelSimple; iFlightModel = modelApi; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show( string.Format("Failed to load the flightmodel plugin : {0}", ex.ToString())); } } else { if (parameters.Version == 2) { iFlightModel = new FlightModelWind2(); } else { iFlightModel = new FlightModelWind(); } } iFlightModel.AircraftParameters = parameters; iFlightModel.Initialize(); iFlightModel.Reset(); iFlightModel.Wind = new Vector3(0, 0, 0); iFlightModel.Heightmap = Heightmap; iFlightModel.Water = Program.Instance.Scenery.Water; airplane = new AirplaneModel(iFlightModel); CurrentModel = fileName; if (smoke != null) { smoke.Dispose(); smoke = null; } smoke = new Smoke(owner, iFlightModel); UpdateVariometer(); this.owner.UpdateCameras(); this.Reset(); }