/// <summary> /// R_MarkLeaves /// </summary> private static void MarkLeaves() { if (_OldViewLeaf == _ViewLeaf && _NoVis.Value == 0) { return; } if (_IsMirror) { return; } _VisFrameCount++; _OldViewLeaf = _ViewLeaf; byte[] vis; if (_NoVis.Value != 0) { vis = new byte[4096]; Common.FillArray <Byte>(vis, 0xff); // todo: add count parameter? //memset(solid, 0xff, (cl.worldmodel->numleafs + 7) >> 3); } else { vis = Mod.LeafPVS(_ViewLeaf, Client.Cl.worldmodel); } Model world = Client.Cl.worldmodel; for (int i = 0; i < world.numleafs; i++) { if (vis[i >> 3] != 0 & (1 << (i & 7)) != 0) { mnodebase_t node = world.leafs[i + 1]; do { if (node.visframe == _VisFrameCount) { break; } node.visframe = _VisFrameCount; node = node.parent; } while (node != null); } } }
/// <summary> /// SV_AddToFatPVS /// The PVS must include a small area around the client to allow head bobbing /// or other small motion on the client side. Otherwise, a bob might cause an /// entity that should be visible to not show up, especially when the bob /// crosses a waterline. /// </summary> private static void AddToFatPVS(ref Vector3 org, mnodebase_t node) { while (true) { // if this is a leaf, accumulate the pvs bits if (node.contents < 0) { if (node.contents != Contents.CONTENTS_SOLID) { byte[] pvs = Mod.LeafPVS((mleaf_t)node, sv.worldmodel); for (int i = 0; i < _FatBytes; i++) { _FatPvs[i] |= pvs[i]; } } return; } mnode_t n = (mnode_t)node; mplane_t plane = n.plane; float d = Vector3.Dot(org, plane.normal) - plane.dist; if (d > 8) { node = n.children[0]; } else if (d < -8) { node = n.children[1]; } else { // go down both AddToFatPVS(ref org, n.children[0]); node = n.children[1]; } } }
static int PF_newcheckclient(int check) { // cycle to the next one if (check < 1) { check = 1; } if (check > Server.svs.maxclients) { check = Server.svs.maxclients; } int i = check + 1; if (check == Server.svs.maxclients) { i = 1; } edict_t ent; for (; ; i++) { if (i == Server.svs.maxclients + 1) { i = 1; } ent = Server.EdictNum(i); if (i == check) { break; // didn't find anything else } if (ent.free) { continue; } if (ent.v.health <= 0) { continue; } if (((int)ent.v.flags & EdictFlags.FL_NOTARGET) != 0) { continue; } // anything that is a client, or has a client as an enemy break; } // get the PVS for the entity Vector3 org = Common.ToVector(ref ent.v.origin) + Common.ToVector(ref ent.v.view_ofs); mleaf_t leaf = Mod.PointInLeaf(ref org, Server.sv.worldmodel); byte[] pvs = Mod.LeafPVS(leaf, Server.sv.worldmodel); Buffer.BlockCopy(pvs, 0, _CheckPvs, 0, pvs.Length); return(i); }