Example #1
0
 /// <summary>
 /// Initializes a new instance of the Maze<TTheme> class.
 /// </summary>
 /// <param name="objmnr">Object manager.</param>
 /// <param name="seed">Seed.</param>
 /// <param name="sizeX">Size x.</param>
 /// <param name="sizeY">Size y.</param>
 /// <param name="scale">Scale.</param>
 /// <param name="physics">The physics instance the maze should register to.</param>
 /// <param name="initFunc">Init func.</param>
 /// <param name="generateFunc">Generate func.</param>
 /// <param name="addToSceneDelegate">Add to scene delegate.</param>
 /// <param name="exitFunc">Calculate path to exit function.</param>
 /// <param name="placeFeaturesFunc">Spawn portals function.</param>
 /// <param name="turbulence">Turbulence.</param>
 /// <param name="maximumContinuousPathLength">Maximum continuous path length.</param>
 /// <param name="portalSpawnFactor">Portal spawn factor.</param>
 internal Maze (ObjectManager objmnr, MessageProvider messageProvider, AudioManager am, int seed, int sizeX, int sizeY,
     float scale, PhysicsManager physics, IMazeTheme theme, InitializeMazeDelegate initFunc,
     GenerateMazeDelegate generateFunc, AddMazeToGameStateDelegate addToSceneDelegate,
     CalculatePathToExitDelegate exitFunc, PlaceFeaturesDelegate placeFeaturesFunc, double turbulence,
     int maximumContinuousPathLength, uint portalSpawnFactor)
 {
     objectManager = objmnr;
     Seed = seed;
     Size = new Vector2i(sizeX, sizeY);
     this.Scale = scale;
     Turbulence = turbulence;
     PortalSpawnFactor = portalSpawnFactor;
     MaximumContinuousPathLength = maximumContinuousPathLength;
     rand = new FastRandom (seed);
     initMazeDelegate = initFunc;
     generateMazeDelegate = generateFunc;
     addMazeToGameStateDelegate = addToSceneDelegate;
     calcExitPathDelegate = exitFunc;
     placeFeaturesDelegate = placeFeaturesFunc;
     this.physics = physics;
     this.audio = am;
     this.messageProvider = messageProvider;
     HasFinished = false;
     this.theme = theme;
 }
Example #2
0
        /// <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);
        }