Example #1
0
        /// <summary>
        /// Message handler for messages meant only for the scene manager.
        /// </summary>
        /// <param name="message">Incoming message</param>
        /// <exception cref="ArgumentException">Thrown if a <see cref="MessageType"/> is not handled properly."/></exception>
        public bool ExecuteMessage(IMessage message)
        {
            switch (message.Type)
            {
            case MessageType.RemoveEntity:
            {
                MsgRemoveEntity remEntityMsg = message as MsgRemoveEntity;
                message.TypeCheck(remEntityMsg);

                if (remEntityMsg.EntityID != QSGame.UniqueIDEmpty)
                {
                    BaseEntity entity;
                    if (this.entities.TryGetValue(remEntityMsg.EntityID, out entity))
                    {
                        ShutdownEntity(entity);
                    }
                }
            }
                return(true);

            case MessageType.GetEntityIDList:
            {
                MsgGetEntityIDList msgGetEntityIDs = message as MsgGetEntityIDList;
                message.TypeCheck(msgGetEntityIDs);

                msgGetEntityIDs.EntityIDList = new Int64[this.entities.Count];
                this.entities.Keys.CopyTo(msgGetEntityIDs.EntityIDList, 0);
            }
                return(true);

            case MessageType.SetControlledEntity:
            {
                MsgSetControlledEntity msgSetControlled = message as MsgSetControlledEntity;
                message.TypeCheck(msgSetControlled);

                Int64 oldControlledEntity = this.controlledEntity;

                this.controlledEntity = msgSetControlled.ControlledEntityID;

                // Was there a change
                if (oldControlledEntity != this.controlledEntity)
                {
                    if (oldControlledEntity != QSGame.UniqueIDEmpty)
                    {
                        MsgRemoveChild msgRemoveChild = ObjectPool.Aquire <MsgRemoveChild>();
                        msgRemoveChild.Child        = this.sceneMgrRootEntity;
                        msgRemoveChild.UniqueTarget = oldControlledEntity;
                        this.Game.SendMessage(msgRemoveChild);

                        MsgSetIsControlled msgControlled = ObjectPool.Aquire <MsgSetIsControlled>();
                        msgControlled.Controlled   = false;
                        msgControlled.UniqueTarget = oldControlledEntity;
                        this.Game.SendMessage(msgControlled);
                    }

                    // If the new ID is empty, there is no more controlled entity
                    if (this.controlledEntity == QSGame.UniqueIDEmpty)
                    {
                        CreateAndStartFreeMovingCamera();
                    }
                    else
                    {
                        MsgSetIsControlled msgControlled = ObjectPool.Aquire <MsgSetIsControlled>();
                        msgControlled.Controlled   = true;
                        msgControlled.UniqueTarget = this.controlledEntity;
                        this.Game.SendMessage(msgControlled);

                        BaseEntity controlledEntity;
                        if (entities.TryGetValue(this.controlledEntity, out controlledEntity))
                        {
                            CreateAndStartArcBallCamera();
                        }
                    }
                }
            }
                return(true);

            case MessageType.GetControlledEntity:
            {
                MsgGetControlledEntity msgGetControlled = message as MsgGetControlledEntity;
                message.TypeCheck(msgGetControlled);

                msgGetControlled.ControlledEntityID = this.controlledEntity;
            }
                return(true);

            case MessageType.GetEntityByID:
            {
                MsgGetEntityByID msgGetEntity = message as MsgGetEntityByID;
                message.TypeCheck(msgGetEntity);

                BaseEntity entity;
                if (this.entities.TryGetValue(msgGetEntity.EntityID, out entity))
                {
                    msgGetEntity.Entity = entity;
                }
            }
                return(true);

            case MessageType.GetFogSettings:
            {
                if (this.activeScene != null)
                {
                    MsgGetFogSettings msgGetFog = message as MsgGetFogSettings;
                    message.TypeCheck(msgGetFog);

                    msgGetFog.Settings = this.activeScene.FogSettings;
                }
            }
                return(true);

            default:
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Draws the debug scene
        /// </summary>
        /// <param name="batch">The <see cref="SpriteBatch"/> to use for 2D drawing.</param>
        /// <param name="background">The previous screen's output as a texture, if NeedBackgroundAsTexture is true.</param>
        /// <param name="gameTime">The <see cref="GameTime"/> structure for the current Game.Draw() cycle.</param>
        public void DrawScreen(SpriteBatch batch, Texture2D background, GameTime gameTime)
        {
            // No need to create the string for a closed window
            if (!this.guiScreen.IsOpen)
            {
                return;
            }

            // We don't want the window to drag if the cursor is invisible.
            this.guiScreen.EnableDragging = this.game.IsMouseVisible;

            if (!this.game.IsMouseVisible)
            {
                this.guiScreen.Title = "Stats - F3 to enable cursor";
            }
            else
            {
                if (this.guiScreen.Minimized)
                {
                    this.guiScreen.Title = "Stats - Double-click to Open";
                }
                else
                {
                    this.guiScreen.Title = "Stats - Double-click to Hide";
                }
            }

            // Get the current camera's position
            MsgGetPosition msgGetPos = ObjectPool.Aquire <MsgGetPosition>();

            msgGetPos.UniqueTarget = QSGame.SceneMgrRootEntityID;
            this.game.SendMessage(msgGetPos);

            MsgGetRotation msgGetRot = ObjectPool.Aquire <MsgGetRotation>();

            msgGetRot.UniqueTarget = QSGame.SceneMgrRootEntityID;
            this.game.SendMessage(msgGetRot);

            MsgGetName msgName = ObjectPool.Aquire <MsgGetName>();

            msgName.UniqueTarget = QSGame.SceneMgrRootEntityID;
            this.game.SendMessage(msgName);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("-- On-screen --");
            sb.AppendLine("Triangles: " + this.game.Graphics.TrianglesProcessedLastFrame +
                          " -- Geometry chunks: " + this.game.Graphics.GeometryChunksRenderedLastFrame);
            sb.AppendLine("Particles: " + this.game.Graphics.ParticlesRenderedLastFrame);
            sb.AppendLine();

            sb.AppendLine("Object Pool: ");
            sb.Append("Types: " + ObjectPool.free.Count);
            int count = 0;

            foreach (List <IPoolItem> list in ObjectPool.free.Values)
            {
                count += list.Count;
            }
            sb.Append(", free: " + count);

            count = 0;
            foreach (List <IPoolItem> list in ObjectPool.locked.Values)
            {
                count += list.Count;
            }
            sb.AppendLine(", locked: " + count);
            sb.AppendLine();

            sb.AppendLine("Messages sent last frame: " + this.game.MessagesSentThisFrame);
            sb.AppendLine("Number of current messages: " + this.game.currentMessages.Count);
            sb.AppendLine("Number of queued messages: " + this.game.queuedMessages.Count);
            sb.AppendLine("  Queued messages:");
            for (int i = this.game.queuedMessages.Count - 1; i >= 0; --i)
            {
                IMessage message = this.game.queuedMessages[i];
                sb.AppendLine(string.Format("  {0} - {1}", message.Type, message.GetType().Name));
            }
            sb.AppendLine();

            sb.AppendLine(string.Format("Entities, total: {0}, active: {1}",
                                        this.game.SceneManager.Entities.Count,
                                        this.game.SceneManager.NumberOfActiveEntities));
            sb.AppendLine();
            sb.AppendLine("Entity acting as camera: " + msgName.Name);

            Vector3 camPos = msgGetPos.Position;

            sb.AppendLine(string.Format("Cam Pos - X: {0:0.00}, Y: {1:0.00}, Z: {2:0.00}", camPos.X, camPos.Y, camPos.Z));

            Vector3 camFwd = msgGetRot.Rotation.Forward;

            sb.AppendLine(string.Format("Cam Fwd - X: {0:0.00}, Y: {1:0.00}, Z: {2:0.00}", camFwd.X, camFwd.Y, camFwd.Z));

            MsgGetControlledEntity msgControlled = ObjectPool.Aquire <MsgGetControlledEntity>();

            this.game.SendInterfaceMessage(msgControlled, InterfaceType.SceneManager);
            if (msgControlled.ControlledEntityID != QSGame.UniqueIDEmpty)
            {
                MsgGetName msgGetName = ObjectPool.Aquire <MsgGetName>();
                msgGetName.UniqueTarget = msgControlled.ControlledEntityID;
                this.game.SendMessage(msgGetName);

                sb.AppendLine("Camera attached to: " + msgGetName.Name);
            }
            sb.AppendLine();

            sb.AppendLine("Keys pressed: ");
            for (int i = this.keys.Count - 1; i >= 0; --i)
            {
                sb.Append(this.keys[i].ToString() + " ");
            }
            sb.AppendLine();

            this.guiScreen.Label.Text = sb.ToString();
        }
Example #3
0
        /// <summary>
        /// Draws the debug scene
        /// </summary>
        /// <param name="batch">The <see cref="SpriteBatch"/> to use for 2D drawing.</param>
        /// <param name="background">The previous screen's output as a texture, if NeedBackgroundAsTexture is true.</param>
        /// <param name="gameTime">The <see cref="GameTime"/> structure for the current Game.Draw() cycle.</param>
        public void DrawScreen(SpriteBatch batch, Texture2D background, GameTime gameTime)
        {
            // No need to create the string for a closed window
            if (!this.guiScreen.IsOpen)
            {
                return;
            }

            // We don't want the window to drag if the cursor is invisible.
            this.guiScreen.EnableDragging = this.game.IsMouseVisible;

            if (!this.game.IsMouseVisible)
            {
                this.guiScreen.Title = "Controls - F3 to enable cursor";
            }
            else
            {
                if (this.guiScreen.Minimized)
                {
                    this.guiScreen.Title = "Controls - Double-click to Open";
                }
                else
                {
                    this.guiScreen.Title = "Controls - Double-click to Hide";
                }
            }

            StringBuilder sb = new StringBuilder();

            MsgGetName msgName = ObjectPool.Aquire <MsgGetName>();

            msgName.UniqueTarget = QSGame.SceneMgrRootEntityID;
            this.game.SendMessage(msgName);

            sb.AppendLine("Press F3 to toggle mouse cursor");
            sb.AppendLine();

            MsgGetControlledEntity msgControlled = ObjectPool.Aquire <MsgGetControlledEntity>();

            this.game.SendInterfaceMessage(msgControlled, InterfaceType.SceneManager);

            if (msgControlled.ControlledEntityID != QSGame.UniqueIDEmpty)
            {
                MsgGetIsACharacter msgIsChar = ObjectPool.Aquire <MsgGetIsACharacter>();
                msgIsChar.UniqueTarget = msgControlled.ControlledEntityID;
                this.game.SendMessage(msgIsChar);

                if (msgIsChar.IsCharacter)
                {
                    sb.AppendLine("HOLD Left Mouse Button - Rotate Character");
                    sb.AppendLine("SPACEBAR - Jump");
                    sb.AppendLine("W, A, S, D - Move/Strafe");
                }

                sb.AppendLine("F2 - Switch to Free-Cam Mode");
                sb.AppendLine("TAB - Attach to another entity");
            }
            else
            {
                sb.AppendLine("-- Keyboard --");
                sb.AppendLine("LEFT CTRL - Fire lightweight sphere");
                sb.AppendLine("LEFT SHIFT - Fire heavy sphere");
                sb.AppendLine("SPACEBAR - Fire a medium weight sphere");
                sb.AppendLine("W, A, S, D - Move Camera");
                sb.AppendLine("Q, E - Roll Camera");
                sb.AppendLine("TAB - Attach camera to an entity");
                sb.AppendLine("Hold left mouse button to fly faster");
                sb.AppendLine();
                sb.AppendLine("-- Gamepad Controls --");
                sb.AppendLine("Gamepad Thumbsticks to fly/look");
                sb.AppendLine("Gamepad buttons to fire spheres");
                sb.AppendLine();
                sb.AppendLine("-- GUI Controls --");
                sb.AppendLine("Double-click GUI to minimize/restore");
                sb.AppendLine("Click and hold to drag GUI windows");
            }

            this.guiScreen.Label.Text = sb.ToString();
        }