public MessagingTest () { messageManager = new MessageManager(); messageManager += this; messageManager += new MessageConsumerExample("global"); messageProxy1 = new MessageProxy(messageManager); messageProxy1 += new MessageConsumerExample("proxy1"); messageProxy2 = new MessageProxy(messageManager); messageProxy2 += new MessageConsumerExample("proxy2"); messageProxy3 = new MessageProxy(messageProxy2); messageProxy3 += new MessageConsumerExample("proxy3"); messageProxy1.StartProcessing(); messageProxy3.StartProcessing(); messageProxy2.StartProcessing(); messageManager.StartProcessing(); Thread.Sleep(100); MessageCreated(new MessageExample("test1")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Disabling proxy1"); messageProxy1.AddToBlacklist(42); MessageCreated(new MessageExample("test2")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Disabling proxy2"); messageProxy2.AddToBlacklist(42); MessageCreated(new MessageExample("test3")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Enabling proxy1 and proxy2"); messageProxy1.RemoveFromBlacklist(42); messageProxy2.RemoveFromBlacklist(42); MessageCreated(new MessageExample("test4")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Disabling proxy3"); messageProxy3.AddToBlacklist(42); MessageCreated(new MessageExample("test5")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Enabling proxy3"); messageProxy3.RemoveFromBlacklist(42); MessageCreated(new MessageExample("test6")); Thread.Sleep(100); Logger.Log.AddLogEntry(LogLevel.Debug, "MessagingTest", "Stopping proxy2"); messageProxy2.StopProcessing(); MessageCreated(new MessageExample("test7")); Thread.Sleep(100); }
/// <summary> /// Initializes a new instance of the <see cref="FreezingArcher.Core.Application"/> class. /// </summary> // / <param name="game">The initial root game.</param> public Application (string name, string[] args) { ManagedThreadId = Thread.CurrentThread.ManagedThreadId; Name = name; Frametime = 5; Logger.Initialize (name); ObjectManager = new ObjectManager(); ValidMessages = new[] { (int) MessageId.Input }; MessageManager = new MessageManager (); MessageManager += this; ConfigManager.Initialize (MessageManager); EntityFactory.Instance = new EntityFactory(ObjectManager); CommandLineInterface.Instance.SetHelp ("Freezing Archer 3D game engine/framework", "Alpha 0.0.1", "AreonDev", 2015, 'h', "help", true, true, null, new string[] {"Authors: David Bögelsack, Fin Christensen, Willy Failla und Martin Koppehel\n"}); // set fullscreen if overriden by command line. CommandLineInterface.Instance.AddOption<bool> (b => { if (b) ConfigManager.Instance["freezing_archer"].AddOverride ("general", "fullscreen", new Value (true)); }, 'f', "fullscreen", "Set window to fullscreen. By default the value from the config file is used."); CommandLineInterface.Instance.AddOption<int> ( i => ConfigManager.Instance ["freezing_archer"].AddOverride ("general", "fullscreen_monitor", new Value (i)), 'm', "fullscreen-monitor", "Set the physical monitor the application should use for a fullscreen window.", "INT"); CommandLineInterface.Instance.AddOption<string> ( r => ConfigManager.Instance ["freezing_archer"].AddOverride ("general", "resolution", new Value (r)), 'r', "resolution", "Set the resolution a fullscreen window should have.", "RES", false, ConfigManager.Instance["freezing_archer"].GetString ("general", "resolution")); CommandLineInterface.Instance.AddOption<string> ( s => ConfigManager.Instance ["freezing_archer"].AddOverride ("general", "size", new Value (s)), 's', "size", "Set window size.", "SIZE", false, ConfigManager.Instance ["freezing_archer"].GetString ("general", "size")); CommandLineInterface.Instance.AddOption<int> (i => { if (i > 0) { if (i > 8) { Logger.Log.AddLogEntry (LogLevel.Error, "CommandLineInterface", Status.BadArgument, "The given loglevel '{0}' is not valid. Using configuration value...", i); return; } ConfigManager.Instance["freezing_archer"].AddOverride ("general", "loglevel", new Value (i)); } }, 'l', "loglevel", "Set loglevel. If 0 or nothing is given the value from the config file is used.", "INT"); if (!CommandLineInterface.Instance.ParseArguments (args)) { IsCommandLineInterface = true; return; } Logger.Log.SetLogLevel ((LogLevel) ConfigManager.Instance["freezing_archer"] .GetInteger ("general", "loglevel")); Logger.Log.AddLogEntry (LogLevel.Info, ClassName, "Creating new application '{0}'", name); AudioManager = new AudioManager (); RendererContext = new RendererContext(MessageManager); Localizer.Initialize (MessageManager); Logger.Log.AddLogEntry(LogLevel.Warning, ClassName, Status.ZombieApocalypse); Window = new Window ( ParserUtils.ParseVector ( ConfigManager.Instance["freezing_archer"].GetString ("general", "size")), ParserUtils.ParseVector ( ConfigManager.Instance["freezing_archer"].GetString ("general", "resolution")), name); MessageManager += Window; Game = new Game (name, ObjectManager, MessageManager, null, RendererContext); LoadAgain = false; InitAgain = false; Window.WindowResize = (GlfwWindowPtr window, int width, int height) => { Window.MSize = new Vector2i(width, height); if (MessageCreated != null) MessageCreated (new WindowResizeMessage (Window, width, height)); }; Window.WindowMove = (GlfwWindowPtr window, int x, int y) => { if (MessageCreated != null) MessageCreated (new WindowMoveMessage (Window, x, y)); }; Window.WindowClose = (GlfwWindowPtr window) => { if (MessageCreated != null) MessageCreated (new WindowCloseMessage (Window)); }; Window.WindowFocus = (GlfwWindowPtr window, bool focus) => { Logger.Log.AddLogEntry (LogLevel.Debug, ClassName, "Window '{0}' changed focus state to '{1}'", Window.Title, focus); if (MessageCreated != null) MessageCreated (new WindowFocusMessage (Window, focus)); }; Window.WindowMinimize = (GlfwWindowPtr window, bool minimized) => { Logger.Log.AddLogEntry (LogLevel.Debug, ClassName, "Window '{0}' changed minimized state to '{1}'", Window.Title, minimized); if (MessageCreated != null) MessageCreated (new WindowMinimizeMessage (Window, minimized)); }; Window.WindowError = (GlfwError error, string desc) => { Logger.Log.AddLogEntry (LogLevel.Debug, ClassName, "Window '{0}' threw an error: [{1}] {2}", Window.Title, error.ToString (), desc); if (MessageCreated != null) MessageCreated (new WindowErrorMessage (Window, error.ToString (), desc)); }; Window.MouseButton = (GlfwWindowPtr wnd, MouseButton btn, KeyAction action) => InputManager.HandleMouseButton(wnd, btn, action); Window.MouseMove = (GlfwWindowPtr wnd, double x, double y) => InputManager.HandleMouseMove(wnd, x, y); Window.MouseOver = (GlfwWindowPtr window, bool enter) => { if (enter) Logger.Log.AddLogEntry (LogLevel.Debug, ClassName, "Mouse entered window '{0}'", Window.Title); else Logger.Log.AddLogEntry (LogLevel.Debug, ClassName, "Mouse left window '{0}'", Window.Title); if (MessageCreated != null) MessageCreated (new WindowMouseOverMessage (Window, enter)); }; Window.MouseScroll = (GlfwWindowPtr wnd, double xoffset, double yoffset) => InputManager.HandleMouseScroll(wnd, xoffset, yoffset); Window.KeyAction = (GlfwWindowPtr wnd, Key key, int scanCode, KeyAction action, KeyModifiers mods) => InputManager.HandleKeyboardInput(wnd, key, scanCode, action, mods); }