コード例 #1
0
        public override void Initialize()
        {
            // Get debug manager from game service.
            debugManager =
                Game.Services.GetService(typeof(DebugManager)) as DebugManager;

            if (debugManager == null)
            {
                throw new InvalidOperationException("DebugManaer is not registered.");
            }

            // Register 'fps' command if debug command is registered as a service.
            IDebugCommandHost host =
                Game.Services.GetService(typeof(IDebugCommandHost))
                as IDebugCommandHost;

            if (host != null)
            {
                host.RegisterCommand("fps", "FPS Counter", this.CommandExecute);
                Visible = true;
            }

            // Initialize parameters.
            Fps                  = 0;
            sampleFrames         = 0;
            stopwatch            = Stopwatch.StartNew();
            stringBuilder.Length = 0;

            base.Initialize();
        }
コード例 #2
0
        public override void Initialize()
        {
            // Get debug manager from game service.
            debugManager =
                Game.Services.GetService(typeof(DebugManager)) as DebugManager;

            if (debugManager == null)
            {
                throw new InvalidOperationException("DebugManaer is not registered.");
            }

            // Register 'fps' command if debug command is registered as a service.
            IDebugCommandHost host =
                Game.Services.GetService(typeof(IDebugCommandHost))
                as IDebugCommandHost;

            if (host != null)
            {
                host.RegisterCommand("th", "Time History", this.CommandExecute);
                Visible = false;
            }

            // Initialize parameters.
            stringBuilder.Length = 0;

            InitializeHistory();

            base.Initialize();
        }
コード例 #3
0
 public void EchoAllProperties(IDebugCommandHost host)
 {
     foreach (Command command in commands)
     {
         EchoProperty(host, command);
     }
 }
コード例 #4
0
        public override void Initialize()
        {
#if TRACE
            debugManager =
                Game.Services.GetService(typeof(vxDebugManager)) as vxDebugManager;

            if (debugManager == null)
            {
                throw new InvalidOperationException("DebugManager is not registered.");
            }

            // Add "tr" command if DebugCommandHost is registered.
            IDebugCommandHost host =
                Game.Services.GetService(typeof(IDebugCommandHost))
                as IDebugCommandHost;
            if (host != null)
            {
                host.RegisterCommand("tr", "Toggles the time ruler to measure system performace for different code regions.", this.CommandExecute);
                this.Visible = false;
            }

            // Initialize Parameters.
            logs = new FrameLog[2];
            for (int i = 0; i < logs.Length; ++i)
            {
                logs[i] = new FrameLog();
            }

            sampleFrames = TargetSampleFrames = 1;

            // Time-Ruler's update method doesn't need to get called.
            this.Enabled = false;
#endif
            base.Initialize();
        }
コード例 #5
0
        /// <summary>
        /// FPS command implementation.
        /// </summary>
        private void CommandExecute(IDebugCommandHost host, string command, IList<string> arguments)
        {
            foreach (string arg in arguments) { arg.ToLower(); }

            if (arguments.Contains("list")) { ShowList(); }

            if (arguments.Contains("open"))
            {
                int index = arguments.IndexOf("open");
                string sceneToOpen = arguments[index + 1];

                if (sceneManager.ContainsScene(sceneToOpen))
                {
                    // activate the selected scene
                    sceneManager.ActivateScene(sceneToOpen);
                }
            }

            if (arguments.Contains("close"))
            {
                int index = arguments.IndexOf("close");
                string sceneToClose = arguments[index + 1];

                if (sceneManager.ContainsScene(sceneToClose))
                {
                    sceneManager.ExitScene(sceneToClose);
                }
            }
            // TODO: allow loading and disposing of scenes
        }
コード例 #6
0
        private void ExecuteRemoteCommand(IDebugCommandHost host, string command,
                                          IList <string> arguments)
        {
            if (NetworkSession == null)
            {
                try
                {
                    GamerServicesDispatcher.WindowHandle = Game.Window.Handle;
                    GamerServicesDispatcher.Initialize(Game.Services);
                }
                catch { }

                if (SignedInGamer.SignedInGamers.Count > 0)
                {
                    commandHost.Echo("Finding available sessions...");

                    asyncResult = NetworkSession.BeginFind(
                        NetworkSessionType.SystemLink, 1, null, null, null);

                    phase = ConnectionPahse.FindSessions;
                }
                else
                {
                    host.Echo("Please signed in.");
                    phase = ConnectionPahse.EnsureSignedIn;
                }
            }
            else
            {
                ConnectedToRemote();
            }
        }
