#include "quakedef.h"
#include "image.h"
#include "r_shadow.h"
+#include "winding.h"
// note: model_shared.c sets up r_notexture, and r_surf_notexture
return (mleaf_t *)node;
}
+static void Mod_Q1BSP_AmbientSoundLevelsForPoint(model_t *model, const vec3_t p, qbyte *out, int outsize)
+{
+ int i;
+ mleaf_t *leaf;
+ leaf = Mod_Q1BSP_PointInLeaf(model, p);
+ if (leaf)
+ {
+ i = min(outsize, (int)sizeof(leaf->ambient_sound_level));;
+ if (i)
+ {
+ memcpy(out, leaf->ambient_sound_level, i);
+ out += i;
+ outsize -= i;
+ }
+ }
+ if (outsize)
+ memset(out, 0, outsize);
+}
+
static int Mod_Q1BSP_BoxTouchingPVS_RecursiveBSPNode(const model_t *model, const mnode_t *node, const qbyte *pvs, const vec3_t mins, const vec3_t maxs)
{
VectorCopy(info.center, out);
}
+int Mod_Q1BSP_SuperContentsFromNativeContents(model_t *model, int nativecontents)
+{
+ switch(nativecontents)
+ {
+ case CONTENTS_EMPTY:
+ return 0;
+ case CONTENTS_SOLID:
+ return SUPERCONTENTS_SOLID;
+ case CONTENTS_WATER:
+ return SUPERCONTENTS_WATER;
+ case CONTENTS_SLIME:
+ return SUPERCONTENTS_SLIME;
+ case CONTENTS_LAVA:
+ return SUPERCONTENTS_LAVA;
+ case CONTENTS_SKY:
+ return SUPERCONTENTS_SKY;
+ }
+ return 0;
+}
+
+int Mod_Q1BSP_NativeContentsFromSuperContents(model_t *model, int supercontents)
+{
+ if (supercontents & SUPERCONTENTS_SOLID)
+ return CONTENTS_SOLID;
+ if (supercontents & SUPERCONTENTS_SKY)
+ return CONTENTS_SKY;
+ if (supercontents & SUPERCONTENTS_LAVA)
+ return CONTENTS_LAVA;
+ if (supercontents & SUPERCONTENTS_SLIME)
+ return CONTENTS_SLIME;
+ if (supercontents & SUPERCONTENTS_WATER)
+ return CONTENTS_WATER;
+ return CONTENTS_EMPTY;
+}
+
typedef struct
{
// the hull we're tracing through
// check for empty
if (num < 0)
{
- t->trace->endcontents = num;
- if (t->trace->thiscontents)
+ num = Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
+ if (!t->trace->startfound)
{
- if (num == t->trace->thiscontents)
- t->trace->allsolid = false;
- else
- {
- // if the first leaf is solid, set startsolid
- if (t->trace->allsolid)
- t->trace->startsolid = true;
- return HULLCHECKSTATE_SOLID;
- }
- return HULLCHECKSTATE_EMPTY;
+ t->trace->startfound = true;
+ t->trace->startsupercontents |= num;
+ }
+ if (num & SUPERCONTENTS_LIQUIDSMASK)
+ t->trace->inwater = true;
+ if (num == 0)
+ t->trace->inopen = true;
+ if (num & t->trace->hitsupercontentsmask)
+ {
+ // if the first leaf is solid, set startsolid
+ if (t->trace->allsolid)
+ t->trace->startsolid = true;
+ return HULLCHECKSTATE_SOLID;
}
else
{
- if (num != CONTENTS_SOLID)
- {
- t->trace->allsolid = false;
- if (num == CONTENTS_EMPTY)
- t->trace->inopen = true;
- else
- t->trace->inwater = true;
- }
- else
- {
- // if the first leaf is solid, set startsolid
- if (t->trace->allsolid)
- t->trace->startsolid = true;
- return HULLCHECKSTATE_SOLID;
- }
+ t->trace->allsolid = false;
return HULLCHECKSTATE_EMPTY;
}
}
return HULLCHECKSTATE_DONE;
}
-static void Mod_Q1BSP_TraceBox(struct model_s *model, trace_t *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs)
+static void Mod_Q1BSP_TraceBox(struct model_s *model, trace_t *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs, int hitsupercontentsmask)
{
// this function currently only supports same size start and end
double boxsize[3];
memset(&rhc, 0, sizeof(rhc));
memset(trace, 0, sizeof(trace_t));
rhc.trace = trace;
+ rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
rhc.trace->fraction = 1;
rhc.trace->allsolid = true;
VectorSubtract(boxstartmaxs, boxstartmins, boxsize);
if (boxsize[0] < 3)
rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
- else if (model->brushq1.ishlbsp)
+ else if (model->brush.ishlbsp)
{
if (boxsize[0] <= 32)
{
}
// LordHavoc: HL sky textures are entirely different than quake
- if (!loadmodel->brushq1.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == 256 && mtheight == 128)
+ if (!loadmodel->brush.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == 256 && mtheight == 128)
{
if (loadmodel->isworldmodel)
{
if (!Mod_LoadSkinFrame(&tx->skin, tx->name, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE, false, true, true))
{
// did not find external texture, load it from the bsp or wad3
- if (loadmodel->brushq1.ishlbsp)
+ if (loadmodel->brush.ishlbsp)
{
// internal texture overrides wad
qbyte *pixels, *freepixels, *fogpixels;
qbyte *in, *out, *data, d;
char litfilename[1024];
loadmodel->brushq1.lightdata = NULL;
- if (loadmodel->brushq1.ishlbsp) // LordHavoc: load the colored lighting data straight
+ if (loadmodel->brush.ishlbsp) // LordHavoc: load the colored lighting data straight
{
loadmodel->brushq1.lightdata = Mem_Alloc(loadmodel->mempool, l->filelen);
memcpy(loadmodel->brushq1.lightdata, mod_base + l->fileofs, l->filelen);
}
}
-/*
-static int castshadowcount = 0;
-static void Mod_Q1BSP_ProcessLightList(void)
-{
- int j, k, l, *mark, lnum;
- mlight_t *e;
- msurface_t *surf;
- float dist;
- mleaf_t *leaf;
- qbyte *pvs;
- vec3_t temp;
- float *v, radius2;
- for (lnum = 0, e = loadmodel->brushq1.lights;lnum < loadmodel->brushq1.numlights;lnum++, e++)
- {
- e->cullradius2 = DotProduct(e->light, e->light) / (e->falloff * e->falloff * 8192.0f * 8192.0f * 2.0f * 2.0f);// + 4096.0f;
- if (e->cullradius2 > 4096.0f * 4096.0f)
- e->cullradius2 = 4096.0f * 4096.0f;
- e->cullradius = e->lightradius = sqrt(e->cullradius2);
- leaf = Mod_Q1BSP_PointInLeaf(e->origin, loadmodel);
- if (leaf->compressed_vis)
- pvs = Mod_Q1BSP_DecompressVis(leaf->compressed_vis, loadmodel);
- else
- pvs = mod_q1bsp_novis;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- loadmodel->brushq1.surfacevisframes[j] = -1;
- for (j = 0, leaf = loadmodel->brushq1.leafs + 1;j < loadmodel->brushq1.numleafs - 1;j++, leaf++)
- {
- if (pvs[j >> 3] & (1 << (j & 7)))
- {
- for (k = 0, mark = leaf->firstmarksurface;k < leaf->nummarksurfaces;k++, mark++)
- {
- surf = loadmodel->brushq1.surfaces + *mark;
- if (surf->number != *mark)
- Con_Printf("%d != %d\n", surf->number, *mark);
- dist = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
- if (surf->flags & SURF_PLANEBACK)
- dist = -dist;
- if (dist > 0 && dist < e->cullradius)
- {
- temp[0] = bound(surf->poly_mins[0], e->origin[0], surf->poly_maxs[0]) - e->origin[0];
- temp[1] = bound(surf->poly_mins[1], e->origin[1], surf->poly_maxs[1]) - e->origin[1];
- temp[2] = bound(surf->poly_mins[2], e->origin[2], surf->poly_maxs[2]) - e->origin[2];
- if (DotProduct(temp, temp) < lightradius2)
- loadmodel->brushq1.surfacevisframes[*mark] = -2;
- }
- }
- }
- }
- // build list of light receiving surfaces
- e->numsurfaces = 0;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- if (loadmodel->brushq1.surfacevisframes[j] == -2)
- e->numsurfaces++;
- e->surfaces = NULL;
- if (e->numsurfaces > 0)
- {
- e->surfaces = Mem_Alloc(loadmodel->mempool, sizeof(msurface_t *) * e->numsurfaces);
- e->numsurfaces = 0;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- if (loadmodel->brushq1.surfacevisframes[j] == -2)
- e->surfaces[e->numsurfaces++] = loadmodel->brushq1.surfaces + j;
- }
- // find bounding box and sphere of lit surfaces
- // (these will be used for creating a shape to clip the light)
- radius2 = 0;
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (j == 0)
- {
- VectorCopy(surf->poly_verts, e->mins);
- VectorCopy(surf->poly_verts, e->maxs);
- }
- for (k = 0, v = surf->poly_verts;k < surf->poly_numverts;k++, v += 3)
- {
- if (e->mins[0] > v[0]) e->mins[0] = v[0];if (e->maxs[0] < v[0]) e->maxs[0] = v[0];
- if (e->mins[1] > v[1]) e->mins[1] = v[1];if (e->maxs[1] < v[1]) e->maxs[1] = v[1];
- if (e->mins[2] > v[2]) e->mins[2] = v[2];if (e->maxs[2] < v[2]) e->maxs[2] = v[2];
- VectorSubtract(v, e->origin, temp);
- dist = DotProduct(temp, temp);
- if (radius2 < dist)
- radius2 = dist;
- }
- }
- if (e->cullradius2 > radius2)
- {
- e->cullradius2 = radius2;
- e->cullradius = sqrt(e->cullradius2);
- }
- if (e->mins[0] < e->origin[0] - e->lightradius) e->mins[0] = e->origin[0] - e->lightradius;
- if (e->maxs[0] > e->origin[0] + e->lightradius) e->maxs[0] = e->origin[0] + e->lightradius;
- if (e->mins[1] < e->origin[1] - e->lightradius) e->mins[1] = e->origin[1] - e->lightradius;
- if (e->maxs[1] > e->origin[1] + e->lightradius) e->maxs[1] = e->origin[1] + e->lightradius;
- if (e->mins[2] < e->origin[2] - e->lightradius) e->mins[2] = e->origin[2] - e->lightradius;
- if (e->maxs[2] > e->origin[2] + e->lightradius) e->maxs[2] = e->origin[2] + e->lightradius;
- // clip shadow volumes against eachother to remove unnecessary
- // polygons(and sections of polygons)
- {
- //vec3_t polymins, polymaxs;
- int maxverts = 4;
- float *verts = Mem_Alloc(loadmodel->mempool, maxverts * sizeof(float[3]));
- float f, *v0, *v1, projectdistance;
-
- e->shadowvolume = Mod_ShadowMesh_Begin(loadmodel->mempool, 1024);
-#if 0
- {
- vec3_t outermins, outermaxs, innermins, innermaxs;
- innermins[0] = e->mins[0] - 1;
- innermins[1] = e->mins[1] - 1;
- innermins[2] = e->mins[2] - 1;
- innermaxs[0] = e->maxs[0] + 1;
- innermaxs[1] = e->maxs[1] + 1;
- innermaxs[2] = e->maxs[2] + 1;
- outermins[0] = loadmodel->normalmins[0] - 1;
- outermins[1] = loadmodel->normalmins[1] - 1;
- outermins[2] = loadmodel->normalmins[2] - 1;
- outermaxs[0] = loadmodel->normalmaxs[0] + 1;
- outermaxs[1] = loadmodel->normalmaxs[1] + 1;
- outermaxs[2] = loadmodel->normalmaxs[2] + 1;
- // add bounding box around the whole shadow volume set,
- // facing inward to limit light area, with an outer bounding box
- // facing outward (this is needed by the shadow rendering method)
- // X major
- verts[ 0] = innermaxs[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermaxs[0];verts[ 7] = innermaxs[1];verts[ 8] = innermins[2];
- verts[ 9] = innermaxs[0];verts[10] = innermaxs[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermaxs[0];verts[ 7] = outermins[1];verts[ 8] = outermins[2];
- verts[ 9] = outermaxs[0];verts[10] = outermins[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // X minor
- verts[ 0] = innermins[0];verts[ 1] = innermaxs[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermins[0];verts[ 4] = innermaxs[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermins[0];verts[ 1] = outermins[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermins[0];verts[ 4] = outermins[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Y major
- verts[ 0] = innermaxs[0];verts[ 1] = innermaxs[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermaxs[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermaxs[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermaxs[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermins[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermins[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermaxs[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermaxs[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Y minor
- verts[ 0] = innermins[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermins[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermaxs[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermaxs[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermins[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermins[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermins[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermins[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Z major
- verts[ 0] = innermaxs[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermaxs[1];verts[ 5] = innermaxs[2];
- verts[ 6] = innermins[0];verts[ 7] = innermaxs[1];verts[ 8] = innermaxs[2];
- verts[ 9] = innermins[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermins[1];verts[ 5] = outermaxs[2];
- verts[ 6] = outermins[0];verts[ 7] = outermins[1];verts[ 8] = outermaxs[2];
- verts[ 9] = outermins[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Z minor
- verts[ 0] = innermaxs[0];verts[ 1] = innermaxs[1];verts[ 2] = innermins[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermaxs[1];verts[11] = innermins[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermins[1];verts[ 2] = outermins[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermins[1];verts[11] = outermins[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- }
-#endif
- castshadowcount++;
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (surf->flags & SURF_SHADOWCAST)
- surf->castshadow = castshadowcount;
- }
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (surf->castshadow != castshadowcount)
- continue;
- f = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
- if (surf->flags & SURF_PLANEBACK)
- f = -f;
- projectdistance = e->lightradius;
- if (maxverts < surf->poly_numverts)
- {
- maxverts = surf->poly_numverts;
- if (verts)
- Mem_Free(verts);
- verts = Mem_Alloc(loadmodel->mempool, maxverts * sizeof(float[3]));
- }
- // copy the original polygon, for the front cap of the volume
- for (k = 0, v0 = surf->poly_verts, v1 = verts;k < surf->poly_numverts;k++, v0 += 3, v1 += 3)
- VectorCopy(v0, v1);
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, surf->poly_numverts, verts);
- // project the original polygon, reversed, for the back cap of the volume
- for (k = 0, v0 = surf->poly_verts + (surf->poly_numverts - 1) * 3, v1 = verts;k < surf->poly_numverts;k++, v0 -= 3, v1 += 3)
- {
- VectorSubtract(v0, e->origin, temp);
- VectorNormalize(temp);
- VectorMA(v0, projectdistance, temp, v1);
- }
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, surf->poly_numverts, verts);
- // project the shadow volume sides
- for (l = surf->poly_numverts - 1, k = 0, v0 = surf->poly_verts + (surf->poly_numverts - 1) * 3, v1 = surf->poly_verts;k < surf->poly_numverts;l = k, k++, v0 = v1, v1 += 3)
- {
- if (!surf->neighborsurfaces[l] || surf->neighborsurfaces[l]->castshadow != castshadowcount)
- {
- VectorCopy(v1, &verts[0]);
- VectorCopy(v0, &verts[3]);
- VectorCopy(v0, &verts[6]);
- VectorCopy(v1, &verts[9]);
- VectorSubtract(&verts[6], e->origin, temp);
- VectorNormalize(temp);
- VectorMA(&verts[6], projectdistance, temp, &verts[6]);
- VectorSubtract(&verts[9], e->origin, temp);
- VectorNormalize(temp);
- VectorMA(&verts[9], projectdistance, temp, &verts[9]);
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- }
- }
- }
- // build the triangle mesh
- e->shadowvolume = Mod_ShadowMesh_Finish(loadmodel->mempool, e->shadowvolume);
- {
- shadowmesh_t *mesh;
- l = 0;
- for (mesh = e->shadowvolume;mesh;mesh = mesh->next)
- l += mesh->numtriangles;
- Con_Printf("light %i shadow volume built containing %i triangles\n", lnum, l);
- }
- }
- }
-}
-*/
-
-
static void Mod_Q1BSP_LoadVisibility(lump_t *l)
{
loadmodel->brushq1.num_compressedpvs = 0;
strcpy(value, com_token);
if (!strcmp("wad", key)) // for HalfLife maps
{
- if (loadmodel->brushq1.ishlbsp)
+ if (loadmodel->brush.ishlbsp)
{
j = 0;
for (i = 0;i < 4096;i++)
return;
loadmodel->brush.entities = Mem_Alloc(loadmodel->mempool, l->filelen);
memcpy(loadmodel->brush.entities, mod_base + l->fileofs, l->filelen);
- if (loadmodel->brushq1.ishlbsp)
+ if (loadmodel->brush.ishlbsp)
Mod_Q1BSP_ParseWadsFromEntityLump(loadmodel->brush.entities);
}
out = Mem_Alloc(loadmodel->mempool, count*sizeof(*out));
loadmodel->brushq1.submodels = out;
- loadmodel->brushq1.numsubmodels = count;
+ loadmodel->brush.numsubmodels = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
i = LittleLong(in->lightofs);
if (i == -1)
surf->samples = NULL;
- else if (loadmodel->brushq1.ishlbsp) // LordHavoc: HalfLife map (bsp version 30)
+ else if (loadmodel->brush.ishlbsp) // LordHavoc: HalfLife map (bsp version 30)
surf->samples = loadmodel->brushq1.lightdata + i;
else // LordHavoc: white lighting (bsp version 29)
surf->samples = loadmodel->brushq1.lightdata + (i * 3);
loadmodel->brushq1.leafs = out;
loadmodel->brushq1.numleafs = count;
- pvschainbytes = ((loadmodel->brushq1.num_leafs - 1)+7)>>3;
+ pvschainbytes = ((loadmodel->brushq1.numleafs - 1)+7)>>3;
loadmodel->brushq1.data_decompressedpvs = pvs = Mem_Alloc(loadmodel->mempool, loadmodel->brushq1.numleafs * pvschainbytes);
for ( i=0 ; i<count ; i++, in++, out++)
loadmodel->brushq1.clipnodes = out;
loadmodel->brushq1.numclipnodes = count;
- if (loadmodel->brushq1.ishlbsp)
+ if (loadmodel->brush.ishlbsp)
{
hull = &loadmodel->brushq1.hulls[1];
hull->clipnodes = out;
}
}
-#define MAX_POINTS_ON_WINDING 64
-
-typedef struct
-{
- int numpoints;
- int padding;
- double points[8][3]; // variable sized
-}
-winding_t;
-
-/*
-==================
-NewWinding
-==================
-*/
-static winding_t *NewWinding(int points)
-{
- winding_t *w;
- int size;
-
- if (points > MAX_POINTS_ON_WINDING)
- Sys_Error("NewWinding: too many points\n");
-
- size = sizeof(winding_t) + sizeof(double[3]) * (points - 8);
- w = Mem_Alloc(loadmodel->mempool, size);
- memset(w, 0, size);
-
- return w;
-}
-
-static void FreeWinding(winding_t *w)
-{
- Mem_Free(w);
-}
-
-/*
-=================
-BaseWindingForPlane
-=================
-*/
-static winding_t *BaseWindingForPlane(mplane_t *p)
-{
- double org[3], vright[3], vup[3], normal[3];
- winding_t *w;
-
- VectorCopy(p->normal, normal);
- VectorVectorsDouble(normal, vright, vup);
-
- VectorScale(vup, 1024.0*1024.0*1024.0, vup);
- VectorScale(vright, 1024.0*1024.0*1024.0, vright);
-
- // project a really big axis aligned box onto the plane
- w = NewWinding(4);
-
- VectorScale(p->normal, p->dist, org);
-
- VectorSubtract(org, vright, w->points[0]);
- VectorAdd(w->points[0], vup, w->points[0]);
-
- VectorAdd(org, vright, w->points[1]);
- VectorAdd(w->points[1], vup, w->points[1]);
-
- VectorAdd(org, vright, w->points[2]);
- VectorSubtract(w->points[2], vup, w->points[2]);
-
- VectorSubtract(org, vright, w->points[3]);
- VectorSubtract(w->points[3], vup, w->points[3]);
-
- w->numpoints = 4;
-
- return w;
-}
-
-/*
-==================
-ClipWinding
-
-Clips the winding to the plane, returning the new winding on the positive side
-Frees the input winding.
-If keepon is true, an exactly on-plane winding will be saved, otherwise
-it will be clipped away.
-==================
-*/
-static winding_t *ClipWinding(winding_t *in, mplane_t *split, int keepon)
-{
- double dists[MAX_POINTS_ON_WINDING + 1];
- int sides[MAX_POINTS_ON_WINDING + 1];
- int counts[3];
- double dot;
- int i, j;
- double *p1, *p2;
- double mid[3];
- winding_t *neww;
- int maxpts;
-
- counts[SIDE_FRONT] = counts[SIDE_BACK] = counts[SIDE_ON] = 0;
-
- // determine sides for each point
- for (i = 0;i < in->numpoints;i++)
- {
- dists[i] = dot = DotProduct(in->points[i], split->normal) - split->dist;
- if (dot > ON_EPSILON)
- sides[i] = SIDE_FRONT;
- else if (dot < -ON_EPSILON)
- sides[i] = SIDE_BACK;
- else
- sides[i] = SIDE_ON;
- counts[sides[i]]++;
- }
- sides[i] = sides[0];
- dists[i] = dists[0];
-
- if (keepon && !counts[0] && !counts[1])
- return in;
-
- if (!counts[0])
- {
- FreeWinding(in);
- return NULL;
- }
- if (!counts[1])
- return in;
-
- maxpts = in->numpoints+4; // can't use counts[0]+2 because of fp grouping errors
- if (maxpts > MAX_POINTS_ON_WINDING)
- Sys_Error("ClipWinding: maxpts > MAX_POINTS_ON_WINDING");
-
- neww = NewWinding(maxpts);
-
- for (i = 0;i < in->numpoints;i++)
- {
- if (neww->numpoints >= maxpts)
- Sys_Error("ClipWinding: points exceeded estimate");
-
- p1 = in->points[i];
-
- if (sides[i] == SIDE_ON)
- {
- VectorCopy(p1, neww->points[neww->numpoints]);
- neww->numpoints++;
- continue;
- }
-
- if (sides[i] == SIDE_FRONT)
- {
- VectorCopy(p1, neww->points[neww->numpoints]);
- neww->numpoints++;
- }
-
- if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
- continue;
-
- // generate a split point
- p2 = in->points[(i+1)%in->numpoints];
-
- dot = dists[i] / (dists[i]-dists[i+1]);
- for (j = 0;j < 3;j++)
- { // avoid round off error when possible
- if (split->normal[j] == 1)
- mid[j] = split->dist;
- else if (split->normal[j] == -1)
- mid[j] = -split->dist;
- else
- mid[j] = p1[j] + dot* (p2[j]-p1[j]);
- }
-
- VectorCopy(mid, neww->points[neww->numpoints]);
- neww->numpoints++;
- }
-
- // free the original winding
- FreeWinding(in);
-
- return neww;
-}
-
-
-/*
-==================
-DivideWinding
-
-Divides a winding by a plane, producing one or two windings. The
-original winding is not damaged or freed. If only on one side, the
-returned winding will be the input winding. If on both sides, two
-new windings will be created.
-==================
-*/
-static void DivideWinding(winding_t *in, mplane_t *split, winding_t **front, winding_t **back)
-{
- double dists[MAX_POINTS_ON_WINDING + 1];
- int sides[MAX_POINTS_ON_WINDING + 1];
- int counts[3];
- double dot;
- int i, j;
- double *p1, *p2;
- double mid[3];
- winding_t *f, *b;
- int maxpts;
-
- counts[SIDE_FRONT] = counts[SIDE_BACK] = counts[SIDE_ON] = 0;
-
- // determine sides for each point
- for (i = 0;i < in->numpoints;i++)
- {
- dot = DotProduct(in->points[i], split->normal);
- dot -= split->dist;
- dists[i] = dot;
- if (dot > ON_EPSILON) sides[i] = SIDE_FRONT;
- else if (dot < -ON_EPSILON) sides[i] = SIDE_BACK;
- else sides[i] = SIDE_ON;
- counts[sides[i]]++;
- }
- sides[i] = sides[0];
- dists[i] = dists[0];
-
- *front = *back = NULL;
-
- if (!counts[0])
- {
- *back = in;
- return;
- }
- if (!counts[1])
- {
- *front = in;
- return;
- }
-
- maxpts = in->numpoints+4; // can't use counts[0]+2 because of fp grouping errors
-
- if (maxpts > MAX_POINTS_ON_WINDING)
- Sys_Error("ClipWinding: maxpts > MAX_POINTS_ON_WINDING");
-
- *front = f = NewWinding(maxpts);
- *back = b = NewWinding(maxpts);
-
- for (i = 0;i < in->numpoints;i++)
- {
- if (f->numpoints >= maxpts || b->numpoints >= maxpts)
- Sys_Error("DivideWinding: points exceeded estimate");
-
- p1 = in->points[i];
-
- if (sides[i] == SIDE_ON)
- {
- VectorCopy(p1, f->points[f->numpoints]);
- f->numpoints++;
- VectorCopy(p1, b->points[b->numpoints]);
- b->numpoints++;
- continue;
- }
-
- if (sides[i] == SIDE_FRONT)
- {
- VectorCopy(p1, f->points[f->numpoints]);
- f->numpoints++;
- }
- else if (sides[i] == SIDE_BACK)
- {
- VectorCopy(p1, b->points[b->numpoints]);
- b->numpoints++;
- }
-
- if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
- continue;
-
- // generate a split point
- p2 = in->points[(i+1)%in->numpoints];
-
- dot = dists[i] / (dists[i]-dists[i+1]);
- for (j = 0;j < 3;j++)
- { // avoid round off error when possible
- if (split->normal[j] == 1)
- mid[j] = split->dist;
- else if (split->normal[j] == -1)
- mid[j] = -split->dist;
- else
- mid[j] = p1[j] + dot* (p2[j]-p1[j]);
- }
-
- VectorCopy(mid, f->points[f->numpoints]);
- f->numpoints++;
- VectorCopy(mid, b->points[b->numpoints]);
- b->numpoints++;
- }
-}
-
typedef struct portal_s
{
mplane_t plane;
// advance to next portal
portal++;
}
- FreeWinding(p->winding);
+ Winding_Free(p->winding);
}
FreePortal(p);
p = pnext;
nodeportal = AllocPortal();
nodeportal->plane = *node->plane;
- nodeportalwinding = BaseWindingForPlane(node->plane);
+ nodeportalwinding = Winding_NewFromPlane(node->plane->normal[0], node->plane->normal[1], node->plane->normal[2], node->plane->dist);
side = 0; // shut up compiler warning
for (portal = (portal_t *)node->portals;portal;portal = portal->next[side])
{
else
Host_Error("Mod_Q1BSP_RecursiveNodePortals: mislinked portal");
- nodeportalwinding = ClipWinding(nodeportalwinding, &clipplane, true);
+ nodeportalwinding = Winding_Clip(nodeportalwinding, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, true);
if (!nodeportalwinding)
{
Con_Printf("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal was clipped away\n");
RemovePortalFromNodes(portal);
// cut the portal into two portals, one on each side of the node plane
- DivideWinding(portal->winding, plane, &frontwinding, &backwinding);
+ Winding_Divide(portal->winding, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, &frontwinding, &backwinding);
if (!frontwinding)
{
*splitportal = *portal;
splitportal->chain = temp;
splitportal->winding = backwinding;
- FreeWinding(portal->winding);
+ Winding_Free(portal->winding);
portal->winding = frontwinding;
if (side == 0)
Mod_Q1BSP_RecursiveNodePortals(back);
}
-
static void Mod_Q1BSP_MakePortals(void)
{
portalchain = NULL;
}
}
-void Mod_Q1BSP_FatPVS_RecursiveBSPNode(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbytes, mnode_t *node)
+static void Mod_Q1BSP_FatPVS_RecursiveBSPNode(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbytes, mnode_t *node)
{
int i;
mplane_t *plane;
//Calculates a PVS that is the inclusive or of all leafs within radius pixels
//of the given point.
-int Mod_Q1BSP_FatPVS(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength)
+static int Mod_Q1BSP_FatPVS(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength)
{
- int bytes = ((model->brushq1.num_leafs - 1) + 7) >> 3;
+ int bytes = ((model->brushq1.numleafs - 1) + 7) >> 3;
bytes = min(bytes, pvsbufferlength);
memset(pvsbuffer, 0, bytes);
- Mod_Q1BSP_FatPVS_RecursiveBSPNode(model, org, radius, pvsbuffer, bytes, sv.worldmodel->brushq1.nodes);
+ Mod_Q1BSP_FatPVS_RecursiveBSPNode(model, org, radius, pvsbuffer, bytes, model->brushq1.nodes);
return bytes;
}
+static void Mod_Q1BSP_RoundUpToHullSize(model_t *cmodel, const vec3_t inmins, const vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs)
+{
+ vec3_t size;
+ const hull_t *hull;
+
+ VectorSubtract(inmaxs, inmins, size);
+ if (cmodel->brush.ishlbsp)
+ {
+ if (size[0] < 3)
+ hull = &cmodel->brushq1.hulls[0]; // 0x0x0
+ else if (size[0] <= 32)
+ {
+ if (size[2] < 54) // pick the nearest of 36 or 72
+ hull = &cmodel->brushq1.hulls[3]; // 32x32x36
+ else
+ hull = &cmodel->brushq1.hulls[1]; // 32x32x72
+ }
+ else
+ hull = &cmodel->brushq1.hulls[2]; // 64x64x64
+ }
+ else
+ {
+ if (size[0] < 3)
+ hull = &cmodel->brushq1.hulls[0]; // 0x0x0
+ else if (size[0] <= 32)
+ hull = &cmodel->brushq1.hulls[1]; // 32x32x56
+ else
+ hull = &cmodel->brushq1.hulls[2]; // 64x64x88
+ }
+ VectorCopy(inmins, outmins);
+ VectorAdd(inmins, hull->clip_size, outmaxs);
+}
+
extern void R_Model_Brush_DrawSky(entity_render_t *ent);
extern void R_Model_Brush_Draw(entity_render_t *ent);
extern void R_Model_Brush_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius);
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->brushq1.ishlbsp = i == 30;
+ mod->brush.ishlbsp = i == 30;
+ mod->brush.SuperContentsFromNativeContents = Mod_Q1BSP_SuperContentsFromNativeContents;
+ mod->brush.NativeContentsFromSuperContents = Mod_Q1BSP_NativeContentsFromSuperContents;
+ mod->brush.AmbientSoundLevelsForPoint = Mod_Q1BSP_AmbientSoundLevelsForPoint;
mod->brush.FatPVS = Mod_Q1BSP_FatPVS;
mod->brush.BoxTouchingPVS = Mod_Q1BSP_BoxTouchingPVS;
mod->brush.LightPoint = Mod_Q1BSP_LightPoint;
mod->brush.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation;
mod->brush.TraceBox = Mod_Q1BSP_TraceBox;
+ mod->brush.RoundUpToHullSize = Mod_Q1BSP_RoundUpToHullSize;
mod->brushq1.PointInLeaf = Mod_Q1BSP_PointInLeaf;
mod->brushq1.BuildPVSTextureChains = Mod_Q1BSP_BuildPVSTextureChains;
if (loadmodel->isworldmodel)
{
- Cvar_SetValue("halflifebsp", mod->brushq1.ishlbsp);
+ Cvar_SetValue("halflifebsp", mod->brush.ishlbsp);
// until we get a texture for it...
R_ResetQuakeSky();
}
Mod_Q1BSP_MakePortals();
if (developer.integer)
- Con_Printf("Some stats for q1bsp model \"%s\": %i faces, %i nodes, %i leafs, %i visleafs, %i visleafportals\n", loadmodel->name, loadmodel->brushq1.numsurfaces, loadmodel->brushq1.numnodes, loadmodel->brushq1.numleafs, loadmodel->brushq1.num_leafs - 1, loadmodel->brushq1.numportals);
+ Con_Printf("Some stats for q1bsp model \"%s\": %i faces, %i nodes, %i leafs, %i visleafs, %i visleafportals\n", loadmodel->name, loadmodel->brushq1.numsurfaces, loadmodel->brushq1.numnodes, loadmodel->brushq1.numleafs, loadmodel->brushq1.numleafs - 1, loadmodel->brushq1.numportals);
mod->numframes = 2; // regular and alternate animation
//
// set up the submodels(FIXME: this is confusing)
//
- for (i = 0;i < mod->brushq1.numsubmodels;i++)
+ for (i = 0;i < mod->brush.numsubmodels;i++)
{
bm = &mod->brushq1.submodels[i];
if (surf->texinfo->texture->shader == &Cshader_sky)
mod->DrawSky = R_Model_Brush_DrawSky;
// LordHavoc: submodels always clip, even if water
- if (mod->brushq1.numsubmodels - 1)
+ if (mod->brush.numsubmodels - 1)
surf->flags |= SURF_SOLIDCLIP;
// calculate bounding shapes
for (mesh = surf->mesh;mesh;mesh = mesh->chain)
}
Mod_Q1BSP_BuildSurfaceNeighbors(mod->brushq1.surfaces + mod->brushq1.firstmodelsurface, mod->brushq1.nummodelsurfaces, originalloadmodel->mempool);
- mod->brushq1.numleafs = bm->visleafs;
+ mod->brushq1.visleafs = bm->visleafs;
// LordHavoc: only register submodels if it is the world
// (prevents bsp models from replacing world submodels)
- if (loadmodel->isworldmodel && i < (mod->brushq1.numsubmodels - 1))
+ if (loadmodel->isworldmodel && i < (mod->brush.numsubmodels - 1))
{
char name[10];
// duplicate the basic information
*/
}
-void Mod_Q2BSP_Load(model_t *mod, void *buffer)
+void static Mod_Q2BSP_Load(model_t *mod, void *buffer)
{
int i;
q2dheader_t *header;
i = LittleLong(header->version);
if (i != Q2BSPVERSION)
Host_Error("Mod_Q2BSP_Load: %s has wrong version number (%i, should be %i)", mod->name, i, Q2BSPVERSION);
- mod->brushq1.ishlbsp = false;
+ mod->brush.ishlbsp = false;
if (loadmodel->isworldmodel)
{
- Cvar_SetValue("halflifebsp", mod->brushq1.ishlbsp);
+ Cvar_SetValue("halflifebsp", mod->brush.ishlbsp);
// until we get a texture for it...
R_ResetQuakeSky();
}
Mod_Q2BSP_LoadModels(&header->lumps[Q2LUMP_MODELS]);
}
+static int Mod_Q3BSP_SuperContentsFromNativeContents(model_t *model, int nativecontents);
+static int Mod_Q3BSP_NativeContentsFromSuperContents(model_t *model, int supercontents);
static void Mod_Q3BSP_LoadEntities(lump_t *l)
{
{
strncpy(out->name, in->name, sizeof(out->name) - 1);
out->surfaceflags = LittleLong(in->surfaceflags);
- out->contents = LittleLong(in->contents);
+ out->nativecontents = LittleLong(in->contents);
+ out->supercontents = Mod_Q3BSP_SuperContentsFromNativeContents(loadmodel, out->nativecontents);
+ out->renderflags = 0;
+ if (!strcmp(out->name, "caulk") || !strcmp(out->name, "common/caulk") || !strcmp(out->name, "textures/common/caulk"))
+ out->renderflags |= Q3MTEXTURERENDERFLAGS_NODRAW;
out->number = i;
Mod_LoadSkinFrame(&out->skin, out->name, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE, false, true, true);
{
q3dbrush_t *in;
q3mbrush_t *out;
- int i, j, k, m, n, c, count, numpoints, numplanes;
- winding_t *w;
- colpointf_t pointsbuf[256*3];
- colplanef_t planesbuf[256], colplanef;
+ int i, j, n, c, count, numplanes, maxplanes;
+ mplane_t *planes;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
loadmodel->brushq3.data_brushes = out;
loadmodel->brushq3.num_brushes = count;
+ maxplanes = 0;
+ planes = NULL;
+
for (i = 0;i < count;i++, in++, out++)
{
n = LittleLong(in->firstbrushside);
Host_Error("Mod_Q3BSP_LoadBrushes: invalid textureindex %i (%i textures)\n", n, loadmodel->brushq3.num_textures);
out->texture = loadmodel->brushq3.data_textures + n;
- // construct a collision brush, which needs points and planes...
- // each point and plane should be unique, and they don't refer to
- // eachother in any way, so keeping them unique is fairly easy
- numpoints = 0;
- numplanes = 0;
- for (j = 0;j < out->numbrushsides;j++)
+ // make a list of mplane_t structs to construct a colbrush from
+ if (maxplanes < numplanes)
{
- // create a huge polygon for the plane
- w = BaseWindingForPlane(out->firstbrushside[j].plane);
- // clip it by all other planes
- for (k = 0;k < out->numbrushsides && w;k++)
- if (k != j)
- w = ClipWinding(w, out->firstbrushside[k].plane, true);
- // if nothing is left, skip it
- // FIXME: should keep count of how many were skipped and report
- // it, just for sake of statistics
- if (!w)
- continue;
- // add the points uniquely (no duplicates)
- for (k = 0;k < w->numpoints;k++)
- {
- for (m = 0;m < numpoints;m++)
- if (VectorDistance2(w->points[k * 3], pointsbuf[m * 3].v) < DIST_EPSILON)
- break;
- if (m == numpoints)
- {
- // check if there are too many and skip the brush
- if (numpoints >= 256)
- {
- Con_Printf("Mod_Q3BSP_LoadBrushes: failed to build collision brush: too many points for buffer\n");
- FreeWinding(w);
- goto failedtomakecolbrush;
- }
- // add the new one
- VectorCopy(w->points[k * 3], pointsbuf[numpoints * 3].v);
- numpoints++;
- }
- }
- // add the plane uniquely (no duplicates)
- memset(&colplanef, 0, sizeof(colplanef));
- VectorCopy(out->firstbrushside[k].plane->normal, colplanef.normal);
- colplanef.dist = out->firstbrushside[k].plane->dist;
- for (k = 0;k < numplanes;k++)
- if (VectorCompare(planesbuf[k].normal, colplanef.normal) && planesbuf[k].dist == colplanef.dist)
- break;
- if (k == numplanes)
- {
- // check if there are too many and skip the brush
- if (numplanes >= 256)
- {
- Con_Printf("Mod_Q3BSP_LoadBrushes: failed to build collision brush: too many planes for buffer\n");
- FreeWinding(w);
- goto failedtomakecolbrush;
- }
- // add the new one
- planesbuf[numplanes++] = colplanef;
- }
- FreeWinding(w);
+ maxplanes = numplanes;
+ if (planes)
+ Mem_Free(planes);
+ planes = Mem_Alloc(tempmempool, sizeof(mplane_t) * maxplanes);
}
- // if anything is left, create the collision brush
- if (numplanes && numpoints)
+ for (j = 0;j < out->numbrushsides;j++)
{
- out->colbrushf = Collision_AllocBrushFloat(loadmodel->mempool, numpoints, numplanes);
- memcpy(out->colbrushf->points, pointsbuf, numpoints * sizeof(float[3]));
- memcpy(out->colbrushf->planes, planesbuf, numplanes * sizeof(mplane_t));
+ VectorCopy(out->firstbrushside[j].plane->normal, planes[j].normal);
+ planes[j].dist = out->firstbrushside[j].plane->dist;
}
- // return from errors to here
- failedtomakecolbrush:;
+ // make the colbrush from the planes
+ out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes, out->texture->supercontents);
}
+ if (planes)
+ Mem_Free(planes);
}
static void Mod_Q3BSP_LoadEffects(lump_t *l)
Host_Error("Mod_Q3BSP_LoadVertices: funny lump size in %s",loadmodel->name);
loadmodel->brushq3.num_vertices = count = l->filelen / sizeof(*in);
loadmodel->brushq3.data_vertex3f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[3]));
- loadmodel->brushq3.data_texturetexcoord2f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[2]));
- loadmodel->brushq3.data_lightmaptexcoord2f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[2]));
+ loadmodel->brushq3.data_texcoordtexture2f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[2]));
+ loadmodel->brushq3.data_texcoordlightmap2f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[2]));
loadmodel->brushq3.data_svector3f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[3]));
loadmodel->brushq3.data_tvector3f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[3]));
loadmodel->brushq3.data_normal3f = Mem_Alloc(loadmodel->mempool, count * sizeof(float[3]));
loadmodel->brushq3.data_vertex3f[i * 3 + 0] = LittleFloat(in->origin3f[0]);
loadmodel->brushq3.data_vertex3f[i * 3 + 1] = LittleFloat(in->origin3f[1]);
loadmodel->brushq3.data_vertex3f[i * 3 + 2] = LittleFloat(in->origin3f[2]);
- loadmodel->brushq3.data_texturetexcoord2f[i * 2 + 0] = LittleFloat(in->texcoord2f[0]);
- loadmodel->brushq3.data_texturetexcoord2f[i * 2 + 1] = LittleFloat(in->texcoord2f[1]);
- loadmodel->brushq3.data_lightmaptexcoord2f[i * 2 + 0] = LittleFloat(in->lightmap2f[0]);
- loadmodel->brushq3.data_lightmaptexcoord2f[i * 2 + 1] = LittleFloat(in->lightmap2f[1]);
+ loadmodel->brushq3.data_texcoordtexture2f[i * 2 + 0] = LittleFloat(in->texcoord2f[0]);
+ loadmodel->brushq3.data_texcoordtexture2f[i * 2 + 1] = LittleFloat(in->texcoord2f[1]);
+ loadmodel->brushq3.data_texcoordlightmap2f[i * 2 + 0] = LittleFloat(in->lightmap2f[0]);
+ loadmodel->brushq3.data_texcoordlightmap2f[i * 2 + 1] = LittleFloat(in->lightmap2f[1]);
// svector/tvector are calculated later in face loading
loadmodel->brushq3.data_svector3f[i * 3 + 0] = 0;
loadmodel->brushq3.data_svector3f[i * 3 + 1] = 0;
case Q3FACETYPE_POLYGON:
case Q3FACETYPE_MESH:
out->data_vertex3f = loadmodel->brushq3.data_vertex3f + out->firstvertex * 3;
- out->data_texturetexcoord2f = loadmodel->brushq3.data_texturetexcoord2f + out->firstvertex * 2;
- out->data_lightmaptexcoord2f = loadmodel->brushq3.data_lightmaptexcoord2f + out->firstvertex * 2;
+ out->data_texcoordtexture2f = loadmodel->brushq3.data_texcoordtexture2f + out->firstvertex * 2;
+ out->data_texcoordlightmap2f = loadmodel->brushq3.data_texcoordlightmap2f + out->firstvertex * 2;
out->data_svector3f = loadmodel->brushq3.data_svector3f + out->firstvertex * 3;
out->data_tvector3f = loadmodel->brushq3.data_tvector3f + out->firstvertex * 3;
out->data_normal3f = loadmodel->brushq3.data_normal3f + out->firstvertex * 3;
invalidelements++;
if (invalidelements)
{
- Con_Printf("Mod_Q3BSP_LoadFaces: Warning: face #%i has %i invalid elements, type = %i, texture->name = \"%s\", texture->surfaceflags = %i, texture->contents = %i, firstvertex = %i, numvertices = %i, firstelement = %i, numelements = %i, elements list:\n", i, invalidelements, out->type, out->texture->name, out->texture->surfaceflags, out->texture->contents, out->firstvertex, out->numvertices, out->firstelement, out->numelements);
+ Con_Printf("Mod_Q3BSP_LoadFaces: Warning: face #%i has %i invalid elements, type = %i, texture->name = \"%s\", texture->surfaceflags = %i, texture->nativecontents = %i, firstvertex = %i, numvertices = %i, firstelement = %i, numelements = %i, elements list:\n", i, invalidelements, out->type, out->texture->name, out->texture->surfaceflags, out->texture->nativecontents, out->firstvertex, out->numvertices, out->firstelement, out->numelements);
for (j = 0;j < out->numelements;j++)
{
Con_Printf(" %i", out->data_element3i[j]);
memcpy(loadmodel->brushq3.data_pvschains, (qbyte *)(in + 1), totalchains);
}
-void Mod_Q3BSP_FindNonSolidLocation(model_t *model, const vec3_t in, vec3_t out, vec_t radius)
+static void Mod_Q3BSP_FindNonSolidLocation(model_t *model, const vec3_t in, vec3_t out, vec_t radius)
{
// FIXME: finish this code
VectorCopy(in, out);
}
-void Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace_t *trace, q3mnode_t *node, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end)
+static void Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace_t *trace, q3mnode_t *node, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end)
{
if (node->isnode)
{
dist = node->plane->dist - (1.0f / 8.0f);
for (i = 0, ps = thisbrush_start->points, pe = thisbrush_end->points;i < thisbrush_start->numpoints;i++, ps++, pe++)
{
- if (DotProduct(ps->v, node->plane->normal) > dist || DotProduct(pe->v, node->plane->normal) > dist)
+ if (DotProduct(ps->v, node->plane->normal) >= dist || DotProduct(pe->v, node->plane->normal) >= dist)
{
Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, node->children[0], thisbrush_start, thisbrush_end);
break;
dist = node->plane->dist + (1.0f / 8.0f);
for (i = 0, ps = thisbrush_start->points, pe = thisbrush_end->points;i < thisbrush_start->numpoints;i++, ps++, pe++)
{
- if (DotProduct(ps->v, node->plane->normal) < dist || DotProduct(pe->v, node->plane->normal) < dist)
+ if (DotProduct(ps->v, node->plane->normal) <= dist || DotProduct(pe->v, node->plane->normal) <= dist)
{
Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, node->children[1], thisbrush_start, thisbrush_end);
break;
q3mleaf_t *leaf;
leaf = (q3mleaf_t *)node;
for (i = 0;i < leaf->numleafbrushes;i++)
- Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, leaf->firstleafbrush[i]->colbrushf, leaf->firstleafbrush[i]->colbrushf);
+ if (leaf->firstleafbrush[i]->colbrushf)
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, leaf->firstleafbrush[i]->colbrushf, leaf->firstleafbrush[i]->colbrushf);
}
}
-void Mod_Q3BSP_LightPoint(model_t *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal)
+static void Mod_Q3BSP_LightPoint(model_t *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal)
{
// FIXME: write this
ambientcolor[0] += 255;
ambientcolor[2] += 255;
}
-void Mod_Q3BSP_TraceBox(model_t *model, trace_t *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs)
+static void Mod_Q3BSP_TraceBox(model_t *model, trace_t *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs, int hitsupercontentsmask)
{
int i;
colbrushf_t *thisbrush_start, *thisbrush_end;
thisbrush_end = Collision_BrushForBox(&endmatrix, boxendmins, boxendmaxs);
memset(trace, 0, sizeof(*trace));
trace->fraction = 1;
+ trace->hitsupercontentsmask = hitsupercontentsmask;
if (model->brushq3.num_nodes)
Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, model->brushq3.data_nodes, thisbrush_start, thisbrush_end);
else
for (i = 0;i < model->brushq3.num_brushes;i++)
- Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, model->brushq3.data_brushes[i].colbrushf, model->brushq3.data_brushes[i].colbrushf);
+ if (model->brushq3.data_brushes[i].colbrushf)
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, model->brushq3.data_brushes[i].colbrushf, model->brushq3.data_brushes[i].colbrushf);
}
return false;
}
-int Mod_Q3BSP_BoxTouchingPVS(model_t *model, const qbyte *pvs, const vec3_t mins, const vec3_t maxs)
+static int Mod_Q3BSP_BoxTouchingPVS(model_t *model, const qbyte *pvs, const vec3_t mins, const vec3_t maxs)
{
return Mod_Q3BSP_BoxTouchingPVS_RecursiveBSPNode(model, model->brushq3.data_nodes, pvs, mins, maxs);
}
-int Mod_Q3BSP_FatPVS(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength)
+static int Mod_Q3BSP_FatPVS(model_t *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength)
{
// FIXME: write this
memset(pvsbuffer, 0xFF, pvsbufferlength);
return pvsbufferlength;
}
+static int Mod_Q3BSP_SuperContentsFromNativeContents(model_t *model, int nativecontents)
+{
+ int supercontents = 0;
+ if (nativecontents & Q2CONTENTS_SOLID)
+ supercontents |= SUPERCONTENTS_SOLID;
+ if (nativecontents & Q2CONTENTS_WATER)
+ supercontents |= SUPERCONTENTS_WATER;
+ if (nativecontents & Q2CONTENTS_SLIME)
+ supercontents |= SUPERCONTENTS_SLIME;
+ if (nativecontents & Q2CONTENTS_LAVA)
+ supercontents |= SUPERCONTENTS_LAVA;
+ return supercontents;
+}
+
+static int Mod_Q3BSP_NativeContentsFromSuperContents(model_t *model, int supercontents)
+{
+ int nativecontents = 0;
+ if (supercontents & SUPERCONTENTS_SOLID)
+ nativecontents |= Q2CONTENTS_SOLID;
+ if (supercontents & SUPERCONTENTS_WATER)
+ nativecontents |= Q2CONTENTS_WATER;
+ if (supercontents & SUPERCONTENTS_SLIME)
+ nativecontents |= Q2CONTENTS_SLIME;
+ if (supercontents & SUPERCONTENTS_LAVA)
+ nativecontents |= Q2CONTENTS_LAVA;
+ return nativecontents;
+}
+
+//extern void R_Q3BSP_DrawSky(struct entity_render_s *ent);
+extern void R_Q3BSP_Draw(struct entity_render_s *ent);
+//extern void R_Q3BSP_DrawFakeShadow(struct entity_render_s *ent);
+//extern void R_Q3BSP_DrawShadowVolume(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
+//extern void R_Q3BSP_DrawLight(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz);
void Mod_Q3BSP_Load(model_t *mod, void *buffer)
{
int i;
q3dheader_t *header;
+ float corner[3], yawradius, modelradius;
- mod->type = mod_brushq2;
+ mod->type = mod_brushq3;
header = (q3dheader_t *)buffer;
R_ResetQuakeSky();
}
+ mod->brush.SuperContentsFromNativeContents = Mod_Q3BSP_SuperContentsFromNativeContents;
+ mod->brush.NativeContentsFromSuperContents = Mod_Q3BSP_NativeContentsFromSuperContents;
mod->brush.FatPVS = Mod_Q3BSP_FatPVS;
mod->brush.BoxTouchingPVS = Mod_Q3BSP_BoxTouchingPVS;
mod->brush.LightPoint = Mod_Q3BSP_LightPoint;
mod->brush.FindNonSolidLocation = Mod_Q3BSP_FindNonSolidLocation;
mod->brush.TraceBox = Mod_Q3BSP_TraceBox;
- //mod->brushq1.PointInLeaf = Mod_Q1BSP_PointInLeaf;
- //mod->brushq1.BuildPVSTextureChains = Mod_Q1BSP_BuildPVSTextureChains;
+ //mod->DrawSky = R_Q3BSP_DrawSky;
+ mod->Draw = R_Q3BSP_Draw;
+ //mod->DrawFakeShadow = R_Q3BSP_DrawFakeShadow;
+ //mod->DrawShadowVolume = R_Q3BSP_DrawShadowVolume;
+ //mod->DrawLight = R_Q3BSP_DrawLight;
mod_base = (qbyte *)header;
Mod_Q3BSP_LoadNodes(&header->lumps[Q3LUMP_NODES]);
Mod_Q3BSP_LoadLightGrid(&header->lumps[Q3LUMP_LIGHTGRID]);
Mod_Q3BSP_LoadPVS(&header->lumps[Q3LUMP_PVS]);
+ loadmodel->brush.numsubmodels = loadmodel->brushq3.num_models;
+
+ for (i = 0;i < loadmodel->brushq3.num_models;i++)
+ {
+ if (i == 0)
+ mod = loadmodel;
+ else
+ {
+ char name[10];
+ // LordHavoc: only register submodels if it is the world
+ // (prevents bsp models from replacing world submodels)
+ if (!loadmodel->isworldmodel)
+ continue;
+ // duplicate the basic information
+ sprintf(name, "*%i", i);
+ mod = Mod_FindName(name);
+ *mod = *loadmodel;
+ strcpy(mod->name, name);
+ // textures and memory belong to the main model
+ mod->texturepool = NULL;
+ mod->mempool = NULL;
+ }
+ mod->brushq3.data_thismodel = loadmodel->brushq3.data_models + i;
+
+ VectorCopy(mod->brushq3.data_thismodel->mins, mod->normalmins);
+ VectorCopy(mod->brushq3.data_thismodel->maxs, mod->normalmaxs);
+ corner[0] = max(fabs(mod->normalmins[0]), fabs(mod->normalmaxs[0]));
+ corner[1] = max(fabs(mod->normalmins[1]), fabs(mod->normalmaxs[1]));
+ corner[2] = max(fabs(mod->normalmins[2]), fabs(mod->normalmaxs[2]));
+ modelradius = sqrt(corner[0]*corner[0]+corner[1]*corner[1]+corner[2]*corner[2]);
+ yawradius = sqrt(corner[0]*corner[0]+corner[1]*corner[1]);
+ mod->rotatedmins[0] = mod->rotatedmins[1] = mod->rotatedmins[2] = -modelradius;
+ mod->rotatedmaxs[0] = mod->rotatedmaxs[1] = mod->rotatedmaxs[2] = modelradius;
+ mod->yawmaxs[0] = mod->yawmaxs[1] = yawradius;
+ mod->yawmins[0] = mod->yawmins[1] = -yawradius;
+ mod->yawmins[2] = mod->normalmins[2];
+ mod->yawmaxs[2] = mod->normalmaxs[2];
+ mod->radius = modelradius;
+ mod->radius2 = modelradius * modelradius;
+ }
}
void Mod_IBSP_Load(model_t *mod, void *buffer)