Exemple #1
0
        ///<summary>
        ///Called after the graphics device is created and before the game is
        ///about to start running.
        ///</summary>
        protected override void BeginRun()
        {
            base.BeginRun();

            //load our scene objects from XML.  Torque X is designed to load
            //game data from XML, but this is not strictly required; anything
            //in an XML file can also be created manually in C# code.  The
            //SceneLoader is provided by TorqueGame and can be used to load
            //and unload XML files.
            //SceneLoader.Load(@"data\levels\EmptyLevel.txscene");

            T2DSceneGraph sceneGraph = new T2DSceneGraph(true);
            sceneGraph.Name = "DefaultSceneGraph";

            T2DSceneCamera camera = new T2DSceneCamera();
            camera.Name = "Camera";
            camera.CenterPosition = new Vector2(384, 384);
            camera.Extent = new Vector2(768, 768);
            camera.SceneGraph = sceneGraph;

            GUISceneview sceneview = new GUISceneview();
            sceneview.Name = "DefaultSceneView";
            sceneview.Camera = camera;

            if (null != Engine.SFXDevice)
            {
                _waveBank =
                    new WaveBank(Engine.SFXDevice, @"data\sounds\Sounds.xwb");
                _soundBank =
                    new SoundBank(Engine.SFXDevice, @"data\sounds\Sounds.xsb");
            }

            //Press escape on the keyboard or back on gamepad to exit game
            InputUtil.BindBackEscQuickExit();

            GamePaused = true;

            InitializeLibraries();

            GUILayout.Instance.Setup();

            //new GameManager(@"data\maps\RavenMap");
            //new GameManager(@"data\maps\RavenMapWithDoors");
            //new GameManager(@"data\maps\RavenMapWithDoorsAndItems");
            //new GameManager(@"data\maps\RavenMapWithDoorsAndItems2");
            new GameManager.GameManager(@"data\maps\mindcrafters");
        }
        /// <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
        }
Exemple #3
0
        ///<summary>
        ///Called when the owner is registered
        ///</summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            //todo: perform initialization for the component

            //todo: look up interfaces exposed by other components
            //E.g.,
            //_theirInterface =
            //     Owner.Components.GetInterface<ValueInterface<float>>(
            //         "float", "their interface name");

            //activate tick callback for this component.
            ProcessList.Instance.AddTickCallback(Owner, this);

            if (null != _monitoredObject as T2DSpawnObject)
            {
                string name;
                if (_monitoredObject.Name.EndsWith("Template") ||
                    _monitoredObject.Name.EndsWith("template"))
                {
                    name =
                        _monitoredObject.Name.Substring(
                            0, _monitoredObject.Name.Length - 8);
                }
                else
                {
                    name = _monitoredObject.Name + "Instance";
                }
                _monitoredObject =
                    TorqueObjectDatabase.Instance.FindObject<T2DStaticSprite>(name);
            }

            if ((_monitoredObject != null) && (_monitoredInterfaceName != null))
            {
                _monitoredInterface =
                    _monitoredObject.Components.GetInterface<ValueInterface<float>>(
                        "float", _monitoredInterfaceName);
            }

            //create a camera for the compass
            T2DSceneCamera defaultCamera =
                TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
            if (defaultCamera != null)
            {
                T2DSceneCamera instrumentCam =
                    (T2DSceneCamera)defaultCamera.Clone();
                instrumentCam.Name = "InstrumentCam";
                TorqueObjectType instrument =
                    TorqueObjectDatabase.Instance.GetObjectType("instrument");

                instrumentCam.CenterPosition = CameraCenter;
                instrumentCam.Extent = CameraExtent;

                TorqueObjectDatabase.Instance.Register(instrumentCam);

                //display the instrument camera on screen
                GUIControlStyle instrumentStyle = new GUIControlStyle();
                GUISceneview instrumentView = new GUISceneview();
                instrumentView.Name = "InstrumentView";
                instrumentView.Style = instrumentStyle;
                instrumentView.Camera = instrumentCam;

                //only render objects of type "instrument"
                instrumentView.RenderMask = instrument;
                instrumentView.Visible = true;
                instrumentView.Folder =
                    TorqueObjectDatabase.Instance.FindObject<GUISceneview>("DefaultSceneView");
                instrumentView.Position = ViewPosition;
                instrumentView.Size = ViewSize;
            }

            return true;
        }
Exemple #4
0
        ///<summary>
        ///Called when the owner is registered
        ///</summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            //todo: perform initialization for the component

            //todo: look up interfaces exposed by other components
            //E.g.,
            //_theirInterface =
            //     Owner.Components.GetInterface<ValueInterface<float>>(
            //         "float", "their interface name");

            T2DSceneCamera camera =
                TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");

            camera.CenterPosition = CameraCenter;
            camera.Extent = CameraExtent;
            camera.Mount(SceneObject, "", false);
            camera.TrackMountRotation = false;

            GUISceneview sceneview = new GUISceneview();
            sceneview.Name = "DefaultSceneView";
            sceneview.Camera = camera;
            sceneview.NoRenderMask =
                TorqueObjectDatabase.Instance.GetObjectType("instrument");

            GUISceneview minimapView =
                TorqueObjectDatabase.Instance.FindObject<GUISceneview>("MinimapView");
            if (null != minimapView)
                minimapView.Folder = sceneview;
            GUISceneview instrumentView =
                TorqueObjectDatabase.Instance.FindObject<GUISceneview>("InstrumentView");
            if (null != instrumentView)
                instrumentView.Folder = sceneview;

            GUICanvas.Instance.SetContentControl(sceneview);

            return true;
        }