public void CleanupServices() { services = null; servicesSet = null; renderer = null; materialManager = null; sceneManager = null; textRenderer = null; userInterfaceManager = null; }
public void Connect( MaterialManager materialManager, Renderer renderer, SceneManager sceneManager, TextRenderer textRenderer, OpenTK.GameWindow window ) { this.materialManager = materialManager; this.renderer = renderer; this.sceneManager = sceneManager; this.window = window; InitializationDependsOn(materialManager); InitializationDependsOn(renderer); InitializationDependsOn(sceneManager); InitializationDependsOn(textRenderer); }
public void InitializeServices() { services = this; materialManager = new MaterialManager(); renderer = new Renderer(); sceneManager = new SceneManager(); textRenderer = new TextRenderer(); userInterfaceManager = new UserInterfaceManager(); if (materialManager != null) { materialManager.Connect(renderer, textRenderer); } if (sceneManager != null) { sceneManager.Connect(materialManager); } if (textRenderer != null) { textRenderer.Connect(this, renderer); } if (userInterfaceManager != null) { userInterfaceManager.Connect(materialManager, renderer, sceneManager, textRenderer, this); } HashSet <Service> uninitialized = new HashSet <Service>(servicesSet); HashSet <Service> removeSet = new HashSet <Service>(); int count = uninitialized.Count; while (uninitialized.Count > 0) { removeSet.Clear(); foreach (var service in uninitialized) { if (service.Dependencies.Count == 0) { string message = "Initializing " + service.Name + " (" + count + " left)"; Trace.TraceInformation(message); if (textRenderer != null && textRenderer.IsInitialized) { textRenderer.Message(message); } service.Initialize(); removeSet.Add(service); --count; } } if (removeSet.Count == 0) { Trace.TraceError("Circular Service Dependencies Detected"); foreach (var service in uninitialized) { Trace.TraceInformation(service.ToString()); } //Debugger.Break(); This does not work right yet with Monodevelop throw new System.InvalidOperationException(); } uninitialized.ExceptWith(removeSet); foreach (var other in uninitialized) { other.Dependencies.ExceptWith(removeSet); } } }