コード例 #7
0
        public override void Initialize()
        {
#if TRACE
            debugManager =
                Game.Services.GetService(typeof(DebugManager)) as DebugManager;

            if (debugManager == null)
            {
                throw new InvalidOperationException("DebugManager is not registered.");
            }

            // Add "tr" command if DebugCommandHost is registered.
            IDebugCommandHost host =
                Game.Services.GetService(typeof(IDebugCommandHost))
                as IDebugCommandHost;

            if (host != null)
            {
                host.RegisterCommand("tr", "TimeRuler", this.CommandExecute);
                this.Visible = false;
                this.Enabled = false;
            }

            // Initialize Parameters.
            logs = new FrameLog[2];
            for (int i = 0; i < logs.Length; ++i)
            {
                logs[i] = new FrameLog();
            }

            sampleFrames = TargetSampleFrames = 1;
#endif
            base.Initialize();
        }
コード例 #8
0
        public override void Initialize()
        {
            // Get debug manager from game service.
            debugManager = Game.Services.GetService(typeof(DebugManager)) as DebugManager;

            if (debugManager == null)
            {
                throw new InvalidOperationException("DebugManaer is not registered.");
            }

            // Register 'fps' command if debug command is registered as a service.
            IDebugCommandHost host = Game.Services.GetService(typeof(IDebugCommandHost)) as IDebugCommandHost;

            if (host != null)
            {
                host.RegisterCommand("memory", "Memory Tracker", this.CommandExecute);
                Visible = false;
            }

            // Initialize parameters.
            Collections      = 0;
            ManagedHeapSize  = GC.GetTotalMemory(false);
            ManagedHeapDelta = 0;
            stopwatch        = Stopwatch.StartNew();

            stringBuilder.Length = 0;

            base.Initialize();
        }
コード例 #9
0
        public static void Initialize(Game g)
        {
            IDebugCommandHost host = g.Services.GetService(typeof(IDebugCommandHost)) as IDebugCommandHost;

            if (host != null)
            {
                host.RegisterCommand("rendercol", "Render Collision Geometry", RenderCollisionCommand);
            }
        }
コード例 #10
0
 private void ToggleCollisionDisplay(IDebugCommandHost host, string command, IList <string> arguments)
 {
     foreach (var component in ScreenManager.Game.Components)
     {
         if (component is TexturedDrawableGameComponent)
         {
             TexturedDrawableGameComponent texturedComponent = component as TexturedDrawableGameComponent;
             texturedComponent.DrawCollisionArea = !texturedComponent.DrawCollisionArea;
         }
     }
 }
コード例 #11
0
        public RemoteDebugCommand(Game game)
            : base(game)
        {
            commandHost =
                game.Services.GetService(typeof(IDebugCommandHost)) as IDebugCommandHost;

            if (!IsHost)
            {
                commandHost.RegisterCommand("remote", "Start remote command",
                                                ExecuteRemoteCommand);
            }
        }
コード例 #12
0
        public RemoteDebugCommand(Game game)
            : base(game)
        {
            commandHost =
                game.Services.GetService(typeof(IDebugCommandHost)) as IDebugCommandHost;

            if (!IsHost)
            {
                commandHost.RegisterCommand("remote", "Start remote command",
                                            ExecuteRemoteCommand);
            }
        }
コード例 #13
0
        public void ToggleEditModeCommand(IDebugCommandHost host, string command, string[] arguments)
        {
            if (Config.EditMode == false)
            {
                game.IsMouseVisible = true;

                Config.EditMode = true;
            }
            else
            {
                game.IsMouseVisible = false;

                Config.EditMode = false;
            }
        }
コード例 #14
0
 /// <summary>
 /// This method is called from DebugCommandHost when the user types the 'pos'
 /// command into the command prompt. This is registered with the command prompt
 /// through the DebugCommandUI.RegisterCommand method we called in Initialize.
 /// </summary>
 void PosCommand(IDebugCommandHost host, string command, IList <string> arguments)
 {
     // if we got two arguments from the command
     if (arguments.Count == 2)
     {
         // process text "pos xPos yPos" by parsing our two arguments
         debugPos.X = Single.Parse(arguments[0], CultureInfo.InvariantCulture);
         debugPos.Y = Single.Parse(arguments[1], CultureInfo.InvariantCulture);
     }
     else
     {
         // if we didn't get two arguments, we echo the current position of the cat
         host.Echo(String.Format("Pos={0},{1}", debugPos.X, debugPos.Y));
     }
 }
