Пример #1
0
        /// <summary>
        /// PR_LeaveFunction
        /// </summary>
        static int LeaveFunction()
        {
            if (_Depth <= 0)
            {
                Sys.Error("prog stack underflow");
            }

            // restore locals from the stack
            int c = xFunction.locals;

            _LocalStackUsed -= c;
            if (_LocalStackUsed < 0)
            {
                RunError("PR_ExecuteProgram: locals stack underflow\n");
            }

            for (int i = 0; i < c; i++)
            {
                Set(xFunction.parm_start + i, _LocalStack[_LocalStackUsed + i]);
                //((int*)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i];
            }

            // up stack
            _Depth--;
            xFunction = _Stack[_Depth].f;

            return(_Stack[_Depth].s);
        }
Пример #2
0
        /// <summary>
        /// SV_CheckForNewClients
        /// </summary>
        public static void CheckForNewClients()
        {
            //
            // check for new connections
            //
            while (true)
            {
                qsocket_t ret = Net.CheckNewConnections();
                if (ret == null)
                {
                    break;
                }

                //
                // init a new client structure
                //
                int i;
                for (i = 0; i < svs.maxclients; i++)
                {
                    if (!svs.clients[i].active)
                    {
                        break;
                    }
                }
                if (i == svs.maxclients)
                {
                    Sys.Error("Host_CheckForNewClients: no free clients");
                }

                svs.clients[i].netconnection = ret;
                ConnectClient(i);

                Net.ActiveConnections++;
            }
        }
Пример #3
0
        // Cache_Alloc
        public static cache_user_t Alloc(int size, string name)
        {
            if (size <= 0)
            {
                Sys.Error("Cache_Alloc: size {0}", size);
            }

            size = (size + 15) & ~15;

            CacheEntry entry = null;

            // find memory for it
            while (true)
            {
                entry = TryAlloc(size);
                if (entry != null)
                {
                    break;
                }

                // free the least recently used cahedat
                if (_Head.LruPrev == _Head)        // cache_head.lru_prev == &cache_head)
                {
                    Sys.Error("Cache_Alloc: out of memory");
                }
                // not enough memory at all
                Free(_Head.LruPrev);
            }

            Check(entry);
            return(entry);
        }
Пример #4
0
        /// <summary>
        /// Host_EndGame
        /// </summary>
        public static void EndGame(string message, params object[] args)
        {
            string str = String.Format(message, args);

            Con.DPrint("Host_EndGame: {0}\n", str);

            if (Server.IsActive)
            {
                Host.ShutdownServer(false);
            }

            if (Client.cls.state == cactive_t.ca_dedicated)
            {
                Sys.Error("Host_EndGame: {0}\n", str);  // dedicated servers exit
            }
            if (Client.cls.demonum != -1)
            {
                Client.NextDemo();
            }
            else
            {
                Client.Disconnect();
            }

            throw new EndGameException();  //longjmp (host_abortserver, 1);
        }
Пример #5
0
        // S_FindName
        static sfx_t FindName(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                Sys.Error("S_FindName: NULL or empty\n");
            }

            if (name.Length >= QDef.MAX_QPATH)
            {
                Sys.Error("Sound name too long: {0}", name);
            }

            // see if already loaded
            for (int i = 0; i < _NumSfx; i++)
            {
                if (_KnownSfx[i].name == name)// !Q_strcmp(known_sfx[i].name, name))
                {
                    return(_KnownSfx[i]);
                }
            }

            if (_NumSfx == MAX_SFX)
            {
                Sys.Error("S_FindName: out of sfx_t");
            }

            sfx_t sfx = _KnownSfx[_NumSfx];

            sfx.name = name;

            _NumSfx++;
            return(sfx);
        }
