[models] Move brush data into its own struct

This is a big step towards a cleaner api. The struct reference in
model_t really should be a pointer, but bsp submodel(?) loading messed
that up, though that's just a matter of taking more care in the loading
code. It seems sensible to make that a separate step.
This commit is contained in:
Bill Currie 2021-02-01 19:31:11 +09:00
parent 6969adf02c
commit 34dc7cf2df
54 changed files with 607 additions and 527 deletions

View file

@ -50,6 +50,6 @@ void gl_lightmap_init (void);
void GL_BuildLightmaps (struct model_s **models, int num_models); void GL_BuildLightmaps (struct model_s **models, int num_models);
void R_BlendLightmaps (void); void R_BlendLightmaps (void);
void R_CalcLightmaps (void); void R_CalcLightmaps (void);
extern void (*R_BuildLightMap) (msurface_t *surf); extern void (*R_BuildLightMap) (mod_brush_t *brush, msurface_t *surf);
#endif // __QF_GL_lightmap_h #endif // __QF_GL_lightmap_h

View file

@ -36,7 +36,7 @@
void glsl_lightmap_init (void); void glsl_lightmap_init (void);
void glsl_R_BuildLightmaps (struct model_s **models, int num_models); void glsl_R_BuildLightmaps (struct model_s **models, int num_models);
void glsl_R_CalcLightmaps (void); void glsl_R_CalcLightmaps (void);
extern void (*glsl_R_BuildLightMap) (msurface_t *surf); extern void (*glsl_R_BuildLightMap) (mod_brush_t *brush, msurface_t *surf);
int glsl_R_LightmapTexture (void) __attribute__((pure)); int glsl_R_LightmapTexture (void) __attribute__((pure));
void glsl_R_FlushLightmaps (void); void glsl_R_FlushLightmaps (void);

View file

@ -36,12 +36,13 @@
struct vulkan_ctx_s; struct vulkan_ctx_s;
struct model_s; struct model_s;
struct mod_brush_s;
struct msurface_s; struct msurface_s;
void Vulkan_lightmap_init (struct vulkan_ctx_s *ctx); void Vulkan_lightmap_init (struct vulkan_ctx_s *ctx);
void Vulkan_BuildLightmaps (struct model_s **models, int num_models, struct vulkan_ctx_s *ctx); void Vulkan_BuildLightmaps (struct model_s **models, int num_models, struct vulkan_ctx_s *ctx);
void Vulkan_CalcLightmaps (struct vulkan_ctx_s *ctx); void Vulkan_CalcLightmaps (struct vulkan_ctx_s *ctx);
void Vulkan_BuildLightMap (struct msurface_s *surf, struct vulkan_ctx_s *ctx); void Vulkan_BuildLightMap (struct mod_brush_s *brush, struct msurface_s *surf, struct vulkan_ctx_s *ctx);
VkImageView Vulkan_LightmapImageView (struct vulkan_ctx_s *ctx) __attribute__((pure)); VkImageView Vulkan_LightmapImageView (struct vulkan_ctx_s *ctx) __attribute__((pure));
void Vulkan_FlushLightmaps (struct vulkan_ctx_s *ctx); void Vulkan_FlushLightmaps (struct vulkan_ctx_s *ctx);

View file

@ -62,7 +62,6 @@ typedef struct efrag_s {
struct efrag_s *entnext; struct efrag_s *entnext;
} efrag_t; } efrag_t;
// in memory representation =================================================== // in memory representation ===================================================
// !!! if this is changed, it must be changed in asm_draw.h too !!! // !!! if this is changed, it must be changed in asm_draw.h too !!!
@ -228,6 +227,58 @@ typedef struct hull_s {
int depth; ///< maximum depth of the tree int depth; ///< maximum depth of the tree
} hull_t; } hull_t;
typedef struct mod_brush_s {
int firstmodelsurface, nummodelsurfaces;
int numsubmodels;
dmodel_t *submodels;
int numplanes;
plane_t *planes;
int numleafs; // number of visible leafs, not counting 0
mleaf_t *leafs;
int numvertexes;
mvertex_t *vertexes;
int numedges;
medge_t *edges;
int numnodes;
mnode_t *nodes;
int depth; ///< maximum depth of the tree
int numtexinfo;
mtexinfo_t *texinfo;
int numsurfaces;
msurface_t *surfaces;
int numsurfedges;
int *surfedges;
int numclipnodes;
mclipnode_t *clipnodes;
int nummarksurfaces;
msurface_t **marksurfaces;
hull_t hulls[MAX_MAP_HULLS];
hull_t *hull_list[MAX_MAP_HULLS];
int numtextures;
texture_t **textures;
texture_t *skytexture;
byte *visdata;
byte *lightdata;
char *entities; //FIXME should not be here
unsigned int checksum;
unsigned int checksum2;
} mod_brush_t;
// SPRITE MODELS ============================================================== // SPRITE MODELS ==============================================================
// FIXME: shorten these? // FIXME: shorten these?
@ -375,55 +426,8 @@ typedef struct model_s {
vec3_t clipmins, clipmaxs; vec3_t clipmins, clipmaxs;
// brush model // brush model
int firstmodelsurface, nummodelsurfaces; //FIXME should be a pointer (submodels make things tricky)
mod_brush_t brush;
int numsubmodels;
dmodel_t *submodels;
int numplanes;
plane_t *planes;
int numleafs; // number of visible leafs, not counting 0
mleaf_t *leafs;
int numvertexes;
mvertex_t *vertexes;
int numedges;
medge_t *edges;
int numnodes;
mnode_t *nodes;
int depth; ///< maximum depth of the tree
int numtexinfo;
mtexinfo_t *texinfo;
int numsurfaces;
msurface_t *surfaces;
int numsurfedges;
int *surfedges;
int numclipnodes;
mclipnode_t *clipnodes;
int nummarksurfaces;
msurface_t **marksurfaces;
hull_t hulls[MAX_MAP_HULLS];
hull_t *hull_list[MAX_MAP_HULLS];
int numtextures;
texture_t **textures;
texture_t *skytexture;
byte *visdata;
byte *lightdata;
char *entities;
unsigned int checksum;
unsigned int checksum2;
// additional model data // additional model data
cache_user_t cache; cache_user_t cache;

View file

@ -149,7 +149,7 @@ typedef struct vid_render_funcs_s {
void (*R_ClearState) (void); void (*R_ClearState) (void);
void (*R_LoadSkys) (const char *); void (*R_LoadSkys) (const char *);
void (*R_NewMap) (model_t *worldmodel, model_t **models, int num_models); void (*R_NewMap) (model_t *worldmodel, model_t **models, int num_models);
void (*R_AddEfrags) (entity_t *ent); void (*R_AddEfrags) (mod_brush_t *brush, entity_t *ent);
void (*R_RemoveEfrags) (entity_t *ent); void (*R_RemoveEfrags) (entity_t *ent);
void (*R_EnqueueEntity) (struct entity_s *ent); //FIXME should not be here void (*R_EnqueueEntity) (struct entity_s *ent); //FIXME should not be here
void (*R_LineGraph) (int x, int y, int *h_vals, int count); void (*R_LineGraph) (int x, int y, int *h_vals, int count);

View file

@ -83,7 +83,7 @@ void R_RenderView (void); // must set r_refdef first
void R_ViewChanged (float aspect); // must set r_refdef first void R_ViewChanged (float aspect); // must set r_refdef first
// called whenever r_refdef or vid change // called whenever r_refdef or vid change
void R_AddEfrags (entity_t *ent); void R_AddEfrags (mod_brush_t *, entity_t *ent);
void R_RemoveEfrags (entity_t *ent); void R_RemoveEfrags (entity_t *ent);
void R_NewMap (model_t *worldmodel, model_t **models, int num_models); void R_NewMap (model_t *worldmodel, model_t **models, int num_models);

View file

@ -182,7 +182,7 @@ void R_RemoveEdges (edge_t *pedge);
void R_AddTexture (texture_t *tex); void R_AddTexture (texture_t *tex);
struct vulkan_ctx_s; struct vulkan_ctx_s;
void R_ClearTextures (void); void R_ClearTextures (void);
void R_InitSurfaceChains (model_t *model); void R_InitSurfaceChains (mod_brush_t *brush);
extern void R_Surf8Start (void); extern void R_Surf8Start (void);
extern void R_Surf8End (void); extern void R_Surf8End (void);
@ -303,13 +303,13 @@ void R_ZGraph (void);
void R_PrintAliasStats (void); void R_PrintAliasStats (void);
void R_PrintTimes (void); void R_PrintTimes (void);
void R_AnimateLight (void); void R_AnimateLight (void);
int R_LightPoint (const vec3_t p); int R_LightPoint (mod_brush_t *brush, const vec3_t p);
void R_SetupFrame (void); void R_SetupFrame (void);
void R_cshift_f (void); void R_cshift_f (void);
void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1); void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);
void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip); void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
void R_RecursiveMarkLights (const vec3_t lightorigin, struct dlight_s *light, void R_RecursiveMarkLights (mod_brush_t *brush, const vec3_t lightorigin,
int bit, mnode_t *node); struct dlight_s *light, int bit, mnode_t *node);
void R_MarkLights (const vec3_t lightorigin, struct dlight_s *light, int bit, void R_MarkLights (const vec3_t lightorigin, struct dlight_s *light, int bit,
model_t *model); model_t *model);

View file

@ -150,9 +150,10 @@ gl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
size_t i; size_t i;
int ver; int ver;
QFile *lit_file; QFile *lit_file;
mod_brush_t *brush = &mod->brush;
dstring_copystr (litfilename, mod->path); dstring_copystr (litfilename, mod->path);
mod->lightdata = NULL; brush->lightdata = NULL;
if (mod_lightmap_bytes > 1) { if (mod_lightmap_bytes > 1) {
// LordHavoc: check for a .lit file to load // LordHavoc: check for a .lit file to load
QFS_StripExtension (litfilename->str, litfilename->str); QFS_StripExtension (litfilename->str, litfilename->str);
@ -165,7 +166,7 @@ gl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
ver = LittleLong (((int32_t *) data)[1]); ver = LittleLong (((int32_t *) data)[1]);
if (ver == 1) { if (ver == 1) {
Sys_MaskPrintf (SYS_DEV, "%s loaded", litfilename->str); Sys_MaskPrintf (SYS_DEV, "%s loaded", litfilename->str);
mod->lightdata = data + 8; brush->lightdata = data + 8;
return; return;
} else } else
Sys_MaskPrintf (SYS_DEV, Sys_MaskPrintf (SYS_DEV,
@ -179,10 +180,10 @@ gl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
dstring_delete (litfilename); dstring_delete (litfilename);
return; return;
} }
mod->lightdata = Hunk_AllocName (bsp->lightdatasize * mod_lightmap_bytes, brush->lightdata = Hunk_AllocName (bsp->lightdatasize * mod_lightmap_bytes,
litfilename->str); litfilename->str);
in = bsp->lightdata; in = bsp->lightdata;
out = mod->lightdata; out = brush->lightdata;
if (mod_lightmap_bytes > 1) if (mod_lightmap_bytes > 1)
for (i = 0; i < bsp->lightdatasize ; i++) { for (i = 0; i < bsp->lightdatasize ; i++) {
@ -308,18 +309,19 @@ gl_Mod_SubdivideSurface (model_t *mod, msurface_t *fa)
float *vec; float *vec;
int lindex, numverts, i; int lindex, numverts, i;
vec3_t verts[64]; vec3_t verts[64];
mod_brush_t *brush = &mod->brush;
warpface = fa; warpface = fa;
// convert edges back to a normal polygon // convert edges back to a normal polygon
numverts = 0; numverts = 0;
for (i = 0; i < fa->numedges; i++) { for (i = 0; i < fa->numedges; i++) {
lindex = mod->surfedges[fa->firstedge + i]; lindex = brush->surfedges[fa->firstedge + i];
if (lindex > 0) if (lindex > 0)
vec = mod->vertexes[mod->edges[lindex].v[0]].position; vec = brush->vertexes[brush->edges[lindex].v[0]].position;
else else
vec = mod->vertexes[mod->edges[-lindex].v[1]].position; vec = brush->vertexes[brush->edges[-lindex].v[1]].position;
VectorCopy (vec, verts[numverts]); VectorCopy (vec, verts[numverts]);
numverts++; numverts++;
} }

View file

@ -65,13 +65,14 @@ static void
glsl_brush_clear (model_t *m, void *data) glsl_brush_clear (model_t *m, void *data)
{ {
int i; int i;
mod_brush_t *brush = &m->brush;
m->needload = true; m->needload = true;
for (i = 0; i < m->numtextures; i++) { for (i = 0; i < brush->numtextures; i++) {
// NOTE: some maps (eg e1m2) have empty texture slots // NOTE: some maps (eg e1m2) have empty texture slots
glsltex_t *tex = 0; glsltex_t *tex = 0;
if (m->textures[i]) { if (brush->textures[i]) {
tex = m->textures[i]->render; tex = brush->textures[i]->render;
} }
if (tex && tex->gl_texturenum) { if (tex && tex->gl_texturenum) {
GLSL_ReleaseTexture (tex->gl_texturenum); GLSL_ReleaseTexture (tex->gl_texturenum);
@ -80,10 +81,10 @@ glsl_brush_clear (model_t *m, void *data)
tex->gl_texturenum = 0; tex->gl_texturenum = 0;
} }
} }
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
if (m->surfaces[i].polys) { if (brush->surfaces[i].polys) {
free (m->surfaces[i].polys); free (brush->surfaces[i].polys);
m->surfaces[i].polys = 0; brush->surfaces[i].polys = 0;
} }
} }
} }
@ -151,9 +152,9 @@ glsl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
mod->clear = glsl_brush_clear; mod->clear = glsl_brush_clear;
mod_lightmap_bytes = 1; mod_lightmap_bytes = 1;
if (!bsp->lightdatasize) { if (!bsp->lightdatasize) {
mod->lightdata = NULL; mod->brush.lightdata = NULL;
return; return;
} }
mod->lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name); mod->brush.lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name);
memcpy (mod->lightdata, bsp->lightdata, bsp->lightdatasize); memcpy (mod->brush.lightdata, bsp->lightdata, bsp->lightdatasize);
} }

View file

