double t1, t2;
// variables that need to be stored on the stack when recursing
- dclipnode_t *node;
+ mclipnode_t *node;
int side;
double midf, mid[3];
rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
else if (model->brush.ismcbsp)
{
- if (boxsize[2] < 48) // pick the nearest of 40 or 56
- rhc.hull = &model->brushq1.hulls[2]; // 16x16x40
- else
- rhc.hull = &model->brushq1.hulls[1]; // 16x16x56
+ 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)
{
#else
RecursiveHullCheckTraceInfo_t rhc;
static hull_t box_hull;
- static dclipnode_t box_clipnodes[6];
+ static mclipnode_t box_clipnodes[6];
static mplane_t box_planes[6];
// fill in a default trace
memset(&rhc, 0, sizeof(rhc));
tx->surfaceflags = mod_q1bsp_texture_solid.surfaceflags;
}
tx->currentframe = tx;
+
+ // clear water settings
+ tx->reflectmin = 0;
+ tx->reflectmax = 1;
+ tx->refractfactor = 1;
+ Vector4Set(tx->refractcolor4f, 1, 1, 1, 1);
+ tx->reflectfactor = 1;
+ Vector4Set(tx->reflectcolor4f, 1, 1, 1, 1);
}
if (!m)
{
if (loadmodel->isworldmodel)
{
- data = loadimagepixels(tx->name, false, 0, 0);
+ data = loadimagepixels(tx->name, false, 0, 0, false);
if (data)
{
R_Q1BSP_LoadSplitSky(data, image_width, image_height, 4);
if (strncmp(tx->name,"*lava",5)
&& strncmp(tx->name,"*teleport",9)
&& strncmp(tx->name,"*rift",5)) // Scourge of Armagon texture
- tx->basematerialflags |= MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW;
+ tx->basematerialflags |= MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW | MATERIALFLAG_WATERSHADER;
tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_NOSHADOW;
}
else if (!strncmp(tx->name, "sky", 3))
for (j=0 ; j<2 ; j++)
{
- // LordHavoc: this code supports more than 32768 nodes or leafs,
- // by simply assuming that there are no more than 65536 combined,
- // this makes it compatible with the broken arguire qbsp utility
- // which can produce more than 32768 nodes (breaking the format)
- // note that arguire light and vis utilities still crash on this
- //
- // I do not encourage support for this weirdness, this code was
- // reworked simply to allow flying around leaky maps that exceed
- // the limits, with the assumption that a final compile will be
- // valid after the leak is fixed.
+ // LordHavoc: this code supports broken bsp files produced by
+ // arguire qbsp which can produce more than 32768 nodes, any value
+ // below count is assumed to be a node number, any other value is
+ // assumed to be a leaf number
p = (unsigned short)LittleShort(in->children[j]);
- if (p < 65536 - loadmodel->brush.num_leafs)
+ if (p < count)
{
if (p < loadmodel->brush.num_nodes)
out->children[j] = loadmodel->brush.data_nodes + p;
}
else
{
+ // note this uses 65535 intentionally, -1 is leaf 0
p = 65535 - p;
if (p < loadmodel->brush.num_leafs)
out->children[j] = (mnode_t *)(loadmodel->brush.data_leafs + p);
static void Mod_Q1BSP_LoadClipnodes(lump_t *l, hullinfo_t *hullinfo)
{
- dclipnode_t *in, *out;
+ dclipnode_t *in;
+ mclipnode_t *out;
int i, count;
hull_t *hull;
if (l->filelen % sizeof(*in))
Host_Error("Mod_Q1BSP_LoadClipnodes: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
- out = (dclipnode_t *)Mem_Alloc(loadmodel->mempool, count*sizeof(*out));
+ out = (mclipnode_t *)Mem_Alloc(loadmodel->mempool, count*sizeof(*out));
loadmodel->brushq1.clipnodes = out;
loadmodel->brushq1.numclipnodes = count;
for (i=0 ; i<count ; i++, out++, in++)
{
out->planenum = LittleLong(in->planenum);
- out->children[0] = LittleShort(in->children[0]);
- out->children[1] = LittleShort(in->children[1]);
+ // LordHavoc: this code supports arguire qbsp's broken clipnodes indices (more than 32768 clipnodes), values above count are assumed to be contents values
+ out->children[0] = (unsigned short)LittleShort(in->children[0]);
+ out->children[1] = (unsigned short)LittleShort(in->children[1]);
+ if (out->children[0] >= count)
+ out->children[0] -= 65536;
+ if (out->children[1] >= count)
+ out->children[1] -= 65536;
if (out->planenum < 0 || out->planenum >= loadmodel->brush.num_planes)
Host_Error("Corrupt clipping hull(out of range planenum)");
- if (out->children[0] >= count || out->children[1] >= count)
- Host_Error("Corrupt clipping hull(out of range child)");
}
}
static void Mod_Q1BSP_MakeHull0(void)
{
mnode_t *in;
- dclipnode_t *out;
+ mclipnode_t *out;
int i;
hull_t *hull;
hull = &loadmodel->brushq1.hulls[0];
in = loadmodel->brush.data_nodes;
- out = (dclipnode_t *)Mem_Alloc(loadmodel->mempool, loadmodel->brush.num_nodes * sizeof(dclipnode_t));
+ out = (mclipnode_t *)Mem_Alloc(loadmodel->mempool, loadmodel->brush.num_nodes * sizeof(*out));
hull->clipnodes = out;
hull->firstclipnode = 0;
Host_Error("Mod_Q1BSP_Load: %s has wrong version number(%i should be %i)", mod->name, i, MCBSPVERSION);
// read hull info
- hullinfo.numhulls = LittleLong(*(int*)index); index += 4;
+ 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.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);
{
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);
mod->DrawAddWaterPlanes = NULL;
mod->Draw = R_Q1BSP_Draw;
mod->DrawDepth = R_Q1BSP_DrawDepth;
+ mod->DrawDebug = R_Q1BSP_DrawDebug;
mod->GetLightInfo = R_Q1BSP_GetLightInfo;
mod->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
mod->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
// we only need to have a drawsky function if it is used(usually only on world model)
if (surface->texture->basematerialflags & MATERIALFLAG_SKY)
mod->DrawSky = R_Q1BSP_DrawSky;
- if (surface->texture->basematerialflags & MATERIALFLAG_WATERALPHA)
+ if (surface->texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION))
mod->DrawAddWaterPlanes = R_Q1BSP_DrawAddWaterPlanes;
// calculate bounding shapes
for (k = 0, vec = (loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex);k < surface->num_vertices;k++, vec += 3)
c = 0;
for (i = 0;i < count;i++, in++, out++)
- if (Mod_LoadTextureFromQ3Shader(out, out->name, false, true, false))
+ if (!Mod_LoadTextureFromQ3Shader(out, out->name, false, true, false))
c++;
if (c)
Con_DPrintf("%s: %i textures missing shaders\n", loadmodel->name, c);
mod->brush.PointInLeaf = Mod_Q1BSP_PointInLeaf;
mod->Draw = R_Q1BSP_Draw;
mod->DrawDepth = R_Q1BSP_DrawDepth;
+ mod->DrawDebug = R_Q1BSP_DrawDebug;
mod->GetLightInfo = R_Q1BSP_GetLightInfo;
mod->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
mod->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
mod->DrawSky = NULL;
for (j = 0;j < mod->nummodelsurfaces;j++)
- if (mod->data_surfaces[j + mod->firstmodelsurface].texture->basematerialflags & MATERIALFLAG_WATERALPHA)
+ if (mod->data_surfaces[j + mod->firstmodelsurface].texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION))
break;
if (j < mod->nummodelsurfaces)
mod->DrawAddWaterPlanes = R_Q1BSP_DrawAddWaterPlanes;