コード例 #15
0
        public void ToggleEditModeCommand(IDebugCommandHost host, string command, string[] arguments)
        {
            if(Config.EditMode == false)
            {
                game.IsMouseVisible = true;

                Config.EditMode = true;
            }
            else
            {
                game.IsMouseVisible = false;

                Config.EditMode = false;
            }
        }
コード例 #16
0
 public bool HandlePropertyCommand(
     IDebugCommandHost host,
     string commandName,
     string value)
 {
     bool handled = false;
     foreach (Command command in commands)
     {
         if (string.Compare(command.CommandName, commandName, true) == 0 ||
             string.Compare(command.PropertyName, commandName, true) == 0)
         {
             HandleProperty(host, command, value);
             handled = true;
             break;
         }
     }
     return handled;
 }
コード例 #17
0
        private void CommandExecute(IDebugCommandHost host,
                                    string command, IList<string> arguments)
        {
            if (arguments.Count == 0)
                Visible = !Visible;

            foreach (string arg in arguments)
            {
                switch (arg.ToLower())
                {
                    case "on":
                        Visible = true;
                        break;
                    case "off":
                        Visible = false;
                        break;
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// memory command implementation.
        /// </summary>
        private void CommandExecute(IDebugCommandHost host, string command, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                Visible = !Visible;
            }

            foreach (string arg in arguments)
            {
                switch (arg.ToLower())
                {
                case "on":
                    Visible = true;
                    break;

                case "off":
                    Visible = false;
                    break;
                }
            }
        }
コード例 #19
0
        private static void RenderCollisionCommand(IDebugCommandHost host, string command, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                RenderCollisionGeometry = !RenderCollisionGeometry;
            }

            foreach (string arg in arguments)
            {
                switch (arg.ToLower())
                {
                case "on":
                    RenderCollisionGeometry = true;
                    break;

                case "off":
                    RenderCollisionGeometry = false;
                    break;
                }
            }
        }
コード例 #20
0
ファイル: FpsCounter.cs プロジェクト: hoangvantu/Gem
        /// <summary>
        /// FPS command implementation.
        /// </summary>
        private string CommandExecute(IDebugCommandHost host,
                                      string command, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                Visible = !Visible;
            }

            foreach (string arg in arguments)
            {
                switch (arg.ToLower())
                {
                case "on":
                    Visible = true;
                    break;

                case "off":
                    Visible = false;
                    break;
                }
            }
            return(String.Format("FPS is {0}", Visible));
        }
コード例 #21
0
 void HandleProperty(IDebugCommandHost host, Command command, string value)
 {
     if (value == null)
     {
         EchoProperty(host, command);
     }
     else
     {
         SetProperty(host, command, value);
     }
 }
コード例 #22
0
ファイル: TimeRuler.cs プロジェクト: alittle1234/XNA_Project
        /// <summary>
        /// 'tr' command execution.
        /// </summary>
        void CommandExecute(IDebugCommandHost host, string command,
                                                                IList<string> arguments)
        {
            bool previousVisible = Visible;

            if (arguments.Count == 0)
                Visible = !Visible;

            char[] subArgSeparator = new[] { ':' };
            foreach (string orgArg in arguments)
            {
                string arg = orgArg.ToLower();
                string[] subargs = arg.Split(subArgSeparator);
                switch (subargs[0])
                {
                    case "on":
                        Visible = true;
                        break;
                    case "off":
                        Visible = false;
                        break;
                    case "reset":
                        ResetLog();
                        break;
                    case "log":
                        if (subargs.Length > 1)
                        {
                            if (String.Compare(subargs[1], "on") == 0)
                                ShowLog = true;
                            if (String.Compare(subargs[1], "off") == 0)
                                ShowLog = false;
                        }
                        else
                        {
                            ShowLog = !ShowLog;
                        }
                        break;
                    case "frame":
                        int a = Int32.Parse(subargs[1]);
                        a = Math.Max(a, 1);
                        a = Math.Min(a, MaxSampleFrames);
                        TargetSampleFrames = a;
                        break;
                    case "/?":
                    case "--help":
                        host.Echo("tr [log|on|off|reset|frame]");
                        host.Echo("Options:");
                        host.Echo("       on     Display TimeRuler.");
                        host.Echo("       off    Hide TimeRuler.");
                        host.Echo("       log    Show/Hide marker log.");
                        host.Echo("       reset  Reset marker log.");
                        host.Echo("       frame:sampleFrames");
                        host.Echo("              Change target sample frame count");
                        break;
                    default:
                        break;
                }
            }

            // Reset update count when Visible state changed.
            if (Visible != previousVisible)
            {
                Interlocked.Exchange(ref updateCount, 0);
            }
        }