@ -67,10 +67,10 @@ Mod_PointInLeaf (const vec3_t p, model_t *model)
mnode_t *node; mnode_t *node;
plane_t *plane; plane_t *plane;
if (!model || !model->nodes) if (!model || !model->brush.nodes)
Sys_Error ("Mod_PointInLeaf: bad model"); Sys_Error ("Mod_PointInLeaf: bad model");
node = model->nodes; node = model->brush.nodes;
while (1) { while (1) {
if (node->contents < 0) if (node->contents < 0)
return (mleaf_t *) node; return (mleaf_t *) node;
@ -86,13 +86,13 @@ Mod_PointInLeaf (const vec3_t p, model_t *model)
} }
static inline byte * static inline byte *
Mod_DecompressVis (byte * in, model_t *model) Mod_DecompressVis (byte * in, mod_brush_t *brush)
{ {
static byte decompressed[MAX_MAP_LEAFS / 8]; static byte decompressed[MAX_MAP_LEAFS / 8];
byte *out; byte *out;
int row, c; int row, c;
row = (model->numleafs + 7) >> 3; row = (brush->numleafs + 7) >> 3;
out = decompressed; out = decompressed;
if (!in) { // no vis info, so make all visible if (!in) { // no vis info, so make all visible
@ -123,13 +123,13 @@ Mod_DecompressVis (byte * in, model_t *model)
VISIBLE byte * VISIBLE byte *
Mod_LeafPVS (mleaf_t *leaf, model_t *model) Mod_LeafPVS (mleaf_t *leaf, model_t *model)
{ {
if (leaf == model->leafs) { if (leaf == model->brush.leafs) {
if (!mod_novis[0]) { if (!mod_novis[0]) {
memset (mod_novis, 0xff, sizeof (mod_novis)); memset (mod_novis, 0xff, sizeof (mod_novis));
} }
return mod_novis; return mod_novis;
} }
return Mod_DecompressVis (leaf->compressed_vis, model); return Mod_DecompressVis (leaf->compressed_vis, &model->brush);
} }
// BRUSHMODEL LOADING ========================================================= // BRUSHMODEL LOADING =========================================================
@ -170,16 +170,17 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
miptex_t *mt; miptex_t *mt;
texture_t *tx, *tx2; texture_t *tx, *tx2;
texture_t *anims[10], *altanims[10]; texture_t *anims[10], *altanims[10];
mod_brush_t *brush = &mod->brush;
if (!bsp->texdatasize) { if (!bsp->texdatasize) {
mod->textures = NULL; brush->textures = NULL;
return; return;
} }
m = (dmiptexlump_t *) bsp->texdata; m = (dmiptexlump_t *) bsp->texdata;
mod->numtextures = m->nummiptex; brush->numtextures = m->nummiptex;
mod->textures = Hunk_AllocName (m->nummiptex * sizeof (*mod->textures), brush->textures = Hunk_AllocName (m->nummiptex * sizeof (*brush->textures),
mod->name); mod->name);
for (i = 0; i < m->nummiptex; i++) { for (i = 0; i < m->nummiptex; i++) {
if (m->dataofs[i] == -1) if (m->dataofs[i] == -1)
@ -195,10 +196,10 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
pixels = mt->width * mt->height / 64 * 85; pixels = mt->width * mt->height / 64 * 85;
tx = Hunk_AllocName (sizeof (texture_t) + pixels, mod->name); tx = Hunk_AllocName (sizeof (texture_t) + pixels, mod->name);
mod->textures[i] = tx; brush->textures[i] = tx;
tx->name = strndup(mt->name, sizeof (mt->name)); tx->name = strndup(mt->name, sizeof (mt->name));
mod_unique_miptex_name (mod->textures, tx, i); mod_unique_miptex_name (brush->textures, tx, i);
tx->width = mt->width; tx->width = mt->width;
tx->height = mt->height; tx->height = mt->height;
for (j = 0; j < MIPLEVELS; j++) for (j = 0; j < MIPLEVELS; j++)
@ -208,7 +209,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
memcpy (tx + 1, mt + 1, pixels); memcpy (tx + 1, mt + 1, pixels);
if (!strncmp (mt->name, "sky", 3)) if (!strncmp (mt->name, "sky", 3))
mod->skytexture = tx; brush->skytexture = tx;
} }
if (mod_funcs && mod_funcs->Mod_ProcessTexture) { if (mod_funcs && mod_funcs->Mod_ProcessTexture) {
size_t render_size = mod_funcs->texture_render_size; size_t render_size = mod_funcs->texture_render_size;
@ -218,7 +219,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
mod->name); mod->name);
} }
for (i = 0; i < m->nummiptex; i++) { for (i = 0; i < m->nummiptex; i++) {
tx = mod->textures[i]; tx = brush->textures[i];
tx->render = render_data; tx->render = render_data;
render_data += render_size; render_data += render_size;
mod_funcs->Mod_ProcessTexture (mod, tx); mod_funcs->Mod_ProcessTexture (mod, tx);
@ -229,7 +230,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
// sequence the animations // sequence the animations
for (i = 0; i < m->nummiptex; i++) { for (i = 0; i < m->nummiptex; i++) {
tx = mod->textures[i]; tx = brush->textures[i];
if (!tx || tx->name[0] != '+') if (!tx || tx->name[0] != '+')
continue; continue;
if (tx->anim_next) if (tx->anim_next)
@ -256,7 +257,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
Sys_Error ("Bad animating texture %s", tx->name); Sys_Error ("Bad animating texture %s", tx->name);
for (j = i + 1; j < m->nummiptex; j++) { for (j = i + 1; j < m->nummiptex; j++) {
tx2 = mod->textures[j]; tx2 = brush->textures[j];
if (!tx2 || tx2->name[0] != '+') if (!tx2 || tx2->name[0] != '+')
continue; continue;
if (strcmp (tx2->name + 2, tx->name + 2)) if (strcmp (tx2->name + 2, tx->name + 2))
@ -310,22 +311,22 @@ static void
Mod_LoadVisibility (model_t *mod, bsp_t *bsp) Mod_LoadVisibility (model_t *mod, bsp_t *bsp)
{ {
if (!bsp->visdatasize) { if (!bsp->visdatasize) {
mod->visdata = NULL; mod->brush.visdata = NULL;
return; return;
} }
mod->visdata = Hunk_AllocName (bsp->visdatasize, mod->name); mod->brush.visdata = Hunk_AllocName (bsp->visdatasize, mod->name);
memcpy (mod->visdata, bsp->visdata, bsp->visdatasize); memcpy (mod->brush.visdata, bsp->visdata, bsp->visdatasize);
} }
static void static void
Mod_LoadEntities (model_t *mod, bsp_t *bsp) Mod_LoadEntities (model_t *mod, bsp_t *bsp)
{ {
if (!bsp->entdatasize) { if (!bsp->entdatasize) {
mod->entities = NULL; mod->brush.entities = NULL;
return; return;
} }
mod->entities = Hunk_AllocName (bsp->entdatasize, mod->name); mod->brush.entities = Hunk_AllocName (bsp->entdatasize, mod->name);
memcpy (mod->entities, bsp->entdata, bsp->entdatasize); memcpy (mod->brush.entities, bsp->entdata, bsp->entdatasize);
} }
static void static void
@ -339,8 +340,8 @@ Mod_LoadVertexes (model_t *mod, bsp_t *bsp)
count = bsp->numvertexes; count = bsp->numvertexes;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
mod->vertexes = out; mod->brush.vertexes = out;
mod->numvertexes = count; mod->brush.numvertexes = count;
for (i = 0; i < count; i++, in++, out++) for (i = 0; i < count; i++, in++, out++)
VectorCopy (in->point, out->position); VectorCopy (in->point, out->position);
@ -351,13 +352,14 @@ Mod_LoadSubmodels (model_t *mod, bsp_t *bsp)
{ {
dmodel_t *in, *out; dmodel_t *in, *out;
int count, i, j; int count, i, j;
mod_brush_t *brush = &mod->brush;
in = bsp->models; in = bsp->models;
count = bsp->nummodels; count = bsp->nummodels;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
mod->submodels = out; brush->submodels = out;
mod->numsubmodels = count; brush->numsubmodels = count;
for (i = 0; i < count; i++, in++, out++) { for (i = 0; i < count; i++, in++, out++) {
static vec3_t offset = {1, 1, 1}; static vec3_t offset = {1, 1, 1};
@ -372,7 +374,7 @@ Mod_LoadSubmodels (model_t *mod, bsp_t *bsp)
out->numfaces = in->numfaces; out->numfaces = in->numfaces;
} }
out = mod->submodels; out = brush->submodels;
if (out->visleafs > MAX_MAP_LEAFS) { if (out->visleafs > MAX_MAP_LEAFS) {
Sys_Error ("Mod_LoadSubmodels: too many visleafs (%d, max = %d) in %s", Sys_Error ("Mod_LoadSubmodels: too many visleafs (%d, max = %d) in %s",
@ -396,8 +398,8 @@ Mod_LoadEdges (model_t *mod, bsp_t *bsp)
count = bsp->numedges; count = bsp->numedges;
out = Hunk_AllocName ((count + 1) * sizeof (*out), mod->name); out = Hunk_AllocName ((count + 1) * sizeof (*out), mod->name);
mod->edges = out; mod->brush.edges = out;
mod->numedges = count; mod->brush.numedges = count;
for (i = 0; i < count; i++, in++, out++) { for (i = 0; i < count; i++, in++, out++) {
out->v[0] = in->v[0]; out->v[0] = in->v[0];
@ -417,8 +419,8 @@ Mod_LoadTexinfo (model_t *mod, bsp_t *bsp)
count = bsp->numtexinfo; count = bsp->numtexinfo;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
mod->texinfo = out; mod->brush.texinfo = out;
mod->numtexinfo = count; mod->brush.numtexinfo = count;
for (i = 0; i < count; i++, in++, out++) { for (i = 0; i < count; i++, in++, out++) {
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
@ -441,13 +443,13 @@ Mod_LoadTexinfo (model_t *mod, bsp_t *bsp)
miptex = in->miptex; miptex = in->miptex;
out->flags = in->flags; out->flags = in->flags;
if (!mod->textures) { if (!mod->brush.textures) {
out->texture = r_notexture_mip; // checkerboard texture out->texture = r_notexture_mip; // checkerboard texture
out->flags = 0; out->flags = 0;
} else { } else {
if (miptex >= mod->numtextures) if (miptex >= mod->brush.numtextures)
Sys_Error ("miptex >= mod->numtextures"); Sys_Error ("miptex >= mod->brush.numtextures");
out->texture = mod->textures[miptex]; out->texture = mod->brush.textures[miptex];
if (!out->texture) { if (!out->texture) {
out->texture = r_notexture_mip; // texture not found out->texture = r_notexture_mip; // texture not found
out->flags = 0; out->flags = 0;
@ -469,6 +471,7 @@ CalcSurfaceExtents (model_t *mod, msurface_t *s)
int bmins[2], bmaxs[2]; int bmins[2], bmaxs[2];
mtexinfo_t *tex; mtexinfo_t *tex;
mvertex_t *v; mvertex_t *v;
mod_brush_t *brush = &mod->brush;
mins[0] = mins[1] = 999999; mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999; maxs[0] = maxs[1] = -99999;
@ -476,11 +479,11 @@ CalcSurfaceExtents (model_t *mod, msurface_t *s)
tex = s->texinfo; tex = s->texinfo;
for (i = 0; i < s->numedges; i++) { for (i = 0; i < s->numedges; i++) {
e = mod->surfedges[s->firstedge + i]; e = brush->surfedges[s->firstedge + i];
if (e >= 0) if (e >= 0)
v = &mod->vertexes[mod->edges[e].v[0]]; v = &brush->vertexes[brush->edges[e].v[0]];
else else
v = &mod->vertexes[mod->edges[-e].v[1]]; v = &brush->vertexes[brush->edges[-e].v[1]];
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
val = v->position[0] * tex->vecs[j][0] + val = v->position[0] * tex->vecs[j][0] +
@ -512,6 +515,7 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp)
dface_t *in; dface_t *in;
int count, planenum, side, surfnum, i; int count, planenum, side, surfnum, i;
msurface_t *out; msurface_t *out;
mod_brush_t *brush = &mod->brush;
in = bsp->faces; in = bsp->faces;
count = bsp->numfaces; count = bsp->numfaces;
@ -522,8 +526,8 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp)
"%i faces exceeds standard limit of 32767.\n", count); "%i faces exceeds standard limit of 32767.\n", count);
} }
mod->surfaces = out; brush->surfaces = out;
mod->numsurfaces = count; brush->numsurfaces = count;
for (surfnum = 0; surfnum < count; surfnum++, in++, out++) { for (surfnum = 0; surfnum < count; surfnum++, in++, out++) {
out->firstedge = in->firstedge; out->firstedge = in->firstedge;
@ -535,9 +539,9 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp)
if (side) if (side)
out->flags |= SURF_PLANEBACK; out->flags |= SURF_PLANEBACK;
out->plane = mod->planes + planenum; out->plane = brush->planes + planenum;
out->texinfo = mod->texinfo + in->texinfo; out->texinfo = brush->texinfo + in->texinfo;
CalcSurfaceExtents (mod, out); CalcSurfaceExtents (mod, out);
@ -549,7 +553,7 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp)
if (i == -1) if (i == -1)
out->samples = NULL; out->samples = NULL;
else else
out->samples = mod->lightdata + (i * mod_lightmap_bytes); out->samples = brush->lightdata + (i * mod_lightmap_bytes);
// set the drawing flags flag // set the drawing flags flag
if (!out->texinfo->texture || !out->texinfo->texture->name) if (!out->texinfo->texture || !out->texinfo->texture->name)
@ -596,6 +600,7 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
dnode_t *in; dnode_t *in;
int count, i, j, p; int count, i, j, p;
mnode_t *out; mnode_t *out;
mod_brush_t *brush = &mod->brush;
in = bsp->nodes; in = bsp->nodes;
count = bsp->numnodes; count = bsp->numnodes;
@ -606,8 +611,8 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
"%i nodes exceeds standard limit of 32767.\n", count); "%i nodes exceeds standard limit of 32767.\n", count);
} }
mod->nodes = out; brush->nodes = out;
mod->numnodes = count; brush->numnodes = count;
for (i = 0; i < count; i++, in++, out++) { for (i = 0; i < count; i++, in++, out++) {
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
@ -616,7 +621,7 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
} }
p = in->planenum; p = in->planenum;
out->plane = mod->planes + p; out->plane = brush->planes + p;
out->firstsurface = in->firstface; out->firstsurface = in->firstface;
out->numsurfaces = in->numfaces; out->numsurfaces = in->numfaces;
@ -625,23 +630,23 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
p = in->children[j]; p = in->children[j];
// this check is for extended bsp 29 files // this check is for extended bsp 29 files
if (p >= 0) { if (p >= 0) {
out->children[j] = mod->nodes + p; out->children[j] = brush->nodes + p;
} else { } else {
p = ~p; p = ~p;
if (p < mod->numleafs) { if (p < brush->numleafs) {
out->children[j] = (mnode_t *) (mod->leafs + p); out->children[j] = (mnode_t *) (brush->leafs + p);
} else { } else {
Sys_Printf ("Mod_LoadNodes: invalid leaf index %i " Sys_Printf ("Mod_LoadNodes: invalid leaf index %i "
"(file has only %i leafs)\n", p, "(file has only %i leafs)\n", p,
mod->numleafs); brush->numleafs);
//map it to the solid leaf //map it to the solid leaf
out->children[j] = (mnode_t *)(mod->leafs); out->children[j] = (mnode_t *)(brush->leafs);
} }
} }
} }
} }
Mod_SetParent (mod->nodes, NULL); // sets nodes and leafs Mod_SetParent (brush->nodes, NULL); // sets nodes and leafs
} }
static void static void
@ -651,13 +656,14 @@ Mod_LoadLeafs (model_t *mod, bsp_t *bsp)
int count, i, j, p; int count, i, j, p;
mleaf_t *out; mleaf_t *out;
qboolean isnotmap = true; qboolean isnotmap = true;
mod_brush_t *brush = &mod->brush;
in = bsp->leafs; in = bsp->leafs;
count = bsp->numleafs; count = bsp->numleafs;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
mod->leafs = out; brush->leafs = out;
mod->numleafs = count; brush->numleafs = count;
// snprintf(s, sizeof (s), "maps/%s.bsp", // snprintf(s, sizeof (s), "maps/%s.bsp",
// Info_ValueForKey(cl.serverinfo,"map")); // Info_ValueForKey(cl.serverinfo,"map"));
if (!strncmp ("maps/", mod->path, 5)) if (!strncmp ("maps/", mod->path, 5))
@ -671,14 +677,14 @@ Mod_LoadLeafs (model_t *mod, bsp_t *bsp)
p = in->contents; p = in->contents;
out->contents = p; out->contents = p;
out->firstmarksurface = mod->marksurfaces + in->firstmarksurface; out->firstmarksurface = brush->marksurfaces + in->firstmarksurface;
out->nummarksurfaces = in->nummarksurfaces; out->nummarksurfaces = in->nummarksurfaces;
p = in->visofs; p = in->visofs;
if (p == -1) if (p == -1)
out->compressed_vis = NULL; out->compressed_vis = NULL;
else else
out->compressed_vis = mod->visdata + p; out->compressed_vis = brush->visdata + p;
out->efrags = NULL; out->efrags = NULL;
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
@ -703,6 +709,7 @@ Mod_LoadClipnodes (model_t *mod, bsp_t *bsp)
mclipnode_t *out; mclipnode_t *out;
hull_t *hull; hull_t *hull;
int count, i; int count, i;
mod_brush_t *brush = &mod->brush;
in = bsp->clipnodes; in = bsp->clipnodes;
count = bsp->numclipnodes; count = bsp->numclipnodes;
@ -714,15 +721,15 @@ Mod_LoadClipnodes (model_t *mod, bsp_t *bsp)
count); count);
} }
mod->clipnodes = out; brush->clipnodes = out;
mod->numclipnodes = count; brush->numclipnodes = count;
hull = &mod->hulls[1]; hull = &brush->hulls[1];
mod->hull_list[1] = hull; brush->hull_list[1] = hull;
hull->clipnodes = out; hull->clipnodes = out;
hull->firstclipnode = 0; hull->firstclipnode = 0;
hull->lastclipnode = count - 1; hull->lastclipnode = count - 1;
hull->planes = mod->planes; hull->planes = brush->planes;
hull->clip_mins[0] = -16; hull->clip_mins[0] = -16;
hull->clip_mins[1] = -16; hull->clip_mins[1] = -16;
hull->clip_mins[2] = -24; hull->clip_mins[2] = -24;
@ -730,12 +737,12 @@ Mod_LoadClipnodes (model_t *mod, bsp_t *bsp)
hull->clip_maxs[1] = 16; hull->clip_maxs[1] = 16;
hull->clip_maxs[2] = 32; hull->clip_maxs[2] = 32;
hull = &mod->hulls[2]; hull = &brush->hulls[2];
mod->hull_list[2] = hull; brush->hull_list[2] = hull;
hull->clipnodes = out; hull->clipnodes = out;
hull->firstclipnode = 0; hull->firstclipnode = 0;
hull->lastclipnode = count - 1; hull->lastclipnode = count - 1;
hull->planes = mod->planes; hull->planes = brush->planes;
hull->clip_mins[0] = -32; hull->clip_mins[0] = -32;
hull->clip_mins[1] = -32; hull->clip_mins[1] = -32;
hull->clip_mins[2] = -24; hull->clip_mins[2] = -24;
@ -745,7 +752,7 @@ Mod_LoadClipnodes (model_t *mod, bsp_t *bsp)
for (i = 0; i < count; i++, out++, in++) { for (i = 0; i < count; i++, out++, in++) {
out->planenum = in->planenum; out->planenum = in->planenum;
if (out->planenum < 0 || out->planenum >= mod->numplanes) if (out->planenum < 0 || out->planenum >= brush->numplanes)
Sys_Error ("Mod_LoadClipnodes: planenum out of bounds"); Sys_Error ("Mod_LoadClipnodes: planenum out of bounds");
out->children[0] = in->children[0]; out->children[0] = in->children[0];
out->children[1] = in->children[1]; out->children[1] = in->children[1];
@ -776,27 +783,28 @@ Mod_MakeHull0 (model_t *mod)
hull_t *hull; hull_t *hull;
int count, i, j; int count, i, j;
mnode_t *in, *child; mnode_t *in, *child;
mod_brush_t *brush = &mod->brush;
hull = &mod->hulls[0]; hull = &brush->hulls[0];
mod->hull_list[0] = hull; brush->hull_list[0] = hull;
in = mod->nodes; in = brush->nodes;
count = mod->numnodes; count = brush->numnodes;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
hull->clipnodes = out; hull->clipnodes = out;
hull->firstclipnode = 0; hull->firstclipnode = 0;
hull->lastclipnode = count - 1; hull->lastclipnode = count - 1;
hull->planes = mod->planes; hull->planes = brush->planes;
for (i = 0; i < count; i++, out++, in++) { for (i = 0; i < count; i++, out++, in++) {
out->planenum = in->plane - mod->planes; out->planenum = in->plane - brush->planes;
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
child = in->children[j]; child = in->children[j];
if (child->contents < 0) if (child->contents < 0)
out->children[j] = child->contents; out->children[j] = child->contents;
else else
out->children[j] = child - mod->nodes; out->children[j] = child - brush->nodes;
} }
} }
} }
@ -807,6 +815,7 @@ Mod_LoadMarksurfaces (model_t *mod, bsp_t *bsp)
int count, i, j; int count, i, j;
msurface_t **out; msurface_t **out;
uint32_t *in; uint32_t *in;
mod_brush_t *brush = &mod->brush;
in = bsp->marksurfaces; in = bsp->marksurfaces;
count = bsp->nummarksurfaces; count = bsp->nummarksurfaces;
@ -818,14 +827,14 @@ Mod_LoadMarksurfaces (model_t *mod, bsp_t *bsp)
count); count);
} }
mod->marksurfaces = out; brush->marksurfaces = out;
mod->nummarksurfaces = count; brush->nummarksurfaces = count;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
j = in[i]; j = in[i];
if (j >= mod->numsurfaces) if (j >= brush->numsurfaces)
Sys_Error ("Mod_ParseMarksurfaces: bad surface number"); Sys_Error ("Mod_ParseMarksurfaces: bad surface number");
out[i] = mod->surfaces + j; out[i] = brush->surfaces + j;
} }
} }
@ -835,13 +844,14 @@ Mod_LoadSurfedges (model_t *mod, bsp_t *bsp)
int count, i; int count, i;
int32_t *in; int32_t *in;
int *out; int *out;
mod_brush_t *brush = &mod->brush;
in = bsp->surfedges; in = bsp->surfedges;
count = bsp->numsurfedges; count = bsp->numsurfedges;
out = Hunk_AllocName (count * sizeof (*out), mod->name); out = Hunk_AllocName (count * sizeof (*out), mod->name);
mod->surfedges = out; brush->surfedges = out;
mod->numsurfedges = count; brush->numsurfedges = count;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
out[i] = in[i]; out[i] = in[i];
@ -853,13 +863,14 @@ Mod_LoadPlanes (model_t *mod, bsp_t *bsp)
dplane_t *in; dplane_t *in;
int bits, count, i, j; int bits, count, i, j;
plane_t *out; plane_t *out;
mod_brush_t *brush = &mod->brush;
in = bsp->planes; in = bsp->planes;
count = bsp->numplanes; count = bsp->numplanes;
out = Hunk_AllocName (count * 2 * sizeof (*out), mod->name); out = Hunk_AllocName (count * 2 * sizeof (*out), mod->name);
mod->planes = out; brush->planes = out;
mod->numplanes = count; brush->numplanes = count;
for (i = 0; i < count; i++, in++, out++) { for (i = 0; i < count; i++, in++, out++) {
bits = 0; bits = 0;
@ -881,12 +892,13 @@ do_checksums (const bsp_t *bsp, void *_mod)
int i; int i;
model_t *mod = (model_t *) _mod; model_t *mod = (model_t *) _mod;
byte *base; byte *base;
mod_brush_t *brush = &mod->brush;
base = (byte *) bsp->header; base = (byte *) bsp->header;
// checksum all of the map, except for entities // checksum all of the map, except for entities
mod->checksum = 0; brush->checksum = 0;
mod->checksum2 = 0; brush->checksum2 = 0;
for (i = 0; i < HEADER_LUMPS; i++) { for (i = 0; i < HEADER_LUMPS; i++) {
lump_t *lump = bsp->header->lumps + i; lump_t *lump = bsp->header->lumps + i;
int csum; int csum;
@ -894,30 +906,30 @@ do_checksums (const bsp_t *bsp, void *_mod)
if (i == LUMP_ENTITIES) if (i == LUMP_ENTITIES)
continue; continue;
csum = Com_BlockChecksum (base + lump->fileofs, lump->filelen); csum = Com_BlockChecksum (base + lump->fileofs, lump->filelen);
mod->checksum ^= csum; brush->checksum ^= csum;
if (i != LUMP_VISIBILITY && i != LUMP_LEAFS && i != LUMP_NODES) if (i != LUMP_VISIBILITY && i != LUMP_LEAFS && i != LUMP_NODES)
mod->checksum2 ^= csum; brush->checksum2 ^= csum;
} }
} }
static void static void
recurse_draw_tree (model_t *mod, mnode_t *node, int depth) recurse_draw_tree (mod_brush_t *brush, mnode_t *node, int depth)
{ {
if (!node || node->contents < 0) { if (!node || node->contents < 0) {
if (depth > mod->depth) if (depth > brush->depth)
mod->depth = depth; brush->depth = depth;
return; return;
} }
recurse_draw_tree (mod, node->children[0], depth + 1); recurse_draw_tree (brush, node->children[0], depth + 1);
recurse_draw_tree (mod, node->children[1], depth + 1); recurse_draw_tree (brush, node->children[1], depth + 1);
} }
static void static void
Mod_FindDrawDepth (model_t *mod) Mod_FindDrawDepth (mod_brush_t *brush)
{ {
mod->depth = 0; brush->depth = 0;
recurse_draw_tree (mod, mod->nodes, 1); recurse_draw_tree (brush, brush->nodes, 1);
} }
void void
@ -954,35 +966,35 @@ Mod_LoadBrushModel (model_t *mod, void *buffer)
Mod_MakeHull0 (mod); Mod_MakeHull0 (mod);
Mod_FindDrawDepth (mod); Mod_FindDrawDepth (&mod->brush);
for (i = 0; i < MAX_MAP_HULLS; i++) for (i = 0; i < MAX_MAP_HULLS; i++)
Mod_FindClipDepth (&mod->hulls[i]); Mod_FindClipDepth (&mod->brush.hulls[i]);
mod->numframes = 2; // regular and alternate animation mod->numframes = 2; // regular and alternate animation
// set up the submodels (FIXME: this is confusing) // set up the submodels (FIXME: this is confusing)
for (i = 0; i < mod->numsubmodels; i++) { for (i = 0; i < mod->brush.numsubmodels; i++) {
bm = &mod->submodels[i]; bm = &mod->brush.submodels[i];
mod->hulls[0].firstclipnode = bm->headnode[0]; mod->brush.hulls[0].firstclipnode = bm->headnode[0];
mod->hull_list[0] = &mod->hulls[0]; mod->brush.hull_list[0] = &mod->brush.hulls[0];
for (j = 1; j < MAX_MAP_HULLS; j++) { for (j = 1; j < MAX_MAP_HULLS; j++) {
mod->hulls[j].firstclipnode = bm->headnode[j]; mod->brush.hulls[j].firstclipnode = bm->headnode[j];
mod->hulls[j].lastclipnode = mod->numclipnodes - 1; mod->brush.hulls[j].lastclipnode = mod->brush.numclipnodes - 1;
mod->hull_list[j] = &mod->hulls[j]; mod->brush.hull_list[j] = &mod->brush.hulls[j];
} }
mod->firstmodelsurface = bm->firstface; mod->brush.firstmodelsurface = bm->firstface;
mod->nummodelsurfaces = bm->numfaces; mod->brush.nummodelsurfaces = bm->numfaces;
VectorCopy (bm->maxs, mod->maxs); VectorCopy (bm->maxs, mod->maxs);
VectorCopy (bm->mins, mod->mins); VectorCopy (bm->mins, mod->mins);
mod->radius = RadiusFromBounds (mod->mins, mod->maxs); mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
mod->numleafs = bm->visleafs; mod->brush.numleafs = bm->visleafs;
if (i < mod->numsubmodels - 1) { if (i < mod->brush.numsubmodels - 1) {
// duplicate the basic information // duplicate the basic information
char name[12]; char name[12];

View file

@ -45,9 +45,9 @@ sw_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
{ {
mod_lightmap_bytes = 1; mod_lightmap_bytes = 1;
if (!bsp->lightdatasize) { if (!bsp->lightdatasize) {
mod->lightdata = NULL; mod->brush.lightdata = NULL;
return; return;
} }
mod->lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name); mod->brush.lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name);
memcpy (mod->lightdata, bsp->lightdata, bsp->lightdatasize); memcpy (mod->brush.lightdata, bsp->lightdata, bsp->lightdatasize);
} }

View file

@ -69,9 +69,10 @@ static void vulkan_brush_clear (model_t *mod, void *data)
vulkan_ctx_t *ctx = mctx->ctx; vulkan_ctx_t *ctx = mctx->ctx;
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
mod_brush_t *brush = &mod->brush;
for (int i = 0; i < mod->numtextures; i++) { for (int i = 0; i < brush->numtextures; i++) {
texture_t *tx = mod->textures[i]; texture_t *tx = brush->textures[i];
if (!tx) { if (!tx) {
continue; continue;
} }
@ -180,12 +181,13 @@ load_textures (model_t *mod, vulkan_ctx_t *ctx)
modelctx_t *mctx = mod->data; modelctx_t *mctx = mod->data;
VkImage image = 0; VkImage image = 0;
byte *buffer; byte *buffer;
mod_brush_t *brush = &mod->brush;
size_t image_count = 0; size_t image_count = 0;
size_t copy_count = 0; size_t copy_count = 0;
size_t memsize = 0; size_t memsize = 0;
for (int i = 0; i < mod->numtextures; i++) { for (int i = 0; i < brush->numtextures; i++) {
texture_t *tx = mod->textures[i]; texture_t *tx = brush->textures[i];
if (!tx) { if (!tx) {
continue; continue;
} }
@ -221,8 +223,8 @@ load_textures (model_t *mod, vulkan_ctx_t *ctx)
qfv_packet_t *packet = QFV_PacketAcquire (stage); qfv_packet_t *packet = QFV_PacketAcquire (stage);
buffer = QFV_PacketExtend (packet, memsize); buffer = QFV_PacketExtend (packet, memsize);
for (int i = 0; i < mod->numtextures; i++) { for (int i = 0; i < brush->numtextures; i++) {
texture_t *tx = mod->textures[i]; texture_t *tx = brush->textures[i];
byte *palette = vid.palette32; byte *palette = vid.palette32;
if (!tx) { if (!tx) {
continue; continue;
@ -275,8 +277,8 @@ load_textures (model_t *mod, vulkan_ctx_t *ctx)
__auto_type barriers = QFV_AllocImageBarrierSet (image_count, malloc); __auto_type barriers = QFV_AllocImageBarrierSet (image_count, malloc);
barriers->size = 0; barriers->size = 0;
for (int i = 0; i < mod->numtextures; i++) { for (int i = 0; i < brush->numtextures; i++) {
texture_t *tx = mod->textures[i]; texture_t *tx = brush->textures[i];
if (!tx) { if (!tx) {
continue; continue;
} }
@ -296,8 +298,8 @@ load_textures (model_t *mod, vulkan_ctx_t *ctx)
dfunc->vkCmdPipelineBarrier (packet->cmd, stages.src, stages.dst, dfunc->vkCmdPipelineBarrier (packet->cmd, stages.src, stages.dst,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
barriers->size, barriers->a); barriers->size, barriers->a);
for (int i = 0, j = 0; i < mod->numtextures; i++) { for (int i = 0, j = 0; i < brush->numtextures; i++) {
texture_t *tx = mod->textures[i]; texture_t *tx = brush->textures[i];
if (!tx) { if (!tx) {
continue; continue;
} }
@ -401,9 +403,11 @@ Vulkan_Mod_ProcessTexture (model_t *mod, texture_t *tx, vulkan_ctx_t *ctx)
void void
Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx) Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx)
{ {
mod_brush_t *brush = &mod->brush;
mod_lightmap_bytes = 3; mod_lightmap_bytes = 3;
if (!bsp->lightdatasize) { if (!bsp->lightdatasize) {
mod->lightdata = NULL; brush->lightdata = NULL;
return; return;
} }
@ -413,7 +417,7 @@ Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx)
int ver; int ver;
QFile *lit_file; QFile *lit_file;
mod->lightdata = 0; brush->lightdata = 0;
if (mod_lightmap_bytes > 1) { if (mod_lightmap_bytes > 1) {
// LordHavoc: check for a .lit file to load // LordHavoc: check for a .lit file to load
dstring_t *litfilename = dstring_new (); dstring_t *litfilename = dstring_new ();
@ -428,7 +432,7 @@ Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx)
ver = LittleLong (((int32_t *) data)[1]); ver = LittleLong (((int32_t *) data)[1]);
if (ver == 1) { if (ver == 1) {
Sys_MaskPrintf (SYS_DEV, "%s loaded", litfilename->str); Sys_MaskPrintf (SYS_DEV, "%s loaded", litfilename->str);
mod->lightdata = data + 8; brush->lightdata = data + 8;
} else { } else {
Sys_MaskPrintf (SYS_DEV, Sys_MaskPrintf (SYS_DEV,
"Unknown .lit file version (%d)\n", ver); "Unknown .lit file version (%d)\n", ver);
@ -439,13 +443,13 @@ Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx)
} }
dstring_delete (litfilename); dstring_delete (litfilename);
} }
if (mod->lightdata || !bsp->lightdatasize) { if (brush->lightdata || !bsp->lightdatasize) {
return; return;
} }
// LordHavoc: oh well, expand the white lighting data // LordHavoc: oh well, expand the white lighting data
mod->lightdata = Hunk_AllocName (bsp->lightdatasize * 3, mod->name); brush->lightdata = Hunk_AllocName (bsp->lightdatasize * 3, mod->name);
in = bsp->lightdata; in = bsp->lightdata;
out = mod->lightdata; out = brush->lightdata;
for (i = 0; i < bsp->lightdatasize ; i++) { for (i = 0; i < bsp->lightdatasize ; i++) {
d = *in++; d = *in++;

View file

@ -74,7 +74,7 @@ glRect_t gl_lightmap_rectchange[MAX_LIGHTMAPS];
static int lmshift = 7; static int lmshift = 7;
void (*gl_R_BuildLightMap) (msurface_t *surf); void (*gl_R_BuildLightMap) (mod_brush_t *brush, msurface_t *surf);
extern void gl_multitexture_f (cvar_t *var); extern void gl_multitexture_f (cvar_t *var);
@ -240,7 +240,7 @@ R_AddDynamicLights_3 (msurface_t *surf)
} }
static void static void
R_BuildLightMap_1 (msurface_t *surf) R_BuildLightMap_1 (mod_brush_t *brush, msurface_t *surf)
{ {
byte *dest; byte *dest;
int maps, size, stride, smax, tmax, i, j; int maps, size, stride, smax, tmax, i, j;
@ -254,7 +254,7 @@ R_BuildLightMap_1 (msurface_t *surf)
size = smax * tmax * gl_internalformat; size = smax * tmax * gl_internalformat;
// set to full bright if no light data // set to full bright if no light data
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
memset (&blocklights[0], 0xff, size * sizeof(int)); memset (&blocklights[0], 0xff, size * sizeof(int));
goto store; goto store;
} }
@ -300,7 +300,7 @@ R_BuildLightMap_1 (msurface_t *surf)
} }
static void static void
R_BuildLightMap_3 (msurface_t *surf) R_BuildLightMap_3 (mod_brush_t *brush, msurface_t *surf)
{ {
byte *dest; byte *dest;
int maps, size, stride, smax, tmax, i, j; int maps, size, stride, smax, tmax, i, j;
@ -314,7 +314,7 @@ R_BuildLightMap_3 (msurface_t *surf)
size = smax * tmax * gl_internalformat; size = smax * tmax * gl_internalformat;
// set to full bright if no light data // set to full bright if no light data
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
memset (&blocklights[0], 0xff, size * sizeof(int)); memset (&blocklights[0], 0xff, size * sizeof(int));
goto store; goto store;
} }
@ -365,7 +365,7 @@ R_BuildLightMap_3 (msurface_t *surf)
} }
static void static void
R_BuildLightMap_4 (msurface_t *surf) R_BuildLightMap_4 (mod_brush_t *brush, msurface_t *surf)
{ {
byte *dest; byte *dest;
int maps, size, smax, tmax, i, j, stride; int maps, size, smax, tmax, i, j, stride;
@ -379,7 +379,7 @@ R_BuildLightMap_4 (msurface_t *surf)
size = smax * tmax * gl_internalformat; size = smax * tmax * gl_internalformat;
// set to full bright if no light data // set to full bright if no light data
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
memset (&blocklights[0], 0xff, size * sizeof(int)); memset (&blocklights[0], 0xff, size * sizeof(int));
goto store; goto store;
} }
@ -535,6 +535,7 @@ gl_overbright_f (cvar_t *var)
model_t *m; model_t *m;
msurface_t *fa; msurface_t *fa;
entity_t *ent; entity_t *ent;
mod_brush_t *brush;
if (!var) if (!var)
return; return;
@ -588,7 +589,8 @@ gl_overbright_f (cvar_t *var)
if (m->path[0] == '*') if (m->path[0] == '*')
continue; continue;
for (j = 0, fa = m->surfaces; j < m->numsurfaces; j++, fa++) { brush = &m->brush;
for (j = 0, fa = brush->surfaces; j < brush->numsurfaces; j++, fa++) {
if (fa->flags & (SURF_DRAWTURB | SURF_DRAWSKY)) if (fa->flags & (SURF_DRAWTURB | SURF_DRAWSKY))
continue; continue;
@ -599,13 +601,13 @@ gl_overbright_f (cvar_t *var)
gl_lightmap_rectchange[num].w = BLOCK_WIDTH; gl_lightmap_rectchange[num].w = BLOCK_WIDTH;
gl_lightmap_rectchange[num].h = BLOCK_HEIGHT; gl_lightmap_rectchange[num].h = BLOCK_HEIGHT;
gl_R_BuildLightMap (fa); gl_R_BuildLightMap (brush, fa);
} }
} }
m = r_worldentity.model; brush = &r_worldentity.model->brush;
for (i = 0, fa = m->surfaces; i < m->numsurfaces; i++, fa++) { for (i = 0, fa = brush->surfaces; i < brush->numsurfaces; i++, fa++) {
if (fa->flags & (SURF_DRAWTURB | SURF_DRAWSKY)) if (fa->flags & (SURF_DRAWTURB | SURF_DRAWSKY))
continue; continue;
@ -616,7 +618,7 @@ gl_overbright_f (cvar_t *var)
gl_lightmap_rectchange[num].w = BLOCK_WIDTH; gl_lightmap_rectchange[num].w = BLOCK_WIDTH;
gl_lightmap_rectchange[num].h = BLOCK_HEIGHT; gl_lightmap_rectchange[num].h = BLOCK_HEIGHT;
gl_R_BuildLightMap (fa); gl_R_BuildLightMap (brush, fa);
} }
} }
@ -665,7 +667,7 @@ AllocBlock (int w, int h, int *x, int *y)
} }
static void static void
GL_CreateSurfaceLightmap (msurface_t *surf) GL_CreateSurfaceLightmap (mod_brush_t *brush, msurface_t *surf)
{ {
int smax, tmax; int smax, tmax;
@ -677,7 +679,7 @@ GL_CreateSurfaceLightmap (msurface_t *surf)
surf->lightmaptexturenum = surf->lightmaptexturenum =
AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
gl_R_BuildLightMap (surf); gl_R_BuildLightMap (brush, surf);
} }
/* /*
@ -690,6 +692,7 @@ GL_BuildLightmaps (model_t **models, int num_models)
{ {
int i, j; int i, j;
model_t *m; model_t *m;
mod_brush_t *brush;
memset (allocated, 0, sizeof (allocated)); memset (allocated, 0, sizeof (allocated));
@ -732,21 +735,22 @@ GL_BuildLightmaps (model_t **models, int num_models)
m = models[j]; m = models[j];
if (!m) if (!m)
break; break;
if (m->path[0] == '*') { if (m->path[0] == '*' || m->type != mod_brush) {
// sub model surfaces are processed as part of the main model // sub model surfaces are processed as part of the main model
continue; continue;
} }
r_pcurrentvertbase = m->vertexes; brush = &m->brush;
r_pcurrentvertbase = brush->vertexes;
gl_currentmodel = m; gl_currentmodel = m;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
if (m->surfaces[i].flags & SURF_DRAWTURB) if (brush->surfaces[i].flags & SURF_DRAWTURB)
continue; continue;
if (gl_sky_divide->int_val && (m->surfaces[i].flags & if (gl_sky_divide->int_val && (brush->surfaces[i].flags &
SURF_DRAWSKY)) SURF_DRAWSKY))
continue; continue;
GL_CreateSurfaceLightmap (m->surfaces + i); GL_CreateSurfaceLightmap (brush, brush->surfaces + i);
GL_BuildSurfaceDisplayList (m->surfaces + i); GL_BuildSurfaceDisplayList (brush->surfaces + i);
} }
} }

View file

@ -436,7 +436,7 @@ gl_R_DrawAliasModel (entity_t *e)
float lightadj; float lightadj;
// get lighting information // get lighting information
R_LightPoint (e->origin); R_LightPoint (&r_worldentity.model->brush, e->origin);
lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0; lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0;

View file

@ -167,13 +167,13 @@ gl_R_Init (void)
} }
static void static void
register_textures (model_t *model) register_textures (mod_brush_t *brush)
{ {
int i; int i;
texture_t *tex; texture_t *tex;
for (i = 0; i < model->numtextures; i++) { for (i = 0; i < brush->numtextures; i++) {
tex = model->textures[i]; tex = brush->textures[i];
if (!tex) if (!tex)
continue; continue;
gl_R_AddTexture (tex); gl_R_AddTexture (tex);
@ -185,18 +185,20 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
{ {
int i; int i;
texture_t *tex; texture_t *tex;
mod_brush_t *brush;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
d_lightstylevalue[i] = 264; // normal light value d_lightstylevalue[i] = 264; // normal light value
memset (&r_worldentity, 0, sizeof (r_worldentity)); memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = worldmodel; r_worldentity.model = worldmodel;
brush = &worldmodel->brush;
R_FreeAllEntities (); R_FreeAllEntities ();
// clear out efrags in case the level hasn't been reloaded // clear out efrags in case the level hasn't been reloaded
for (i = 0; i < r_worldentity.model->numleafs; i++) for (i = 0; i < brush->numleafs; i++)
r_worldentity.model->leafs[i].efrags = NULL; brush->leafs[i].efrags = NULL;
// Force a vis update // Force a vis update
r_viewleaf = NULL; r_viewleaf = NULL;
@ -209,8 +211,8 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
// identify sky texture // identify sky texture
gl_mirrortexturenum = -1; gl_mirrortexturenum = -1;
gl_R_ClearTextures (); gl_R_ClearTextures ();
for (i = 0; i < r_worldentity.model->numtextures; i++) { for (i = 0; i < brush->numtextures; i++) {
tex = r_worldentity.model->textures[i]; tex = brush->textures[i];
if (!tex) if (!tex)
continue; continue;
if (!strncmp (tex->name, "sky", 3)) { if (!strncmp (tex->name, "sky", 3)) {
@ -220,16 +222,16 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
gl_mirrortexturenum = i; gl_mirrortexturenum = i;
} }
gl_R_InitSurfaceChains (r_worldentity.model); gl_R_InitSurfaceChains (brush);
gl_R_AddTexture (r_notexture_mip); gl_R_AddTexture (r_notexture_mip);
register_textures (r_worldentity.model); register_textures (brush);
for (i = 0; i < num_models; i++) { for (i = 0; i < num_models; i++) {
if (!models[i]) if (!models[i])
continue; continue;
if (*models[i]->path == '*') if (*models[i]->path == '*')
continue; continue;
if (models[i] != r_worldentity.model && models[i]->type == mod_brush) if (models[i] != r_worldentity.model && models[i]->type == mod_brush)
register_textures (models[i]); register_textures (&models[i]->brush);
} }
} }

View file

@ -146,15 +146,15 @@ gl_R_AddTexture (texture_t *tx)
} }
void void
gl_R_InitSurfaceChains (model_t *model) gl_R_InitSurfaceChains (mod_brush_t *brush)
{ {
int i; int i;
if (static_chains) if (static_chains)
free (static_chains); free (static_chains);
static_chains = calloc (model->nummodelsurfaces, sizeof (instsurf_t)); static_chains = calloc (brush->nummodelsurfaces, sizeof (instsurf_t));
for (i = 0; i < model->nummodelsurfaces; i++) for (i = 0; i < brush->nummodelsurfaces; i++)
model->surfaces[i].instsurf = static_chains + i; brush->surfaces[i].instsurf = static_chains + i;
release_instsurfs (); release_instsurfs ();
} }
@ -267,7 +267,7 @@ R_RenderBrushPoly_1 (msurface_t *fa)
} }
static inline void static inline void
R_AddToLightmapChain (msurface_t *fa) R_AddToLightmapChain (mod_brush_t *brush, msurface_t *fa)
{ {
int maps, smax, tmax; int maps, smax, tmax;
glRect_t *theRect; glRect_t *theRect;
@ -306,7 +306,7 @@ R_AddToLightmapChain (msurface_t *fa)
theRect->w = (fa->light_s - theRect->l) + smax; theRect->w = (fa->light_s - theRect->l) + smax;
if ((theRect->h + theRect->t) < (fa->light_t + tmax)) if ((theRect->h + theRect->t) < (fa->light_t + tmax))
theRect->h = (fa->light_t - theRect->t) + tmax; theRect->h = (fa->light_t - theRect->t) + tmax;
gl_R_BuildLightMap (fa); gl_R_BuildLightMap (brush, fa);
} }
} }
} }
@ -490,7 +490,8 @@ clear_texture_chains (void)
} }
static inline void static inline void
chain_surface (msurface_t *surf, vec_t *transform, float *color) chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
float *color)
{ {
instsurf_t *sc; instsurf_t *sc;
@ -509,7 +510,7 @@ chain_surface (msurface_t *surf, vec_t *transform, float *color)
tex = tx->render; tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain); CHAIN_SURF_F2B (surf, tex->tex_chain);
R_AddToLightmapChain (surf); R_AddToLightmapChain (brush, surf);
} }
if (!(sc = surf->instsurf)) if (!(sc = surf->instsurf))
sc = surf->tinst; sc = surf->tinst;
@ -528,8 +529,10 @@ gl_R_DrawBrushModel (entity_t *e)
msurface_t *psurf; msurface_t *psurf;
qboolean rotated; qboolean rotated;
vec3_t mins, maxs; vec3_t mins, maxs;
mod_brush_t *brush;
model = e->model; model = e->model;
brush = &model->brush;
if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) { if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) {
rotated = true; rotated = true;
@ -565,7 +568,7 @@ gl_R_DrawBrushModel (entity_t *e)
} }
// calculate dynamic lighting for bmodel if it's not an instanced model // calculate dynamic lighting for bmodel if it's not an instanced model
if (model->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { if (brush->firstmodelsurface != 0 && r_dlight_lightmap->int_val) {
vec3_t lightorigin; vec3_t lightorigin;
for (k = 0; k < r_maxdlights; k++) { for (k = 0; k < r_maxdlights; k++) {
@ -574,8 +577,8 @@ gl_R_DrawBrushModel (entity_t *e)
continue; continue;
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
R_RecursiveMarkLights (lightorigin, &r_dlights[k], k, R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k,
model->nodes + model->hulls[0].firstclipnode); brush->nodes + brush->hulls[0].firstclipnode);
} }
} }
@ -584,10 +587,10 @@ gl_R_DrawBrushModel (entity_t *e)
qfglGetFloatv (GL_MODELVIEW_MATRIX, e->full_transform); qfglGetFloatv (GL_MODELVIEW_MATRIX, e->full_transform);
qfglPopMatrix (); qfglPopMatrix ();
psurf = &model->surfaces[model->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
// draw texture // draw texture
for (i = 0; i < model->nummodelsurfaces; i++, psurf++) { for (i = 0; i < brush->nummodelsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on
pplane = psurf->plane; pplane = psurf->plane;
@ -596,7 +599,7 @@ gl_R_DrawBrushModel (entity_t *e)
// draw the polygon // draw the polygon
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) || if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) { (!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
chain_surface (psurf, e->full_transform, e->colormod); chain_surface (brush, psurf, e->full_transform, e->colormod);
} }
} }
} }
@ -623,7 +626,7 @@ get_side (mnode_t *node)
} }
static inline void static inline void
visit_node (mnode_t *node, int side) visit_node (mod_brush_t *brush, mnode_t *node, int side)
{ {
int c; int c;
msurface_t *surf; msurface_t *surf;
@ -632,7 +635,7 @@ visit_node (mnode_t *node, int side)
side = (~side + 1) & SURF_PLANEBACK; side = (~side + 1) & SURF_PLANEBACK;
// draw stuff // draw stuff
if ((c = node->numsurfaces)) { if ((c = node->numsurfaces)) {
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) { for (; c; c--, surf++) {
if (surf->visframe != r_visframecount) if (surf->visframe != r_visframecount)
continue; continue;
@ -641,7 +644,7 @@ visit_node (mnode_t *node, int side)
if (side ^ (surf->flags & SURF_PLANEBACK)) if (side ^ (surf->flags & SURF_PLANEBACK))
continue; // wrong side continue; // wrong side
chain_surface (surf, 0, 0); chain_surface (brush, surf, 0, 0);
} }
} }
} }
@ -659,7 +662,7 @@ test_node (mnode_t *node)
} }
static void static void
R_VisitWorldNodes (model_t *model) R_VisitWorldNodes (mod_brush_t *brush)
{ {
typedef struct { typedef struct {
mnode_t *node; mnode_t *node;
@ -671,9 +674,9 @@ R_VisitWorldNodes (model_t *model)
mnode_t *front; mnode_t *front;
int side; int side;
node = model->nodes; node = brush->nodes;
// +2 for paranoia // +2 for paranoia
node_stack = alloca ((model->depth + 2) * sizeof (rstack_t)); node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
node_ptr = node_stack; node_ptr = node_stack;
while (1) { while (1) {
@ -689,7 +692,7 @@ R_VisitWorldNodes (model_t *model)
} }
if (front->contents < 0 && front->contents != CONTENTS_SOLID) if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front); visit_leaf ((mleaf_t *) front);
visit_node (node, side); visit_node (brush, node, side);
node = node->children[!side]; node = node->children[!side];
} }
if (node->contents < 0 && node->contents != CONTENTS_SOLID) if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -698,7 +701,7 @@ R_VisitWorldNodes (model_t *model)
node_ptr--; node_ptr--;
node = node_ptr->node; node = node_ptr->node;
side = node_ptr->side; side = node_ptr->side;
visit_node (node, side); visit_node (brush, node, side);
node = node->children[!side]; node = node->children[!side];
continue; continue;
} }
@ -726,7 +729,7 @@ gl_R_DrawWorld (void)
gl_R_DrawSky (); gl_R_DrawSky ();
} }
R_VisitWorldNodes (r_worldentity.model); R_VisitWorldNodes (&r_worldentity.model->brush);
if (r_drawentities->int_val) { if (r_drawentities->int_val) {
entity_t *ent; entity_t *ent;
for (ent = r_ent_queue; ent; ent = ent->next) { for (ent = r_ent_queue; ent; ent = ent->next) {
@ -821,7 +824,7 @@ GL_BuildSurfaceDisplayList (msurface_t *fa)
medge_t *pedges, *r_pedge; medge_t *pedges, *r_pedge;
// reconstruct the polygon // reconstruct the polygon
pedges = gl_currentmodel->edges; pedges = gl_currentmodel->brush.edges;
lnumverts = fa->numedges; lnumverts = fa->numedges;
// draw texture // draw texture
@ -833,7 +836,7 @@ GL_BuildSurfaceDisplayList (msurface_t *fa)
poly->numverts = lnumverts; poly->numverts = lnumverts;
for (i = 0; i < lnumverts; i++) { for (i = 0; i < lnumverts; i++) {
lindex = gl_currentmodel->surfedges[fa->firstedge + i]; lindex = gl_currentmodel->brush.surfedges[fa->firstedge + i];
if (lindex > 0) { if (lindex > 0) {
r_pedge = &pedges[lindex]; r_pedge = &pedges[lindex];

View file

@ -159,7 +159,7 @@ calc_lighting (entity_t *ent, float *ambient, float *shadelight,
int light; int light;
VectorSet ( -1, 0, 0, lightvec); //FIXME VectorSet ( -1, 0, 0, lightvec); //FIXME
light = R_LightPoint (ent->origin); light = R_LightPoint (&r_worldentity.model->brush, ent->origin);
*ambient = max (light, max (ent->model->min_light, ent->min_light) * 128); *ambient = max (light, max (ent->model->min_light, ent->min_light) * 128);
*shadelight = *ambient; *shadelight = *ambient;

View file

@ -311,17 +311,17 @@ glsl_R_AddTexture (texture_t *tx)
tex->elechain_tail = &tex->elechain; tex->elechain_tail = &tex->elechain;
} }
void static void
glsl_R_InitSurfaceChains (model_t *model) glsl_R_InitSurfaceChains (mod_brush_t *brush)
{ {
int i; int i;
release_static_instsurfs (); release_static_instsurfs ();
release_instsurfs (); release_instsurfs ();
for (i = 0; i < model->nummodelsurfaces; i++) { for (i = 0; i < brush->nummodelsurfaces; i++) {
model->surfaces[i].instsurf = get_static_instsurf (); brush->surfaces[i].instsurf = get_static_instsurf ();
model->surfaces[i].instsurf->surface = &model->surfaces[i]; brush->surfaces[i].instsurf->surface = &brush->surfaces[i];
} }
} }
@ -358,7 +358,7 @@ glsl_R_ClearElements (void)
} }
static void static void
update_lightmap (msurface_t *surf) update_lightmap (mod_brush_t *brush, msurface_t *surf)
{ {
int maps; int maps;
@ -369,12 +369,13 @@ update_lightmap (msurface_t *surf)
if ((surf->dlightframe == r_framecount) || surf->cached_dlight) { if ((surf->dlightframe == r_framecount) || surf->cached_dlight) {
dynamic: dynamic:
if (r_dynamic->int_val) if (r_dynamic->int_val)
glsl_R_BuildLightMap (surf); glsl_R_BuildLightMap (brush, surf);
} }
} }
static inline void static inline void
chain_surface (msurface_t *surf, vec_t *transform, float *color) chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
float *color)
{ {
instsurf_t *is; instsurf_t *is;
@ -393,7 +394,7 @@ chain_surface (msurface_t *surf, vec_t *transform, float *color)
tex = tx->render; tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain); CHAIN_SURF_F2B (surf, tex->tex_chain);
update_lightmap (surf); update_lightmap (brush, surf);
} }
if (!(is = surf->instsurf)) if (!(is = surf->instsurf))
is = surf->tinst; is = surf->tinst;
@ -402,13 +403,13 @@ chain_surface (msurface_t *surf, vec_t *transform, float *color)
} }
static void static void
register_textures (model_t *model) register_textures (mod_brush_t *brush)
{ {
int i; int i;
texture_t *tex; texture_t *tex;
for (i = 0; i < model->numtextures; i++) { for (i = 0; i < brush->numtextures; i++) {
tex = model->textures[i]; tex = brush->textures[i];
if (!tex) if (!tex)
continue; continue;
glsl_R_AddTexture (tex); glsl_R_AddTexture (tex);
@ -426,11 +427,12 @@ glsl_R_RegisterTextures (model_t **models, int num_models)
{ {
int i; int i;
model_t *m; model_t *m;
mod_brush_t *brush;
glsl_R_ClearTextures (); glsl_R_ClearTextures ();
glsl_R_InitSurfaceChains (r_worldentity.model); glsl_R_InitSurfaceChains (&r_worldentity.model->brush);
glsl_R_AddTexture (r_notexture_mip); glsl_R_AddTexture (r_notexture_mip);
register_textures (r_worldentity.model); register_textures (&r_worldentity.model->brush);
for (i = 0; i < num_models; i++) { for (i = 0; i < num_models; i++) {
m = models[i]; m = models[i];
if (!m) if (!m)
@ -441,8 +443,9 @@ glsl_R_RegisterTextures (model_t **models, int num_models)
// world has already been done, not interested in non-brush models // world has already been done, not interested in non-brush models
if (m == r_worldentity.model || m->type != mod_brush) if (m == r_worldentity.model || m->type != mod_brush)
continue; continue;
m->numsubmodels = 1; // no support for submodels in non-world model brush = &m->brush;
register_textures (m); brush->numsubmodels = 1; // no support for submodels in non-world model
register_textures (brush);
} }
} }
@ -478,16 +481,17 @@ build_surf_displist (model_t **models, msurface_t *fa, int base,
glslpoly_t *poly; glslpoly_t *poly;
GLushort *ind; GLushort *ind;
float s, t; float s, t;
mod_brush_t *brush;
if (fa->ec_index < 0) { if (fa->ec_index < 0) {
vertices = models[-fa->ec_index - 1]->vertexes; brush = &models[-fa->ec_index - 1]->brush;
edges = models[-fa->ec_index - 1]->edges;
surfedges = models[-fa->ec_index - 1]->surfedges;
} else { } else {
vertices = r_worldentity.model->vertexes; brush = &r_worldentity.model->brush;
edges = r_worldentity.model->edges;
surfedges = r_worldentity.model->surfedges;
} }
vertices = brush->vertexes;
edges = brush->edges;
surfedges = brush->surfedges;
numverts = fa->numedges; numverts = fa->numedges;
numtris = numverts - 2; numtris = numverts - 2;
numindices = numtris * 3; numindices = numtris * 3;
@ -545,6 +549,7 @@ glsl_R_BuildDisplayLists (model_t **models, int num_models)
dmodel_t *dm; dmodel_t *dm;
msurface_t *surf; msurface_t *surf;
dstring_t *vertices; dstring_t *vertices;
mod_brush_t *brush;
QuatSet (0, 0, sqrt(0.5), sqrt(0.5), sky_fix); // proper skies QuatSet (0, 0, sqrt(0.5), sqrt(0.5), sky_fix); // proper skies
QuatSet (0, 0, 0, 1, sky_rotation[0]); QuatSet (0, 0, 0, 1, sky_rotation[0]);
@ -561,24 +566,25 @@ glsl_R_BuildDisplayLists (model_t **models, int num_models)
if (!m) if (!m)
continue; continue;
// sub-models are done as part of the main model // sub-models are done as part of the main model
if (*m->path == '*') if (*m->path == '*' || m->type != mod_brush)
continue; continue;
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
dm = m->submodels; dm = brush->submodels;
for (j = 0; j < m->numsurfaces; j++) { for (j = 0; j < brush->numsurfaces; j++) {
glsltex_t *tex; glsltex_t *tex;
if (j == dm->firstface + dm->numfaces) { if (j == dm->firstface + dm->numfaces) {
dm++; dm++;
if (dm - m->submodels == m->numsubmodels) { if (dm - brush->submodels == brush->numsubmodels) {
// limit the surfaces // limit the surfaces
// probably never hit // probably never hit
Sys_Printf ("R_BuildDisplayLists: too many surfaces\n"); Sys_Printf ("R_BuildDisplayLists: too many surfaces\n");
m->numsurfaces = j; brush->numsurfaces = j;
break; break;
} }
} }
surf = m->surfaces + j; surf = brush->surfaces + j;
surf->ec_index = dm - m->submodels; surf->ec_index = dm - brush->submodels;
if (!surf->ec_index && m != r_worldentity.model) if (!surf->ec_index && m != r_worldentity.model)
surf->ec_index = -1 - i; // instanced model surf->ec_index = -1 - i; // instanced model
tex = surf->texinfo->texture->render; tex = surf->texinfo->texture->render;
@ -654,8 +660,10 @@ R_DrawBrushModel (entity_t *e)
msurface_t *surf; msurface_t *surf;
qboolean rotated; qboolean rotated;
vec3_t mins, maxs, org; vec3_t mins, maxs, org;
mod_brush_t *brush;
model = e->model; model = e->model;
brush = &model->brush;
if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) { if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) {
rotated = true; rotated = true;
radius = model->radius; radius = model->radius;
@ -680,7 +688,7 @@ R_DrawBrushModel (entity_t *e)
} }
// calculate dynamic lighting for bmodel if it's not an instanced model // calculate dynamic lighting for bmodel if it's not an instanced model
if (model->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { if (brush->firstmodelsurface != 0 && r_dlight_lightmap->int_val) {
vec3_t lightorigin; vec3_t lightorigin;
for (k = 0; k < r_maxdlights; k++) { for (k = 0; k < r_maxdlights; k++) {
@ -689,14 +697,14 @@ R_DrawBrushModel (entity_t *e)
continue; continue;
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
R_RecursiveMarkLights (lightorigin, &r_dlights[k], k, R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k,
model->nodes + model->hulls[0].firstclipnode); brush->nodes + brush->hulls[0].firstclipnode);
} }
} }
surf = &model->surfaces[model->firstmodelsurface]; surf = &brush->surfaces[brush->firstmodelsurface];
for (i = 0; i < model->nummodelsurfaces; i++, surf++) { for (i = 0; i < brush->nummodelsurfaces; i++, surf++) {
// find the node side on which we are // find the node side on which we are
plane = surf->plane; plane = surf->plane;
@ -705,7 +713,7 @@ R_DrawBrushModel (entity_t *e)
// enqueue the polygon // enqueue the polygon
if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON))
|| (!(surf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) { || (!(surf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
chain_surface (surf, e->transform, e->colormod); chain_surface (brush, surf, e->transform, e->colormod);
} }
} }
} }
@ -730,7 +738,7 @@ get_side (mnode_t *node)
} }
static inline void static inline void
visit_node (mnode_t *node, int side) visit_node (mod_brush_t *brush, mnode_t *node, int side)
{ {
int c; int c;
msurface_t *surf; msurface_t *surf;
@ -739,7 +747,7 @@ visit_node (mnode_t *node, int side)
side = (~side + 1) & SURF_PLANEBACK; side = (~side + 1) & SURF_PLANEBACK;
// draw stuff // draw stuff
if ((c = node->numsurfaces)) { if ((c = node->numsurfaces)) {
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) { for (; c; c--, surf++) {
if (surf->visframe != r_visframecount) if (surf->visframe != r_visframecount)
continue; continue;
@ -748,7 +756,7 @@ visit_node (mnode_t *node, int side)
if (side ^ (surf->flags & SURF_PLANEBACK)) if (side ^ (surf->flags & SURF_PLANEBACK))
continue; // wrong side continue; // wrong side
chain_surface (surf, 0, 0); chain_surface (brush, surf, 0, 0);
} }
} }
} }
@ -766,7 +774,7 @@ test_node (mnode_t *node)
} }
static void static void
R_VisitWorldNodes (model_t *model) R_VisitWorldNodes (mod_brush_t *brush)
{ {
typedef struct { typedef struct {
mnode_t *node; mnode_t *node;
@ -778,9 +786,9 @@ R_VisitWorldNodes (model_t *model)
mnode_t *front; mnode_t *front;
int side; int side;
node = model->nodes; node = brush->nodes;
// +2 for paranoia // +2 for paranoia
node_stack = alloca ((model->depth + 2) * sizeof (rstack_t)); node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
node_ptr = node_stack; node_ptr = node_stack;
while (1) { while (1) {
@ -796,7 +804,7 @@ R_VisitWorldNodes (model_t *model)
} }
if (front->contents < 0 && front->contents != CONTENTS_SOLID) if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front); visit_leaf ((mleaf_t *) front);
visit_node (node, side); visit_node (brush, node, side);
node = node->children[!side]; node = node->children[!side];
} }
if (node->contents < 0 && node->contents != CONTENTS_SOLID) if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -805,7 +813,7 @@ R_VisitWorldNodes (model_t *model)
node_ptr--; node_ptr--;
node = node_ptr->node; node = node_ptr->node;
side = node_ptr->side; side = node_ptr->side;
visit_node (node, side); visit_node (brush, node, side);
node = node->children[!side]; node = node->children[!side];
continue; continue;
} }
@ -1123,7 +1131,7 @@ glsl_R_DrawWorld (void)
currententity = &worldent; currententity = &worldent;
R_VisitWorldNodes (worldent.model); R_VisitWorldNodes (&worldent.model->brush);
if (r_drawentities->int_val) { if (r_drawentities->int_val) {
entity_t *ent; entity_t *ent;
for (ent = r_ent_queue; ent; ent = ent->next) { for (ent = r_ent_queue; ent; ent = ent->next) {

View file

@ -217,7 +217,7 @@ glsl_R_DrawIQM (void)
float blend; float blend;
iqmframe_t *frame; iqmframe_t *frame;
R_LightPoint (ent->origin); //FIXME min_light? R_LightPoint (&r_worldentity.model->brush, ent->origin);//FIXME min_light?
VectorScale (ambientcolor, 1/255.0, ambientcolor); VectorScale (ambientcolor, 1/255.0, ambientcolor);
R_FindNearLights (ent->origin, MAX_IQM_LIGHTS, lights); R_FindNearLights (ent->origin, MAX_IQM_LIGHTS, lights);

View file

@ -61,7 +61,7 @@ static scrap_t *light_scrap;
static unsigned *blocklights; static unsigned *blocklights;
static int bl_extents[2]; static int bl_extents[2];
void (*glsl_R_BuildLightMap) (msurface_t *surf); void (*glsl_R_BuildLightMap) (mod_brush_t *brush, msurface_t *surf);
static void static void
R_AddDynamicLights_1 (msurface_t *surf) R_AddDynamicLights_1 (msurface_t *surf)
@ -121,7 +121,7 @@ R_AddDynamicLights_1 (msurface_t *surf)
} }
static void static void
R_BuildLightMap_1 (msurface_t *surf) R_BuildLightMap_1 (mod_brush_t *brush, msurface_t *surf)
{ {
int smax, tmax, size; int smax, tmax, size;
unsigned scale; unsigned scale;
@ -138,7 +138,7 @@ R_BuildLightMap_1 (msurface_t *surf)
// clear to no light // clear to no light
memset (blocklights, 0, size * sizeof (blocklights[0])); memset (blocklights, 0, size * sizeof (blocklights[0]));
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
// because we by-pass the inversion, "no light" = "full bright" // because we by-pass the inversion, "no light" = "full bright"
GLSL_SubpicUpdate (surf->lightpic, (byte *) blocklights, 1); GLSL_SubpicUpdate (surf->lightpic, (byte *) blocklights, 1);
return; return;
@ -196,6 +196,7 @@ glsl_R_BuildLightmaps (model_t **models, int num_models)
{ {
int i, j, size; int i, j, size;
model_t *m; model_t *m;
mod_brush_t *brush;
//FIXME RGB support //FIXME RGB support
if (!light_scrap) { if (!light_scrap) {
@ -210,13 +211,14 @@ glsl_R_BuildLightmaps (model_t **models, int num_models)
m = models[j]; m = models[j];
if (!m) if (!m)
break; break;
if (m->path[0] == '*') { if (m->path[0] == '*' || m->type != mod_brush) {
// sub model surfaces are processed as part of the main model // sub model surfaces are processed as part of the main model
continue; continue;
} }
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = m->surfaces + i; msurface_t *surf = brush->surfaces + i;
surf->lightpic = 0; // paranoia surf->lightpic = 0; // paranoia
if (surf->flags & SURF_DRAWTURB) if (surf->flags & SURF_DRAWTURB)
continue; continue;
@ -231,15 +233,16 @@ glsl_R_BuildLightmaps (model_t **models, int num_models)
m = models[j]; m = models[j];
if (!m) if (!m)
break; break;
if (m->path[0] == '*') { if (m->path[0] == '*' || m->type != mod_brush) {
// sub model surfaces are processed as part of the main model // sub model surfaces are processed as part of the main model
continue; continue;
} }
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = m->surfaces + i; msurface_t *surf = brush->surfaces + i;
if (surf->lightpic) if (surf->lightpic)
glsl_R_BuildLightMap (surf); glsl_R_BuildLightMap (brush, surf);
} }
} }
} }

View file

@ -52,7 +52,6 @@
#define R_InitParticles glsl_R_InitParticles #define R_InitParticles glsl_R_InitParticles
#define R_InitSky glsl_R_InitSky #define R_InitSky glsl_R_InitSky
#define R_InitSprites glsl_R_InitSprites #define R_InitSprites glsl_R_InitSprites
#define R_InitSurfaceChains glsl_R_InitSurfaceChains
#define R_LineGraph glsl_R_LineGraph #define R_LineGraph glsl_R_LineGraph
#define R_LoadSky_f glsl_R_LoadSky_f #define R_LoadSky_f glsl_R_LoadSky_f
#define R_LoadSkys glsl_R_LoadSkys #define R_LoadSkys glsl_R_LoadSkys

View file

@ -67,13 +67,13 @@ R_MarkLeaves (void)
r_oldviewleaf = 0; // so vis will be recalcualted when novis gets r_oldviewleaf = 0; // so vis will be recalcualted when novis gets
// turned off // turned off
vis = solid; vis = solid;
memset (solid, 0xff, (r_worldentity.model->numleafs + 7) >> 3); memset (solid, 0xff, (r_worldentity.model->brush.numleafs + 7) >> 3);
} else } else
vis = Mod_LeafPVS (r_viewleaf, r_worldentity.model); vis = Mod_LeafPVS (r_viewleaf, r_worldentity.model);
for (i = 0; (int) i < r_worldentity.model->numleafs; i++) { for (i = 0; (int) i < r_worldentity.model->brush.numleafs; i++) {
if (vis[i >> 3] & (1 << (i & 7))) { if (vis[i >> 3] & (1 << (i & 7))) {
leaf = &r_worldentity.model->leafs[i + 1]; leaf = &r_worldentity.model->brush.leafs[i + 1];
if ((c = leaf->nummarksurfaces)) { if ((c = leaf->nummarksurfaces)) {
mark = leaf->firstmarksurface; mark = leaf->firstmarksurface;
do { do {

View file

@ -195,7 +195,7 @@ R_SplitEntityOnNode (mnode_t *node)
} }
void void
R_AddEfrags (entity_t *ent) R_AddEfrags (mod_brush_t *brush, entity_t *ent)
{ {
model_t *entmodel; model_t *entmodel;
@ -215,7 +215,7 @@ R_AddEfrags (entity_t *ent)
VectorAdd (ent->origin, entmodel->mins, r_emins); VectorAdd (ent->origin, entmodel->mins, r_emins);
VectorAdd (ent->origin, entmodel->maxs, r_emaxs); VectorAdd (ent->origin, entmodel->maxs, r_emaxs);
R_SplitEntityOnNode (r_worldentity.model->nodes); R_SplitEntityOnNode (brush->nodes);
ent->topnode = r_pefragtopnode; ent->topnode = r_pefragtopnode;
} }

View file

@ -203,8 +203,8 @@ mark_surfaces (msurface_t *surf, const vec3_t lightorigin, dlight_t *light,
// LordHavoc: heavily modified, to eliminate unnecessary texture uploads, // LordHavoc: heavily modified, to eliminate unnecessary texture uploads,
// and support bmodel lighting better // and support bmodel lighting better
void void
R_RecursiveMarkLights (const vec3_t lightorigin, dlight_t *light, int lightnum, R_RecursiveMarkLights (mod_brush_t *brush, const vec3_t lightorigin,
mnode_t *node) dlight_t *light, int lightnum, mnode_t *node)
{ {
unsigned i; unsigned i;
float ndist, maxdist; float ndist, maxdist;
@ -240,14 +240,14 @@ loc0:
} }
// mark the polygons // mark the polygons
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++) { for (i = 0; i < node->numsurfaces; i++, surf++) {
mark_surfaces (surf, lightorigin, light, lightnum); mark_surfaces (surf, lightorigin, light, lightnum);
} }
if (node->children[0]->contents >= 0) { if (node->children[0]->contents >= 0) {
if (node->children[1]->contents >= 0) if (node->children[1]->contents >= 0)
R_RecursiveMarkLights (lightorigin, light, lightnum, R_RecursiveMarkLights (brush, lightorigin, light, lightnum,
node->children[1]); node->children[1]);
node = node->children[0]; node = node->children[0];
goto loc0; goto loc0;
@ -262,11 +262,12 @@ void
R_MarkLights (const vec3_t lightorigin, dlight_t *light, int lightnum, R_MarkLights (const vec3_t lightorigin, dlight_t *light, int lightnum,
model_t *model) model_t *model)
{ {
mod_brush_t *brush = &model->brush;
mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model); mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
if (!pvsleaf->compressed_vis) { if (!pvsleaf->compressed_vis) {
mnode_t *node = model->nodes + model->hulls[0].firstclipnode; mnode_t *node = brush->nodes + brush->hulls[0].firstclipnode;
R_RecursiveMarkLights (lightorigin, light, lightnum, node); R_RecursiveMarkLights (brush, lightorigin, light, lightnum, node);
} else { } else {
float radius = light->radius; float radius = light->radius;
vec3_t mins, maxs; vec3_t mins, maxs;
@ -280,16 +281,16 @@ R_MarkLights (const vec3_t lightorigin, dlight_t *light, int lightnum,
maxs[0] = lightorigin[0] + radius; maxs[0] = lightorigin[0] + radius;
maxs[1] = lightorigin[1] + radius; maxs[1] = lightorigin[1] + radius;
maxs[2] = lightorigin[2] + radius; maxs[2] = lightorigin[2] + radius;
while (leafnum < model->numleafs) { while (leafnum < brush->numleafs) {
int b; int b;
if (!(vis_bits = *in++)) { if (!(vis_bits = *in++)) {
leafnum += (*in++) * 8; leafnum += (*in++) * 8;
continue; continue;
} }
for (b = 1; b < 256 && leafnum < model->numleafs; for (b = 1; b < 256 && leafnum < brush->numleafs;
b <<= 1, leafnum++) { b <<= 1, leafnum++) {
int m; int m;
mleaf_t *leaf = &model->leafs[leafnum + 1]; mleaf_t *leaf = &brush->leafs[leafnum + 1];
if (!(vis_bits & b)) if (!(vis_bits & b))
continue; continue;
if (leaf->visframe != r_visframecount) if (leaf->visframe != r_visframecount)
@ -400,7 +401,8 @@ calc_lighting_3 (msurface_t *surf, int ds, int dt)
} }
static int static int
RecursiveLightPoint (mnode_t *node, const vec3_t start, const vec3_t end) RecursiveLightPoint (mod_brush_t *brush, mnode_t *node, const vec3_t start,
const vec3_t end)
{ {
unsigned i; unsigned i;
int r, s, t, ds, dt, side; int r, s, t, ds, dt, side;
@ -430,7 +432,7 @@ loop:
mid[2] = start[2] + (end[2] - start[2]) * frac; mid[2] = start[2] + (end[2] - start[2]) * frac;
// go down front side // go down front side
r = RecursiveLightPoint (node->children[side], start, mid); r = RecursiveLightPoint (brush, node->children[side], start, mid);
if (r >= 0) if (r >= 0)
return r; // hit something return r; // hit something
@ -441,7 +443,7 @@ loop:
VectorCopy (mid, lightspot); VectorCopy (mid, lightspot);
lightplane = plane; lightplane = plane;
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++) { for (i = 0; i < node->numsurfaces; i++, surf++) {
if (surf->flags & SURF_DRAWTILED) if (surf->flags & SURF_DRAWTILED)
continue; // no lightmaps continue; // no lightmaps
@ -472,16 +474,16 @@ loop:
} }
// go down back side // go down back side
return RecursiveLightPoint (node->children[!side], mid, end); return RecursiveLightPoint (brush, node->children[!side], mid, end);
} }
int int
R_LightPoint (const vec3_t p) R_LightPoint (mod_brush_t *brush, const vec3_t p)
{ {
vec3_t end; vec3_t end;
int r; int r;
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
// allow dlights to have some effect, so don't go /quite/ fullbright // allow dlights to have some effect, so don't go /quite/ fullbright
ambientcolor[2] = ambientcolor[1] = ambientcolor[0] = 200; ambientcolor[2] = ambientcolor[1] = ambientcolor[0] = 200;
return 200; return 200;
@ -491,7 +493,7 @@ R_LightPoint (const vec3_t p)
end[1] = p[1]; end[1] = p[1];
end[2] = p[2] - 2048; end[2] = p[2] - 2048;
r = RecursiveLightPoint (r_worldentity.model->nodes, p, end); r = RecursiveLightPoint (brush, brush->nodes, p, end);
if (r == -1) if (r == -1)
r = 0; r = 0;

View file

@ -237,7 +237,7 @@ R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
void void
R_DrawSolidClippedSubmodelPolygons (model_t *pmodel) R_DrawSolidClippedSubmodelPolygons (model_t *model)
{ {
int i, j, lindex; int i, j, lindex;
vec_t dot; vec_t dot;
@ -247,12 +247,13 @@ R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
mvertex_t bverts[MAX_BMODEL_VERTS]; mvertex_t bverts[MAX_BMODEL_VERTS];
bedge_t bedges[MAX_BMODEL_EDGES], *pbedge; bedge_t bedges[MAX_BMODEL_EDGES], *pbedge;
medge_t *pedge, *pedges; medge_t *pedge, *pedges;
mod_brush_t *brush = &model->brush;
// FIXME: use bounding-box-based frustum clipping info? // FIXME: use bounding-box-based frustum clipping info?
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
pedges = pmodel->edges; pedges = brush->edges;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on
@ -278,7 +279,7 @@ R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
numbedges += psurf->numedges; numbedges += psurf->numedges;
for (j = 0; j < psurf->numedges; j++) { for (j = 0; j < psurf->numedges; j++) {
lindex = pmodel->surfedges[psurf->firstedge + j]; lindex = brush->surfedges[psurf->firstedge + j];
if (lindex > 0) { if (lindex > 0) {
pedge = &pedges[lindex]; pedge = &pedges[lindex];
@ -306,18 +307,19 @@ R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
void void
R_DrawSubmodelPolygons (model_t *pmodel, int clipflags) R_DrawSubmodelPolygons (model_t *model, int clipflags)
{ {
int i; int i;
vec_t dot; vec_t dot;
msurface_t *psurf; msurface_t *psurf;
int numsurfaces; int numsurfaces;
plane_t *pplane; plane_t *pplane;
mod_brush_t *brush = &model->brush;
// FIXME: use bounding-box-based frustum clipping info? // FIXME: use bounding-box-based frustum clipping info?
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on
@ -358,7 +360,7 @@ get_side (mnode_t *node)
} }
static void static void
visit_node (mnode_t *node, int side, int clipflags) visit_node (mod_brush_t *brush, mnode_t *node, int side, int clipflags)
{ {
int c; int c;
msurface_t *surf; msurface_t *surf;
@ -367,7 +369,7 @@ visit_node (mnode_t *node, int side, int clipflags)
side = (~side + 1) & SURF_PLANEBACK; side = (~side + 1) & SURF_PLANEBACK;
// draw stuff // draw stuff
if ((c = node->numsurfaces)) { if ((c = node->numsurfaces)) {
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) { for (; c; c--, surf++) {
if (surf->visframe != r_visframecount) if (surf->visframe != r_visframecount)
continue; continue;
@ -444,7 +446,7 @@ test_node (mnode_t *node, int *clipflags)
} }
static void static void
R_VisitWorldNodes (model_t *model, int clipflags) R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
{ {
typedef struct { typedef struct {
mnode_t *node; mnode_t *node;
@ -456,9 +458,9 @@ R_VisitWorldNodes (model_t *model, int clipflags)
mnode_t *front; mnode_t *front;
int side, cf; int side, cf;
node = model->nodes; node = brush->nodes;
// +2 for paranoia // +2 for paranoia
node_stack = alloca ((model->depth + 2) * sizeof (rstack_t)); node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
node_ptr = node_stack; node_ptr = node_stack;
cf = clipflags; cf = clipflags;
@ -478,7 +480,7 @@ R_VisitWorldNodes (model_t *model, int clipflags)
} }
if (front->contents < 0 && front->contents != CONTENTS_SOLID) if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front); visit_leaf ((mleaf_t *) front);
visit_node (node, side, clipflags); visit_node (brush, node, side, clipflags);
node = node->children[!side]; node = node->children[!side];
} }
if (node->contents < 0 && node->contents != CONTENTS_SOLID) if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -488,7 +490,7 @@ R_VisitWorldNodes (model_t *model, int clipflags)
node = node_ptr->node; node = node_ptr->node;
side = node_ptr->side; side = node_ptr->side;
clipflags = node_ptr->clipflags; clipflags = node_ptr->clipflags;
visit_node (node, side, clipflags); visit_node (brush, node, side, clipflags);
node = node->children[!side]; node = node->children[!side];
continue; continue;
} }
@ -502,17 +504,17 @@ void
R_RenderWorld (void) R_RenderWorld (void)
{ {
int i; int i;
model_t *clmodel;
btofpoly_t btofpolys[MAX_BTOFPOLYS]; btofpoly_t btofpolys[MAX_BTOFPOLYS];
mod_brush_t *brush;
pbtofpolys = btofpolys; pbtofpolys = btofpolys;
currententity = &r_worldentity; currententity = &r_worldentity;
VectorCopy (r_origin, modelorg); VectorCopy (r_origin, modelorg);
clmodel = currententity->model; brush = &currententity->model->brush;
r_pcurrentvertbase = clmodel->vertexes; r_pcurrentvertbase = brush->vertexes;
R_VisitWorldNodes (clmodel, 15); R_VisitWorldNodes (brush, 15);
// if the driver wants the polygons back to front, play the visible ones // if the driver wants the polygons back to front, play the visible ones
// back in that order // back in that order

View file

@ -353,6 +353,7 @@ R_RenderFace (msurface_t *fa, int clipflags)
vec3_t p_normal; vec3_t p_normal;
medge_t *pedges, tedge; medge_t *pedges, tedge;
clipplane_t *pclip; clipplane_t *pclip;
mod_brush_t *brush = &currententity->model->brush;
// skip out if no more surfs // skip out if no more surfs
if ((surface_p) >= surf_max) { if ((surface_p) >= surf_max) {
@ -382,11 +383,11 @@ R_RenderFace (msurface_t *fa, int clipflags)
r_nearzi = 0; r_nearzi = 0;
r_nearzionly = false; r_nearzionly = false;
makeleftedge = makerightedge = false; makeleftedge = makerightedge = false;
pedges = currententity->model->edges; pedges = brush->edges;
r_lastvertvalid = false; r_lastvertvalid = false;
for (i = 0; i < fa->numedges; i++) { for (i = 0; i < fa->numedges; i++) {
lindex = currententity->model->surfedges[fa->firstedge + i]; lindex = brush->surfedges[fa->firstedge + i];
if (lindex > 0) { if (lindex > 0) {
r_pedge = &pedges[lindex]; r_pedge = &pedges[lindex];
@ -623,6 +624,7 @@ R_RenderPoly (msurface_t *fa, int clipflags)
polyvert_t pverts[100]; // FIXME: do real number, safely polyvert_t pverts[100]; // FIXME: do real number, safely
int vertpage, newverts, newpage, lastvert; int vertpage, newverts, newpage, lastvert;
qboolean visible; qboolean visible;
mod_brush_t *brush = &currententity->model->brush;
// FIXME: clean this up and make it faster // FIXME: clean this up and make it faster
// FIXME: guard against running out of vertices // FIXME: guard against running out of vertices
@ -641,12 +643,12 @@ R_RenderPoly (msurface_t *fa, int clipflags)
// reconstruct the polygon // reconstruct the polygon
// FIXME: these should be precalculated and loaded off disk // FIXME: these should be precalculated and loaded off disk
pedges = currententity->model->edges; pedges = brush->edges;
lnumverts = fa->numedges; lnumverts = fa->numedges;
vertpage = 0; vertpage = 0;
for (i = 0; i < lnumverts; i++) { for (i = 0; i < lnumverts; i++) {
lindex = currententity->model->surfedges[fa->firstedge + i]; lindex = brush->surfedges[fa->firstedge + i];
if (lindex > 0) { if (lindex > 0) {
r_pedge = &pedges[lindex]; r_pedge = &pedges[lindex];
@ -777,15 +779,16 @@ R_RenderPoly (msurface_t *fa, int clipflags)
void void
R_ZDrawSubmodelPolys (model_t *pmodel) R_ZDrawSubmodelPolys (model_t *model)
{ {
int i, numsurfaces; int i, numsurfaces;
msurface_t *psurf; msurface_t *psurf;
float dot; float dot;
plane_t *pplane; plane_t *pplane;
mod_brush_t *brush = &model->brush;
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on

View file

@ -164,6 +164,7 @@ void
R_NewMap (model_t *worldmodel, struct model_s **models, int num_models) R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
{ {
int i; int i;
mod_brush_t *brush = &worldmodel->brush;
memset (&r_worldentity, 0, sizeof (r_worldentity)); memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = worldmodel; r_worldentity.model = worldmodel;
@ -172,11 +173,11 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
// clear out efrags in case the level hasn't been reloaded // clear out efrags in case the level hasn't been reloaded
// FIXME: is this one short? // FIXME: is this one short?
for (i = 0; i < r_worldentity.model->numleafs; i++) for (i = 0; i < brush->numleafs; i++)
r_worldentity.model->leafs[i].efrags = NULL; brush->leafs[i].efrags = NULL;
if (worldmodel->skytexture) if (brush->skytexture)
R_InitSky (worldmodel->skytexture); R_InitSky (brush->skytexture);
// Force a vis update // Force a vis update
r_viewleaf = NULL; r_viewleaf = NULL;
@ -381,7 +382,8 @@ R_DrawEntitiesOnList (void)
if (currententity->model->type == mod_iqm//FIXME if (currententity->model->type == mod_iqm//FIXME
|| R_AliasCheckBBox ()) { || R_AliasCheckBBox ()) {
// 128 instead of 255 due to clamping below // 128 instead of 255 due to clamping below
j = max (R_LightPoint (currententity->origin), minlight * 128); j = max (R_LightPoint (&r_worldentity.model->brush,
currententity->origin), minlight * 128);
lighting.ambientlight = j; lighting.ambientlight = j;
lighting.shadelight = j; lighting.shadelight = j;
@ -448,7 +450,8 @@ R_DrawViewModel (void)
minlight = max (currententity->min_light, currententity->model->min_light); minlight = max (currententity->min_light, currententity->model->min_light);
j = max (R_LightPoint (currententity->origin), minlight * 128); j = max (R_LightPoint (&r_worldentity.model->brush,
currententity->origin), minlight * 128);
r_viewlighting.ambientlight = j; r_viewlighting.ambientlight = j;
r_viewlighting.shadelight = j; r_viewlighting.shadelight = j;
@ -568,19 +571,20 @@ R_DrawBEntitiesOnList (void)
clipflags = R_BmodelCheckBBox (clmodel, minmaxs); clipflags = R_BmodelCheckBBox (clmodel, minmaxs);
if (clipflags != BMODEL_FULLY_CLIPPED) { if (clipflags != BMODEL_FULLY_CLIPPED) {
mod_brush_t *brush = &clmodel->brush;
VectorCopy (currententity->origin, r_entorigin); VectorCopy (currententity->origin, r_entorigin);
VectorSubtract (r_origin, r_entorigin, modelorg); VectorSubtract (r_origin, r_entorigin, modelorg);
// FIXME: is this needed? // FIXME: is this needed?
VectorCopy (modelorg, r_worldmodelorg); VectorCopy (modelorg, r_worldmodelorg);
r_pcurrentvertbase = clmodel->vertexes; r_pcurrentvertbase = brush->vertexes;
// FIXME: stop transforming twice // FIXME: stop transforming twice
R_RotateBmodel (); R_RotateBmodel ();
// calculate dynamic lighting for bmodel if it's not an // calculate dynamic lighting for bmodel if it's not an
// instanced model // instanced model
if (clmodel->firstmodelsurface != 0) { if (brush->firstmodelsurface != 0) {
vec3_t lightorigin; vec3_t lightorigin;
for (k = 0; k < r_maxdlights; k++) { for (k = 0; k < r_maxdlights; k++) {
@ -590,9 +594,10 @@ R_DrawBEntitiesOnList (void)
VectorSubtract (r_dlights[k].origin, VectorSubtract (r_dlights[k].origin,
currententity->origin, currententity->origin,
lightorigin); lightorigin);
R_RecursiveMarkLights (lightorigin, &r_dlights[k], R_RecursiveMarkLights (brush, lightorigin,
k, clmodel->nodes + &r_dlights[k], k,
clmodel->hulls[0].firstclipnode); brush->nodes
+ brush->hulls[0].firstclipnode);
} }
} }
// if the driver wants polygons, deliver those. // if the driver wants polygons, deliver those.

View file

@ -154,7 +154,7 @@ R_BuildLightMap (void)
size = smax * tmax; size = smax * tmax;
lightmap = surf->samples; lightmap = surf->samples;
if (!r_worldentity.model->lightdata) { if (!r_worldentity.model->brush.lightdata) {
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
blocklights[i] = 0; blocklights[i] = 0;
return; return;

View file

@ -240,7 +240,7 @@ R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
void void
sw32_R_DrawSolidClippedSubmodelPolygons (model_t *pmodel) sw32_R_DrawSolidClippedSubmodelPolygons (model_t *model)
{ {
int i, j, lindex; int i, j, lindex;
vec_t dot; vec_t dot;
@ -250,12 +250,13 @@ sw32_R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
mvertex_t bverts[MAX_BMODEL_VERTS]; mvertex_t bverts[MAX_BMODEL_VERTS];
bedge_t bedges[MAX_BMODEL_EDGES], *pbedge; bedge_t bedges[MAX_BMODEL_EDGES], *pbedge;
medge_t *pedge, *pedges; medge_t *pedge, *pedges;
mod_brush_t *brush = &model->brush;
// FIXME: use bounding-box-based frustum clipping info? // FIXME: use bounding-box-based frustum clipping info?
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
pedges = pmodel->edges; pedges = brush->edges;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on
@ -281,7 +282,7 @@ sw32_R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
numbedges += psurf->numedges; numbedges += psurf->numedges;
for (j = 0; j < psurf->numedges; j++) { for (j = 0; j < psurf->numedges; j++) {
lindex = pmodel->surfedges[psurf->firstedge + j]; lindex = brush->surfedges[psurf->firstedge + j];
if (lindex > 0) { if (lindex > 0) {
pedge = &pedges[lindex]; pedge = &pedges[lindex];
@ -309,18 +310,19 @@ sw32_R_DrawSolidClippedSubmodelPolygons (model_t *pmodel)
void void
sw32_R_DrawSubmodelPolygons (model_t *pmodel, int clipflags) sw32_R_DrawSubmodelPolygons (model_t *model, int clipflags)
{ {
int i; int i;
vec_t dot; vec_t dot;
msurface_t *psurf; msurface_t *psurf;
int numsurfaces; int numsurfaces;
plane_t *pplane; plane_t *pplane;
mod_brush_t *brush = &model->brush;
// FIXME: use bounding-box-based frustum clipping info? // FIXME: use bounding-box-based frustum clipping info?
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on
@ -361,7 +363,7 @@ get_side (mnode_t *node)
} }
static void static void
visit_node (mnode_t *node, int side, int clipflags) visit_node (mod_brush_t *brush, mnode_t *node, int side, int clipflags)
{ {
int c; int c;
msurface_t *surf; msurface_t *surf;
@ -370,7 +372,7 @@ visit_node (mnode_t *node, int side, int clipflags)
side = (~side + 1) & SURF_PLANEBACK; side = (~side + 1) & SURF_PLANEBACK;
// draw stuff // draw stuff
if ((c = node->numsurfaces)) { if ((c = node->numsurfaces)) {
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) { for (; c; c--, surf++) {
if (surf->visframe != r_visframecount) if (surf->visframe != r_visframecount)
continue; continue;
@ -447,7 +449,7 @@ test_node (mnode_t *node, int *clipflags)
} }
static void static void
R_VisitWorldNodes (model_t *model, int clipflags) R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
{ {
typedef struct { typedef struct {
mnode_t *node; mnode_t *node;
@ -459,9 +461,9 @@ R_VisitWorldNodes (model_t *model, int clipflags)
mnode_t *front; mnode_t *front;
int side, cf; int side, cf;
node = model->nodes; node = brush->nodes;
// +2 for paranoia // +2 for paranoia
node_stack = alloca ((model->depth + 2) * sizeof (rstack_t)); node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
node_ptr = node_stack; node_ptr = node_stack;
cf = clipflags; cf = clipflags;
@ -481,7 +483,7 @@ R_VisitWorldNodes (model_t *model, int clipflags)
} }
if (front->contents < 0 && front->contents != CONTENTS_SOLID) if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front); visit_leaf ((mleaf_t *) front);
visit_node (node, side, clipflags); visit_node (brush, node, side, clipflags);
node = node->children[!side]; node = node->children[!side];
} }
if (node->contents < 0 && node->contents != CONTENTS_SOLID) if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -491,7 +493,7 @@ R_VisitWorldNodes (model_t *model, int clipflags)
node = node_ptr->node; node = node_ptr->node;
side = node_ptr->side; side = node_ptr->side;
clipflags = node_ptr->clipflags; clipflags = node_ptr->clipflags;
visit_node (node, side, clipflags); visit_node (brush, node, side, clipflags);
node = node->children[!side]; node = node->children[!side];
continue; continue;
} }
@ -505,17 +507,17 @@ void
sw32_R_RenderWorld (void) sw32_R_RenderWorld (void)
{ {
int i; int i;
model_t *clmodel;
btofpoly_t btofpolys[MAX_BTOFPOLYS]; btofpoly_t btofpolys[MAX_BTOFPOLYS];
mod_brush_t *brush;
pbtofpolys = btofpolys; pbtofpolys = btofpolys;
currententity = &r_worldentity; currententity = &r_worldentity;
VectorCopy (r_origin, modelorg); VectorCopy (r_origin, modelorg);
clmodel = currententity->model; brush = &currententity->model->brush;
r_pcurrentvertbase = clmodel->vertexes; r_pcurrentvertbase = brush->vertexes;
R_VisitWorldNodes (clmodel, 15); R_VisitWorldNodes (brush, 15);
// if the driver wants the polygons back to front, play the visible ones // if the driver wants the polygons back to front, play the visible ones
// back in that order // back in that order

View file

@ -349,6 +349,7 @@ sw32_R_RenderFace (msurface_t *fa, int clipflags)
vec3_t p_normal; vec3_t p_normal;
medge_t *pedges, tedge; medge_t *pedges, tedge;
clipplane_t *pclip; clipplane_t *pclip;
mod_brush_t *brush = &currententity->model->brush;
// skip out if no more surfs // skip out if no more surfs
if ((sw32_surface_p) >= sw32_surf_max) { if ((sw32_surface_p) >= sw32_surf_max) {
@ -378,11 +379,11 @@ sw32_R_RenderFace (msurface_t *fa, int clipflags)
sw32_r_nearzi = 0; sw32_r_nearzi = 0;
sw32_r_nearzionly = false; sw32_r_nearzionly = false;
makeleftedge = makerightedge = false; makeleftedge = makerightedge = false;
pedges = currententity->model->edges; pedges = brush->edges;
sw32_r_lastvertvalid = false; sw32_r_lastvertvalid = false;
for (i = 0; i < fa->numedges; i++) { for (i = 0; i < fa->numedges; i++) {
lindex = currententity->model->surfedges[fa->firstedge + i]; lindex = brush->surfedges[fa->firstedge + i];
if (lindex > 0) { if (lindex > 0) {
sw32_r_pedge = &pedges[lindex]; sw32_r_pedge = &pedges[lindex];
@ -621,6 +622,7 @@ sw32_R_RenderPoly (msurface_t *fa, int clipflags)
polyvert_t pverts[100]; // FIXME: do real number, safely polyvert_t pverts[100]; // FIXME: do real number, safely
int vertpage, newverts, newpage, lastvert; int vertpage, newverts, newpage, lastvert;
qboolean visible; qboolean visible;
mod_brush_t *brush = &currententity->model->brush;
// FIXME: clean this up and make it faster // FIXME: clean this up and make it faster
// FIXME: guard against running out of vertices // FIXME: guard against running out of vertices
@ -639,12 +641,12 @@ sw32_R_RenderPoly (msurface_t *fa, int clipflags)
// reconstruct the polygon // reconstruct the polygon
// FIXME: these should be precalculated and loaded off disk // FIXME: these should be precalculated and loaded off disk
pedges = currententity->model->edges; pedges = brush->edges;
lnumverts = fa->numedges; lnumverts = fa->numedges;
vertpage = 0; vertpage = 0;
for (i = 0; i < lnumverts; i++) { for (i = 0; i < lnumverts; i++) {
lindex = currententity->model->surfedges[fa->firstedge + i]; lindex = brush->surfedges[fa->firstedge + i];
if (lindex > 0) { if (lindex > 0) {
sw32_r_pedge = &pedges[lindex]; sw32_r_pedge = &pedges[lindex];
@ -775,15 +777,16 @@ sw32_R_RenderPoly (msurface_t *fa, int clipflags)
void void
sw32_R_ZDrawSubmodelPolys (model_t *pmodel) sw32_R_ZDrawSubmodelPolys (model_t *model)
{ {
int i, numsurfaces; int i, numsurfaces;
msurface_t *psurf; msurface_t *psurf;
float dot; float dot;
plane_t *pplane; plane_t *pplane;
mod_brush_t *brush = &model->brush;
psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; psurf = &brush->surfaces[brush->firstmodelsurface];
numsurfaces = pmodel->nummodelsurfaces; numsurfaces = brush->nummodelsurfaces;
for (i = 0; i < numsurfaces; i++, psurf++) { for (i = 0; i < numsurfaces; i++, psurf++) {
// find which side of the node we are on // find which side of the node we are on

View file

@ -180,6 +180,7 @@ void
sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models) sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
{ {
int i; int i;
mod_brush_t *brush = &worldmodel->brush;
memset (&r_worldentity, 0, sizeof (r_worldentity)); memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = worldmodel; r_worldentity.model = worldmodel;
@ -188,11 +189,11 @@ sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
// clear out efrags in case the level hasn't been reloaded // clear out efrags in case the level hasn't been reloaded
// FIXME: is this one short? // FIXME: is this one short?
for (i = 0; i < r_worldentity.model->numleafs; i++) for (i = 0; i < brush->numleafs; i++)
r_worldentity.model->leafs[i].efrags = NULL; brush->leafs[i].efrags = NULL;
if (worldmodel->skytexture) if (brush->skytexture)
sw32_R_InitSky (worldmodel->skytexture); sw32_R_InitSky (brush->skytexture);
// Force a vis update // Force a vis update
r_viewleaf = NULL; r_viewleaf = NULL;
@ -388,7 +389,9 @@ R_DrawEntitiesOnList (void)
if (currententity->model->type == mod_iqm//FIXME if (currententity->model->type == mod_iqm//FIXME
|| sw32_R_AliasCheckBBox ()) { || sw32_R_AliasCheckBBox ()) {
// 128 instead of 255 due to clamping below // 128 instead of 255 due to clamping below
j = max (R_LightPoint (currententity->origin), minlight * 128); j = max (R_LightPoint (&r_worldentity.model->brush,
currententity->origin),
minlight * 128);
lighting.ambientlight = j; lighting.ambientlight = j;
lighting.shadelight = j; lighting.shadelight = j;
@ -454,7 +457,8 @@ R_DrawViewModel (void)
minlight = max (currententity->min_light, currententity->model->min_light); minlight = max (currententity->min_light, currententity->model->min_light);
j = max (R_LightPoint (currententity->origin), minlight * 128); j = max (R_LightPoint (&r_worldentity.model->brush,
currententity->origin), minlight * 128);
r_viewlighting.ambientlight = j; r_viewlighting.ambientlight = j;
r_viewlighting.shadelight = j; r_viewlighting.shadelight = j;
@ -574,19 +578,20 @@ R_DrawBEntitiesOnList (void)
clipflags = R_BmodelCheckBBox (clmodel, minmaxs); clipflags = R_BmodelCheckBBox (clmodel, minmaxs);
if (clipflags != BMODEL_FULLY_CLIPPED) { if (clipflags != BMODEL_FULLY_CLIPPED) {
mod_brush_t *brush = &clmodel->brush;
VectorCopy (currententity->origin, r_entorigin); VectorCopy (currententity->origin, r_entorigin);
VectorSubtract (r_origin, r_entorigin, modelorg); VectorSubtract (r_origin, r_entorigin, modelorg);
// FIXME: is this needed? // FIXME: is this needed?
VectorCopy (modelorg, sw32_r_worldmodelorg); VectorCopy (modelorg, sw32_r_worldmodelorg);
r_pcurrentvertbase = clmodel->vertexes; r_pcurrentvertbase = brush->vertexes;
// FIXME: stop transforming twice // FIXME: stop transforming twice
sw32_R_RotateBmodel (); sw32_R_RotateBmodel ();
// calculate dynamic lighting for bmodel if it's not an // calculate dynamic lighting for bmodel if it's not an
// instanced model // instanced model
if (clmodel->firstmodelsurface != 0) { if (brush->firstmodelsurface != 0) {
vec3_t lightorigin; vec3_t lightorigin;
for (k = 0; k < r_maxdlights; k++) { for (k = 0; k < r_maxdlights; k++) {
@ -596,9 +601,10 @@ R_DrawBEntitiesOnList (void)
VectorSubtract (r_dlights[k].origin, VectorSubtract (r_dlights[k].origin,
currententity->origin, currententity->origin,
lightorigin); lightorigin);
R_RecursiveMarkLights (lightorigin, &r_dlights[k], R_RecursiveMarkLights (brush, lightorigin,
k, clmodel->nodes + &r_dlights[k], k,
clmodel->hulls[0].firstclipnode); brush->nodes
+ brush->hulls[0].firstclipnode);
} }
} }
// if the driver wants polygons, deliver those. // if the driver wants polygons, deliver those.

View file

@ -172,7 +172,7 @@ R_BuildLightMap (void)
size = smax * tmax; size = smax * tmax;
lightmap = surf->samples; lightmap = surf->samples;
if (!r_worldentity.model->lightdata) { if (!r_worldentity.model->brush.lightdata) {
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
blocklights[i] = 0; blocklights[i] = 0;
return; return;

View file

@ -144,7 +144,7 @@ calc_lighting (qfv_light_t *light, entity_t *ent)
{ {
vec3_t ambient_color; vec3_t ambient_color;
//FIXME should be ent->position //FIXME should be ent->position
float l = R_LightPoint (r_origin) / 128.0; float l = R_LightPoint (&r_worldentity.model->brush, r_origin) / 128.0;
//XXX l = max (light, max (ent->model->min_light, ent->min_light)); //XXX l = max (light, max (ent->model->min_light, ent->min_light));
light->type = 2; light->type = 2;

View file

@ -153,7 +153,7 @@ add_texture (texture_t *tx, vulkan_ctx_t *ctx)
} }
static void static void
init_surface_chains (model_t *model, vulkan_ctx_t *ctx) init_surface_chains (mod_brush_t *brush, vulkan_ctx_t *ctx)
{ {
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
int i; int i;
@ -161,9 +161,9 @@ init_surface_chains (model_t *model, vulkan_ctx_t *ctx)
release_static_instsurfs (bctx); release_static_instsurfs (bctx);
release_instsurfs (bctx); release_instsurfs (bctx);
for (i = 0; i < model->nummodelsurfaces; i++) { for (i = 0; i < brush->nummodelsurfaces; i++) {
model->surfaces[i].instsurf = get_static_instsurf (bctx); brush->surfaces[i].instsurf = get_static_instsurf (bctx);
model->surfaces[i].instsurf->surface = &model->surfaces[i]; brush->surfaces[i].instsurf->surface = &brush->surfaces[i];
} }
} }
@ -199,7 +199,7 @@ Vulkan_ClearElements (vulkan_ctx_t *ctx)
} }
static void static void
update_lightmap (msurface_t *surf, vulkan_ctx_t *ctx) update_lightmap (mod_brush_t *brush, msurface_t *surf, vulkan_ctx_t *ctx)
{ {
int maps; int maps;
@ -210,13 +210,13 @@ update_lightmap (msurface_t *surf, vulkan_ctx_t *ctx)
if ((surf->dlightframe == r_framecount) || surf->cached_dlight) { if ((surf->dlightframe == r_framecount) || surf->cached_dlight) {
dynamic: dynamic:
if (r_dynamic->int_val) if (r_dynamic->int_val)
Vulkan_BuildLightMap (surf, ctx); Vulkan_BuildLightMap (brush, surf, ctx);
} }
} }
static inline void static inline void
chain_surface (msurface_t *surf, vec_t *transform, float *color, chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
vulkan_ctx_t *ctx) float *color, vulkan_ctx_t *ctx)
{ {
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
instsurf_t *is; instsurf_t *is;
@ -236,7 +236,7 @@ chain_surface (msurface_t *surf, vec_t *transform, float *color,
tex = tx->render; tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain); CHAIN_SURF_F2B (surf, tex->tex_chain);
update_lightmap (surf, ctx); update_lightmap (brush, surf, ctx);
} }
if (!(is = surf->instsurf)) if (!(is = surf->instsurf))
is = surf->tinst; is = surf->tinst;
@ -245,13 +245,13 @@ chain_surface (msurface_t *surf, vec_t *transform, float *color,
} }
static void static void
register_textures (model_t *model, vulkan_ctx_t *ctx) register_textures (mod_brush_t *brush, vulkan_ctx_t *ctx)
{ {
int i; int i;
texture_t *tex; texture_t *tex;
for (i = 0; i < model->numtextures; i++) { for (i = 0; i < brush->numtextures; i++) {
tex = model->textures[i]; tex = brush->textures[i];
if (!tex) if (!tex)
continue; continue;
add_texture (tex, ctx); add_texture (tex, ctx);
@ -270,11 +270,12 @@ Vulkan_RegisterTextures (model_t **models, int num_models, vulkan_ctx_t *ctx)
{ {
int i; int i;
model_t *m; model_t *m;
mod_brush_t *brush = &r_worldentity.model->brush;
clear_textures (ctx); clear_textures (ctx);
init_surface_chains (r_worldentity.model, ctx); init_surface_chains (brush, ctx);
add_texture (r_notexture_mip, ctx); add_texture (r_notexture_mip, ctx);
register_textures (r_worldentity.model, ctx); register_textures (brush, ctx);
for (i = 0; i < num_models; i++) { for (i = 0; i < num_models; i++) {
m = models[i]; m = models[i];
if (!m) if (!m)
@ -285,8 +286,9 @@ Vulkan_RegisterTextures (model_t **models, int num_models, vulkan_ctx_t *ctx)
// world has already been done, not interested in non-brush models // world has already been done, not interested in non-brush models
if (m == r_worldentity.model || m->type != mod_brush) if (m == r_worldentity.model || m->type != mod_brush)
continue; continue;
m->numsubmodels = 1; // no support for submodels in non-world model brush = &m->brush;
register_textures (m, ctx); brush->numsubmodels = 1; // no support for submodels in non-world model
register_textures (brush, ctx);
} }
} }
@ -329,18 +331,18 @@ build_surf_displist (model_t **models, msurface_t *fa, int base,
bsppoly_t *poly; bsppoly_t *poly;
uint32_t *ind; uint32_t *ind;
float s, t; float s, t;
mod_brush_t *brush;
if (fa->ec_index < 0) { if (fa->ec_index < 0) {
// instance model // instance model
vertices = models[~fa->ec_index]->vertexes; brush = &models[~fa->ec_index]->brush;
edges = models[~fa->ec_index]->edges;
surfedges = models[~fa->ec_index]->surfedges;
} else { } else {
// main or sub model // main or sub model
vertices = r_worldentity.model->vertexes; brush = &r_worldentity.model->brush;
edges = r_worldentity.model->edges;
surfedges = r_worldentity.model->surfedges;
} }
vertices = brush->vertexes;
edges = brush->edges;
surfedges = brush->surfedges;
// create a triangle fan // create a triangle fan
numverts = fa->numedges; numverts = fa->numedges;
numindices = numverts + 1; numindices = numverts + 1;
@ -405,6 +407,7 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
qfv_stagebuf_t *stage; qfv_stagebuf_t *stage;
bspvert_t *vertices; bspvert_t *vertices;
bsppoly_t *poly; bsppoly_t *poly;
mod_brush_t *brush;
QuatSet (0, 0, sqrt(0.5), sqrt(0.5), bctx->sky_fix); // proper skies QuatSet (0, 0, sqrt(0.5), sqrt(0.5), bctx->sky_fix); // proper skies
QuatSet (0, 0, 0, 1, bctx->sky_rotation[0]); QuatSet (0, 0, 0, 1, bctx->sky_rotation[0]);
@ -421,24 +424,25 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
if (!m) if (!m)
continue; continue;
// sub-models are done as part of the main model // sub-models are done as part of the main model
if (*m->path == '*') if (*m->path == '*' || m->type != mod_brush)
continue; continue;
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
dm = m->submodels; dm = brush->submodels;
for (j = 0; j < m->numsurfaces; j++) { for (j = 0; j < brush->numsurfaces; j++) {
vulktex_t *tex; vulktex_t *tex;
if (j == dm->firstface + dm->numfaces) { if (j == dm->firstface + dm->numfaces) {
dm++; dm++;
if (dm - m->submodels == m->numsubmodels) { if (dm - brush->submodels == brush->numsubmodels) {
// limit the surfaces // limit the surfaces
// probably never hit // probably never hit
Sys_Printf ("R_BuildDisplayLists: too many surfaces\n"); Sys_Printf ("R_BuildDisplayLists: too many surfaces\n");
m->numsurfaces = j; brush->numsurfaces = j;
break; break;
} }
} }
surf = m->surfaces + j; surf = brush->surfaces + j;
surf->ec_index = dm - m->submodels; surf->ec_index = dm - brush->submodels;
if (!surf->ec_index && m != r_worldentity.model) if (!surf->ec_index && m != r_worldentity.model)
surf->ec_index = -1 - i; // instanced model surf->ec_index = -1 - i; // instanced model
tex = surf->texinfo->texture->render; tex = surf->texinfo->texture->render;
@ -602,8 +606,10 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx)
msurface_t *surf; msurface_t *surf;
qboolean rotated; qboolean rotated;
vec3_t mins, maxs, org; vec3_t mins, maxs, org;
mod_brush_t *brush;
model = e->model; model = e->model;
brush = &model->brush;
if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) { if (e->transform[0] != 1 || e->transform[5] != 1 || e->transform[10] != 1) {
rotated = true; rotated = true;
radius = model->radius; radius = model->radius;
@ -628,7 +634,7 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx)
} }
// calculate dynamic lighting for bmodel if it's not an instanced model // calculate dynamic lighting for bmodel if it's not an instanced model
if (model->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { if (brush->firstmodelsurface != 0 && r_dlight_lightmap->int_val) {
vec3_t lightorigin; vec3_t lightorigin;
for (k = 0; k < r_maxdlights; k++) { for (k = 0; k < r_maxdlights; k++) {
@ -637,14 +643,14 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx)
continue; continue;
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
R_RecursiveMarkLights (lightorigin, &r_dlights[k], k, R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k,
model->nodes + model->hulls[0].firstclipnode); brush->nodes + brush->hulls[0].firstclipnode);
} }
} }
surf = &model->surfaces[model->firstmodelsurface]; surf = &brush->surfaces[brush->firstmodelsurface];
for (i = 0; i < model->nummodelsurfaces; i++, surf++) { for (i = 0; i < brush->nummodelsurfaces; i++, surf++) {
// find the node side on which we are // find the node side on which we are
plane = surf->plane; plane = surf->plane;
@ -653,7 +659,7 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx)
// enqueue the polygon // enqueue the polygon
if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON))
|| (!(surf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) { || (!(surf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
chain_surface (surf, e->transform, e->colormod, ctx); chain_surface (brush, surf, e->transform, e->colormod, ctx);
} }
} }
} }
@ -678,7 +684,7 @@ get_side (mnode_t *node)
} }
static inline void static inline void
visit_node (mnode_t *node, int side, vulkan_ctx_t *ctx) visit_node (mod_brush_t *brush, mnode_t *node, int side, vulkan_ctx_t *ctx)
{ {
int c; int c;
msurface_t *surf; msurface_t *surf;
@ -687,7 +693,7 @@ visit_node (mnode_t *node, int side, vulkan_ctx_t *ctx)
side = (~side + 1) & SURF_PLANEBACK; side = (~side + 1) & SURF_PLANEBACK;
// draw stuff // draw stuff
if ((c = node->numsurfaces)) { if ((c = node->numsurfaces)) {
surf = r_worldentity.model->surfaces + node->firstsurface; surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) { for (; c; c--, surf++) {
if (surf->visframe != r_visframecount) if (surf->visframe != r_visframecount)
continue; continue;
@ -696,7 +702,7 @@ visit_node (mnode_t *node, int side, vulkan_ctx_t *ctx)
if (side ^ (surf->flags & SURF_PLANEBACK)) if (side ^ (surf->flags & SURF_PLANEBACK))
continue; // wrong side continue; // wrong side
chain_surface (surf, 0, 0, ctx); chain_surface (brush, surf, 0, 0, ctx);
} }
} }
} }
@ -714,7 +720,7 @@ test_node (mnode_t *node)
} }
static void static void
R_VisitWorldNodes (model_t *model, vulkan_ctx_t *ctx) R_VisitWorldNodes (mod_brush_t *brush, vulkan_ctx_t *ctx)
{ {
typedef struct { typedef struct {
mnode_t *node; mnode_t *node;
@ -726,9 +732,9 @@ R_VisitWorldNodes (model_t *model, vulkan_ctx_t *ctx)
mnode_t *front; mnode_t *front;
int side; int side;
node = model->nodes; node = brush->nodes;
// +2 for paranoia // +2 for paranoia
node_stack = alloca ((model->depth + 2) * sizeof (rstack_t)); node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
node_ptr = node_stack; node_ptr = node_stack;
while (1) { while (1) {
@ -744,7 +750,7 @@ R_VisitWorldNodes (model_t *model, vulkan_ctx_t *ctx)
} }
if (front->contents < 0 && front->contents != CONTENTS_SOLID) if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front); visit_leaf ((mleaf_t *) front);
visit_node (node, side, ctx); visit_node (brush, node, side, ctx);
node = node->children[!side]; node = node->children[!side];
} }
if (node->contents < 0 && node->contents != CONTENTS_SOLID) if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -753,7 +759,7 @@ R_VisitWorldNodes (model_t *model, vulkan_ctx_t *ctx)
node_ptr--; node_ptr--;
node = node_ptr->node; node = node_ptr->node;
side = node_ptr->side; side = node_ptr->side;
visit_node (node, side, ctx); visit_node (brush, node, side, ctx);
node = node->children[!side]; node = node->children[!side];
continue; continue;
} }
@ -1099,19 +1105,21 @@ Vulkan_DrawWorld (vulkan_ctx_t *ctx)
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
bspframe_t *bframe = &bctx->frames.a[ctx->curFrame]; bspframe_t *bframe = &bctx->frames.a[ctx->curFrame];
entity_t worldent; entity_t worldent;
mod_brush_t *brush;
clear_texture_chains (bctx); // do this first for water and skys clear_texture_chains (bctx); // do this first for water and skys
bframe->index_count = 0; bframe->index_count = 0;
memset (&worldent, 0, sizeof (worldent)); memset (&worldent, 0, sizeof (worldent));
worldent.model = r_worldentity.model; worldent.model = r_worldentity.model;
brush = &r_worldentity.model->brush;
//vulktex_t *tex = r_worldentity.model->skytexture->render; //vulktex_t *tex = r_worldentity.model->skytexture->render;
//bctx->skysheet_tex = tex->tex; //bctx->skysheet_tex = tex->tex;
currententity = &worldent; currententity = &worldent;
R_VisitWorldNodes (worldent.model, ctx); R_VisitWorldNodes (brush, ctx);
if (r_drawentities->int_val) { if (r_drawentities->int_val) {
entity_t *ent; entity_t *ent;
for (ent = r_ent_queue; ent; ent = ent->next) { for (ent = r_ent_queue; ent; ent = ent->next) {

View file

@ -125,7 +125,7 @@ add_dynamic_lights (msurface_t *surf, float *block)
} }
void void
Vulkan_BuildLightMap (msurface_t *surf, vulkan_ctx_t *ctx) Vulkan_BuildLightMap (mod_brush_t *brush, msurface_t *surf, vulkan_ctx_t *ctx)
{ {
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
int smax, tmax, size; int smax, tmax, size;
@ -142,7 +142,7 @@ Vulkan_BuildLightMap (msurface_t *surf, vulkan_ctx_t *ctx)
block = QFV_SubpicBatch (surf->lightpic, bctx->light_stage); block = QFV_SubpicBatch (surf->lightpic, bctx->light_stage);
// set to full bright if no light data // set to full bright if no light data
if (!r_worldentity.model->lightdata) { if (!brush->lightdata) {
out = block; out = block;
while (size-- > 0) { while (size-- > 0) {
*out++ = 1; *out++ = 1;
@ -219,6 +219,7 @@ Vulkan_BuildLightmaps (model_t **models, int num_models, vulkan_ctx_t *ctx)
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
int i, j; int i, j;
model_t *m; model_t *m;
mod_brush_t *brush;
QFV_ScrapClear (bctx->light_scrap); QFV_ScrapClear (bctx->light_scrap);
@ -228,13 +229,14 @@ Vulkan_BuildLightmaps (model_t **models, int num_models, vulkan_ctx_t *ctx)
m = models[j]; m = models[j];
if (!m) if (!m)
break; break;
if (m->path[0] == '*') { if (m->path[0] == '*' || m->type != mod_brush) {
// sub model surfaces are processed as part of the main model // sub model surfaces are processed as part of the main model
continue; continue;
} }
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = m->surfaces + i; msurface_t *surf = brush->surfaces + i;
surf->lightpic = 0; // paranoia surf->lightpic = 0; // paranoia
if (surf->flags & SURF_DRAWTURB) { if (surf->flags & SURF_DRAWTURB) {
continue; continue;
@ -251,15 +253,16 @@ Vulkan_BuildLightmaps (model_t **models, int num_models, vulkan_ctx_t *ctx)
if (!m) { if (!m) {
break; break;
} }
if (m->path[0] == '*') { if (m->path[0] == '*' || m->type != mod_brush) {
// sub model surfaces are processed as part of the main model // sub model surfaces are processed as part of the main model
continue; continue;
} }
brush = &m->brush;
// non-bsp models don't have surfaces. // non-bsp models don't have surfaces.
for (i = 0; i < m->numsurfaces; i++) { for (i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = m->surfaces + i; msurface_t *surf = brush->surfaces + i;
if (surf->lightpic) { if (surf->lightpic) {
Vulkan_BuildLightMap (surf, ctx); Vulkan_BuildLightMap (brush, surf, ctx);
} }
} }
} }

View file

@ -86,7 +86,7 @@ TraceLine (vec3_t start, vec3_t end, vec3_t impact)
memset (&trace, 0, sizeof (trace)); memset (&trace, 0, sizeof (trace));
trace.fraction = 1; trace.fraction = 1;
MOD_TraceLine (cl.worldmodel->hulls, 0, start, end, &trace); MOD_TraceLine (cl.worldmodel->brush.hulls, 0, start, end, &trace);
VectorCopy (trace.endpos, impact); VectorCopy (trace.endpos, impact);
} }

View file

@ -381,7 +381,7 @@ CL_RelinkEntities (void)
if (i != cl.viewentity || chase_active->int_val) { if (i != cl.viewentity || chase_active->int_val) {
if (ent->efrag) if (ent->efrag)
r_funcs->R_RemoveEfrags (ent); r_funcs->R_RemoveEfrags (ent);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
VectorCopy (ent->origin, ent->old_origin); VectorCopy (ent->origin, ent->old_origin);
} else { } else {
@ -416,10 +416,10 @@ CL_RelinkEntities (void)
if (ent->efrag) { if (ent->efrag) {
if (!VectorCompare (ent->origin, ent->old_origin)) { if (!VectorCompare (ent->origin, ent->old_origin)) {
r_funcs->R_RemoveEfrags (ent); r_funcs->R_RemoveEfrags (ent);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} else { } else {
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} }
} }

View file

@ -301,7 +301,7 @@ map_ent (const char *mapname)
edicts = ED_Parse (&edpr, buf); edicts = ED_Parse (&edpr, buf);
free (buf); free (buf);
} else { } else {
edicts = ED_Parse (&edpr, cl.model_precache[1]->entities); edicts = ED_Parse (&edpr, cl.model_precache[1]->brush.entities);
} }
free (name); free (name);
return edicts; return edicts;
@ -315,7 +315,7 @@ CL_NewMap (const char *mapname)
Hunk_Check (); // make sure nothing is hurt Hunk_Check (); // make sure nothing is hurt
Sbar_CenterPrint (0); Sbar_CenterPrint (0);
if (cl.model_precache[1] && cl.model_precache[1]->entities) { if (cl.model_precache[1] && cl.model_precache[1]->brush.entities) {
cl.edicts = map_ent (mapname); cl.edicts = map_ent (mapname);
if (cl.edicts) { if (cl.edicts) {
cl.worldspawn = PL_ObjectAtIndex (cl.edicts, 0); cl.worldspawn = PL_ObjectAtIndex (cl.edicts, 0);
@ -795,7 +795,7 @@ CL_ParseStatic (int version)
VectorCopy (baseline.origin, ent->origin); VectorCopy (baseline.origin, ent->origin);
CL_TransformEntity (ent, baseline.angles, true); CL_TransformEntity (ent, baseline.angles, true);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
static void static void

View file

@ -294,7 +294,7 @@ beam_setup (beam_t *b, qboolean transform)
CL_TransformEntity (&tent->ent, ang, true); CL_TransformEntity (&tent->ent, ang, true);
} }
VectorCopy (ang, tent->ent.angles); VectorCopy (ang, tent->ent.angles);
r_funcs->R_AddEfrags (&tent->ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, &tent->ent);
} }
} }
@ -588,7 +588,7 @@ CL_UpdateExplosions (void)
ent->frame = f; ent->frame = f;
if (!ent->efrag) if (!ent->efrag)
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} }

View file

@ -432,9 +432,9 @@ SV_AddToFatPVS (vec3_t org, mnode_t *node)
static byte * static byte *
SV_FatPVS (vec3_t org) SV_FatPVS (vec3_t org)
{ {
fatbytes = (sv.worldmodel->numleafs + 31) >> 3; fatbytes = (sv.worldmodel->brush.numleafs + 31) >> 3;
memset (fatpvs, 0, fatbytes); memset (fatpvs, 0, fatbytes);
SV_AddToFatPVS (org, sv.worldmodel->nodes); SV_AddToFatPVS (org, sv.worldmodel->brush.nodes);
return fatpvs; return fatpvs;
} }
@ -1189,7 +1189,7 @@ SV_SpawnServer (const char *server)
sv.model_precache[0] = sv_pr_state.pr_strings; sv.model_precache[0] = sv_pr_state.pr_strings;
sv.model_precache[1] = sv.modelname; sv.model_precache[1] = sv.modelname;
for (i = 1; i < sv.worldmodel->numsubmodels; i++) { for (i = 1; i < sv.worldmodel->brush.numsubmodels; i++) {
sv.model_precache[1 + i] = localmodels[i]; sv.model_precache[1 + i] = localmodels[i];
sv.models[i + 1] = Mod_ForName (localmodels[i], false); sv.models[i + 1] = Mod_ForName (localmodels[i], false);
} }
@ -1220,7 +1220,7 @@ SV_SpawnServer (const char *server)
ED_LoadFromFile (&sv_pr_state, (char *) buf); ED_LoadFromFile (&sv_pr_state, (char *) buf);
free (buf); free (buf);
} else { } else {
ED_LoadFromFile (&sv_pr_state, sv.worldmodel->entities); ED_LoadFromFile (&sv_pr_state, sv.worldmodel->brush.entities);
} }
sv.active = true; sv.active = true;

View file

@ -585,7 +585,7 @@ PF_newcheckclient (progs_t *pr, int check)
VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org); VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org);
leaf = Mod_PointInLeaf (org, sv.worldmodel); leaf = Mod_PointInLeaf (org, sv.worldmodel);
pvs = Mod_LeafPVS (leaf, sv.worldmodel); pvs = Mod_LeafPVS (leaf, sv.worldmodel);
memcpy (checkpvs, pvs, (sv.worldmodel->numleafs + 7) >> 3); memcpy (checkpvs, pvs, (sv.worldmodel->brush.numleafs + 7) >> 3);
return i; return i;
} }
@ -630,7 +630,7 @@ PF_checkclient (progs_t *pr)
self = PROG_TO_EDICT (pr, *sv_globals.self); self = PROG_TO_EDICT (pr, *sv_globals.self);
VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view); VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view);
leaf = Mod_PointInLeaf (view, sv.worldmodel); leaf = Mod_PointInLeaf (view, sv.worldmodel);
l = (leaf - sv.worldmodel->leafs) - 1; l = (leaf - sv.worldmodel->brush.leafs) - 1;
if ((l < 0) || !(checkpvs[l >> 3] & (1 << (l & 7)))) { if ((l < 0) || !(checkpvs[l >> 3] & (1 << (l & 7)))) {
c_notvis++; c_notvis++;
RETURN_EDICT (pr, sv.edicts); RETURN_EDICT (pr, sv.edicts);

View file

@ -245,7 +245,7 @@ SV_HullForEntity (edict_t *ent, const vec3_t mins, const vec3_t maxs,
PR_GetString (&sv_pr_state, PR_GetString (&sv_pr_state,
SVstring (ent, classname))); SVstring (ent, classname)));
hull_list = model->hull_list; hull_list = model->brush.hull_list;
} }
if (hull_list) { if (hull_list) {
// decide which clipping hull to use, based on the size // decide which clipping hull to use, based on the size
@ -425,7 +425,7 @@ SV_FindTouchedLeafs (edict_t *ent, mnode_t *node)
leaf = (mleaf_t *) node; leaf = (mleaf_t *) node;
edict_leaf = alloc_edict_leaf (); edict_leaf = alloc_edict_leaf ();
edict_leaf->leafnum = leaf - sv.worldmodel->leafs - 1; edict_leaf->leafnum = leaf - sv.worldmodel->brush.leafs - 1;
edict_leaf->next = SVdata (ent)->leafs; edict_leaf->next = SVdata (ent)->leafs;
SVdata (ent)->leafs = edict_leaf; SVdata (ent)->leafs = edict_leaf;
return; return;
@ -497,7 +497,7 @@ SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
// link to PVS leafs // link to PVS leafs
free_edict_leafs (&SVdata (ent)->leafs); free_edict_leafs (&SVdata (ent)->leafs);
if (SVfloat (ent, modelindex)) if (SVfloat (ent, modelindex))
SV_FindTouchedLeafs (ent, sv.worldmodel->nodes); SV_FindTouchedLeafs (ent, sv.worldmodel->brush.nodes);
if (SVfloat (ent, solid) == SOLID_NOT) if (SVfloat (ent, solid) == SOLID_NOT)
return; return;
@ -560,7 +560,7 @@ SV_PointContents (const vec3_t p)
{ {
int cont; int cont;
cont = SV_HullPointContents (&sv.worldmodel->hulls[0], 0, p); cont = SV_HullPointContents (&sv.worldmodel->brush.hulls[0], 0, p);
if (cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN) if (cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN)
cont = CONTENTS_WATER; cont = CONTENTS_WATER;
return cont; return cont;
@ -569,7 +569,7 @@ SV_PointContents (const vec3_t p)
int int
SV_TruePointContents (const vec3_t p) SV_TruePointContents (const vec3_t p)
{ {
return SV_HullPointContents (&sv.worldmodel->hulls[0], 0, p); return SV_HullPointContents (&sv.worldmodel->brush.hulls[0], 0, p);
} }
/* /*
@ -903,7 +903,7 @@ SV_TestPlayerPosition (edict_t *ent, const vec3_t origin)
vec3_t boxmins, boxmaxs, offset; vec3_t boxmins, boxmaxs, offset;
// check world first // check world first
hull = &sv.worldmodel->hulls[1]; hull = &sv.worldmodel->brush.hulls[1];
if (SV_HullPointContents (hull, hull->firstclipnode, origin) != if (SV_HullPointContents (hull, hull->firstclipnode, origin) !=
CONTENTS_EMPTY) return sv.edicts; CONTENTS_EMPTY) return sv.edicts;

View file

@ -86,7 +86,7 @@ TraceLine (vec3_t start, vec3_t end, vec3_t impact)
memset (&trace, 0, sizeof (trace)); memset (&trace, 0, sizeof (trace));
trace.fraction = 1; trace.fraction = 1;
MOD_TraceLine (cl.worldmodel->hulls, 0, start, end, &trace); MOD_TraceLine (cl.worldmodel->brush.hulls, 0, start, end, &trace);
VectorCopy (trace.endpos, impact); VectorCopy (trace.endpos, impact);
} }

View file

@ -542,7 +542,7 @@ CL_SetSolidEntities (void)
continue; continue;
if (!cl.model_precache[state->modelindex]) if (!cl.model_precache[state->modelindex])
continue; continue;
if (cl.model_precache[state->modelindex]->hulls[1].firstclipnode if (cl.model_precache[state->modelindex]->brush.hulls[1].firstclipnode
|| cl.model_precache[state->modelindex]->clipbox) { || cl.model_precache[state->modelindex]->clipbox) {
if (pmove.numphysent == MAX_PHYSENTS) { if (pmove.numphysent == MAX_PHYSENTS) {
Sys_Printf ("WARNING: entity physent overflow, email " Sys_Printf ("WARNING: entity physent overflow, email "

View file

@ -335,7 +335,7 @@ CL_LinkPacketEntities (void)
if (i != cl.viewentity || chase_active->int_val) { if (i != cl.viewentity || chase_active->int_val) {
if (ent->efrag) if (ent->efrag)
r_funcs->R_RemoveEfrags (ent); r_funcs->R_RemoveEfrags (ent);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
VectorCopy (ent->origin, ent->old_origin); VectorCopy (ent->origin, ent->old_origin);
} else { } else {
@ -370,15 +370,15 @@ CL_LinkPacketEntities (void)
if (ent->efrag) { if (ent->efrag) {
if (!VectorCompare (ent->origin, ent->old_origin)) { if (!VectorCompare (ent->origin, ent->old_origin)) {
r_funcs->R_RemoveEfrags (ent); r_funcs->R_RemoveEfrags (ent);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} else { } else {
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} }
} }
if (!ent->efrag) if (!ent->efrag)
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
// rotate binary objects locally // rotate binary objects locally
if (ent->model->flags & EF_ROTATE) { if (ent->model->flags & EF_ROTATE) {
@ -567,7 +567,7 @@ CL_LinkPlayers (void)
} }
// stuff entity in map // stuff entity in map
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
if (state->pls.effects & EF_FLAG1) if (state->pls.effects & EF_FLAG1)
CL_AddFlagModels (ent, 0, j); CL_AddFlagModels (ent, 0, j);

View file

@ -288,7 +288,7 @@ map_ent (const char *mapname)
edicts = ED_Parse (&edpr, buf); edicts = ED_Parse (&edpr, buf);
free (buf); free (buf);
} else { } else {
edicts = ED_Parse (&edpr, cl.model_precache[1]->entities); edicts = ED_Parse (&edpr, cl.model_precache[1]->brush.entities);
} }
free (name); free (name);
return edicts; return edicts;
@ -305,7 +305,7 @@ CL_NewMap (const char *mapname)
Hunk_Check (); // make sure nothing is hurt Hunk_Check (); // make sure nothing is hurt
Sbar_CenterPrint (0); Sbar_CenterPrint (0);
if (cl.model_precache[1] && cl.model_precache[1]->entities) { if (cl.model_precache[1] && cl.model_precache[1]->brush.entities) {
cl.edicts = map_ent (mapname); cl.edicts = map_ent (mapname);
if (cl.edicts) { if (cl.edicts) {
cl.worldspawn = PL_ObjectAtIndex (cl.edicts, 0); cl.worldspawn = PL_ObjectAtIndex (cl.edicts, 0);
@ -404,7 +404,7 @@ Model_NextDownload (void)
MSG_WriteByte (&cls.netchan.message, clc_stringcmd); MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message, MSG_WriteString (&cls.netchan.message,
va (0, prespawn_name, cl.servercount, va (0, prespawn_name, cl.servercount,
cl.worldmodel->checksum2)); cl.worldmodel->brush.checksum2));
} }
} }
@ -986,7 +986,7 @@ CL_ParseStatic (void)
VectorCopy (es.origin, ent->origin); VectorCopy (es.origin, ent->origin);
CL_TransformEntity (ent, es.angles, true); CL_TransformEntity (ent, es.angles, true);
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
static void static void

View file

@ -298,7 +298,7 @@ beam_setup (beam_t *b, qboolean transform)
CL_TransformEntity (&tent->ent, ang, true); CL_TransformEntity (&tent->ent, ang, true);
} }
VectorCopy (ang, tent->ent.angles); VectorCopy (ang, tent->ent.angles);
r_funcs->R_AddEfrags (&tent->ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, &tent->ent);
} }
} }
@ -595,7 +595,7 @@ CL_UpdateExplosions (void)
ent->frame = f; ent->frame = f;
if (!ent->efrag) if (!ent->efrag)
r_funcs->R_AddEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
} }
} }
@ -658,7 +658,7 @@ CL_ParseProjectiles (qboolean nail2)
pr->angles[2] = 0; pr->angles[2] = 0;
CL_TransformEntity (&tent->ent, tent->ent.angles, true); CL_TransformEntity (&tent->ent, tent->ent.angles, true);
r_funcs->R_AddEfrags (&tent->ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, &tent->ent);
} }
*tail = cl_projectiles; *tail = cl_projectiles;

View file

@ -136,7 +136,7 @@ PM_PointContents (const vec3_t p)
hull_t *hull; hull_t *hull;
plane_t *plane; plane_t *plane;
hull = &pmove.physents[0].model->hulls[0]; hull = &pmove.physents[0].model->brush.hulls[0];
num = hull->firstclipnode; num = hull->firstclipnode;
@ -174,7 +174,7 @@ PM_TestPlayerPosition (const vec3_t pos)
pe = &pmove.physents[i]; pe = &pmove.physents[i];
// get the clipping hull // get the clipping hull
if (pe->model) if (pe->model)
hull = &pmove.physents[i].model->hulls[1]; hull = &pmove.physents[i].model->brush.hulls[1];
else { else {
VectorSubtract (pe->mins, player_maxs, mins); VectorSubtract (pe->mins, player_maxs, mins);
VectorSubtract (pe->maxs, player_mins, maxs); VectorSubtract (pe->maxs, player_mins, maxs);
@ -235,7 +235,7 @@ PM_PlayerMove (const vec3_t start, const vec3_t end)
} else { } else {
check_box = 1; check_box = 1;
if (pe->model) { if (pe->model) {
hull = &pe->model->hulls[1]; hull = &pe->model->brush.hulls[1];
VectorSubtract (pe->model->mins, player_maxs, mins); VectorSubtract (pe->model->mins, player_maxs, mins);
VectorSubtract (pe->model->maxs, player_mins, maxs); VectorSubtract (pe->model->maxs, player_mins, maxs);
} else { } else {

View file

@ -99,9 +99,9 @@ SV_AddToFatPVS (vec3_t org, mnode_t *node)
static byte * static byte *
SV_FatPVS (vec3_t org) SV_FatPVS (vec3_t org)
{ {
fatbytes = (sv.worldmodel->numleafs + 31) >> 3; fatbytes = (sv.worldmodel->brush.numleafs + 31) >> 3;
memset (fatpvs, 0, fatbytes); memset (fatpvs, 0, fatbytes);
SV_AddToFatPVS (org, sv.worldmodel->nodes); SV_AddToFatPVS (org, sv.worldmodel->brush.nodes);
return fatpvs; return fatpvs;
} }
@ -738,7 +738,7 @@ calc_pvs (delta_t *delta)
if (pvs == NULL) { if (pvs == NULL) {
pvs = SV_FatPVS (org); pvs = SV_FatPVS (org);
} else { } else {
SV_AddToFatPVS (org, sv.worldmodel->nodes); SV_AddToFatPVS (org, sv.worldmodel->brush.nodes);
} }
} }
} }

View file

@ -229,7 +229,7 @@ SV_CalcPHS (void)
SV_Printf ("Building PHS...\n"); SV_Printf ("Building PHS...\n");
num = sv.worldmodel->numleafs; num = sv.worldmodel->brush.numleafs;
rowwords = (num + 31) >> 5; rowwords = (num + 31) >> 5;
rowbytes = rowwords * 4; rowbytes = rowwords * 4;
@ -237,7 +237,8 @@ SV_CalcPHS (void)
scan = sv.pvs; scan = sv.pvs;
vcount = 0; vcount = 0;
for (i = 0; i < num; i++, scan += rowbytes) { for (i = 0; i < num; i++, scan += rowbytes) {
memcpy (scan, Mod_LeafPVS (sv.worldmodel->leafs + i, sv.worldmodel), memcpy (scan, Mod_LeafPVS (sv.worldmodel->brush.leafs + i,
sv.worldmodel),
rowbytes); rowbytes);
if (i == 0) if (i == 0)
continue; continue;
@ -402,7 +403,7 @@ SV_SpawnServer (const char *server)
sv.model_precache[0] = sv_pr_state.pr_strings; sv.model_precache[0] = sv_pr_state.pr_strings;
sv.model_precache[1] = sv.modelname; sv.model_precache[1] = sv.modelname;
sv.models[1] = sv.worldmodel; sv.models[1] = sv.worldmodel;
for (i = 1; i < sv.worldmodel->numsubmodels; i++) { for (i = 1; i < sv.worldmodel->brush.numsubmodels; i++) {
sv.model_precache[1 + i] = localmodels[i]; sv.model_precache[1 + i] = localmodels[i];
sv.models[i + 1] = Mod_ForName (localmodels[i], false); sv.models[i + 1] = Mod_ForName (localmodels[i], false);
} }
@ -443,7 +444,7 @@ SV_SpawnServer (const char *server)
ED_LoadFromFile (&sv_pr_state, (char *) buf); ED_LoadFromFile (&sv_pr_state, (char *) buf);
free (buf); free (buf);
} else { } else {
ED_LoadFromFile (&sv_pr_state, sv.worldmodel->entities); ED_LoadFromFile (&sv_pr_state, sv.worldmodel->brush.entities);
} }
// look up some model indexes for specialized message compression // look up some model indexes for specialized message compression

View file

@ -506,7 +506,7 @@ PF_newcheckclient (progs_t *pr, int check)
VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org); VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org);
leaf = Mod_PointInLeaf (org, sv.worldmodel); leaf = Mod_PointInLeaf (org, sv.worldmodel);
pvs = Mod_LeafPVS (leaf, sv.worldmodel); pvs = Mod_LeafPVS (leaf, sv.worldmodel);
memcpy (checkpvs, pvs, (sv.worldmodel->numleafs + 7) >> 3); memcpy (checkpvs, pvs, (sv.worldmodel->brush.numleafs + 7) >> 3);
return i; return i;
} }
@ -551,7 +551,7 @@ PF_checkclient (progs_t *pr)
self = PROG_TO_EDICT (pr, *sv_globals.self); self = PROG_TO_EDICT (pr, *sv_globals.self);
VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view); VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view);
leaf = Mod_PointInLeaf (view, sv.worldmodel); leaf = Mod_PointInLeaf (view, sv.worldmodel);
l = (leaf - sv.worldmodel->leafs) - 1; l = (leaf - sv.worldmodel->brush.leafs) - 1;
if ((l < 0) || !(checkpvs[l >> 3] & (1 << (l & 7)))) { if ((l < 0) || !(checkpvs[l >> 3] & (1 << (l & 7)))) {
c_notvis++; c_notvis++;
RETURN_EDICT (pr, sv.edicts); RETURN_EDICT (pr, sv.edicts);

View file

@ -297,12 +297,13 @@ SV_Multicast (const vec3_t origin, int to)
int leafnum, j; int leafnum, j;
mleaf_t *leaf; mleaf_t *leaf;
qboolean reliable; qboolean reliable;
mod_brush_t *brush = &sv.worldmodel->brush;
leaf = Mod_PointInLeaf (origin, sv.worldmodel); leaf = Mod_PointInLeaf (origin, sv.worldmodel);
if (!leaf) if (!leaf)
leafnum = 0; leafnum = 0;
else else
leafnum = leaf - sv.worldmodel->leafs; leafnum = leaf - sv.worldmodel->brush.leafs;
reliable = false; reliable = false;
@ -316,13 +317,13 @@ SV_Multicast (const vec3_t origin, int to)
case MULTICAST_PHS_R: case MULTICAST_PHS_R:
reliable = true; // intentional fallthrough reliable = true; // intentional fallthrough
case MULTICAST_PHS: case MULTICAST_PHS:
mask = sv.phs + leafnum * 4 * ((sv.worldmodel->numleafs + 31) >> 5); mask = sv.phs + leafnum * 4 * ((brush->numleafs + 31) >> 5);
break; break;
case MULTICAST_PVS_R: case MULTICAST_PVS_R:
reliable = true; // intentional fallthrough reliable = true; // intentional fallthrough
case MULTICAST_PVS: case MULTICAST_PVS:
mask = sv.pvs + leafnum * 4 * ((sv.worldmodel->numleafs + 31) >> 5); mask = sv.pvs + leafnum * 4 * ((brush->numleafs + 31) >> 5);
break; break;
default: default:
@ -347,7 +348,7 @@ SV_Multicast (const vec3_t origin, int to)
sv.worldmodel); sv.worldmodel);
if (leaf) { if (leaf) {
// -1 is because pvs rows are 1 based, not 0 based like leafs // -1 is because pvs rows are 1 based, not 0 based like leafs
leafnum = leaf - sv.worldmodel->leafs - 1; leafnum = leaf - brush->leafs - 1;
if (!(mask[leafnum >> 3] & (1 << (leafnum & 7)))) { if (!(mask[leafnum >> 3] & (1 << (leafnum & 7)))) {
// SV_Printf ("supressed multicast\n"); // SV_Printf ("supressed multicast\n");
continue; continue;

View file

@ -335,14 +335,15 @@ SV_PreSpawn_f (void *unused)
// Sys_MaskPrintf (SYS_DEV, , "Client check = %d\n", check); // Sys_MaskPrintf (SYS_DEV, , "Client check = %d\n", check);
if (sv_mapcheck->int_val && check != sv.worldmodel->checksum && if (sv_mapcheck->int_val && check != sv.worldmodel->brush.checksum &&
check != sv.worldmodel->checksum2) { check != sv.worldmodel->brush.checksum2) {
SV_ClientPrintf (1, host_client, PRINT_HIGH, "Map model file does " SV_ClientPrintf (1, host_client, PRINT_HIGH, "Map model file does "
"not match (%s), %i != %i/%i.\n" "not match (%s), %i != %i/%i.\n"
"You may need a new version of the map, or the " "You may need a new version of the map, or the "
"proper install files.\n", "proper install files.\n",
sv.modelname, check, sv.worldmodel->checksum, sv.modelname, check,
sv.worldmodel->checksum2); sv.worldmodel->brush.checksum,
sv.worldmodel->brush.checksum2);
SV_DropClient (host_client); SV_DropClient (host_client);
return; return;
} }

View file

@ -245,7 +245,7 @@ SV_HullForEntity (edict_t *ent, const vec3_t mins, const vec3_t maxs,
PR_GetString (&sv_pr_state, PR_GetString (&sv_pr_state,
SVstring (ent, classname))); SVstring (ent, classname)));
hull_list = model->hull_list; hull_list = model->brush.hull_list;
} }
if (hull_list) { if (hull_list) {
// decide which clipping hull to use, based on the size // decide which clipping hull to use, based on the size
@ -425,7 +425,7 @@ SV_FindTouchedLeafs (edict_t *ent, mnode_t *node)
leaf = (mleaf_t *) node; leaf = (mleaf_t *) node;
edict_leaf = alloc_edict_leaf (); edict_leaf = alloc_edict_leaf ();
edict_leaf->leafnum = leaf - sv.worldmodel->leafs - 1; edict_leaf->leafnum = leaf - sv.worldmodel->brush.leafs - 1;
edict_leaf->next = SVdata (ent)->leafs; edict_leaf->next = SVdata (ent)->leafs;
SVdata (ent)->leafs = edict_leaf; SVdata (ent)->leafs = edict_leaf;
return; return;
@ -497,7 +497,7 @@ SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
// link to PVS leafs // link to PVS leafs
free_edict_leafs (&SVdata (ent)->leafs); free_edict_leafs (&SVdata (ent)->leafs);
if (SVfloat (ent, modelindex)) if (SVfloat (ent, modelindex))
SV_FindTouchedLeafs (ent, sv.worldmodel->nodes); SV_FindTouchedLeafs (ent, sv.worldmodel->brush.nodes);
if (SVfloat (ent, solid) == SOLID_NOT) if (SVfloat (ent, solid) == SOLID_NOT)
return; return;
@ -560,7 +560,7 @@ SV_PointContents (const vec3_t p)
{ {
int cont; int cont;
cont = SV_HullPointContents (&sv.worldmodel->hulls[0], 0, p); cont = SV_HullPointContents (&sv.worldmodel->brush.hulls[0], 0, p);
if (cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN) if (cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN)
cont = CONTENTS_WATER; cont = CONTENTS_WATER;
return cont; return cont;
@ -569,7 +569,7 @@ SV_PointContents (const vec3_t p)
int int
SV_TruePointContents (const vec3_t p) SV_TruePointContents (const vec3_t p)
{ {
return SV_HullPointContents (&sv.worldmodel->hulls[0], 0, p); return SV_HullPointContents (&sv.worldmodel->brush.hulls[0], 0, p);
} }
/* /*
@ -991,7 +991,7 @@ SV_TestPlayerPosition (edict_t *ent, const vec3_t origin)
vec3_t boxmins, boxmaxs, offset; vec3_t boxmins, boxmaxs, offset;
// check world first // check world first
hull = &sv.worldmodel->hulls[1]; hull = &sv.worldmodel->brush.hulls[1];
if (SV_HullPointContents (hull, hull->firstclipnode, origin) != if (SV_HullPointContents (hull, hull->firstclipnode, origin) !=
CONTENTS_EMPTY) return sv.edicts; CONTENTS_EMPTY) return sv.edicts;