Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new GUICanvas. Only one may exist.
        /// </summary>
        public GUICanvas()
        {
            Assert.Fatal(GUICanvas._instance == null, "GUICanvas Constructor - GUICanvas already exists.");
            GUICanvas._instance = this;

            _awake = true;
            _visible = true;

            Name = "Canvas";

            // initialize the drawing utility
            DrawUtil.Setup();
        }
        /// <summary>
        /// Sets up the engine.  
        /// </summary>
        void _SetupEngine()
        {
            // if we have a d3d device, init video now
            if (_graphicsManager.GraphicsDevice != null)
            {
                // create gfx device
                _gfxDevice = new GFXDevice();

                // override shader profile...
                _gfxDevice.ForceUserShaderProfile = _settings.ForceUserShaderProfile;
                _gfxDevice.UserShaderProfile = _settings.UserShaderProfile;

                // initialize the device
                _gfxDevice.Init(_graphicsManager);

                _ApplyVideoProfile();
            }

            // create audio device
            if (_settings.EnableAudio && _sfxDevice == null && _settings.AudioGlobalSettingsFile != string.Empty)
            {
                TorqueConsole.Echo("Initializing audio...");

                try
                {
                    _sfxDevice = new AudioEngine(_settings.AudioGlobalSettingsFile);
                }
                catch (ArgumentException e) // catch this one so that we can continue running without needing update all of our xact files.
                {
                    _sfxDevice = null;
                    TorqueConsole.Error("TorqueEngineComponent::_SetupEngine - Failed to initialize XACT: " + e.ToString());
                }
            }

            // create gui canvas
            _canvas = new GUICanvas();
            TorqueObjectDatabase.Instance.Register(_canvas);

            TorqueConsole.Echo("Initializing GUICanvas...");

            // put a default gui on the canvas
            GUISceneview defaultContentControl = new GUISceneview();
            defaultContentControl.Name = "DefaultSceneView";
            defaultContentControl.Style = new GUIStyle();
            _canvas.SetContentControl(defaultContentControl);

            // configure time handling on game object.
            if (_settings.UseFixedTimeStep)
            {
                ProcessList.Instance.TickMS = _settings.TickMS; // use for a constant tick (with interpolation)

                if (_settings.UseInterpolation)
                {
                    // We want to interpolate between ticks, have xna give use updates whenever it has time
                    ProcessList.Instance.UseInterpolation = true;
                    Game.IsFixedTimeStep = false;
                }
                else
                {
                    // we only want to render on tick boundaries (no interpolation) so tell xna
                    // to only give us tick divisible updates.
                    ProcessList.Instance.UseInterpolation = false;
                    Game.IsFixedTimeStep = true;
                    Game.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, _settings.TickMS);
                }
            }
            else
            {
                // Variable ticks and no interpolation so tell xna to give us updates whenever it has time
                ProcessList.Instance.TickMS = 0; // use for a variable tick (no interpolation)
                ProcessList.Instance.UseInterpolation = false; // not needed, but for clarity
                Game.IsFixedTimeStep = false;
            }

            TorqueConsole.Echo("Initializing event manager...");

            TorqueEventManager.ListenEvents(_timeEvent, _UpdateSim);
            TorqueEventManager.ListenEvents(PumpEvent, InputManager.Instance.Pump);

            // set up inputs
            Torque.Platform.XGamePadDevice.EnumerateGamepads();
            #if !XBOX
            Torque.Platform.XKeyboardDevice.EnumerateKeyboards();
            Torque.Platform.XMouseDevice.EnumerateMouses();
            Microsoft.Xna.Framework.Input.Mouse.WindowHandle = Game.Window.Handle;
            #endif

            TorqueConsole.Echo("Initializing content manager...");
            // Create global content manager
            ContentManager cm = new ContentManager(this.Game.Services);
            ResourceManager.Instance.GlobalContentManager = cm;

            // make it the current CM
            ResourceManager.Instance.PushContentManager(cm);

            #if DEBUG
            // setup journaling
            if (_settings.JournalMode != TorqueJournal.JournalMode.None)
            {
                TorqueConsole.Echo("Initializing journaling...");
                bool ok;
                string err;
                TorqueJournal journal = new TorqueJournal();

                if (Settings.JournalMode == TorqueJournal.JournalMode.Play)
                {
                    err = " for reading.";
                    ok = journal.OpenForRead(_settings.JournalFile);
                }
                else
                {
                    err = " for writing.";
                    ok = journal.OpenForWrite(_settings.JournalFile);
                }

                Assert.Fatal(ok, "Not able to open journal file " + _settings.JournalFile + err);

                if (ok)
                    TorqueEventManager.Instance.Journal = journal;
            }
            #endif
        }