[qw] Use a dynamic array to track static entities

This takes care of another fixme in the cleanup of entity_t.
This commit is contained in:
Bill Currie 2021-03-11 09:11:08 +09:00
parent c05a15dec5
commit 51e8694195
5 changed files with 10 additions and 9 deletions

View file

@ -69,6 +69,8 @@
ele_type *a; \
}
#define DARRAY_STATIC_INIT(g) { .grow = g }
/** Allocate a fixed-size array using the given allocator
The allocated array is initilized to be ungrowable, and with both size

View file

@ -124,7 +124,6 @@ typedef struct renderer_s {
typedef struct entity_s {
struct entity_s *next;
struct entity_s *unext; //FIXME this shouldn't be here. for qw demos
struct transform_s *transform;
animation_t animation;

View file

@ -28,6 +28,7 @@
#ifndef _CLIENT_H
#define _CLIENT_H
#include "QF/entity.h"
#include "QF/info.h"
#include "QF/quakefs.h"
#include "QF/vid.h"
@ -341,7 +342,7 @@ extern struct cvar_s *cl_fb_players;
extern client_state_t cl;
extern entity_t *cl_static_entities;
extern entityset_t cl_static_entities;
extern entity_t cl_entities[512];
extern byte cl_entity_valid[2][512];

View file

@ -755,7 +755,9 @@ demo_start_recording (int track)
SZ_Clear (&buf);
}
// spawnstatic
for (ent = cl_static_entities; ent; ent = ent->unext) {
for (size_t staticIndex = 0; staticIndex < cl_static_entities.size;
staticIndex++) {
ent = cl_static_entities.a[staticIndex];
MSG_WriteByte (&buf, svc_spawnstatic);
for (j = 1; j < cl.nummodels; j++) {

View file

@ -169,8 +169,7 @@ int packet_latency[NET_TIMINGS];
extern cvar_t *hud_scoreboard_uid;
entity_t *cl_static_entities;
static entity_t **cl_static_tail;
entityset_t cl_static_entities = DARRAY_STATIC_INIT (32);
static void
CL_LoadSky (void)
@ -298,8 +297,7 @@ map_ent (const char *mapname)
static void
CL_NewMap (const char *mapname)
{
cl_static_entities = 0;
cl_static_tail = &cl_static_entities;
cl_static_entities.size = 0;
r_funcs->R_NewMap (cl.worldmodel, cl.model_precache, cl.nummodels);
Team_NewMap ();
Con_NewMap ();
@ -973,8 +971,7 @@ CL_ParseStatic (void)
ent = r_funcs->R_AllocEntity ();
CL_Init_Entity (ent);
*cl_static_tail = ent;
cl_static_tail = &ent->unext;
DARRAY_APPEND (&cl_static_entities, ent);
// copy it to the current state
ent->renderer.model = cl.model_precache[es.modelindex];