public void Start <T>(string[] args) where T : GameScene { using (var game = new GameLoop(args)) { game.GameName = GameName; game.Developer = Developer; game.StartingSceneType = typeof(T); game.Run(); } }
protected override void Initialize() { GraphicsAdapter.UseDriverType = GraphicsAdapter.DriverType.Hardware; //MSAA (Multi-sample Anti Aliasing as requested by lempamo) _graphicsDevice.GraphicsProfile = GraphicsProfile.HiDef; _graphicsDevice.PreferMultiSampling = true; GraphicsDevice.PresentationParameters.MultiSampleCount = 8; //8x MSAA, should be a configurable thing _graphicsDevice.ApplyChanges(); _instance = this; Logger.Log("Peace Engine is now initializing core engine components..."); List <Type> typesToInit = new List <Type>(); foreach (var type in ReflectMan.Types.Where(x => x.Assembly == this.GetType().Assembly&& x.GetInterfaces().Contains(typeof(IEngineModule)))) { if (type.GetConstructor(Type.EmptyTypes) == null) { Logger.Log($"Found {type.Name}, but it doesn't have a parameterless constructor, so it's ignored. Probably a mistake.", System.ConsoleColor.Yellow); continue; } Logger.Log($"Found {type.Name}", System.ConsoleColor.Yellow); typesToInit.Add(type); } foreach (var type in typesToInit) { var componentInfo = new ComponentInfo { IsInitiated = false, Component = (IEngineModule)Activator.CreateInstance(type, null) }; _components.Add(componentInfo); } foreach (var component in _components) { Logger.Log($"{component.Component.GetType().Name}: Injecting dependencies..."); Inject(component.Component); } //I know. This is redundant. I'm only doing this as a safety precaution, to prevent crashes with modules that try to access uninitiated modules as they're initiating. foreach (var component in _components) { RecursiveInit(component.Component); } Logger.Log("Done initiating engine."); ResetMouseListener(); base.Initialize(); }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// game-specific content. /// </summary> protected override void UnloadContent() { Logger.Log("Unloading engine modules."); while (_components.Count > 0) { var component = _components[0]; Logger.Log("Unloading: " + component.Component.GetType().Name); if (component.Component is IDisposable) { (component.Component as IDisposable).Dispose(); } _components.RemoveAt(0); } Logger.Log("Done."); if (_scene != null) { _scene.Unload(); } _instance = null; base.UnloadContent(); }