private static void pluginManager_PluginsRemoving(object sender, DualityPluginEventArgs e) { // Wrapper method for delivering the old API until removing it in v3.0 if (DiscardPluginData != null) { DiscardPluginData(sender, e); } // Dispose any existing Resources that could reference plugin data VisualLog.ClearAll(); if (!Scene.Current.IsEmpty) { Scene.Current.Dispose(); } foreach (Resource r in ContentProvider.EnumeratePluginContent().ToArray()) { ContentProvider.RemoveContent(r.Path); } }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; try { // Clear all playing sounds foreach (SoundInstance inst in this.sounds) { inst.Dispose(); } this.sounds.Clear(); // Clear all audio related Resources ContentProvider.RemoveAllContent <AudioData>(); ContentProvider.RemoveAllContent <Sound>(); // Clear OpenAL source pool foreach (int alSource in this.alSourcePool) { AL.DeleteSource(alSource); } // Shut down OpenAL context if (this.context != null) { this.context.Dispose(); this.context = null; } AudioLibraryLoader.UnloadAudioLibrary(); } catch (Exception e) { Log.Core.WriteError("An error occured while shutting down OpenAL: {0}", Log.Exception(e)); } } }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; foreach (SoundInstance inst in this.sounds) { inst.Dispose(); } this.sounds.Clear(); ContentProvider.RemoveAllContent <Sound>(); if (this.context != null) { this.context.Dispose(); this.context = null; } } }
/// <summary> /// Saves the Resource to the specified path. /// </summary> /// <param name="saveAsPath">The path to which this Resource is saved to. If null, the Resources <see cref="Path"/> is used as destination.</param> /// <param name="makePermanent"> /// When true, the Resource will be made permanently available from now on. If it has been generated at runtime /// or was loaded explicitly outside the ContentProvider, this will set the Resources <see cref="Path"/> Property /// and register it in the ContentProvider. If the Resource already is a permanent, this parameter will be ignored. /// </param> public void Save(string saveAsPath = null, bool makePermanent = true) { if (this.Disposed) { throw new ObjectDisposedException("Can't save a Resource that has been disposed."); } if (string.IsNullOrWhiteSpace(saveAsPath)) { saveAsPath = this.path; if (string.IsNullOrWhiteSpace(saveAsPath)) { throw new ArgumentException("Can't save a Resource to an undefined path.", "saveAsPath"); } } this.CheckedOnSaving(saveAsPath); // We're saving a new Resource for the first time: Register it in the library bool isPermanent = !string.IsNullOrWhiteSpace(this.path); if (makePermanent && !isPermanent) { this.path = saveAsPath; ContentProvider.AddContent(this.path, this); } string dirName = PathOp.GetDirectoryName(saveAsPath); if (!string.IsNullOrEmpty(dirName) && !DirectoryOp.Exists(dirName)) { DirectoryOp.Create(dirName); } using (Stream str = FileOp.Create(saveAsPath)) { this.WriteToStream(str); } this.CheckedOnSaved(saveAsPath); }
/// <summary> /// Saves the Resource to the specified path. /// </summary> /// <param name="saveAsPath">The path to which this Resource is saved to. If null, the Resources <see cref="Path"/> is used as destination.</param> /// <param name="makePermanent"> /// When true, the Resource will be made permanently available from now on. If it has been generated at runtime /// or was loaded explicitly outside the ContentProvider, this will set the Resources <see cref="Path"/> Property /// and register it in the ContentProvider. If the Resource already is a permanent, this parameter will be ignored. /// </param> public void Save(string saveAsPath = null, bool makePermanent = true) { if (this.Disposed) { throw new ApplicationException("Can't save a Ressource that has been disposed."); } if (string.IsNullOrWhiteSpace(saveAsPath)) { saveAsPath = this.path; if (string.IsNullOrWhiteSpace(saveAsPath)) { throw new ArgumentException("Can't save a Resource to an undefined path.", "saveAsPath"); } } this.CheckedOnSaving(saveAsPath); // We're saving a new Ressource for the first time: Register it in the library if (makePermanent && string.IsNullOrWhiteSpace(this.path)) { this.path = saveAsPath; ContentProvider.AddContent(this.path, this); } string streamName; string dirName = System.IO.Path.GetDirectoryName(saveAsPath); if (!string.IsNullOrEmpty(dirName) && !Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } using (FileStream str = File.Open(saveAsPath, FileMode.Create)) { this.WriteToStream(str, out streamName); } this.CheckedOnSaved(saveAsPath); }
/// <summary> /// Terminates this DualityApp. This does not end the current Process, but will instruct the engine to /// leave main loop and message processing as soon as possible. /// </summary> public static void Terminate() { if (!initialized) { return; } if (isUpdating) { terminateScheduled = true; return; } if (environment == ExecutionEnvironment.Editor && execContext == ExecutionContext.Game) { Scene.Current.Dispose(); Logs.Core.Write("DualityApp terminated in sandbox mode."); terminateScheduled = false; return; } if (execContext != ExecutionContext.Editor) { OnTerminating(); DualityApp.UserData.Save(); } // Signal that the game simulation has ended. if (execContext == ExecutionContext.Game) { pluginManager.InvokeGameEnded(); } // Dispose all content that is still loaded ContentProvider.ClearContent(); // Discard plugin data (Resources, current Scene) ahead of time. Otherwise, it'll get shut down in ClearPlugins, after the backend is gone. pluginManager.DiscardPluginData(); sound.Dispose(); sound = null; ShutdownBackend(ref graphicsBack); ShutdownBackend(ref audioBack); pluginManager.ClearPlugins(); // Since this performs file system operations, it needs to happen before shutting down the system backend. Profile.SaveTextReport(environment == ExecutionEnvironment.Editor ? "perflog_editor.txt" : "perflog.txt"); ShutdownBackend(ref systemBack); // Shut down the plugin manager and plugin loader pluginManager.Terminate(); pluginManager.PluginsRemoving -= pluginManager_PluginsRemoving; pluginManager.PluginsRemoved -= pluginManager_PluginsRemoved; assemblyLoader.Terminate(); assemblyLoader = null; Logs.Core.Write("DualityApp terminated"); initialized = false; execContext = ExecutionContext.Terminated; }
/// <summary> /// Initializes the part of Duality that requires a valid rendering context. /// Should be called before performing any rendering related operations with Duality. /// Is called implicitly when using <see cref="OpenWindow"/>. /// </summary> public static void InitPostWindow() { ContentProvider.InitDefaultContent(); }