From e0512e4af368e021ed5d8139dbe02049950f44b7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 20 May 2001 01:58:59 +0000 Subject: [PATCH] r_efrag.c is almost client.h free --- include/QF/render.h | 2 ++ include/r_shared.h | 2 ++ nq/include/client.h | 3 --- nq/source/cl_main.c | 9 ++------- nq/source/r_efrag.c | 36 ++++++++++++++++++++++++++---------- qw/include/client.h | 3 --- qw/source/cl_main.c | 12 ++---------- qw/source/r_efrag.c | 41 ++++++++++++++++++++++++++++------------- 8 files changed, 62 insertions(+), 46 deletions(-) diff --git a/include/QF/render.h b/include/QF/render.h index fd2a9baa9..4b0f567d8 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -162,4 +162,6 @@ void R_SetVrect (vrect_t *pvrect, vrect_t *pvrectin, int lineadj); void R_LoadSkys (const char *); +void R_ClearEfrags (void); + #endif // __render_h diff --git a/include/r_shared.h b/include/r_shared.h index 63ec2db55..d2da772a8 100644 --- a/include/r_shared.h +++ b/include/r_shared.h @@ -33,6 +33,8 @@ #include "d_iface.h" +#define MAX_EFRAGS 640 + #define MAXVERTS 16 // max points in a surface polygon #define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate // polygon (while processing) diff --git a/nq/include/client.h b/nq/include/client.h index fbaeb4914..ef648efde 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -84,7 +84,6 @@ typedef struct #define MAX_DEMOS 8 #define MAX_DEMONAME 16 -#define MAX_EFRAGS 640 #define MAX_MAPSTRING 2048 typedef enum { @@ -221,7 +220,6 @@ typedef struct // refresh related state struct model_s *worldmodel; // cl_entitites[0].model - struct efrag_s *free_efrags; int num_entities; // held in cl_entities array int num_statics; // held in cl_staticentities array entity_t viewent; // the gun model @@ -281,7 +279,6 @@ extern struct cvar_s *cl_name; extern client_state_t cl; // FIXME, allocate dynamically -extern efrag_t cl_efrags[MAX_EFRAGS]; extern entity_t cl_entities[MAX_EDICTS]; extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index c3359687d..0bf40b53b 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -84,7 +84,6 @@ client_static_t cls; client_state_t cl; // FIXME: put these on hunk? -efrag_t cl_efrags[MAX_EFRAGS]; entity_t cl_entities[MAX_EDICTS]; entity_state_t cl_baselines[MAX_EDICTS]; entity_t cl_static_entities[MAX_STATIC_ENTITIES]; @@ -172,7 +171,6 @@ CL_ClearState (void) SZ_Clear (&cls.message); // clear other arrays - memset (cl_efrags, 0, sizeof (cl_efrags)); memset (cl_entities, 0, sizeof (cl_entities)); memset (cl_baselines, 0, sizeof (cl_baselines)); memset (cl_dlights, 0, sizeof (cl_dlights)); @@ -180,11 +178,8 @@ CL_ClearState (void) CL_ClearTEnts (); - // allocate the efrags and chain together into a free list - cl.free_efrags = cl_efrags; - for (i = 0; i < MAX_EFRAGS - 1; i++) - cl.free_efrags[i].entnext = &cl.free_efrags[i + 1]; - cl.free_efrags[i].entnext = NULL; + R_ClearEfrags (); + for (i = 0; i < MAX_EDICTS; i++) { cl_entities[i].baseline = &cl_baselines[i]; cl_entities[i].baseline->alpha = 255; diff --git a/nq/source/r_efrag.c b/nq/source/r_efrag.c index 262268ed8..1c9d28cff 100644 --- a/nq/source/r_efrag.c +++ b/nq/source/r_efrag.c @@ -31,12 +31,16 @@ #endif #include "QF/console.h" +#include "QF/render.h" #include "QF/sys.h" #include "client.h" #include "r_local.h" mnode_t *r_pefragtopnode; +efrag_t *r_free_efrags; +// FIXME: put this on hunk? +efrag_t r_efrags[MAX_EFRAGS]; //=========================================================================== @@ -81,8 +85,8 @@ R_RemoveEfrags (entity_t *ent) ef = ef->entnext; // put it on the free list - old->entnext = cl.free_efrags; - cl.free_efrags = old; + old->entnext = r_free_efrags; + r_free_efrags = old; } ent->efrag = NULL; @@ -111,12 +115,12 @@ R_SplitEntityOnNode (mnode_t *node) leaf = (mleaf_t *) node; // grab an efrag off the free list - ef = cl.free_efrags; + ef = r_free_efrags; if (!ef) { Con_Printf ("Too many efrags!\n"); return; // no free fragments... } - cl.free_efrags = cl.free_efrags->entnext; + r_free_efrags = r_free_efrags->entnext; ef->entity = r_addent; @@ -199,7 +203,7 @@ R_AddEfrags (entity_t *ent) if (!ent->model) return; - if (ent == cl_entities) + if (ent == &r_worldentity) return; // never add the world r_addent = ent; @@ -214,7 +218,7 @@ R_AddEfrags (entity_t *ent) r_emaxs[i] = ent->origin[i] + entmodel->maxs[i]; } - R_SplitEntityOnNode (cl.worldmodel->nodes); + R_SplitEntityOnNode (r_worldentity.model->nodes); ent->topnode = r_pefragtopnode; } @@ -229,15 +233,15 @@ void R_StoreEfrags (efrag_t **ppefrag) { entity_t *pent; - model_t *clmodel; + model_t *model; efrag_t *pefrag; while ((pefrag = *ppefrag) != NULL) { pent = pefrag->entity; - clmodel = pent->model; + model = pent->model; - switch (clmodel->type) { + switch (model->type) { case mod_alias: case mod_brush: case mod_sprite: @@ -258,7 +262,19 @@ R_StoreEfrags (efrag_t **ppefrag) default: Sys_Error ("R_StoreEfrags: Bad entity type %d\n", - clmodel->type); + model->type); } } } + +void +R_ClearEfrags (void) +{ + // allocate the efrags and chain together into a free list + int i; + + r_free_efrags = r_efrags; + for (i = 0; i < MAX_EFRAGS - 1; i++) + r_free_efrags[i].entnext = &r_free_efrags[i + 1]; + r_free_efrags[i].entnext = NULL; +} diff --git a/qw/include/client.h b/qw/include/client.h index 7c9579624..d9b1db95b 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -124,7 +124,6 @@ typedef struct #define MAX_DEMOS 8 #define MAX_DEMONAME 16 -#define MAX_EFRAGS 512 typedef enum { @@ -267,7 +266,6 @@ typedef struct // refresh related state struct model_s *worldmodel; // cl_entitites[0].model - struct efrag_s *free_efrags; int num_entities; // stored bottom up in cl_entities array int num_statics; // stored top down in cl_entitiers @@ -318,7 +316,6 @@ extern client_state_t cl; // FIXME, allocate dynamically extern entity_state_t cl_baselines[MAX_EDICTS]; -extern efrag_t cl_efrags[MAX_EFRAGS]; extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; extern dlight_t cl_dlights[MAX_DLIGHTS]; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 185a7bbf4..1b4fe6c1e 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -405,8 +405,6 @@ CL_Rcon_f (void) void CL_ClearState (void) { - int i; - S_StopAllSounds (true); Con_DPrintf ("Clearing memory\n"); @@ -418,6 +416,8 @@ CL_ClearState (void) CL_ClearEnts (); CL_ClearTEnts (); + R_ClearEfrags (); + // wipe the entire cl structure memset (&cl, 0, sizeof (cl)); @@ -427,14 +427,6 @@ CL_ClearState (void) memset (cl_efrags, 0, sizeof (cl_efrags)); memset (cl_dlights, 0, sizeof (cl_dlights)); memset (cl_lightstyle, 0, sizeof (cl_lightstyle)); - -// -// allocate the efrags and chain together into a free list -// - cl.free_efrags = cl_efrags; - for (i = 0; i < MAX_EFRAGS - 1; i++) - cl.free_efrags[i].entnext = &cl.free_efrags[i + 1]; - cl.free_efrags[i].entnext = NULL; } diff --git a/qw/source/r_efrag.c b/qw/source/r_efrag.c index 623435bc8..bd5455814 100644 --- a/qw/source/r_efrag.c +++ b/qw/source/r_efrag.c @@ -30,14 +30,17 @@ # include "config.h" #endif -#include "bothdefs.h" -#include "cl_main.h" -#include "cl_tent.h" #include "QF/console.h" -#include "r_local.h" +#include "QF/render.h" #include "QF/sys.h" +#include "cl_tent.h" +#include "r_local.h" + mnode_t *r_pefragtopnode; +efrag_t *r_free_efrags; +// FIXME: put this on hunk? +efrag_t r_efrags[MAX_EFRAGS]; //=========================================================================== @@ -82,8 +85,8 @@ R_RemoveEfrags (entity_t *ent) ef = ef->entnext; // put it on the free list - old->entnext = cl.free_efrags; - cl.free_efrags = old; + old->entnext = r_free_efrags; + r_free_efrags = old; } ent->efrag = NULL; @@ -112,12 +115,12 @@ R_SplitEntityOnNode (mnode_t *node) leaf = (mleaf_t *) node; // grab an efrag off the free list - ef = cl.free_efrags; + ef = r_free_efrags; if (!ef) { Con_Printf ("Too many efrags!\n"); return; // no free fragments... } - cl.free_efrags = cl.free_efrags->entnext; + r_free_efrags = r_free_efrags->entnext; ef->entity = r_addent; @@ -215,7 +218,7 @@ R_AddEfrags (entity_t *ent) r_emaxs[i] = ent->origin[i] + entmodel->maxs[i]; } - R_SplitEntityOnNode (cl.worldmodel->nodes); + R_SplitEntityOnNode (r_worldentity.model->nodes); ent->topnode = r_pefragtopnode; } @@ -230,15 +233,15 @@ void R_StoreEfrags (efrag_t **ppefrag) { entity_t *pent; - model_t *clmodel; + model_t *model; efrag_t *pefrag; while ((pefrag = *ppefrag) != NULL) { pent = pefrag->entity; - clmodel = pent->model; + model = pent->model; - switch (clmodel->type) { + switch (model->type) { case mod_alias: case mod_brush: case mod_sprite: @@ -259,7 +262,19 @@ R_StoreEfrags (efrag_t **ppefrag) default: Sys_Error ("R_StoreEfrags: Bad entity type %d\n", - clmodel->type); + model->type); } } } + +void +R_ClearEfrags (void) +{ + // allocate the efrags and chain together into a free list + int i; + + r_free_efrags = r_efrags; + for (i = 0; i < MAX_EFRAGS - 1; i++) + r_free_efrags[i].entnext = &r_free_efrags[i + 1]; + r_free_efrags[i].entnext = NULL; +}