[qtv] Fix a pile of bit-rot

qtv compiles again after rebasing. I doubt the changes actually work.
This commit is contained in:
Bill Currie 2021-12-26 14:45:32 +09:00
parent 0ba00652a1
commit 046b9600d5
4 changed files with 76 additions and 26 deletions

View file

@ -95,6 +95,7 @@ typedef struct server_s {
char *modellist[MAX_MODELS + 1];
char *lightstyles[MAX_LIGHTSTYLES];
struct model_s *worldmodel;
struct set_s *fatpvs;
int playermodel;
int num_signon_buffers;
int signon_buffer_size[MAX_SIGNON_BUFFERS];

View file

@ -35,6 +35,7 @@ qtv_LIBS= \
@server_static_plugin_libs@ \
libs/qw/libqw.a \
libs/net/libnet_chan.la \
libs/models/libQFmodels.la \
libs/console/libQFconsole.la \
libs/ui/libQFui.la \
libs/util/libQFutil.la

View file

@ -48,6 +48,7 @@
#include "QF/hash.h"
#include "QF/idparse.h"
#include "QF/info.h"
#include "QF/set.h"
#include "QF/sys.h"
#include "QF/va.h"
@ -976,14 +977,9 @@ 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)
add_to_fat_pvs (vec4f_t org, mnode_t *node, server_t *sv)
{
byte *pvs;
int i;
float d;
plane_t *plane;
@ -991,9 +987,8 @@ add_to_fat_pvs (vec3_t org, mnode_t *node, server_t *sv)
// 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];
set_union (sv->fatpvs, Mod_LeafPVS ((mleaf_t *) node,
sv->worldmodel));
}
return;
}
@ -1011,24 +1006,28 @@ add_to_fat_pvs (vec3_t org, mnode_t *node, server_t *sv)
}
}
static byte *
fat_pvs (vec3_t org, server_t *sv)
static set_t *
fat_pvs (vec4f_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;
if (!sv->fatpvs) {
sv->fatpvs = set_new_size (sv->worldmodel->brush.visleafs);
}
set_expand (sv->fatpvs, sv->worldmodel->brush.visleafs);
set_empty (sv->fatpvs);
add_to_fat_pvs (org, sv->worldmodel->brush.nodes, sv);
return sv->fatpvs;
}
static void
write_entities (client_t *client, sizebuf_t *msg)
{
byte *pvs = 0;
int i;
set_t *pvs = 0;
int e;
vec3_t org;
vec4f_t org;
frame_t *frame;
entity_state_t *ent;
qtv_entity_t *ent;
qtv_leaf_t *el;
entity_state_t *state;
packet_entities_t *pack;
server_t *sv = client->server;
@ -1037,7 +1036,7 @@ write_entities (client_t *client, sizebuf_t *msg)
frame = &client->frames[client->netchan.incoming_sequence & UPDATE_MASK];
// find the client's PVS
VectorCopy (client->state.origin, org);
org = client->state.es.origin;
org[2] += 22; //XXX standard spectator view offset
pvs = fat_pvs (org, sv);
@ -1052,15 +1051,16 @@ write_entities (client_t *client, sizebuf_t *msg)
e++, ent++) {
if (!sv->ent_valid[e])
continue;
if (ent->number && ent->number != e)
qtv_printf ("%d %d\n", e, ent->number);
if (ent->e.number && ent->e.number != e)
qtv_printf ("%d %d\n", e, ent->e.number);
if (pvs) {
// ignore if not touching a PV leaf
for (i = 0; i < ent->num_leafs; i++)
if (pvs[ent->leafnums[i] >> 3] & (1 << (ent->leafnums[i] & 7)))
for (el = ent->leafs; el; el = el->next) {
if (set_is_member (pvs, el->num))
break;
}
if (i == ent->num_leafs)
if (!el)
continue; // not visible
}
// if (SV_AddNailUpdate (ent))
@ -1074,7 +1074,7 @@ write_entities (client_t *client, sizebuf_t *msg)
state = &pack->entities[pack->num_entities];
pack->num_entities++;
*state = *ent;
*state = ent->e;
state->flags = 0;
}
// encode the packet entities as a delta from the

View file

@ -109,6 +109,50 @@ free_qtv_leafs (qtv_leaf_t **leafs)
*leafs = 0;
}
static void
sv_unlink_entity (server_t *sv, qtv_entity_t *ent)
{
free_qtv_leafs (&ent->leafs);
}
static void
sv_find_touched_leafs (server_t *sv, qtv_entity_t *ent, mnode_t *node)
{
if (node->contents == CONTENTS_SOLID) {
return;
}
// add an efrag if the node is a leaf
if (node->contents < 0) {
qtv_leaf_t *ent_leaf = alloc_qtv_leaf ();
ent_leaf->num = (mleaf_t *) node - sv->worldmodel->brush.leafs - 1;
ent_leaf->next = ent->leafs;
ent->leafs = ent_leaf;
return;
}
vec3_t emins, emaxs;
vec4f_t mins = {-64, -64, -64, 0};//FIXME
vec4f_t maxs = {64, 64, 64, 0};
VectorAdd (ent->e.origin, mins, emins);
VectorAdd (ent->e.origin, maxs, emaxs);
plane_t *splitplane = node->plane;
int sides = BOX_ON_PLANE_SIDE (emins, emaxs, splitplane);
if (sides & 1) {
sv_find_touched_leafs (sv, ent, node->children[0]);
}
if (sides & 2) {
sv_find_touched_leafs (sv, ent, node->children[1]);
}
}
static void
sv_link_entity (server_t *sv, qtv_entity_t *ent)
{
sv_unlink_entity (sv, ent);
sv_find_touched_leafs (sv, ent, sv->worldmodel->brush.nodes);
}
static void
sv_serverdata (server_t *sv, qmsg_t *msg)
{
@ -479,6 +523,7 @@ sv_packetentities (server_t *sv, qmsg_t *msg, int delta)
newp->entities[newindex] = oldp->entities[oldindex];
num = newp->entities[newindex].number;
sv->entities[num].e = newp->entities[newindex];
sv_link_entity (sv, &sv->entities[num]);
sv->ent_valid[num] = 1;
newindex++;
oldindex++;
@ -506,6 +551,7 @@ sv_packetentities (server_t *sv, qmsg_t *msg, int delta)
newp->entities[newindex] = oldp->entities[oldindex];
num = newp->entities[newindex].number;
sv->entities[num].e = newp->entities[newindex];
sv_link_entity (sv, &sv->entities[num]);
sv->ent_valid[num] = 1;
newindex++;
oldindex++;
@ -533,6 +579,7 @@ sv_packetentities (server_t *sv, qmsg_t *msg, int delta)
newp->entities[newindex] = sv->baselines[newnum];
sv_parse_delta (msg, word, &newp->entities[newindex]);
sv->entities[newnum].e = newp->entities[newindex];
sv_link_entity (sv, &sv->entities[newnum]);
newindex++;
continue;
}
@ -549,6 +596,7 @@ sv_packetentities (server_t *sv, qmsg_t *msg, int delta)
newp->entities[newindex] = oldp->entities[oldindex];
sv_parse_delta (msg, word, &newp->entities[newindex]);
sv->entities[newnum].e = newp->entities[newindex];
sv_link_entity (sv, &sv->entities[newnum]);
sv->ent_valid[newnum] = 1;
newindex++;
oldindex++;