Exemplo n.º 1
0
        public static void ExecuteText(int exec_when, string text)
        {
            switch (exec_when)
            {
            case Defines.EXEC_NOW:
                Cmd.ExecuteString(text);

                break;

            case Defines.EXEC_INSERT:
                Cbuf.InsertText(text);

                break;

            case Defines.EXEC_APPEND:
                Cbuf.AddText(text);

                break;

            default:
                Com.Error(Defines.ERR_FATAL, "Cbuf_ExecuteText: bad exec_when");

                break;
            }
        }
Exemplo n.º 2
0
        private static void reconfigure(bool clear)
        {
            Cbuf.AddText("exec default.cfg\n");
            Cbuf.AddText("bind MWHEELUP weapnext\n");
            Cbuf.AddText("bind MWHEELDOWN weapprev\n");
            Cbuf.AddText("bind w +forward\n");
            Cbuf.AddText("bind s +back\n");
            Cbuf.AddText("bind a +moveleft\n");
            Cbuf.AddText("bind d +moveright\n");
            Cbuf.Execute();
            Cvar.Set("vid_fullscreen", "0");
            Cbuf.AddText("exec config.cfg\n");

            Cbuf.AddEarlyCommands(clear);
            Cbuf.Execute();
        }
Exemplo n.º 3
0
        public static void InsertText(string text)
        {
            var templen = 0;

            // copy off any commands still remaining in the exec buffer
            templen = Globals.cmd_text.cursize;

            if (templen != 0)
            {
                Array.Copy(Globals.cmd_text.data, 0, Cbuf.tmp, 0, templen);
                SZ.Clear(Globals.cmd_text);
            }

            // add the entire text of the file
            Cbuf.AddText(text);

            // add the copied off data
            if (templen != 0)
            {
                SZ.Write(Globals.cmd_text, Cbuf.tmp, templen);
            }
        }
Exemplo n.º 4
0
        /**
         * @param clear
         */
        public static void AddEarlyCommands(bool clear)
        {
            for (var i = 0; i < Com.Argc(); i++)
            {
                var s = Com.Argv(i);

                if (!s.Equals("+set"))
                {
                    continue;
                }

                Cbuf.AddText("set " + Com.Argv(i + 1) + " " + Com.Argv(i + 2) + "\n");

                if (clear)
                {
                    Com.ClearArgv(i);
                    Com.ClearArgv(i + 1);
                    Com.ClearArgv(i + 2);
                }

                i += 2;
            }
        }
Exemplo n.º 5
0
        /**
         * @return
         */
        public static bool AddLateCommands()
        {
            int i;
            int j;
            var ret = false;

            // build the combined string to parse from
            var s    = 0;
            var argc = Com.Argc();

            for (i = 1; i < argc; i++)
            {
                s += Com.Argv(i).Length;
            }

            if (s == 0)
            {
                return(false);
            }

            var text = "";

            for (i = 1; i < argc; i++)
            {
                text += Com.Argv(i);

                if (i != argc - 1)
                {
                    text += " ";
                }
            }

            // pull out the commands
            var build = "";

            for (i = 0; i < text.Length; i++)
            {
                if (text[i] == '+')
                {
                    i++;

                    for (j = i; j < text.Length && text[j] != '+' && text[j] != '-'; j++)
                    {
                        ;
                    }

                    build += text.Substring(i, j - i);
                    build += "\n";

                    i = j - 1;
                }
            }

            ret = build.Length != 0;

            if (ret)
            {
                Cbuf.AddText(build);
            }

            text  = null;
            build = null;

            return(ret);
        }
Exemplo n.º 6
0
 /*
  * ============ Cbuf_InsertFromDefer ============
  */
 public static void InsertFromDefer()
 {
     Cbuf.InsertText(Encoding.ASCII.GetString(Globals.defer_text_buf).Split((char)0)[0]);
     Globals.defer_text_buf[0] = 0;
 }
