/// <summary>
        /// Constructs the engine component. Initializes the engine component with default settings, as defined
        /// in TorqueEngineSettings. Settings can be overridden be calling LoadSettings on the component. This 
        /// constructor should be called either from the TorqueGame class or from the main assembly of your game.
        /// Note that only one TorqueEngineComponent is allowed to exist at one time.
        /// </summary>
        /// <param name="game">The XNA game object.</param>
        /// <param name="manager">The XNA graphics manager.</param>
        public TorqueEngineComponent(Game game, GraphicsDeviceManager manager)
            : base(game)
        {
            Assert.Fatal(_instance == null, "TorqueEngineComponent - Only one TorqueEngineComponent is allowed!");
            _instance = this;

            // create default settings object
            _settings = new TorqueEngineSettings();

            _graphicsManager = manager;

            // Set the default executable assembly to the calling assembly. This should be the assembly containing the game's Main function.
            // Note that if the engine component is created from TorqueGame, the calling assembly is actually Torque, which is wrong, but
            // TorqueGame corrects for this. The code here is only needed for games that do not use TorqueGame.
            ExecutableAssembly = Assembly.GetCallingAssembly();
        }
        /// <summary>
        /// Load the engine settings from the specified file. Returns the new TorqueEngineSettings instance. If
        /// the file cannot be loaded, null is returned. The settings in the file will override the defaults
        /// that are hardcoded in the class definition.
        /// </summary>
        /// <param name="filename">The filename to load settings from.</param>
        /// <returns>The new settings object.</returns>
        public static TorqueEngineSettings Load(string filename)
        {
            if (filename == null || filename == string.Empty)
            {
                TorqueConsole.Warn("TorqueEngineSettings.Load - Settings file not specified.");
                return null;
            }

            FileInfo f = new FileInfo(filename);
            if (!f.Exists)
            {
                TorqueConsole.Warn("TorqueEngineSettings.Load - Settings file {0} not found.", filename);
                return null;
            }

            TorqueXmlDeserializer d = new TorqueXmlDeserializer();
            TorqueEngineSettings settings = new TorqueEngineSettings();
            d.Process(filename, settings);

            return settings;
        }
        /// <summary>
        /// Load the engine settings from the specified file. If the file does not exist, default settings are used.
        /// If the settings file contains graphics settings, they are applied only if the graphics device has 
        /// not been created yet.
        /// </summary>
        /// <param name="settingsFile">The filename of the xml settings file.</param>
        public void LoadSettings(string settingsFile)
        {
            _settingsFile = settingsFile;

            // load the settings file
            _settings = TorqueEngineSettings.Load(_settingsFile);
            if (_settings == null)
                _settings = new TorqueEngineSettings(); // use default settings

            // if graphics device is not yet initialized, we can apply graphics settings
            if (_graphicsManager.GraphicsDevice == null && _settings.CurrentGraphicsManagerSettings != null)
            {
                _graphicsManager.IsFullScreen = _settings.CurrentGraphicsManagerSettings.IsFullScreen;
                _graphicsManager.MinimumPixelShaderProfile = _settings.CurrentGraphicsManagerSettings.MinimumPixelShaderProfile;
                _graphicsManager.MinimumVertexShaderProfile = _settings.CurrentGraphicsManagerSettings.MinimumVertexShaderProfile;
                _graphicsManager.PreferMultiSampling = _settings.CurrentGraphicsManagerSettings.PreferMultiSampling;
                _graphicsManager.PreferredBackBufferFormat = _settings.CurrentGraphicsManagerSettings.PreferredBackBufferFormat;
                _graphicsManager.PreferredBackBufferHeight = _settings.CurrentGraphicsManagerSettings.PreferredBackBufferHeight;
                _graphicsManager.PreferredBackBufferWidth = _settings.CurrentGraphicsManagerSettings.PreferredBackBufferWidth;
                _graphicsManager.PreferredDepthStencilFormat = _settings.CurrentGraphicsManagerSettings.PreferredDepthStencilFormat;
                _graphicsManager.SynchronizeWithVerticalRetrace = _settings.CurrentGraphicsManagerSettings.SynchronizeWithVerticalRetrace;

                _graphicsManager.PreparingDeviceSettings += this._PreparingDeviceSettings;
            }

            // check for command line arguments.  because command line args are not supported on xbox, this is only
            // used for certain PC-only features (such as schema export).

            #if !XBOX
            string[] args = System.Environment.GetCommandLineArgs();
            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i].ToLowerInvariant().Trim() == "-exportschema")
                {
                    // schema export requires use of TorqueGame
                    Torque.GameUtil.TorqueGame.ExportSchema = true;

                    // if next arg is present and not -, it is the filename to export to
                    if (i + 1 < args.Length && !args[i + 1].StartsWith("-"))
                        Torque.GameUtil.TorqueGame.ExportSchemaFileName = args[i + 1];
                }
            }
            #endif
        }