/// <summary>
        /// Read the setup file and return a GameProperties object.
        /// </summary>
        /// <returns></returns>
        public GameProperties Read()
        {
            var properties = new GameProperties();

            var setupFile = new XmlDocument();
            setupFile.Load(SetupFileName);

            XmlElement root;
            try
            {
                root = setupFile.ChildNodes[1] as XmlElement;
            }
            catch (IndexOutOfRangeException)
            {
                // LOG: Could not load setup file, invalid Xml structure.
                return properties;
            }

            foreach (var node in root.ChildNodes)
            {
                var element = node as XmlElement;

                // Just continue if we don't know what we're parsing.
                if (element == null)
                {
                    continue;
                }

                ReadElementAsGameProperty(element, properties);
            }

            return properties;
        }
        private Engine(GameProperties properties)
        {
            _GameProperties = properties;

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = properties.ContentFolder;

            Initialize();
        }
        private ArtemisEngine(GameProperties properties, Action initializer) : base()
        {
            this.initializer = initializer;
            Initialized      = false;

            _GameProperties = properties;
            gameKernel      = new GameKernel(this);

            _MultiformManager = new MultiformManager();
            _GameTimer        = new GlobalTimer();
            _GameUpdater      = new GlobalUpdater();

            _Mouse    = new MouseInput();
            _Keyboard = new KeyboardInput();
        }
        private ArtemisEngine(GameProperties properties, Action initializer)
            : base()
        {
            this.initializer = initializer;
            Initialized = false;

            _GameProperties = properties;
            gameKernel = new GameKernel(this);

            _MultiformManager = new MultiformManager();
            _GameTimer        = new GlobalTimer();
            _GameUpdater      = new GlobalUpdater();

            _Mouse            = new MouseInput();
            _Keyboard         = new KeyboardInput();
        }
        /// <summary>
        /// Read an XmlElement found in the document root and apply it
        /// to the GameProperties object.
        /// </summary>
        private void ReadElementAsGameProperty(XmlElement element, GameProperties properties)
        {
            switch (element.Name)
            {
            case BASE_RESOLUTION_ELEMENT:
                properties.BaseResolution = ReadResolution(
                    element, GameProperties.DEFAULT_RESOLUTION);
                break;

            case FULLSCREEN_ELEMENT:
                properties.Fullscreen = ReadBool(
                    element, GameProperties.DEFAULT_FULLSCREEN);
                break;

            case FULLSCREEN_TOGGLABLE_ELEMENT:
                properties.FullscreenTogglable = ReadBool(
                    element, GameProperties.DEFAULT_FULLSCREEN_TOGGLABLE);
                break;

            case MOUSE_VISIBLE_ELEMENT:
                properties.MouseVisible = ReadBool(
                    element, GameProperties.DEFAULT_MOUSE_VISIBLE);
                break;

            case MOUSE_VISIBILITY_TOGGLABLE_ELEMENT:
                properties.MouseVisibilityTogglable = ReadBool(
                    element, GameProperties.DEFAULT_MOUSE_VISIBILITY_TOGGLABLE);
                break;

            case BORDERLESS_ELEMENT:
                properties.Borderless = ReadBool(
                    element, GameProperties.DEFAULT_BORDERLESS);
                break;

            case BORDER_TOGGLABLE_ELEMENT:
                properties.BorderTogglable = ReadBool(
                    element, GameProperties.DEFAULT_BORDER_TOGGLABLE);
                break;

            case VSYNC_ELEMENT:
                properties.VSync = ReadBool(
                    element, GameProperties.DEFAULT_VSYNC);
                break;

            case BG_COLOUR_ELEMENT:
                properties.BackgroundColour = ReadColour(
                    element, GameProperties.DEFAULT_BG_COLOUR);
                break;

            case CONTENT_FOLDER_ELEMENT:
                properties.ContentFolder = element.InnerText;
                break;

            case WINDOW_TITLE_ELEMENT:
                properties.WindowTitle = element.InnerText;
                break;

            default:
                break;
            }
        }
 internal static void Setup(GameProperties properties, Action initializer)
 {
     if (SetupCalled)
     {
         throw new EngineSetupException("Engine.Setup called multiple times.");
     }
     Instance = new ArtemisEngine(properties, initializer);
     Instance.Run();
 }
        /// <summary>
        /// Setup the game's properties using the given setup parameters.
        /// </summary>
        public static void Setup( Action initializer
                                , Resolution? baseResolution    = null
                                , bool fullscreen               = GameProperties.DEFAULT_FULLSCREEN
                                , bool fullscreenTogglable      = GameProperties.DEFAULT_FULLSCREEN_TOGGLABLE
                                , bool mouseVisible             = GameProperties.DEFAULT_MOUSE_VISIBLE
                                , bool mouseVisibilityTogglable = GameProperties.DEFAULT_MOUSE_VISIBILITY_TOGGLABLE
                                , bool borderless               = GameProperties.DEFAULT_BORDERLESS
                                , bool borderTogglable          = GameProperties.DEFAULT_BORDER_TOGGLABLE
                                , bool vsync                    = GameProperties.DEFAULT_VSYNC
                                , Color? bgColour               = null
                                , string windowTitle            = null)
        {
            var properties = new GameProperties();

            properties.BaseResolution = baseResolution.HasValue ?
                baseResolution.Value : GameProperties.DEFAULT_RESOLUTION;

            properties.BackgroundColour = bgColour.HasValue ?
                bgColour.Value : GameProperties.DEFAULT_BG_COLOUR;

            if (windowTitle != null)
            {
                properties.WindowTitle = windowTitle;
            }

            properties.Fullscreen = fullscreen;
            properties.FullscreenTogglable = fullscreenTogglable;
            properties.MouseVisible = mouseVisible;
            properties.MouseVisibilityTogglable = mouseVisibilityTogglable;
            properties.Borderless = borderless;
            properties.BorderTogglable = borderTogglable;
            properties.VSync = vsync;

            Setup(properties, initializer);
        }
 /// <summary>
 /// Read an XmlElement found in the document root and apply it
 /// to the GameProperties object.
 /// </summary>
 private void ReadElementAsGameProperty(XmlElement element, GameProperties properties)
 {
     switch (element.Name)
     {
         case BASE_RESOLUTION_ELEMENT:
             properties.BaseResolution = ReadResolution(
                 element, GameProperties.DEFAULT_RESOLUTION);
             break;
         case FULLSCREEN_ELEMENT:
             properties.Fullscreen = ReadBool(
                 element, GameProperties.DEFAULT_FULLSCREEN);
             break;
         case FULLSCREEN_TOGGLABLE_ELEMENT:
             properties.FullscreenTogglable = ReadBool(
                 element, GameProperties.DEFAULT_FULLSCREEN_TOGGLABLE);
             break;
         case MOUSE_VISIBLE_ELEMENT:
             properties.MouseVisible = ReadBool(
                 element, GameProperties.DEFAULT_MOUSE_VISIBLE);
             break;
         case MOUSE_VISIBILITY_TOGGLABLE_ELEMENT:
             properties.MouseVisibilityTogglable = ReadBool(
                 element, GameProperties.DEFAULT_MOUSE_VISIBILITY_TOGGLABLE);
             break;
         case BORDERLESS_ELEMENT:
             properties.Borderless = ReadBool(
                 element, GameProperties.DEFAULT_BORDERLESS);
             break;
         case BORDER_TOGGLABLE_ELEMENT:
             properties.BorderTogglable = ReadBool(
                 element, GameProperties.DEFAULT_BORDER_TOGGLABLE);
             break;
         case VSYNC_ELEMENT:
             properties.VSync = ReadBool(
                 element, GameProperties.DEFAULT_VSYNC);
             break;
         case BG_COLOUR_ELEMENT:
             properties.BackgroundColour = ReadColour(
                 element, GameProperties.DEFAULT_BG_COLOUR);
             break;
         case CONTENT_FOLDER_ELEMENT:
             properties.ContentFolder = element.InnerText;
             break;
         case WINDOW_TITLE_ELEMENT:
             properties.WindowTitle = element.InnerText;
             break;
         default:
             break;
     }
 }