Exemplo n.º 7
0
        /**
         * This function initializes the different subsystems of
         * the game engine. The setjmp/longjmp mechanism of the original
         * was replaced with exceptions.
         * @param args the original unmodified command line arguments
         */
        public static void Init(string[] args)
        {
            try
            {
                // prepare enough of the subsystems to handle
                // cvar and command buffer management
                Com.InitArgv(args);

                Cbuf.Init();

                Cmd.Init();
                Cvar.Init();

                Key.Init();

                // we need to add the early commands twice, because
                // a basedir or cddir needs to be set before execing
                // config files, but we want other parms to override
                // the settings of the config files
                Cbuf.AddEarlyCommands(false);
                Cbuf.Execute();

                if (Globals.dedicated.value != 1.0f)
                {
                    Console.WriteLine("initializing filesystem...");
                }

                FS.InitFilesystem();

                if (Globals.dedicated.value != 1.0f)
                {
                    Console.WriteLine("loading config...");
                }

                Qcommon.reconfigure(false);

                FS.markBaseSearchPaths();                 // mark the default search paths

                Qcommon.reconfigure(true);                // reload default.cfg and config.cfg

                //
                // init commands and vars
                //
                Cmd.AddCommand("error", Com.Error_f);

                Globals.host_speeds    = Cvar.Get("host_speeds", "0", 0);
                Globals.log_stats      = Cvar.Get("log_stats", "0", 0);
                Globals.developer      = Cvar.Get("developer", "0", Defines.CVAR_ARCHIVE);
                Globals.timescale      = Cvar.Get("timescale", "0", 0);
                Globals.fixedtime      = Cvar.Get("fixedtime", "0", 0);
                Globals.logfile_active = Cvar.Get("logfile", "0", 0);
                Globals.showtrace      = Cvar.Get("showtrace", "0", 0);
                Globals.dedicated      = Cvar.Get("dedicated", "0", Defines.CVAR_NOSET);
                var s = Com.sprintf("%4.2f %s %s %s", Globals.VERSION, Qcommon.CPUSTRING, Globals.__DATE__, Qcommon.BUILDSTRING);

                Cvar.Get("version", s, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET);

                if (Globals.dedicated.value != 1.0f)
                {
                    Console.WriteLine("initializing network subsystem...");
                }

                NET.Init();                 //ok
                Netchan.Netchan_Init();     //ok

                if (Globals.dedicated.value != 1.0f)
                {
                    Console.WriteLine("initializing server subsystem...");
                }

                SV_MAIN.SV_Init();                 //ok

                if (Globals.dedicated.value != 1.0f)
                {
                    Console.WriteLine("initializing client subsystem...");
                }

                Cl.Init();

                // add + commands from command line
                if (!Cbuf.AddLateCommands())
                {
                    // if the user didn't give any commands, run default action
                    if (Globals.dedicated.value == 0)
                    {
                        Cbuf.AddText("d1\n");
                    }
                    else
                    {
                        Cbuf.AddText("dedicated_start\n");
                    }

                    Cbuf.Execute();
                }
                else
                {
                    // the user asked for something explicit
                    // so drop the loading plaque
                    SCR.EndLoadingPlaque();
                }

                Com.Printf("====== Quake2 Initialized ======\n\n");

                // save config when configuration is completed
                Cl.WriteConfiguration();
            }
            catch (Exception)
            {
                Sys.Error("Error during initialization");
            }
        }
Exemplo n.º 8
0
        /**
         * Trigger generation of a frame for the given time. The setjmp/longjmp
         * mechanism of the original was replaced with exceptions.
         * @param msec the current game time
         */
        public static void FrameUpdate(int msec)
        {
            try
            {
                if (Globals.log_stats.modified)
                {
                    Globals.log_stats.modified = false;

                    if (Globals.log_stats.value != 0.0f)
                    {
                        if (Globals.log_stats_file != null)
                        {
                            try
                            {
                                Globals.log_stats_file.Close();
                            }
                            catch (Exception)
                            {
                            }

                            Globals.log_stats_file = null;
                        }

                        try
                        {
                            Globals.log_stats_file = File.CreateText("stats.log");
                        }
                        catch (Exception)
                        {
                            Globals.log_stats_file = null;
                        }

                        if (Globals.log_stats_file != null)
                        {
                            try
                            {
                                Globals.log_stats_file.Write("entities,dlights,parts,frame time\n");
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        if (Globals.log_stats_file != null)
                        {
                            try
                            {
                                Globals.log_stats_file.Close();
                            }
                            catch (Exception)
                            {
                            }

                            Globals.log_stats_file = null;
                        }
                    }
                }

                if (Globals.fixedtime.value != 0.0f)
                {
                    msec = (int)Globals.fixedtime.value;
                }
                else if (Globals.timescale.value != 0.0f)
                {
                    msec = (int)(msec * Globals.timescale.value);

                    if (msec < 1)
                    {
                        msec = 1;
                    }
                }

                if (Globals.showtrace.value != 0.0f)
                {
                    Com.Printf("%4i traces  %4i points\n", Globals.c_traces, Globals.c_pointcontents);

                    Globals.c_traces        = 0;
                    Globals.c_brush_traces  = 0;
                    Globals.c_pointcontents = 0;
                }

                Cbuf.Execute();

                var time_before = 0;
                var time_after  = 0;

                if (Globals.host_speeds.value != 0.0f)
                {
                    time_before = Timer.Milliseconds();
                }

                Com.debugContext = "SV:";
                SV_MAIN.SV_Frame(msec);

                if (Globals.host_speeds.value != 0.0f)
                {
                    time_after = Timer.Milliseconds();

                    var sv = time_after - time_before;
                    var gm = Globals.time_after_game - Globals.time_before_game;
                    var rf = Globals.time_after_ref - Globals.time_before_ref;
                    sv -= gm;

                    Com.Printf("update:%3i gm:%3i rf:%3i\n", sv, gm, rf);
                }
            }
            catch (Exception e)
            {
                Com.DPrintf("exception:" + e);
            }
        }