Пример #6
0
        public int SendMessage(qsocket_t sock, MsgWriter data)
        {
            if (sock.driverdata == null)
            {
                return(-1);
            }

            qsocket_t sock2 = (qsocket_t)sock.driverdata;

            if ((sock2.receiveMessageLength + data.Length + 4) > Net.NET_MAXMESSAGE)
            {
                Sys.Error("Loop_SendMessage: overflow\n");
            }

            // message type
            int offset = sock2.receiveMessageLength;

            sock2.receiveMessage[offset++] = 1;

            // length
            sock2.receiveMessage[offset++] = (byte)(data.Length & 0xff);
            sock2.receiveMessage[offset++] = (byte)(data.Length >> 8);

            // align
            offset++;

            // message
            Buffer.BlockCopy(data.Data, 0, sock2.receiveMessage, offset, data.Length);
            sock2.receiveMessageLength = IntAlign(sock2.receiveMessageLength + data.Length + 4);

            sock.canSend = false;
            return(1);
        }
Пример #7
0
        /// <summary>
        /// Host_Error
        /// This shuts down both the client and server
        /// </summary>
        public static void Error(string error, params object[] args)
        {
            _ErrorDepth++;
            try
            {
                if (_ErrorDepth > 1)
                {
                    Sys.Error("Host_Error: recursively entered. " + error, args);
                }

                Scr.EndLoadingPlaque();         // reenable screen updates

                string message = (args.Length > 0 ? String.Format(error, args) : error);
                Con.Print("Host_Error: {0}\n", message);

                if (Server.sv.active)
                {
                    ShutdownServer(false);
                }

                if (Client.cls.state == cactive_t.ca_dedicated)
                {
                    Sys.Error("Host_Error: {0}\n", message);    // dedicated servers exit
                }
                Client.Disconnect();
                Client.cls.demonum = -1;

                throw new EndGameException(); // longjmp (host_abortserver, 1);
            }
            finally
            {
                _ErrorDepth--;
            }
        }
Пример #8
0
        /// <summary>
        /// SV_HullPointContents
        /// </summary>
        static int HullPointContents(hull_t hull, int num, ref Vector3 p)
        {
            while (num >= 0)
            {
                if (num < hull.firstclipnode || num > hull.lastclipnode)
                {
                    Sys.Error("SV_HullPointContents: bad node number");
                }

                short[]  node_children = hull.clipnodes[num].children;
                mplane_t plane         = hull.planes[hull.clipnodes[num].planenum];
                float    d;
                if (plane.type < 3)
                {
                    d = Mathlib.Comp(ref p, plane.type) - plane.dist;
                }
                else
                {
                    d = Vector3.Dot(plane.normal, p) - plane.dist;
                }
                if (d < 0)
                {
                    num = node_children[1];
                }
                else
                {
                    num = node_children[0];
                }
            }

            return(num);
        }
Пример #9
0
        /// <summary>
        /// R_TextureAnimation
        /// Returns the proper texture for a given time and base texture
        /// </summary>
        static texture_t TextureAnimation(texture_t t)
        {
            if (_CurrentEntity.frame != 0)
            {
                if (t.alternate_anims != null)
                {
                    t = t.alternate_anims;
                }
            }

            if (t.anim_total == 0)
            {
                return(t);
            }

            int reletive = (int)(Client.cl.time * 10) % t.anim_total;
            int count    = 0;

            while (t.anim_min > reletive || t.anim_max <= reletive)
            {
                t = t.anim_next;
                if (t == null)
                {
                    Sys.Error("R_TextureAnimation: broken cycle");
                }
                if (++count > 100)
                {
                    Sys.Error("R_TextureAnimation: infinite cycle");
                }
            }

            return(t);
        }
Пример #10
0
        public qsocket_t CheckNewConnections()
        {
            if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_CONNECT)
            {
                Sys.Error("VCR missmatch");
            }

            if (_Next.session == 0)
            {
                ReadNext();
                return(null);
            }

            qsocket_t sock = Net.NewSocket();

            sock.driverdata = _Next.session;

            byte[] buf = new byte[Net.NET_NAMELEN];
            Host.VcrReader.Read(buf, 0, buf.Length);
            sock.address = Encoding.ASCII.GetString(buf);

            ReadNext();

            return(sock);
        }
