private static void Command_cpuinfo(string[] parameters)
        {
            ConsoleManager.WriteLine();
            ConsoleManager.WriteLine("CPU information...");
            ConsoleManager.WriteLine("================================================================================");
            ConsoleManager.WriteLine("Vendor String             : " + CPUInfo.VendorString);
            ConsoleManager.WriteLine("Vendor Company            : " + CPUInfo.VendorCompany);
            ConsoleManager.WriteLine("Processor Name            : " + CPUInfo.CPUName.Trim());
            ConsoleManager.WriteLine("Processor Speed           : " + CPUInfo.CPUSpeed + " Mhz");

            ConsoleManager.WriteLine();
            ConsoleManager.WriteLine("Processor Type            : " + CPUInfo.CPUType);
            ConsoleManager.WriteLine("Processor Family          : " + CPUInfo.CPUFamily);
            ConsoleManager.WriteLine("Processor Extended Family : " + CPUInfo.CPUExtendedFamily);
            ConsoleManager.WriteLine("Processor Model           : " + CPUInfo.CPUModel);
            ConsoleManager.WriteLine("Processor Extended Model  : " + CPUInfo.CPUExtendedModel);
            ConsoleManager.WriteLine("Processor Stepping ID     : " + CPUInfo.CPUStepping);

            ConsoleManager.WriteLine();
            ConsoleManager.WriteLine("CPU features...");
            ConsoleManager.WriteLine("================================================================================");

            uint   Counter    = 0;
            string FlagBuffer = null;

            foreach (var CPUFlag in CPUInfo.FeatureFlags)
            {
                if (CPUFlag.Value)
                {
                    Counter++;

                    if ((Counter % 4) == 0)
                    {
                        FlagBuffer += CPUFlag.Key.PadRight(20, ' ');

                        ConsoleManager.WriteLine(FlagBuffer);

                        FlagBuffer = null;
                    }
                    else
                    {
                        FlagBuffer += CPUFlag.Key.PadRight(20, ' ');
                    }
                }
            }

            ConsoleManager.WriteLine(FlagBuffer);

            if (CPUInfo.VendorCompany == CPUInfo.VendorCompanies.Intel)
            {
                ConsoleManager.WriteLine();
                ConsoleManager.WriteLine("CPU cache descriptors... (Intel)");
                ConsoleManager.WriteLine("================================================================================");

                for (byte counter = 0; counter < CPUInfo.IntelCacheDescriptors.Count; counter++)
                {
                    ConsoleManager.WriteLine(CPUInfo.IntelCacheDescriptors[counter]);
                }
            }
        }
        private static void Command_playmusic(string[] parameters)
        {
            if (parameters == null || parameters.Length != 1)
            {
                ConsoleManager.WriteLine("HELP: playmusic <trackname>.mp3");
            }
            else
            {
                string MP3FileName = @"Music\" + parameters[0] + ".mp3";

                if (File.Exists(MP3FileName))
                {
                    if (waveOutDevice.PlaybackState == PlaybackState.Playing || waveOutDevice.PlaybackState == PlaybackState.Paused)
                    {
                        waveOutDevice.Stop();
                    }

                    audioFileReader = new AudioFileReader(@"Music\" + parameters[0] + ".mp3");
                    waveOutDevice.Init(audioFileReader);

                    waveOutDevice.Play();
                }
                else
                {
                    ConsoleManager.WriteLine("Error! The specified music track not found!");
                }
            }
        }
 private static void Command_dumpconsole(string[] parameters)
 {
     if (parameters == null || parameters.Length != 1)
     {
         ConsoleManager.WriteLine("HELP: dumpconsole <textfilename>.txt");
     }
     else
     {
         ConsoleLogManager.DumpToFile(parameters[0]);
     }
 }
        private static void Command_cmdlist(string[] parameters)
        {
            ConsoleManager.WriteLine();
            ConsoleManager.WriteLine("Listing available commands...");
            ConsoleManager.WriteLine("================================================================================");

            foreach (CommandNode Node in Commands.Values)
            {
                ConsoleManager.WriteLine(Node.Name.PadRight(16, ' ') + " --> " + Node.Help);
            }
        }
        private static void Command_imagelist(string[] parameters)
        {
            uint MemoryUsage = 0;

            foreach (var Node in TextureManager.GetValues)
            {
                MemoryUsage += Node.DataSize;

                ConsoleManager.WriteLine(Node.FilePath.PadRight(32) + Node.DataSize.ToString().PadLeft(12) + " bytes.");
            }

            ConsoleManager.WriteLine("TOTAL MEMORY USAGE".PadRight(32) + MemoryUsage.ToString().PadLeft(12) + " bytes.");
        }
        private static void Command_openglinfo(string[] parameters)
        {
            string vendor   = GL.GetString(GL.GL_VENDOR).Trim();
            string version  = GL.GetString(GL.GL_VERSION).Trim();
            string renderer = GL.GetString(GL.GL_RENDERER).Trim();
            string shader   = GL.GetString(GL.GL_SHADING_LANGUAGE_VERSION).Trim();

            ConsoleManager.WriteLine();
            ConsoleManager.WriteLine("OpenGL information...");
            ConsoleManager.WriteLine("================================================================================");
            ConsoleManager.WriteLine("VENDOR          : " + vendor);
            ConsoleManager.WriteLine("VERSION         : " + version);
            ConsoleManager.WriteLine("RENDERER        : " + renderer);
            ConsoleManager.WriteLine("SHADER LANGUAGE : " + shader);
        }
        private static void Command_democubemapping(string[] parameters)
        {
            byte DemoCubemapping = ConsoleVarManager.GetValueToByte("DemoCubemapping");

            if (DemoCubemapping == 0)
            {   // Start DemoGlut; Make sure that the other demo is stopped
                ConsoleVarManager.SetOrCreate("DemoCubemapping", "1", 0);
                ConsoleVarManager.SetOrCreate("DemoFreeglut", "0", 0);

                ConsoleManager.WriteLine("Starting demo CUBEMAPPING...");
            }
            else
            {   // Stop DemoGlut
                ConsoleVarManager.SetOrCreate("DemoCubemapping", "0", 0);
                ConsoleVarManager.SetOrCreate("DemoFreeglut", "0", 0);

                ConsoleManager.WriteLine("Stopping demo CUBEMAPPING...");
            }
        }
        private static void Command_background(string[] parameters)
        {
            if (parameters == null || parameters.Length != 1)
            {
                ConsoleManager.WriteLine("HELP: background <imagefilename>");
            }
            else
            {
                string ImageFileName = @"data\" + parameters[0];

                if (File.Exists(ImageFileName))
                {
                    ConsoleVarManager.Set("ConsoleBackground", ImageFileName);
                    ConsoleManager.Init();
                }
                else
                {
                    ConsoleManager.WriteLine("Error! The specified background image not found!");
                }
            }
        }
        private static void Command_demogui(string[] parameters)
        {
            byte DemoGUI = ConsoleVarManager.GetValueToByte("DemoGUI");

            if (DemoGUI == 0)
            {   // Start demo; Make sure that the other demos are stopped
                ConsoleVarManager.SetOrCreate("DemoFreeglut", "0", 0);
                ConsoleVarManager.SetOrCreate("DemoCubemapping", "0", 0);
                ConsoleVarManager.SetOrCreate("DemoGUI", "1", 0);

                ConsoleManager.WriteLine("Starting demo GUI...");
            }
            else
            {   // Stop demo;
                ConsoleVarManager.SetOrCreate("DemoCubemapping", "0", 0);
                ConsoleVarManager.SetOrCreate("DemoFreeglut", "0", 0);
                ConsoleVarManager.SetOrCreate("DemoGUI", "0", 0);

                ConsoleManager.WriteLine("Stopping demo GUI...");
            }
        }
        public static void ExecuteCommand(string CommandLine)
        {
            CommandLine = CommandStandardization(CommandLine);

            if (!String.IsNullOrEmpty(CommandLine))
            {
                string[] CommandWithParameters = Tokenize(CommandLine);
                string   CommandName           = CommandWithParameters[0];
                string[] Parameters            = null;

                // If the command with its parameters presents
                if (CommandWithParameters.Length > 1)
                {
                    Parameters = new string[CommandWithParameters.Length - 1];

                    for (ushort Counter = 1; Counter < CommandWithParameters.Length; Counter++)
                    {
                        Parameters[Counter - 1] = CommandWithParameters[Counter];
                    }
                }

                if (Commands.ContainsKey(CommandName))
                {
                    CommandNode Node = Commands[CommandName];

                    if (Node.CommandProc != null)
                    {
                        Node.CommandProc(Parameters);
                    }
                    else
                    {
                        ConsoleManager.WriteLine("Error! Command delegate not defined!");
                    }
                }
                else
                {
                    ConsoleManager.WriteLine("Error! Invalid command!");
                }
            }
        }
 private static void Command_version(string[] parameters)
 {
     ConsoleManager.WriteLine(ConsoleVarManager.GetValueToString("VersionLong"));
 }
        // Init
        public static void Init()
        {
            if (ConsoleVarManager.GetValueToString("Q2ConsoleInit") == "true")
            {
                // Init FreeGlut
                int[] argc = new int[1]; argc[0] = 0; string[] argv = null;
                FG.Init(argc, argv);

                FG.InitDisplayMode(FG.GLUT_RGBA | FG.GLUT_DOUBLE | FG.GLUT_DEPTH);
                FG.InitWindowPosition(25, 25);
                FG.InitWindowSize(1024, 768);
                FG.InitContextVersion(2, 1);
                FG.InitContextFlags((int)FG.GLUT_FORWARD_COMPATIBLE);
                FG.InitContextProfile((int)FG.GLUT_COMPATIBILITY_PROFILE);
                int hWindow = FG.CreateWindow(ConsoleVarManager.GetValueToString("VersionLong"));

                // Setup OpenGL window and OpenGL itself
                GL.Init(true);

                // Init DevIL -> Developers Image Libary
                IL.Init();
                ILU.Init();
                ILUT.Init();
                ILUT.Renderer(ILUT.ILUT_OPENGL);
            }

            SetupGL();                  // Each time ScreenSize changes, this must be called
            ConsoleManager.Init();      // Each time ScreenSize changes, this must be called

            if (ConsoleVarManager.GetValueToString("Q2ConsoleInit") == "true")
            {
                string[] OpenGLDotNetInitLog = GLConfig.LogDumpToString();
                foreach (string Line in OpenGLDotNetInitLog)
                {
                    ConsoleManager.WriteLine(Line);
                }
            }

            if (ConsoleVarManager.GetValueToString("Q2ConsoleInit") == "true")
            {
                // We don't want to Init and Add commands each time ScreenSize changes
                CommandManager.Init();

                CommandManager.ExecuteCommand("openglinfo");
                CommandManager.ExecuteCommand("cpuinfo");
                CommandManager.ExecuteCommand("help");

                FG.IdleFunc(IdleProc);
                FG.KeyboardFunc(KeyboardProc);
                FG.MouseFunc(MouseProc);
                FG.ReshapeFunc(ReshapeProc);
                FG.DisplayFunc(DisplayProc);

                GL.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                FG.SwapBuffers();

                // Before entering FG.MainLoop(), we must set the variable
                ConsoleVarManager.Set("Q2ConsoleInit", "false");

                // Enter the FG.MainLoop()
                FG.SetOption(FG.GLUT_ACTION_ON_WINDOW_CLOSE, (int)FG.GLUT_ACTION_GLUTMAINLOOP_RETURNS);
                FG.MainLoop();
            }
        }
        public unsafe static void Keyboard(byte key, int x, int y)
        {
            //Console.WriteLine("Key = " + key);

            if (ConsoleManager.IsOpen)
            {   // If console is open...
                switch (key)
                {
                case 96:        // "~" key pressed
                case 126:
                    ConsoleManager.Close();
                    Reshape(ConsoleVarManager.GetValueToUShort("ScreenWidth"), ConsoleVarManager.GetValueToUShort("ScreenHeight"));
                    break;

                case 8:         // Backspace key pressed
                case 127:       // Del key pressed
                    ConsoleLogManager.DeleteBufferChar();
                    break;

                case 9:         // Tab key pressed; do nothing
                case 27:        // Escape key pressed; do nothing
                    break;

                case 13:        // Enter key pressed
                    string Command = ConsoleLogManager.ReadBuffer();
                    // Flush the buffer
                    ConsoleManager.WriteLine();
                    // Execute command
                    CommandManager.ExecuteCommand(Command);
                    // Redisplay the console
                    ConsoleManager.Open();
                    break;

                default:
                    byte *keyptr = &key;
                    ConsoleManager.Write(new string((sbyte *)keyptr));
                    break;
                }
            }
            else
            {   // If console is closed
                switch (key)
                {
                case 96:        // "~" key pressed
                case 126:
                    ConsoleManager.Open();
                    Reshape(ConsoleVarManager.GetValueToUShort("ScreenWidth"), ConsoleVarManager.GetValueToUShort("ScreenHeight"));
                    break;
                }

                if (ConsoleVarManager.GetValueToByte("DemoFreeglut") == 1)
                {
                    switch (key)
                    {
                    case 81:        // 'Q' key pressed
                    case 113:
                        SpinIncrement += 0.25f;
                        break;

                    case 90:        // 'Z' key pressed
                    case 122:
                        SpinIncrement -= 0.25f;
                        break;

                    case 70:        // 'F' key pressed
                    case 102:
                        FG.FullScreenToggle();
                        break;

                    case 49:        // '1', '2', '3', '4', '5' key pressed
                    case 50:
                    case 51:
                    case 52:
                    case 53:
                        key       -= 48;
                        DrawObject = (ObjectNames)key;
                        break;

                    case 65:        // 'A' key pressed
                    case 97:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(-1.0f, 0.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 83:        // 'S' key pressed
                    case 115:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(0.0f, -1.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 68:        // 'D' key pressed
                    case 100:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(+1.0f, 0.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 87:        // 'W' key pressed
                    case 119:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(0.0f, +1.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 27:        // ESCAPE key pressed, so exit the program
                        RotateAroundX = false;
                        RotateAroundY = false;
                        RotateAroundZ = false;

                        FG.IdleFunc(null);
                        FG.KeyboardFunc(null);
                        FG.MouseFunc(null);
                        FG.ReshapeFunc(null);
                        FG.DestroyWindow(FG.GetWindow());
                        break;
                    }
                }

                if (ConsoleVarManager.GetValueToByte("DemoGUI") == 1)
                {
                    switch (key)
                    {
                    case 81:        // 'Q' key pressed
                    case 113:
                        SpinIncrement += 0.25f;
                        break;

                    case 90:        // 'Z' key pressed
                    case 122:
                        SpinIncrement -= 0.25f;
                        break;

                    case 70:        // 'F' key pressed
                    case 102:
                        FG.FullScreenToggle();
                        break;

                    case 65:        // 'A' key pressed
                    case 97:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(-1.0f, 0.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 83:        // 'S' key pressed
                    case 115:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(0.0f, -1.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 68:        // 'D' key pressed
                    case 100:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(+1.0f, 0.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 87:        // 'W' key pressed
                    case 119:
                        GL.MatrixMode(GL.GL_PROJECTION);
                        GL.Translatef(0.0f, +1.0f, 0.0f);
                        GL.MatrixMode(GL.GL_MODELVIEW);
                        break;

                    case 27:        // ESCAPE key pressed, so exit the program
                        RotateAroundX = false;
                        RotateAroundY = false;
                        RotateAroundZ = false;

                        FG.IdleFunc(null);
                        FG.KeyboardFunc(null);
                        FG.MouseFunc(null);
                        FG.ReshapeFunc(null);
                        FG.DestroyWindow(FG.GetWindow());
                        break;
                    }
                }
            }
        }