From 88249a2e3342575dfa57979efce1ce983f9169a3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 24 Aug 2010 10:00:56 +0900 Subject: [PATCH] add pvs culling --- qtv/include/server.h | 1 + qtv/source/client.c | 58 +++++++++++++++++++++++++++++++++++++------ qtv/source/sv_parse.c | 1 + 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/qtv/include/server.h b/qtv/include/server.h index 7752228a1..96b67426d 100644 --- a/qtv/include/server.h +++ b/qtv/include/server.h @@ -84,6 +84,7 @@ typedef struct server_s { char *soundlist[MAX_SOUNDS + 1]; char *modellist[MAX_MODELS + 1]; char *lightstyles[MAX_LIGHTSTYLES]; + struct model_s *worldmodel; int playermodel; int num_signon_buffers; int signon_buffer_size[MAX_SIGNON_BUFFERS]; diff --git a/qtv/source/client.c b/qtv/source/client.c index 5e28eafa6..0d39e6c95 100644 --- a/qtv/source/client.c +++ b/qtv/source/client.c @@ -976,13 +976,57 @@ emit_entities (client_t *client, packet_entities_t *to, sizebuf_t *msg) MSG_WriteShort (msg, 0); // end of packetentities } +static byte fatpvs[MAX_MAP_LEAFS / 8]; +int fatbytes; + +static void +add_to_fat_pvs (vec3_t org, mnode_t *node, server_t *sv) +{ + byte *pvs; + int i; + float d; + mplane_t *plane; + + while (1) { + // if this is a leaf, accumulate the pvs bits + if (node->contents < 0) { + if (node->contents != CONTENTS_SOLID) { + pvs = Mod_LeafPVS ((mleaf_t *) node, sv->worldmodel); + for (i = 0; i < fatbytes; i++) + fatpvs[i] |= pvs[i]; + } + return; + } + + plane = node->plane; + d = DotProduct (org, plane->normal) - plane->dist; + if (d > 8) + node = node->children[0]; + else if (d < -8) + node = node->children[1]; + else { // go down both + add_to_fat_pvs (org, node->children[0], sv); + node = node->children[1]; + } + } +} + +static byte * +fat_pvs (vec3_t org, server_t *sv) +{ + fatbytes = (sv->worldmodel->numleafs + 31) >> 3; + memset (fatpvs, 0, fatbytes); + add_to_fat_pvs (org, sv->worldmodel->nodes, sv); + return fatpvs; +} + static void write_entities (client_t *client, sizebuf_t *msg) { - //byte *pvs = 0; - //int i; + byte *pvs = 0; + int i; int e; - //vec3_t org; + vec3_t org; frame_t *frame; entity_state_t *ent; entity_state_t *state; @@ -993,9 +1037,9 @@ write_entities (client_t *client, sizebuf_t *msg) frame = &client->frames[client->netchan.incoming_sequence & UPDATE_MASK]; // find the client's PVS - //clent = client->edict; - //VectorAdd (SVvector (clent, origin), SVvector (clent, view_ofs), org); - //pvs = SV_FatPVS (org); + VectorCopy (client->state.origin, org); + org[2] += 22; //XXX standard spectator view offset + pvs = fat_pvs (org, sv); // put other visible entities into either a packet_entities or a nails // message @@ -1010,7 +1054,6 @@ write_entities (client_t *client, sizebuf_t *msg) continue; if (ent->number && ent->number != e) qtv_printf ("%d %d\n", e, ent->number); -#if 0 if (pvs) { // ignore if not touching a PV leaf for (i = 0; i < ent->num_leafs; i++) @@ -1020,7 +1063,6 @@ write_entities (client_t *client, sizebuf_t *msg) if (i == ent->num_leafs) continue; // not visible } -#endif // if (SV_AddNailUpdate (ent)) // continue; // added to the special update list diff --git a/qtv/source/sv_parse.c b/qtv/source/sv_parse.c index fcf5c3616..53419b61a 100644 --- a/qtv/source/sv_parse.c +++ b/qtv/source/sv_parse.c @@ -214,6 +214,7 @@ sv_skins_f (server_t *sv) // actual in-game update messages MSG_WriteByte (&sv->netchan.message, qtv_stringcmd); MSG_WriteString (&sv->netchan.message, va (0, "begin %d", sv->spawncount)); + sv->worldmodel = Mod_ForName (sv->modelllist[1], false); sv->next_run = realtime; sv->connected = 2; sv->delta = -1;