コード例 #23
0
 private void ExecuteQuitCommand(IDebugCommandHost host, string command,
                                 IList <string> arguments)
 {
     SendPacket(QuitPacketHeader, "End Remote Debug Command.");
     DisconnectedFromRemote();
 }
コード例 #24
0
 private void ExecuteQuitCommand(IDebugCommandHost host, string command,
                                                     IList<string> arguments)
 {
     SendPacket(QuitPacketHeader, "End Remote Debug Command.");
     DisconnectedFromRemote();
 }
コード例 #25
0
        private void ExecuteRemoteCommand(IDebugCommandHost host, string command,
                                                            IList<string> arguments)
        {
            if (NetworkSession == null)
            {
                try
                {
                    GamerServicesDispatcher.WindowHandle = Game.Window.Handle;
                    GamerServicesDispatcher.Initialize(Game.Services);
                }
                catch { }

                if (SignedInGamer.SignedInGamers.Count > 0)
                {
                    commandHost.Echo("Finding available sessions...");

                    asyncResult = NetworkSession.BeginFind(
                            NetworkSessionType.SystemLink, 1, null, null, null);

                    phase = ConnectionPahse.FindSessions;
                }
                else
                {
                    host.Echo("Please signed in.");
                    phase = ConnectionPahse.EnsureSignedIn;
                }
            }
            else
            {
                ConnectedToRemote();
            }
        }
コード例 #26
0
 public static void ToggleDebugCommand(IDebugCommandHost host, string command, params string[] arguments)
 {
     Config.DebugModeEnabled = !Config.DebugModeEnabled;
 }
コード例 #27
0
 /// <summary>
 /// This method is called from DebugCommandHost when the user types the 'pos'
 /// command into the command prompt. This is registered with the command prompt
 /// through the DebugCommandUI.RegisterCommand method we called in Initialize.
 /// </summary>
 public void PosCommand(IDebugCommandHost host, string command, IList<string> arguments)
 {
     // if we got two arguments from the command
     if (arguments.Count == 2)
     {
         // process text "pos xPos yPos" by parsing our two arguments
         debugPos.X = Single.Parse(arguments[0], CultureInfo.InvariantCulture);
         debugPos.Y = Single.Parse(arguments[1], CultureInfo.InvariantCulture);
     }
     else
     {
         // if we didn't get two arguments, we echo the current position of the cat
         host.Echo(String.Format("Pos={0},{1}", debugPos.X, debugPos.Y));
     }
 }
コード例 #28
0
 public static void ToggleSoundCommand(IDebugCommandHost host, string command, params string[] arguments)
 {
     Config.SoundEnabled = !Config.SoundEnabled;
 }
コード例 #29
0
        bool EchoProperty(
            IDebugCommandHost host,
            Command command,
            object parent)
        {
            //var propertyInfo = parent.GetType().GetProperty(command.PropertyName);
            //if (propertyInfo != null)
            //{
            //    var value = propertyInfo.GetValue(parent, null);
            //    host.Echo(string.Format(
            //        "[{0}] {1}: {2}",
            //        command.CommandName,
            //        command.PropertyName,
            //        value));
            //    return true;
            //}

            var fieldInfo = parent.GetType().GetField(command.PropertyName);
            if (fieldInfo != null)
            {
                var value = fieldInfo.GetValue(parent);
                host.Echo(string.Format(
                    "[{0}] {1}: {2}",
                    command.CommandName,
                    command.PropertyName,
                    value));
                return true;
            }

            return false;
        }
コード例 #30
0
        void EchoProperty(
            IDebugCommandHost host,
            Command command)
        {
            var propertyInfo = target.GetType().GetProperty(command.PropertyName);
            if (propertyInfo != null)
            {
                var value = propertyInfo.GetValue(target, null);
                host.Echo(string.Format(
                    "[{0}] {1}: {2}",
                    command.CommandName,
                    command.PropertyName,
                    value));
                return;
            }

            var fieldInfo = target.GetType().GetField(command.PropertyName);
            if (fieldInfo != null)
            {
                var value = fieldInfo.GetValue(target);
                host.Echo(string.Format(
                    "[{0}] {1}: {2}",
                    command.CommandName,
                    command.PropertyName,
                    value));
                return;
            }

            host.Echo(string.Format(
                "'{0}' have no property/filed '{1}'",
                target.GetType().Name,
                command.PropertyName));
        }
