Пример #1
0
 /// <summary>
 /// Add a CVar to the register
 /// </summary>
 /// <param name="cvar">The cvar to add</param>
 public static void RegisterConvar(Convar cvar)
 {
     CVarList.Add(cvar);
 }
Пример #2
0
        static void Main(string[] args)
        {
            bool G_FULLSCREEN = false;
            bool G_WINDOWED = false;
            int G_WIDTH = 0;
            int G_HEIGHT = 0;
            bool G_CHEATMODE = false;

            ConsoleMsg.P_Msg(Engine.GameName + " version " + Engine.GameVersion);

            if (args.Length != 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-showconsole")
                    {
                        ConsoleMsg.OpenConsole();
                    }

                    if (args[i] == "-fullscreen")
                    {
                        G_FULLSCREEN = true;
                        ConsoleMsg.P_Msg("Game set to fullscreen mode.");
                    }

                    if (args[i] == "-borderless")
                    {
                        G_WINDOWED = true;
                        ConsoleMsg.P_Msg("Game window will be borderless.");
                    }

                    if (args[i] == "-width")
                    {
                        try
                        {
                            G_WIDTH = int.Parse(args[i + 1]);
                        }
                        catch (System.FormatException)
                        {
                            G_WIDTH = 0;
                            ConsoleMsg.P_Warning("Bad value for parameter -width: " + args[i + 1]);
                        }
                    }

                    if (args[i] == "-height")
                    {
                        try
                        {
                            G_HEIGHT = int.Parse(args[i + 1]);
                        }
                        catch (System.FormatException)
                        {
                            G_HEIGHT = 0;
                            ConsoleMsg.P_Warning("Bad value for parameter -height: " + args[i + 1]);
                        }
                    }

                    if (args[i] == "-cheatmode")
                    {
                        G_CHEATMODE = true;
                        ConsoleMsg.P_Msg("Developer Mode Enabled");
                    }

                    if (args[i] == "-nosound")
                    {
                        ConsoleMsg.P_Warning("No audio playback", "NOTE", G_CHEATMODE);
                    }
                }
            }

            else
            {
                ConsoleMsg.P_Warning("No command line parameters.", "Note", G_CHEATMODE);
            }

            Convar r_fullscreen = new Convar("r_fullscreen", "0", "Should the game be fullscreen?");
            Convar r_window_width = new Convar("r_window_width", "1280", "The width of the game window");
            Convar r_window_height = new Convar("r_window_height", "720", "The height of the game window");

            using (var game = new GameWindow())
            {
                GameManager game_man = new GameManager(game);

                game.Load += (sender, e) =>
                    {
                        game_man.Load();

                        //game.VSync = VSyncMode.On;
                        if (!G_WINDOWED)
                        {
                            game.WindowBorder = WindowBorder.Fixed;
                        }
                        else
                        {
                            game.WindowBorder = WindowBorder.Hidden;
                        }

                        if (G_FULLSCREEN)
                        {
                            game.WindowState = WindowState.Fullscreen;
                            r_fullscreen.SetValue("1");
                        }

                        else
                        {
                            game.WindowState = WindowState.Normal;
                        }

                        if (G_WIDTH != 0)
                        {
                            game.Width = G_WIDTH;
                            r_window_width.SetValue(G_WIDTH.ToString());
                        }
                        else
                        {
                            game.Width = r_window_width.GetIntValue();
                        }

                        if (G_HEIGHT != 0)
                        {
                            game.Height = G_HEIGHT;
                            r_window_height.SetValue(G_HEIGHT.ToString());
                        }
                        else
                        {
                            game.Height = r_window_height.GetIntValue();
                        }

                        game_man.CentreGameWindow();

                        GLManager.GL_ResizeRenderer(game.Width, game.Height, game.X, game.Y);

                        ConsoleMsg.P_Warning("This is the console. Press ` (tilde) to enable and type a command.", "NOTICE");
                    };

                game.UpdateFrame += (sender, e) =>
                {
                    // Do the per-frame checks.
                    game.Title = Engine.GameName + " " + Engine.GameVersion + " (" + Math.Round(game.UpdateFrequency).ToString() + " FPS)";

                    if (r_fullscreen.GetIntValue() == 1 && game.WindowState != WindowState.Fullscreen)
                    {
                        game.WindowState = WindowState.Fullscreen;
                    }
                    else if (r_fullscreen.GetIntValue() == 0 && game.WindowState == WindowState.Fullscreen)
                    {
                        game.WindowState = WindowState.Normal;
                    }

                    game.CursorVisible = false;

                    game_man.GameTick();

                };

                game.KeyPress += (sender, e) =>
                    {
                        if (e.KeyChar == '`')
                        {
                            // WE'RE IN THE CONSOLE NOW
                            //game_man.DoConsoleCommand();
                            ConsoleMsg.ToggleConsole();
                        }
                    };

                game.RenderFrame += (sender, e) =>
                {
                    GLManager.BasicRenderFrame();
                    game.SwapBuffers();
                };

                game.Run();
            }
        }