Share mnode_t and mleaf_t struct between renders.

This commit is contained in:
Denis Pauk 2022-10-24 23:49:52 +03:00
parent 54949d59ce
commit 4463e1fcd7
15 changed files with 145 additions and 344 deletions

View file

@ -295,3 +295,83 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
// Unknow format, no images associated with it
return 0;
}
/*
=================
Mod_SetParent
=================
*/
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != CONTENTS_NODE)
{
return;
}
Mod_SetParent (node->children[0], node);
Mod_SetParent (node->children[1], node);
}
/*
=================
Mod_LoadNodes
=================
*/
void
Mod_LoadNodes(const char *name, cplane_t *planes, struct mleaf_s *leafs,
mnode_t **nodes, int *numnodes, const byte *mod_base, const lump_t *l)
{
int i, count;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
*nodes = out;
*numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
int j, p;
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = planes + p;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = CONTENTS_NODE; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
p = LittleLong(in->children[j]);
if (p >= 0)
{
out->children[j] = *nodes + p;
}
else
{
out->children[j] = (mnode_t *)(leafs + (-1 - p));
}
}
}
Mod_SetParent(*nodes, NULL); /* sets nodes and leafs */
}

View file

@ -129,7 +129,7 @@ R_MarkLights(dlight_t *light, int bit, mnode_t *node)
int i;
int sidebit;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return;
}
@ -220,7 +220,7 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return -1; /* didn't hit anything */
}

View file

@ -86,7 +86,7 @@ Mod_PointInLeaf(vec3_t p, model_t *model)
while (1)
{
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return (mleaf_t *)node;
}
@ -753,74 +753,6 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l)
LM_EndBuildingLightmaps();
}
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
{
return;
}
Mod_SetParent(node->children[0], node);
Mod_SetParent(node->children[1], node);
}
static void
Mod_LoadNodes(model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j, count, p;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = -1; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
p = LittleLong(in->children[j]);
if (p >= 0)
{
out->children[j] = loadmodel->nodes + p;
}
else
{
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
}
Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */
}
static void
Mod_LoadLeafs(model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -1063,7 +995,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes(mod->name, mod->planes, mod->leafs, &mod->nodes,
&mod->numnodes, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
mod->numframes = 2; /* regular and alternate animation */
}

View file

@ -837,7 +837,7 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
}
/* if a leaf node, draw stuff */
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
pleaf = (mleaf_t *)node;

View file

@ -72,42 +72,6 @@ typedef struct msurface_s
byte *samples; /* [numstyles*surfsize] */
} msurface_t;
typedef struct mnode_s
{
/* common with leaf */
int contents; /* -1, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with node */
int contents; /* wil be a negative contents number */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
} mleaf_t;
/* Whole model */
typedef struct model_s

View file

@ -45,7 +45,7 @@ GL3_MarkLights(dlight_t *light, int bit, mnode_t *node)
int i;
int sidebit;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return;
}
@ -147,7 +147,7 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return -1; /* didn't hit anything */
}

View file

@ -80,7 +80,7 @@ GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model)
while (1)
{
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return (mleaf_t *)node;
}
@ -623,74 +623,6 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
GL3_LM_EndBuildingLightmaps();
}
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
{
return;
}
Mod_SetParent(node->children[0], node);
Mod_SetParent(node->children[1], node);
}
static void
Mod_LoadNodes(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j, count, p;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = -1; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
p = LittleLong(in->children[j]);
if (p >= 0)
{
out->children[j] = loadmodel->nodes + p;
}
else
{
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
}
Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */
}
static void
Mod_LoadLeafs(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -932,7 +864,8 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen)
Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes(mod->name, mod->planes, mod->leafs, &mod->nodes,
&mod->numnodes, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
mod->numframes = 2; /* regular and alternate animation */
}

View file

@ -694,7 +694,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
}
/* if a leaf node, draw stuff */
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
pleaf = (mleaf_t *)node;

View file

@ -88,42 +88,6 @@ typedef struct msurface_s
byte *samples; /* [numstyles*surfsize] */
} msurface_t;
typedef struct mnode_s
{
/* common with leaf */
int contents; /* -1, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with node */
int contents; /* wil be a negative contents number */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
} mleaf_t;
/* Whole model */
// this, must be struct model_s, not gl3model_s,

View file