コード例 #31
0
        object SetProperty(
            IDebugCommandHost host,
            Command command,
            string value,
            object parent)
        {
            try
            {
                //var propertyInfo = parent.GetType().GetProperty(command.PropertyName);
                //if (propertyInfo != null)
                //{
                //    object convertedValue = ConvertValue(propertyInfo.PropertyType, value);
                //    propertyInfo.SetValue(parent, convertedValue, null);
                //    return parent;
                //}

                var fieldInfo = parent.GetType().GetField(command.PropertyName);
                if (fieldInfo != null)
                {
                    object convertedValue = ConvertValue(fieldInfo.FieldType, value);
                    fieldInfo.SetValue(parent, convertedValue);
                    return parent;
                }
            }
            catch (Exception e)
            {
                host.EchoError(e.Message);
            }

            return null;
        }
コード例 #32
0
        void EchoProperty(
            IDebugCommandHost host,
            Command command)
        {
            bool parentExist = false;
            var parentPropertyInfo = target.GetType().GetProperty(structPropertyName);
            if (parentPropertyInfo != null)
            {
                parentExist = true;
                var parent = parentPropertyInfo.GetValue(target, null);
                if (EchoProperty(host, command, parent))
                {
                    return;
                }
            }

            var parentFieldInfo = target.GetType().GetField(structPropertyName);
            if (parentFieldInfo != null)
            {
                parentExist = true;
                var parent = parentFieldInfo.GetValue(target);
                if (EchoProperty(host, command, parent))
                {
                    return;
                }
            }

            if (!parentExist)
            {
                host.Echo(string.Format(
                    "'{0}' have no property/filed '{1}'",
                    target.GetType().Name,
                    structPropertyName));
            }
            else
            {
                host.Echo(string.Format(
                    "'{0}.{1}' have no property/filed '{2}'",
                    target.GetType().Name,
                    structPropertyName,
                    command.PropertyName));
            }
        }
コード例 #33
0
        /// <summary>
        /// 'tr' command execution.
        /// </summary>
        void CommandExecute(IDebugCommandHost host, string command,
                            IList <string> arguments)
        {
            bool previousVisible = Visible;

            if (arguments.Count == 0)
            {
                Visible = !Visible;
            }

            char[] subArgSeparator = new[] { ':' };
            foreach (string orgArg in arguments)
            {
                string   arg     = orgArg.ToLower();
                string[] subargs = arg.Split(subArgSeparator);
                switch (subargs[0])
                {
                case "on":
                    Visible = true;
                    break;

                case "off":
                    Visible = false;
                    break;

                case "reset":
                    ResetLog();
                    break;

                case "log":
                    if (subargs.Length > 1)
                    {
                        if (String.Compare(subargs[1], "on") == 0)
                        {
                            ShowLog = true;
                        }
                        if (String.Compare(subargs[1], "off") == 0)
                        {
                            ShowLog = false;
                        }
                    }
                    else
                    {
                        ShowLog = !ShowLog;
                    }
                    break;

                case "frame":
                    int a = Int32.Parse(subargs[1]);
                    a = Math.Max(a, 1);
                    a = Math.Min(a, MaxSampleFrames);
                    TargetSampleFrames = a;
                    break;

                case "/?":
                case "--help":
                    host.Echo("tr [log|on|off|reset|frame]");
                    host.Echo("Options:");
                    host.Echo("       on     Display TimeRuler.");
                    host.Echo("       off    Hide TimeRuler.");
                    host.Echo("       log    Show/Hide marker log.");
                    host.Echo("       reset  Reset marker log.");
                    host.Echo("       frame:sampleFrames");
                    host.Echo("              Change target sample frame count");
                    break;

                default:
                    break;
                }
            }

            // Reset update count when Visible state changed.
            if (Visible != previousVisible)
            {
                Interlocked.Exchange(ref updateCount, 0);
            }
        }
コード例 #34
0
        void SetProperty(
            IDebugCommandHost host,
            Command command,
            string value)
        {
            try
            {
                var propertyInfo = target.GetType().GetProperty(command.PropertyName);
                if (propertyInfo != null)
                {
                    object convertedValue = ConvertValue(propertyInfo.PropertyType, value);
                    propertyInfo.SetValue(target, convertedValue, null);
                    return;
                }

                var fieldInfo = target.GetType().GetField(command.PropertyName);
                if (fieldInfo != null)
                {
                    object convertedValue = ConvertValue(fieldInfo.FieldType, value);
                    fieldInfo.SetValue(target, convertedValue);
                    return;
                }

                host.Echo(string.Format(
                    "'{0}' have no property/filed '{1}'",
                    target.GetType().Name,
                    command.PropertyName));
            }
            catch (Exception e)
            {
                host.EchoError(e.Message);
            }
        }