Share mnode_t and mleaf_t struct between renders.

4463e1fcd7
This commit is contained in:
Denis Pauk 2023-01-21 23:24:51 +02:00
parent 0f6d05ed9b
commit 6c3c2f3ec2
6 changed files with 207 additions and 131 deletions

View file

@ -29,6 +29,23 @@
#include "ref_api.h"
#ifdef _MSC_VER
#include <malloc.h>
#define YQ2_VLA(TYPE, VARNAME, NUMELEMS) \
TYPE * VARNAME = (TYPE *) _malloca(sizeof(TYPE) * NUMELEMS)
#define YQ2_VLAFREE(VARNAME) \
_freea(VARNAME); VARNAME=NULL;
#else // other compilers hopefully support C99 VLAs (gcc/mingw and clang do)
#define YQ2_VLA(TYPE, VARNAME, NUMELEMS) \
TYPE VARNAME[NUMELEMS]
#define YQ2_VLAFREE(VARNAME)
#endif
/*
* skins will be outline flood filled and mip mapped
* pics and sprites with alpha will be outline flood filled
@ -120,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,
@ -133,7 +188,10 @@ 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, int numplanes,
mleaf_t *leafs, int numleafs, mnode_t **nodes, int *numnodes,
const byte *mod_base, const lump_t *l);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View file

@ -292,6 +292,144 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
skins[i] = find_image ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
return pheader->num_frames;
}
// Unknow format, no images associated with it
/* 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_NumberLeafs
=================
*/
static void
Mod_NumberLeafs(mleaf_t *leafs, mnode_t *node, int *r_leaftovis, int *r_vistoleaf,
int *numvisleafs)
{
if (node->contents != CONTENTS_NODE)
{
mleaf_t *leaf;
int leafnum;
leaf = (mleaf_t *)node;
leafnum = leaf - leafs;
if (leaf->contents & CONTENTS_SOLID)
{
return;
}
r_leaftovis[leafnum] = *numvisleafs;
r_vistoleaf[*numvisleafs] = leafnum;
(*numvisleafs) ++;
return;
}
Mod_NumberLeafs(leafs, node->children[0], r_leaftovis, r_vistoleaf,
numvisleafs);
Mod_NumberLeafs(leafs, node->children[1], r_leaftovis, r_vistoleaf,
numvisleafs);
}
/*
=================
Mod_LoadNodes
=================
*/
void
Mod_LoadNodes(const char *name, cplane_t *planes, int numplanes, mleaf_t *leafs,
int numleafs, mnode_t **nodes, int *numnodes, const byte *mod_base,
const lump_t *l)
{
int r_leaftovis[MAX_MAP_LEAFS], r_vistoleaf[MAX_MAP_LEAFS];
int i, count, numvisleafs;
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, planenum;
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
planenum = LittleLong(in->planenum);
if (planenum < 0 || planenum >= numplanes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d < %d planenum.",
__func__, planenum, numplanes);
}
out->plane = planes + planenum;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = CONTENTS_NODE; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
int leafnum;
leafnum = LittleLong(in->children[j]);
if (leafnum >= 0)
{
if (leafnum < 0 || leafnum >= *numnodes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d nodenum as leaf.",
__func__, leafnum);
}
out->children[j] = *nodes + leafnum;
}
else
{
leafnum = -1 - leafnum;
if (leafnum < 0 || leafnum >= numleafs)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d leafnum.",
__func__, leafnum);
}
out->children[j] = (mnode_t *)(leafs + leafnum);
}
}
}
Mod_SetParent(*nodes, NULL); /* sets nodes and leafs */
numvisleafs = 0;
Mod_NumberLeafs (leafs, *nodes, r_leaftovis, r_vistoleaf, &numvisleafs);
}

View file

@ -42,18 +42,6 @@ BRUSH MODELS
// in memory representation
//
#define SIDE_FRONT 0
#define SIDE_BACK 1
#define SIDE_ON 2
#define SURF_PLANEBACK 2
#define SURF_DRAWSKY 4
#define SURF_DRAWTURB 0x10
#define SURF_DRAWBACKGROUND 0x40
#define SURF_UNDERWATER 0x80
#define VERTEXSIZE 7
typedef struct vkpoly_s
@ -97,45 +85,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;
//===================================================================
//

View file

@ -125,7 +125,7 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
msurface_t *surf;
int i;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
return;
splitplane = node->plane;
@ -206,7 +206,7 @@ static int 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
// calculate mid point

View file

@ -51,7 +51,7 @@ mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model)
cplane_t *plane;
float d;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
return (mleaf_t *)node;
plane = node->plane;
d = DotProduct (p,plane->normal) - plane->dist;
@ -664,76 +664,6 @@ Mod_LoadFaces (model_t *loadmodel, const byte *mod_base, const lump_t *l)
Vk_EndBuildingLightmaps();
}
/*
=================
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, const byte *mod_base, const lump_t *l)
{
int i, j, 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 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 = -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
}
/*
=================
Mod_LoadLeafs
@ -999,7 +929,9 @@ Mod_LoadBrushModel (model_t *mod, const 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->numplanes,
mod->leafs, mod->numleafs, &mod->nodes,
&mod->numnodes, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
}

View file

@ -692,8 +692,7 @@ static void R_DrawInlineBModel (entity_t *currententity, model_t *currentmodel,
lt = r_newrefdef.dlights;
for (k = 0; k<r_newrefdef.num_dlights; k++, lt++)
{
R_MarkLights(lt, 1 << k,
currentmodel->nodes + currentmodel->firstnode);
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode);
}
}
@ -829,7 +828,7 @@ static void R_RecursiveWorldNode (mnode_t *node, entity_t *currententity)
return;
// if a leaf node, draw stuff
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
msurface_t **mark;