Пример #11
0
        /// <summary>
        /// ED_Alloc
        /// Either finds a free edict, or allocates a new one.
        /// Try to avoid reusing an entity that was recently freed, because it
        /// can cause the client to think the entity morphed into something else
        /// instead of being removed and recreated, which can cause interpolated
        /// angles and bad trails.
        /// </summary>
        public static edict_t AllocEdict()
        {
            edict_t e;
            int     i;

            for (i = svs.maxclients + 1; i < sv.num_edicts; i++)
            {
                e = EdictNum(i);

                // the first couple seconds of server time can involve a lot of
                // freeing and allocating, so relax the replacement policy
                if (e.free && (e.freetime < 2 || sv.time - e.freetime > 0.5))
                {
                    e.Clear();
                    return(e);
                }
            }

            if (i == QDef.MAX_EDICTS)
            {
                Sys.Error("ED_Alloc: no free edicts");
            }

            sv.num_edicts++;
            e = EdictNum(i);
            e.Clear();

            return(e);
        }
Пример #12
0
        /// <summary>
        /// GL_SelectTexture
        /// </summary>
        public static void SelectTexture(MTexTarget target)
        {
            if (!Vid.glMTexable)
            {
                return;
            }

            switch (target)
            {
            case MTexTarget.TEXTURE0_SGIS:
                GL.Arb.ActiveTexture(TextureUnit.Texture0);
                break;

            case MTexTarget.TEXTURE1_SGIS:
                GL.Arb.ActiveTexture(TextureUnit.Texture1);
                break;

            default:
                Sys.Error("GL_SelectTexture: Unknown target\n");
                break;
            }

            if (target == _OldTarget)
            {
                return;
            }

            _CntTextures[_OldTarget - MTexTarget.TEXTURE0_SGIS] = Drawer.CurrentTexture;
            Drawer.CurrentTexture = _CntTextures[target - MTexTarget.TEXTURE0_SGIS];
            _OldTarget            = target;
        }
Пример #13
0
        /// <summary>
        /// R_StoreEfrags
        /// FIXME: a lot of this goes away with edge-based
        /// </summary>
        static void StoreEfrags(efrag_t ef)
        {
            while (ef != null)
            {
                entity_t pent = ef.entity;
                model_t clmodel = pent.model;

                switch (clmodel.type)
                {
                    case modtype_t.mod_alias:
                    case modtype_t.mod_brush:
                    case modtype_t.mod_sprite:
                        if ((pent.visframe != _FrameCount) && (Client.NumVisEdicts < Client.MAX_VISEDICTS))
                        {
                            Client.VisEdicts[Client.NumVisEdicts++] = pent;

                            // mark that we've recorded this entity for this frame
                            pent.visframe = _FrameCount;
                        }

                        ef = ef.leafnext;
                        break;

                    default:
                        Sys.Error("R_StoreEfrags: Bad entity type {0}\n", clmodel.type);
                        break;
                }
            }
        }
Пример #14
0
        // Draw_CachePic
        public static glpic_t CachePic(string path)
        {
            for (int i = 0; i < _MenuNumCachePics; i++)
            {
                cachepic_t p = _MenuCachePics[i];
                if (p.name == path)// !strcmp(path, pic->name))
                {
                    return(p.pic);
                }
            }

            if (_MenuNumCachePics == MAX_CACHED_PICS)
            {
                Sys.Error("menu_numcachepics == MAX_CACHED_PICS");
            }

            cachepic_t pic = _MenuCachePics[_MenuNumCachePics];

            _MenuNumCachePics++;
            pic.name = path;

            //
            // load the pic from disk
            //
            byte[] data = Common.LoadFile(path);
            if (data == null)
            {
                Sys.Error("Draw_CachePic: failed to load {0}", path);
            }
            dqpicheader_t header = Sys.BytesToStructure <dqpicheader_t>(data, 0);

            Wad.SwapPic(header);

            int headerSize = Marshal.SizeOf(typeof(dqpicheader_t));

            // HACK HACK HACK --- we need to keep the bytes for
            // the translatable player picture just for the menu
            // configuration dialog
            if (path == "gfx/menuplyr.lmp")
            {
                Buffer.BlockCopy(data, headerSize, _MenuPlayerPixels, 0, header.width * header.height);
                //memcpy (menuplyr_pixels, dat->data, dat->width*dat->height);
            }

            glpic_t gl = new glpic_t();

            gl.width  = header.width;
            gl.height = header.height;

            //gl = (glpic_t *)pic->pic.data;
            gl.texnum = LoadTexture(gl, new ByteArraySegment(data, headerSize));
            gl.sl     = 0;
            gl.sh     = 1;
            gl.tl     = 0;
            gl.th     = 1;
            pic.pic   = gl;

            return(gl);
        }
