示例#1
0
        /// <summary>
        /// Initializes the DebugSystem and adds all components to the game's Components collection.
        /// </summary>
        /// <param name="game">The game using the DebugSystem.</param>
        /// <param name="debugFont">The font to use by the DebugSystem.</param>
        /// <returns>The DebugSystem for the game to use.</returns>
        public DebugManager(Game game, string debugFont, bool luaConsole)
        {
            instance = this;

            // Create all of the system components
            DebugResourceManager = new DebugResourceManager(game, debugFont);
            game.Components.Add(DebugResourceManager);

            Console = new Console(game, DebugResourceManager, luaConsole);
            game.Components.Add(Console);

            DebugDisplay = new DebugDisplay(game);
            game.Components.Add(DebugDisplay);

            TimeRuler = new TimeRuler(game);
            game.Components.Add(TimeRuler);

            Logger.Initialize(game);
        }
示例#2
0
        public override void Initialize()
        {
            #if TRACE
            debugManager =
                Game.Services.GetService(typeof(DebugResourceManager)) as DebugResourceManager;

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

            // Add "tr" command if DebugCommandHost is registered.
            IConsoleHost host =
                                Game.Services.GetService(typeof(IConsoleHost))
                                                                    as IConsoleHost;
            if (host != null)
            {
                host.RegisterCommand("tr", "TimeRuler", this.CommandExecute);
                this.Visible = true;
            }

            // 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();
        }
示例#3
0
        public Console(Game game,DebugResourceManager resources, bool isUsingPython)
            : base(game)
        {
            // Set defaults.
            Prompt = DefaultPrompt + " ";

            // Set manager
            debugResources = resources;

            // Add this instance as a service.
            Game.Services.AddService(typeof(IConsoleHost), this);

            // Draw the command UI on top of everything
            DrawOrder = int.MaxValue;

            //Initiate the array to hold the console view
            lines = new string[maxLinesInMemory];

            Echo(">>> Xna Console v0.5 <<<");
            Echo("");
            this.usingPython = isUsingPython;

            // Adding default commands
            // Help command displays registered command information.
            RegisterCommand("help", "Show command descriptions.",
                delegate(IConsoleHost host, string command, IList<string> args)
                {
                    int maxLen = 0;
                    foreach (CommandInfo cmd in commandTable.Values)
                        maxLen = Math.Max(maxLen, cmd.Command.Length);

                    string fmt = String.Format("{{0,-{0}}}    {{1}}", maxLen);

                    foreach (CommandInfo cmd in commandTable.Values)
                    {
                        Echo(String.Format(fmt, cmd.Command, cmd.Description));
                    }
                });

            // Clear screen command
            RegisterCommand("cls", "Clear console.",
                delegate(IConsoleHost host, string command, IList<string> args)
                {
                    Clear();
                });

            // Echo command
            RegisterCommand("echo", "Display messages.",
                delegate(IConsoleHost host, string command, IList<string> args)
                {
                    Echo(command.Substring(5));
                });

            if(usingPython)
            {
                pyHost = new IronPythonHost(this);

                // Directory command
                RegisterCommand("pyDir", "List loaded objects.",
                    delegate(IConsoleHost host, string command, IList<string> args)
                    {
                        pyHost.Directory();
                    });
            }
        }
示例#4
0
        public override void Initialize()
        {
            // Get debug manager from game service.
            debugManager =
                Game.Services.GetService(typeof(DebugResourceManager)) as DebugResourceManager;

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

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

            if (host != null)
            {
                host.RegisterCommand("display", "Debug Display", this.CommandExecute);
                Visible = true;
            }

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

            base.Initialize();
        }