@ -137,6 +137,44 @@ typedef struct mtexinfo_s
struct image_s *image;
} mtexinfo_t;
#define CONTENTS_NODE -1
typedef struct mnode_s
{
/* common with leaf */
int contents; /* CONTENTS_NODE, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with leaf */
int contents; /* CONTENTS_NODE, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
struct msurface_s **firstmarksurface;
int nummarksurfaces;
int key; /* BSP sequence number for leaf's contents */
} mleaf_t;
/* Shared models func */
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
@ -150,7 +188,8 @@ extern struct image_s *GetSkyImage(const char *skyname, const char* surfname,
qboolean palettedtexture, findimage_t find_image);
extern struct image_s *GetTexImage(const char *name, findimage_t find_image);
extern struct image_s *R_FindPic(const char *name, findimage_t find_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type,
qboolean r_retexturing, loadimage_t load_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext,
imagetype_t type, qboolean r_retexturing, loadimage_t load_image);
extern void Mod_LoadNodes(const char *name, cplane_t *planes, struct mleaf_s *leafs,
mnode_t **nodes, int *numnodes, const byte *mod_base, const lump_t *l);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View file

@ -69,47 +69,6 @@ typedef struct msurface_s
struct msurface_s *nextalphasurface;
} msurface_t;
#define CONTENTS_NODE -1
typedef struct mnode_s
{
// common with leaf
int contents; // CONTENTS_NODE, to differentiate from leafs
int visframe; // node needs to be traversed if current
/* FIXME: is different type in other renders */
short minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// node specific
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
// common with node
int contents; // wil be something other than CONTENTS_NODE
int visframe; // node needs to be traversed if current
short minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// leaf specific
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
int key; // BSP sequence number for leaf's contents
} mleaf_t;
//===================================================================
//

View file

@ -518,9 +518,9 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
d -= view_clipplanes[i].dist;
if (d <= 0)
return;
acceptpt[0] = (float)node->minmaxs[pindex[3+0]];
acceptpt[1] = (float)node->minmaxs[pindex[3+1]];
acceptpt[2] = (float)node->minmaxs[pindex[3+2]];
acceptpt[0] = node->minmaxs[pindex[3+0]];
acceptpt[1] = node->minmaxs[pindex[3+1]];
acceptpt[2] = node->minmaxs[pindex[3+2]];
d = DotProduct (acceptpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
@ -533,7 +533,7 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
c_drawnode++;
// if a leaf node, draw stuff
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
msurface_t **mark;
pleaf = (mleaf_t *)node;

View file

@ -42,7 +42,7 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
msurface_t *surf;
int i;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
return;
splitplane = node->plane;
@ -122,7 +122,7 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
return -1; // didn't hit anything
// calculate mid point

View file

@ -323,7 +323,7 @@ Mod_PointInLeaf (const vec3_t p, const model_t *model)
}
node = model->nodes;
while (node->contents == -1)
while (node->contents == CONTENTS_NODE)
{
float d;
cplane_t *plane;

View file

@ -295,7 +295,7 @@ static int r_numvisleafs;
static void
R_NumberLeafs (model_t *loadmodel, mnode_t *node)
{
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
mleaf_t *leaf;
int leafnum;
@ -714,78 +714,6 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
/*
=================
Mod_SetParent
=================
*/
static void
Mod_SetParent (mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
return;
Mod_SetParent (node->children[0], node);
Mod_SetParent (node->children[1], node);
}
/*
=================
Mod_LoadNodes
=================
*/
static void
Mod_LoadNodes (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, count;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count*sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
int j, p;
for (j=0 ; j<3 ; j++)
{
out->minmaxs[j] = LittleShort (in->mins[j]);
out->minmaxs[3+j] = LittleShort (in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort (in->firstface);
out->numsurfaces = LittleShort (in->numfaces);
out->contents = CONTENTS_NODE; // differentiate from leafs
for (j=0 ; j<2 ; j++)
{
p = LittleLong (in->children[j]);
if (p >= 0)
out->children[j] = loadmodel->nodes + p;
else
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
}
/*
=================
Mod_LoadLeafs
@ -1047,7 +975,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
Mod_LoadMarksurfaces (mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility (mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs (mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes (mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes (mod->name, mod->planes, mod->leafs, &mod->nodes,
&mod->numnodes, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
r_numvisleafs = 0;