Пример #15
0
 /// <summary>
 /// EDICT_NUM
 /// </summary>
 public static edict_t EdictNum(int n)
 {
     if (n < 0 || n >= _Server.max_edicts)
     {
         Sys.Error("EDICT_NUM: bad number {0}", n);
     }
     return(_Server.edicts[n]);
 }
Пример #16
0
 /// <summary>
 /// PROG_TO_EDICT(e)
 /// Offset in bytes!
 /// </summary>
 public static edict_t ProgToEdict(int e)
 {
     if (e < 0 || e > sv.edicts.Length)
     {
         Sys.Error("ProgToEdict: Bad prog!");
     }
     return(sv.edicts[e]);
 }
Пример #17
0
        public static void Init(quakeparms_t parms)
        {
            _Params = parms;

            Cache.Init(1024 * 1024 * 16); // debug
            Cbuf.Init();
            Cmd.Init();
            View.Init();
            Chase.Init();
            InitVCR(parms);
            Common.Init(parms.basedir, parms.argv);
            InitLocal();
            Wad.LoadWadFile("gfx.wad");
            Key.Init();
            Con.Init();
            Menu.Init();
            Progs.Init();
            Mod.Init();
            Net.Init();
            Server.Init();

            //Con.Print("Exe: "__TIME__" "__DATE__"\n");
            //Con.Print("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));

            Render.InitTextures();              // needed even for dedicated servers

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                _BasePal = Common.LoadFile("gfx/palette.lmp");
                if (_BasePal == null)
                {
                    Sys.Error("Couldn't load gfx/palette.lmp");
                }
                _ColorMap = Common.LoadFile("gfx/colormap.lmp");
                if (_ColorMap == null)
                {
                    Sys.Error("Couldn't load gfx/colormap.lmp");
                }

                // on non win32, mouse comes before video for security reasons
                Input.Init();
                Vid.Init(_BasePal);
                Drawer.Init();
                Scr.Init();
                Render.Init();
                Sound.Init();
                CDAudio.Init();
                Sbar.Init();
                Client.Init();
            }

            Cbuf.InsertText("exec quake.rc\n");

            _IsInitialized = true;

            Con.DPrint("========Quake Initialized=========\n");
        }
Пример #18
0
        /// <summary>
        /// NUM_FOR_EDICT
        /// </summary>
        public static int NumForEdict(edict_t e)
        {
            int i = Array.IndexOf(sv.edicts, e); // todo: optimize this

            if (i < 0)
            {
                Sys.Error("NUM_FOR_EDICT: bad pointer");
            }
            return(i);
        }
Пример #19
0
        // Draw_TransPic
        public static void DrawTransPic(int x, int y, glpic_t pic)
        {
            if (x < 0 || (uint)(x + pic.width) > Scr.vid.width ||
                y < 0 || (uint)(y + pic.height) > Scr.vid.height)
            {
                Sys.Error("Draw_TransPic: bad coordinates");
            }

            DrawPic(x, y, pic);
        }
