//cvar_t r_subdivide_size = {CVAR_SAVE, "r_subdivide_size", "128", "how large water polygons should be (smaller values produce more polygons which give better warping effects)"};
cvar_t halflifebsp = {0, "halflifebsp", "0", "indicates the current map is hlbsp format (useful to know because of different bounding box sizes)"};
-cvar_t mcbsp = {0, "mcbsp", "0", "indicates the current map is mcbsp format (useful to know because of different bounding box sizes)"};
cvar_t r_novis = {0, "r_novis", "0", "draws whole level, see also sv_cullentities_pvs 0"};
cvar_t r_picmipworld = {CVAR_SAVE, "r_picmipworld", "1", "whether gl_picmip shall apply to world textures too"};
cvar_t r_nosurftextures = {0, "r_nosurftextures", "0", "pretends there was no texture lump found in the q1bsp/hlbsp loading (useful for debugging this rare case)"};
{
// Cvar_RegisterVariable(&r_subdivide_size);
Cvar_RegisterVariable(&halflifebsp);
- Cvar_RegisterVariable(&mcbsp);
Cvar_RegisterVariable(&r_novis);
Cvar_RegisterVariable(&r_picmipworld);
Cvar_RegisterVariable(&r_nosurftextures);
//#if COLLISIONPARANOID < 2
static int Mod_Q1BSP_RecursiveHullCheckPoint(RecursiveHullCheckTraceInfo_t *t, int num)
{
+ mplane_t *plane;
+ mclipnode_t *nodes = t->hull->clipnodes;
+ mplane_t *planes = t->hull->planes;
+ vec3_t point;
+ VectorCopy(t->start, point);
while (num >= 0)
- num = t->hull->clipnodes[num].children[(t->hull->planes[t->hull->clipnodes[num].planenum].type < 3 ? t->start[t->hull->planes[t->hull->clipnodes[num].planenum].type] : DotProduct(t->hull->planes[t->hull->clipnodes[num].planenum].normal, t->start)) < t->hull->planes[t->hull->clipnodes[num].planenum].dist];
+ {
+ plane = planes + nodes[num].planenum;
+ num = nodes[num].children[(plane->type < 3 ? point[plane->type] : DotProduct(plane->normal, point)) < plane->dist];
+ }
num = Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
t->trace->startsupercontents |= num;
if (num & SUPERCONTENTS_LIQUIDSMASK)
VectorSubtract(boxmaxs, boxmins, boxsize);
if (boxsize[0] < 3)
rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
- else if (model->brush.ismcbsp)
- {
- int i;
- float vdist, dist;
- int vdisti = 0;
-
- vdist = 0; // shut up compiler warning
-
- // find the closest hull size (this algorithm probably sucks, a qc field to override it might be in order...)
- for (i = 1; i < model->brushq1.numhulls; i++)
- {
- dist = fabs(model->brushq1.hulls[i].clip_size[0] - boxsize[0]) +
- fabs(model->brushq1.hulls[i].clip_size[1] - boxsize[1]) +
- fabs(model->brushq1.hulls[i].clip_size[2] - boxsize[2]) * 0.25;
-
- if (!vdisti || dist < vdist)
- {
- vdisti = i;
- vdist = dist;
- }
- }
- rhc.hull = &model->brushq1.hulls[vdisti];
- }
else if (model->brush.ishlbsp)
{
// LordHavoc: this has to have a minor tolerance (the .1) because of
#endif
}
+static int Mod_Q1BSP_PointSuperContents(struct model_s *model, int frame, const vec3_t point)
+{
+ int num = 0;
+ mplane_t *plane;
+ mclipnode_t *nodes = model->brushq1.hulls[0].clipnodes;
+ mplane_t *planes = model->brushq1.hulls[0].planes;
+ while (num >= 0)
+ {
+ plane = planes + nodes[num].planenum;
+ num = nodes[num].children[(plane->type < 3 ? point[plane->type] : DotProduct(plane->normal, point)) < plane->dist];
+ }
+ return Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
+}
+
void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int boxsupercontents, int boxq3surfaceflags, texture_t *boxtexture)
{
#if 1
// bilinear filter each lightmap style, and sum them
for (maps = 0;maps < MAXLIGHTMAPS && surface->lightmapinfo->styles[maps] != 255;maps++)
{
- scale = r_refdef.lightstylevalue[surface->lightmapinfo->styles[maps]];
+ scale = r_refdef.scene.lightstylevalue[surface->lightmapinfo->styles[maps]];
w = w00 * scale;VectorMA(ambientcolor, w, lightmap , ambientcolor);
w = w01 * scale;VectorMA(ambientcolor, w, lightmap + 3 , ambientcolor);
w = w10 * scale;VectorMA(ambientcolor, w, lightmap + line3 , ambientcolor);
for (i=0; i<l->filelen; i++)
loadmodel->brushq1.lightdata[i] = mod_base[l->fileofs+i] >>= 1;
}
- else if (loadmodel->brush.ismcbsp)
- {
- loadmodel->brushq1.lightdata = (unsigned char *)Mem_Alloc(loadmodel->mempool, l->filelen);
- memcpy(loadmodel->brushq1.lightdata, mod_base + l->fileofs, l->filelen);
- }
else // LordHavoc: bsp version 29 (normal white lighting)
{
// LordHavoc: hope is not lost yet, check for a .lit file to load
}
#endif
-static qboolean Mod_Q1BSP_AllocLightmapBlock(int *lineused, int totalwidth, int totalheight, int blockwidth, int blockheight, int *outx, int *outy)
+/* Maximum size of a single LM */
+#define MAX_SINGLE_LM_SIZE 256
+
+struct alloc_lm_row
+{
+ int rowY;
+ int currentX;
+};
+
+struct alloc_lm_state
{
- int y, x2, y2;
- int bestx = totalwidth, besty = 0;
- // find the left-most space we can find
- for (y = 0;y <= totalheight - blockheight;y++)
- {
- x2 = 0;
- for (y2 = 0;y2 < blockheight;y2++)
- x2 = max(x2, lineused[y+y2]);
- if (bestx > x2)
- {
- bestx = x2;
- besty = y;
- }
- }
- // if the best was not good enough, return failure
- if (bestx > totalwidth - blockwidth)
- return false;
- // we found a good spot
- if (outx)
- *outx = bestx;
- if (outy)
- *outy = besty;
- // now mark the space used
- for (y2 = 0;y2 < blockheight;y2++)
- lineused[besty+y2] = bestx + blockwidth;
- // return success
+ int currentY;
+ struct alloc_lm_row rows[MAX_SINGLE_LM_SIZE];
+};
+
+static void init_alloc_lm_state (struct alloc_lm_state* state)
+{
+ int r;
+
+ state->currentY = 0;
+ for (r = 0; r < MAX_SINGLE_LM_SIZE; r++)
+ {
+ state->rows[r].currentX = 0;
+ state->rows[r].rowY = -1;
+ }
+}
+
+static qboolean Mod_Q1BSP_AllocLightmapBlock(struct alloc_lm_state* state, int totalwidth, int totalheight, int blockwidth, int blockheight, int *outx, int *outy)
+{
+ struct alloc_lm_row* row;
+ int r;
+
+ row = &(state->rows[blockheight]);
+ if ((row->rowY < 0) || (row->currentX + blockwidth > totalwidth))
+ {
+ if (state->currentY + blockheight <= totalheight)
+ {
+ row->rowY = state->currentY;
+ row->currentX = 0;
+ state->currentY += blockheight;
+ }
+ else
+ {
+ /* See if we can stuff the block into a higher row */
+ row = NULL;
+ for (r = blockheight; r < MAX_SINGLE_LM_SIZE; r++)
+ {
+ if ((state->rows[r].rowY >= 0)
+ && (state->rows[r].currentX + blockwidth <= totalwidth))
+ {
+ row = &(state->rows[r]);
+ break;
+ }
+ }
+ if (row == NULL) return false;
+ }
+ }
+ *outy = row->rowY;
+ *outx = row->currentX;
+ row->currentX += blockwidth;
+
return true;
}
msurface_t *surface;
int i, j, count, surfacenum, planenum, smax, tmax, ssize, tsize, firstedge, numedges, totalverts, totaltris, lightmapnumber, lightmapsize, totallightmapsamples;
float texmins[2], texmaxs[2], val;
-#define LIGHTMAPSIZE 1024
rtexture_t *lightmaptexture, *deluxemaptexture;
- int lightmap_lineused[LIGHTMAPSIZE];
in = (dface_t *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
lightmaptexture = NULL;
deluxemaptexture = r_texture_blanknormalmap;
lightmapnumber = 1;
- lightmapsize = bound(256, gl_max_size.integer, LIGHTMAPSIZE);
+ lightmapsize = max(256, gl_max_size.integer);
totallightmapsamples = 0;
totalverts = 0;
// store
// additionally, never choose a lightmapsize that is smaller than the
// largest surface encountered (as it would fail)
- // and finally, limit it to the size of our lineused array
i = lightmapsize;
- for (lightmapsize = 64;lightmapsize < LIGHTMAPSIZE && (lightmapsize < i || (lightmapsize < gl_max_size.integer && totallightmapsamples*2 > lightmapsize*lightmapsize));lightmapsize*=2)
+ for (lightmapsize = 64; (lightmapsize < i) && (lightmapsize < gl_max_size.integer) && (totallightmapsamples > lightmapsize*lightmapsize); lightmapsize*=2)
;
// now that we've decided the lightmap texture size, we can do the rest
if (cls.state != ca_dedicated)
{
+ struct alloc_lm_state allocState;
+
for (surfacenum = 0, surface = loadmodel->data_surfaces;surfacenum < count;surfacenum++, surface++)
{
- // check if we should apply a lightmap to this
- if (surface->cached_dlight)
+ int i, iu, iv, lightmapx, lightmapy;
+ float u, v, ubase, vbase, uscale, vscale;
+
+ smax = surface->lightmapinfo->extents[0] >> 4;
+ tmax = surface->lightmapinfo->extents[1] >> 4;
+ ssize = (surface->lightmapinfo->extents[0] >> 4) + 1;
+ tsize = (surface->lightmapinfo->extents[1] >> 4) + 1;
+
+ // stainmap for permanent marks on walls
+ surface->lightmapinfo->stainsamples = (unsigned char *)Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
+ // clear to white
+ memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3);
+
+ if (!lightmaptexture || !Mod_Q1BSP_AllocLightmapBlock(&allocState, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy))
{
- int i, iu, iv, lightmapx, lightmapy;
- float u, v, ubase, vbase, uscale, vscale;
-
- smax = surface->lightmapinfo->extents[0] >> 4;
- tmax = surface->lightmapinfo->extents[1] >> 4;
- ssize = (surface->lightmapinfo->extents[0] >> 4) + 1;
- tsize = (surface->lightmapinfo->extents[1] >> 4) + 1;
-
- // stainmap for permanent marks on walls
- surface->lightmapinfo->stainsamples = (unsigned char *)Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
- // clear to white
- memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3);
-
- // find a place for this lightmap
- if (!lightmaptexture || !Mod_Q1BSP_AllocLightmapBlock(lightmap_lineused, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy))
- {
- // allocate a texture pool if we need it
- if (loadmodel->texturepool == NULL)
- loadmodel->texturepool = R_AllocTexturePool();
- // could not find room, make a new lightmap
- lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
- if (loadmodel->brushq1.nmaplightdata)
- deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
- lightmapnumber++;
- memset(lightmap_lineused, 0, sizeof(lightmap_lineused));
- Mod_Q1BSP_AllocLightmapBlock(lightmap_lineused, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy);
- }
-
- surface->lightmaptexture = lightmaptexture;
- surface->deluxemaptexture = deluxemaptexture;
- surface->lightmapinfo->lightmaporigin[0] = lightmapx;
- surface->lightmapinfo->lightmaporigin[1] = lightmapy;
+ // allocate a texture pool if we need it
+ if (loadmodel->texturepool == NULL)
+ loadmodel->texturepool = R_AllocTexturePool();
+ // could not find room, make a new lightmap
+ lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ if (loadmodel->brushq1.nmaplightdata)
+ deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ lightmapnumber++;
+ init_alloc_lm_state (&allocState);
+ Mod_Q1BSP_AllocLightmapBlock(&allocState, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy);
+ }
+ surface->lightmaptexture = lightmaptexture;
+ surface->deluxemaptexture = deluxemaptexture;
+ surface->lightmapinfo->lightmaporigin[0] = lightmapx;
+ surface->lightmapinfo->lightmaporigin[1] = lightmapy;
- uscale = 1.0f / (float)lightmapsize;
- vscale = 1.0f / (float)lightmapsize;
- ubase = lightmapx * uscale;
- vbase = lightmapy * vscale;
+ uscale = 1.0f / (float)lightmapsize;
+ vscale = 1.0f / (float)lightmapsize;
+ ubase = lightmapx * uscale;
+ vbase = lightmapy * vscale;
- for (i = 0;i < surface->num_vertices;i++)
- {
- u = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
- v = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
- (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = u * uscale + ubase;
- (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = v * vscale + vbase;
- // LordHavoc: calc lightmap data offset for vertex lighting to use
- iu = (int) u;
- iv = (int) v;
- (loadmodel->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
- }
+ for (i = 0;i < surface->num_vertices;i++)
+ {
+ u = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
+ v = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
+ (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = u * uscale + ubase;
+ (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = v * vscale + vbase;
+ // LordHavoc: calc lightmap data offset for vertex lighting to use
+ iu = (int) u;
+ iv = (int) v;
+ (loadmodel->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
}
+
}
}
}
loadmodel->brushq1.clipnodes = out;
loadmodel->brushq1.numclipnodes = count;
- for (i = 1; i < hullinfo->numhulls; i++)
+ for (i = 1; i < MAX_MAP_HULLS; i++)
{
hull = &loadmodel->brushq1.hulls[i];
hull->clipnodes = out;
const hull_t *hull;
VectorSubtract(inmaxs, inmins, size);
- if (cmodel->brush.ismcbsp)
- {
- if (size[0] < 3)
- hull = &cmodel->brushq1.hulls[0]; // 0x0x0
- else if (size[2] < 48) // pick the nearest of 40 or 56
- hull = &cmodel->brushq1.hulls[2]; // 16x16x40
- else
- hull = &cmodel->brushq1.hulls[1]; // 16x16x56
- }
- else if (cmodel->brush.ishlbsp)
+ if (cmodel->brush.ishlbsp)
{
if (size[0] < 3)
hull = &cmodel->brushq1.hulls[0]; // 0x0x0
float dist, modelyawradius, modelradius, *vec;
msurface_t *surface;
int numshadowmeshtriangles;
- dheader_t _header;
hullinfo_t hullinfo;
int totalstylesurfaces, totalstyles, stylecounts[256], remapstyles[256];
model_brush_lightstyleinfo_t styleinfo[256];
mod->type = mod_brushq1;
- if (!memcmp (buffer, "MCBSPpad", 8))
- {
- unsigned char *index;
-
- mod->brush.ismcbsp = true;
- mod->brush.ishlbsp = false;
-
- mod_base = (unsigned char*)buffer;
+ header = (dheader_t *)buffer;
- index = mod_base;
- index += 8;
- i = SB_ReadInt (&index);
- if (i != MCBSPVERSION)
- Host_Error("Mod_Q1BSP_Load: %s has wrong version number(%i should be %i)", mod->name, i, MCBSPVERSION);
-
- // read hull info
- hullinfo.numhulls = SB_ReadInt (&index);
- hullinfo.filehulls = hullinfo.numhulls;
- mod->brushq1.numhulls = hullinfo.numhulls;
-
- VectorClear (hullinfo.hullsizes[0][0]);
- VectorClear (hullinfo.hullsizes[0][1]);
- for (i = 1; i < hullinfo.numhulls; i++)
- {
- hullinfo.hullsizes[i][0][0] = SB_ReadFloat (&index);
- hullinfo.hullsizes[i][0][1] = SB_ReadFloat (&index);
- hullinfo.hullsizes[i][0][2] = SB_ReadFloat (&index);
- hullinfo.hullsizes[i][1][0] = SB_ReadFloat (&index);
- hullinfo.hullsizes[i][1][1] = SB_ReadFloat (&index);
- hullinfo.hullsizes[i][1][2] = SB_ReadFloat (&index);
- }
+ i = LittleLong(header->version);
+ if (i != BSPVERSION && i != 30)
+ Host_Error("Mod_Q1BSP_Load: %s has wrong version number(%i should be %i(Quake) or 30(HalfLife)", mod->name, i, BSPVERSION);
+ mod->brush.ishlbsp = i == 30;
- // read lumps
- _header.version = 0;
- for (i = 0; i < HEADER_LUMPS; i++)
- {
- _header.lumps[i].fileofs = SB_ReadInt (&index);
- _header.lumps[i].filelen = SB_ReadInt (&index);
- }
+// fill in hull info
+ VectorClear (hullinfo.hullsizes[0][0]);
+ VectorClear (hullinfo.hullsizes[0][1]);
+ if (mod->brush.ishlbsp)
+ {
+ mod->modeldatatypestring = "HLBSP";
- header = &_header;
+ hullinfo.filehulls = 4;
+ VectorSet (hullinfo.hullsizes[1][0], -16, -16, -36);
+ VectorSet (hullinfo.hullsizes[1][1], 16, 16, 36);
+ VectorSet (hullinfo.hullsizes[2][0], -32, -32, -32);
+ VectorSet (hullinfo.hullsizes[2][1], 32, 32, 32);
+ VectorSet (hullinfo.hullsizes[3][0], -16, -16, -18);
+ VectorSet (hullinfo.hullsizes[3][1], 16, 16, 18);
}
else
{
- header = (dheader_t *)buffer;
-
- i = LittleLong(header->version);
- if (i != BSPVERSION && i != 30)
- Host_Error("Mod_Q1BSP_Load: %s has wrong version number(%i should be %i(Quake) or 30(HalfLife)", mod->name, i, BSPVERSION);
- mod->brush.ishlbsp = i == 30;
- mod->brush.ismcbsp = false;
-
- // fill in hull info
- VectorClear (hullinfo.hullsizes[0][0]);
- VectorClear (hullinfo.hullsizes[0][1]);
- if (mod->brush.ishlbsp)
- {
- mod->modeldatatypestring = "HLBSP";
-
- hullinfo.numhulls = 4;
- hullinfo.filehulls = 4;
- mod->brushq1.numhulls = 4;
- VectorSet (hullinfo.hullsizes[1][0], -16, -16, -36);
- VectorSet (hullinfo.hullsizes[1][1], 16, 16, 36);
- VectorSet (hullinfo.hullsizes[2][0], -32, -32, -32);
- VectorSet (hullinfo.hullsizes[2][1], 32, 32, 32);
- VectorSet (hullinfo.hullsizes[3][0], -16, -16, -18);
- VectorSet (hullinfo.hullsizes[3][1], 16, 16, 18);
- }
- else
- {
- hullinfo.numhulls = 3;
- hullinfo.filehulls = 4;
- mod->brushq1.numhulls = 3;
- VectorSet (hullinfo.hullsizes[1][0], -16, -16, -24);
- VectorSet (hullinfo.hullsizes[1][1], 16, 16, 32);
- VectorSet (hullinfo.hullsizes[2][0], -32, -32, -24);
- VectorSet (hullinfo.hullsizes[2][1], 32, 32, 64);
- }
+ hullinfo.filehulls = 4;
+ VectorSet (hullinfo.hullsizes[1][0], -16, -16, -24);
+ VectorSet (hullinfo.hullsizes[1][1], 16, 16, 32);
+ VectorSet (hullinfo.hullsizes[2][0], -32, -32, -24);
+ VectorSet (hullinfo.hullsizes[2][1], 32, 32, 64);
+ }
- // read lumps
- mod_base = (unsigned char*)buffer;
- for (i = 0; i < HEADER_LUMPS; i++)
- {
- header->lumps[i].fileofs = LittleLong(header->lumps[i].fileofs);
- header->lumps[i].filelen = LittleLong(header->lumps[i].filelen);
- }
+// read lumps
+ mod_base = (unsigned char*)buffer;
+ for (i = 0; i < HEADER_LUMPS; i++)
+ {
+ header->lumps[i].fileofs = LittleLong(header->lumps[i].fileofs);
+ header->lumps[i].filelen = LittleLong(header->lumps[i].filelen);
}
mod->soundfromcenter = true;
mod->TraceBox = Mod_Q1BSP_TraceBox;
+ mod->PointSuperContents = Mod_Q1BSP_PointSuperContents;
mod->brush.TraceLineOfSight = Mod_Q1BSP_TraceLineOfSight;
mod->brush.SuperContentsFromNativeContents = Mod_Q1BSP_SuperContentsFromNativeContents;
mod->brush.NativeContentsFromSuperContents = Mod_Q1BSP_NativeContentsFromSuperContents;
mod->brush.PointInLeaf = Mod_Q1BSP_PointInLeaf;
if (loadmodel->isworldmodel)
- {
Cvar_SetValue("halflifebsp", mod->brush.ishlbsp);
- Cvar_SetValue("mcbsp", mod->brush.ismcbsp);
- }
// load into heap
if (loadmodel->brush.numsubmodels)
loadmodel->brush.submodels = (model_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brush.numsubmodels * sizeof(model_t *));
- if (loadmodel->isworldmodel)
- {
- // clear out any stale submodels or worldmodels lying around
- // if we did this clear before now, an error might abort loading and
- // leave things in a bad state
- Mod_RemoveStaleWorldModels(loadmodel);
- }
-
// LordHavoc: to clear the fog around the original quake submodel code, I
// will explain:
// first of all, some background info on the submodels:
if (i != Q2BSPVERSION)
Host_Error("Mod_Q2BSP_Load: %s has wrong version number (%i, should be %i)", mod->name, i, Q2BSPVERSION);
mod->brush.ishlbsp = false;
- mod->brush.ismcbsp = false;
if (loadmodel->isworldmodel)
- {
Cvar_SetValue("halflifebsp", mod->brush.ishlbsp);
- Cvar_SetValue("mcbsp", mod->brush.ismcbsp);
- }
mod_base = (unsigned char *)header;
}
}
}
- if (endlightmap < 2)
- loadmodel->brushq3.deluxemapping = false;
// q3map2 sometimes (or always?) makes a second blank lightmap for no
// reason when only one lightmap is used, which can throw off the
// deluxemapping detection method, so check 2-lightmap bsp's specifically
// to see if the second lightmap is blank, if so it is not deluxemapped.
- if (endlightmap == 1 && count == 2)
+ //
+ // further research has shown q3map2 sometimes creates a deluxemap and two
+ // blank lightmaps, which must be handled properly as well
+ if (endlightmap == 1 && count > 1)
{
c = in[1].rgb;
for (i = 0;i < 128*128*3;i++)
q3dlightgrid_t *a, *s;
// scale lighting by lightstyle[0] so that darkmode in dpmod works properly
- stylescale = r_refdef.rtlightstylevalue[0];
+ stylescale = r_refdef.scene.rtlightstylevalue[0];
if (!model->brushq3.num_lightgrid)
{
colbrushf_t *brush;
// find which leaf the point is in
while (node->plane)
- node = node->children[DotProduct(point, node->plane->normal) < node->plane->dist];
+ node = node->children[(node->plane->type < 3 ? point[node->plane->type] : DotProduct(point, node->plane->normal)) < node->plane->dist];
// point trace the brushes
leaf = (mleaf_t *)node;
for (i = 0;i < leaf->numleafbrushes;i++)
}
}
+static int Mod_Q3BSP_PointSuperContents(struct model_s *model, int frame, const vec3_t point)
+{
+ int i;
+ int supercontents = 0;
+ q3mbrush_t *brush;
+ // test if the point is inside each brush
+ if (model->brush.submodel)
+ {
+ // submodels are effectively one leaf
+ for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
+ if (brush->colbrushf && Collision_PointInsideBrushFloat(point, brush->colbrushf))
+ supercontents |= brush->colbrushf->supercontents;
+ }
+ else
+ {
+ mnode_t *node = model->brush.data_nodes;
+ mleaf_t *leaf;
+ // find which leaf the point is in
+ while (node->plane)
+ node = node->children[(node->plane->type < 3 ? point[node->plane->type] : DotProduct(point, node->plane->normal)) < node->plane->dist];
+ leaf = (mleaf_t *)node;
+ // now check the brushes in the leaf
+ for (i = 0;i < leaf->numleafbrushes;i++)
+ {
+ brush = model->brush.data_brushes + leaf->firstleafbrush[i];
+ if (brush->colbrushf && Collision_PointInsideBrushFloat(point, brush->colbrushf))
+ supercontents |= brush->colbrushf->supercontents;
+ }
+ }
+ return supercontents;
+}
+
static int Mod_Q3BSP_SuperContentsFromNativeContents(model_t *model, int nativecontents)
{
int supercontents = 0;
if (i != Q3BSPVERSION)
Host_Error("Mod_Q3BSP_Load: %s has wrong version number (%i, should be %i)", mod->name, i, Q3BSPVERSION);
mod->brush.ishlbsp = false;
- mod->brush.ismcbsp = false;
if (loadmodel->isworldmodel)
- {
Cvar_SetValue("halflifebsp", mod->brush.ishlbsp);
- Cvar_SetValue("mcbsp", mod->brush.ismcbsp);
- }
mod->soundfromcenter = true;
mod->TraceBox = Mod_Q3BSP_TraceBox;
+ mod->PointSuperContents = Mod_Q3BSP_PointSuperContents;
mod->brush.TraceLineOfSight = Mod_Q1BSP_TraceLineOfSight;
mod->brush.SuperContentsFromNativeContents = Mod_Q3BSP_SuperContentsFromNativeContents;
mod->brush.NativeContentsFromSuperContents = Mod_Q3BSP_NativeContentsFromSuperContents;
loadmodel->brush.num_leafs = 0;
Mod_Q3BSP_RecursiveFindNumLeafs(loadmodel->brush.data_nodes);
- if (loadmodel->isworldmodel)
- {
- // clear out any stale submodels or worldmodels lying around
- // if we did this clear before now, an error might abort loading and
- // leave things in a bad state
- Mod_RemoveStaleWorldModels(loadmodel);
- }
-
mod = loadmodel;
for (i = 0;i < loadmodel->brush.numsubmodels;i++)
{