Пример #20
0
        static void InitVCR(quakeparms_t parms)
        {
            if (Common.HasParam("-playback"))
            {
                if (Common.Argc != 2)
                {
                    Sys.Error("No other parameters allowed with -playback\n");
                }

                Stream file = Sys.FileOpenRead("quake.vcr");
                if (file == null)
                {
                    Sys.Error("playback file not found\n");
                }

                _VcrReader = new BinaryReader(file, Encoding.ASCII);
                int signature = _VcrReader.ReadInt32();  //Sys_FileRead(vcrFile, &i, sizeof(int));
                if (signature != Host.VCR_SIGNATURE)
                {
                    Sys.Error("Invalid signature in vcr file\n");
                }

                int      argc = _VcrReader.ReadInt32(); // Sys_FileRead(vcrFile, &com_argc, sizeof(int));
                string[] argv = new string[argc + 1];
                argv[0] = parms.argv[0];

                for (int i = 1; i < argv.Length; i++)
                {
                    argv[i] = Sys.ReadString(_VcrReader);
                }
                Common.Args = argv;
                parms.argv  = argv;
            }

            int n = Common.CheckParm("-record");

            if (n != 0)
            {
                Stream file = Sys.FileOpenWrite("quake.vcr"); // vcrFile = Sys_FileOpenWrite("quake.vcr");
                _VcrWriter = new BinaryWriter(file, Encoding.ASCII);

                _VcrWriter.Write(VCR_SIGNATURE); //  Sys_FileWrite(vcrFile, &i, sizeof(int));
                _VcrWriter.Write(Common.Argc - 1);
                for (int i = 1; i < Common.Argc; i++)
                {
                    if (i == n)
                    {
                        Sys.WriteString(_VcrWriter, "-playback");
                        continue;
                    }
                    Sys.WriteString(_VcrWriter, Common.Argv(i));
                }
            }
        }
Пример #21
0
        // Cache_Free
        //
        // Frees the memory and removes it from the LRU list
        static void Free(cache_user_t c)
        {
            if (c.data == null)
            {
                Sys.Error("Cache_Free: not allocated");
            }

            CacheEntry entry = (CacheEntry)c;

            entry.Remove();
        }
Пример #22
0
            // Cache_UnlinkLRU
            public void RemoveFromLRU()
            {
                if (_LruNext == null || _LruPrev == null)
                {
                    Sys.Error("Cache_UnlinkLRU: NULL link");
                }

                _LruNext._LruPrev = _LruPrev;
                _LruPrev._LruNext = _LruNext;
                _LruPrev          = _LruNext = null;
            }
Пример #23
0
            // inserts <this> instance after <prev> in LRU list
            public void LRUInstertAfter(CacheEntry prev)
            {
                if (_LruNext != null || _LruPrev != null)
                {
                    Sys.Error("Cache_MakeLRU: active link");
                }

                prev._LruNext._LruPrev = this;
                _LruNext      = prev._LruNext;
                _LruPrev      = prev;
                prev._LruNext = this;
            }
Пример #24
0
        /// <summary>
        /// NET_FreeQSocket
        /// </summary>
        public static void FreeSocket(qsocket_t sock)
        {
            // remove it from active list
            if (!_ActiveSockets.Remove(sock))
            {
                Sys.Error("NET_FreeQSocket: not active\n");
            }

            // add it to free list
            _FreeSockets.Add(sock);
            sock.disconnected = true;
        }
Пример #25
0
        public bool CanSendMessage(qsocket_t sock)
        {
            if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_CANSENDMESSAGE || _Next.session != SocketToSession(sock))
            {
                Sys.Error("VCR missmatch");
            }

            int ret = Host.VcrReader.ReadInt32();

            ReadNext();

            return(ret != 0);
        }
Пример #26
0
        public int SendMessage(qsocket_t sock, MsgWriter data)
        {
            if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_SENDMESSAGE || _Next.session != SocketToSession(sock))
            {
                Sys.Error("VCR missmatch");
            }

            int ret = Host.VcrReader.ReadInt32();

            ReadNext();

            return(ret);
        }
Пример #27
0
        // CalcFov
        static float CalcFov(float fov_x, float width, float height)
        {
            if (fov_x < 1 || fov_x > 179)
            {
                Sys.Error("Bad fov: {0}", fov_x);
            }

            double x = width / Math.Tan(fov_x / 360.0 * Math.PI);
            double a = Math.Atan(height / x);

            a = a * 360.0 / Math.PI;
            return((float)a);
        }
Пример #28
0
        /// <summary>
        /// SV_HullForEntity
        /// Returns a hull that can be used for testing or clipping an object of mins/maxs size.
        /// Offset is filled in to contain the adjustment that must be added to the
        /// testing object's origin to get a point to use with the returned hull.
        /// </summary>
        static hull_t HullForEntity(edict_t ent, ref Vector3 mins, ref Vector3 maxs, out Vector3 offset)
        {
            hull_t hull = null;

            // decide which clipping hull to use, based on the size
            if (ent.v.solid == Solids.SOLID_BSP)
            {   // explicit hulls in the BSP model
                if (ent.v.movetype != Movetypes.MOVETYPE_PUSH)
                {
                    Sys.Error("SOLID_BSP without MOVETYPE_PUSH");
                }

                model_t model = sv.models[(int)ent.v.modelindex];

                if (model == null || model.type != modtype_t.mod_brush)
                {
                    Sys.Error("MOVETYPE_PUSH with a non bsp model");
                }

                Vector3 size = maxs - mins;
                if (size.X < 3)
                {
                    hull = model.hulls[0];
                }
                else if (size.X <= 32)
                {
                    hull = model.hulls[1];
                }
                else
                {
                    hull = model.hulls[2];
                }

                // calculate an offset value to center the origin
                offset  = hull.clip_mins - mins;
                offset += Common.ToVector(ref ent.v.origin);
            }
            else
            {
                // create a temp hull from bounding box sizes
                Vector3 hullmins = Common.ToVector(ref ent.v.mins) - maxs;
                Vector3 hullmaxs = Common.ToVector(ref ent.v.maxs) - mins;
                hull = HullForBox(ref hullmins, ref hullmaxs);

                offset = Common.ToVector(ref ent.v.origin);
            }

            return(hull);
        }
Пример #29
0
        // lumpinfo_t *W_GetLumpinfo (char *name)
        public static lumpinfo_t GetLumpInfo(string name)
        {
            lumpinfo_t lump;

            if (_Lumps.TryGetValue(name, out lump))
            {
                return(lump);
            }
            else
            {
                Sys.Error("W_GetLumpinfo: {0} not found", name);
            }
            // We must never be there
            throw new InvalidOperationException("W_GetLumpinfo: Unreachable code reached!");
        }
Пример #30
0
        // Scrap_AllocBlock
        // returns a texture number and the position inside it
        static int AllocScrapBlock(int w, int h, out int x, out int y)
        {
            x = -1;
            y = -1;
            for (int texnum = 0; texnum < MAX_SCRAPS; texnum++)
            {
                int best = BLOCK_HEIGHT;

                for (int i = 0; i < BLOCK_WIDTH - w; i++)
                {
                    int best2 = 0, j;

                    for (j = 0; j < w; j++)
                    {
                        if (_ScrapAllocated[texnum][i + j] >= best)
                        {
                            break;
                        }
                        if (_ScrapAllocated[texnum][i + j] > best2)
                        {
                            best2 = _ScrapAllocated[texnum][i + j];
                        }
                    }
                    if (j == w)
                    {
                        // this is a valid spot
                        x = i;
                        y = best = best2;
                    }
                }

                if (best + h > BLOCK_HEIGHT)
                {
                    continue;
                }

                for (int i = 0; i < w; i++)
                {
                    _ScrapAllocated[texnum][x + i] = best + h;
                }

                return(texnum);
            }

            Sys.Error("Scrap_AllocBlock: full");
            return(-1);
        }