#include "quakedef.h"
#include "image.h"
#include "r_shadow.h"
-#include "winding.h"
+#include "polygon.h"
#include "curves.h"
// note: model_shared.c sets up r_notexture, and r_surf_notexture
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);
+ for (i=0; i<l->filelen; i++)
+ loadmodel->brushq1.lightdata[i] = mod_base[l->fileofs+i] >>= 1;
}
else // LordHavoc: bsp version 29 (normal white lighting)
{
}
}
+#define MAX_PORTALPOINTS 64
+
typedef struct portal_s
{
mplane_t plane;
mnode_t *nodes[2]; // [0] = front side of plane
struct portal_s *next[2];
- winding_t *winding;
+ int numpoints;
+ double points[3*MAX_PORTALPOINTS];
struct portal_s *chain; // all portals are linked into a list
}
portal_t;
mportal_t *portal;
mvertex_t *point;
mleaf_t *leaf, *endleaf;
- winding_t *w;
// recalculate bounding boxes for all leafs(because qbsp is very sloppy)
leaf = loadmodel->brushq1.data_leafs;
p = portalchain;
while (p)
{
- if (p->winding)
+ if (p->numpoints >= 3)
{
for (i = 0;i < 2;i++)
{
leaf = (mleaf_t *)p->nodes[i];
- w = p->winding;
- for (j = 0;j < w->numpoints;j++)
+ for (j = 0;j < p->numpoints;j++)
{
- if (leaf->mins[0] > w->points[j][0]) leaf->mins[0] = w->points[j][0];
- if (leaf->mins[1] > w->points[j][1]) leaf->mins[1] = w->points[j][1];
- if (leaf->mins[2] > w->points[j][2]) leaf->mins[2] = w->points[j][2];
- if (leaf->maxs[0] < w->points[j][0]) leaf->maxs[0] = w->points[j][0];
- if (leaf->maxs[1] < w->points[j][1]) leaf->maxs[1] = w->points[j][1];
- if (leaf->maxs[2] < w->points[j][2]) leaf->maxs[2] = w->points[j][2];
+ if (leaf->mins[0] > p->points[j*3+0]) leaf->mins[0] = p->points[j*3+0];
+ if (leaf->mins[1] > p->points[j*3+1]) leaf->mins[1] = p->points[j*3+1];
+ if (leaf->mins[2] > p->points[j*3+2]) leaf->mins[2] = p->points[j*3+2];
+ if (leaf->maxs[0] < p->points[j*3+0]) leaf->maxs[0] = p->points[j*3+0];
+ if (leaf->maxs[1] < p->points[j*3+1]) leaf->maxs[1] = p->points[j*3+1];
+ if (leaf->maxs[2] < p->points[j*3+2]) leaf->maxs[2] = p->points[j*3+2];
}
}
}
{
// note: this check must match the one below or it will usually corrupt memory
// the nodes[0] != nodes[1] check is because leaf 0 is the shared solid leaf, it can have many portals inside with leaf 0 on both sides
- if (p->winding && p->nodes[0] != p->nodes[1]
+ if (p->numpoints >= 3 && p->nodes[0] != p->nodes[1]
&& p->nodes[0]->contents != CONTENTS_SOLID && p->nodes[1]->contents != CONTENTS_SOLID
&& p->nodes[0]->contents != CONTENTS_SKY && p->nodes[1]->contents != CONTENTS_SKY)
{
numportals += 2;
- numpoints += p->winding->numpoints * 2;
+ numpoints += p->numpoints * 2;
}
p = p->chain;
}
{
pnext = p->chain;
- if (p->winding)
+ if (p->numpoints >= 3)
{
// note: this check must match the one above or it will usually corrupt memory
// the nodes[0] != nodes[1] check is because leaf 0 is the shared solid leaf, it can have many portals inside with leaf 0 on both sides
{
// first make the back to front portal(forward portal)
portal->points = point;
- portal->numpoints = p->winding->numpoints;
+ portal->numpoints = p->numpoints;
portal->plane.dist = p->plane.dist;
VectorCopy(p->plane.normal, portal->plane.normal);
portal->here = (mleaf_t *)p->nodes[1];
// copy points
for (j = 0;j < portal->numpoints;j++)
{
- VectorCopy(p->winding->points[j], point->position);
+ VectorCopy(p->points + j*3, point->position);
point++;
}
PlaneClassify(&portal->plane);
// then make the front to back portal(backward portal)
portal->points = point;
- portal->numpoints = p->winding->numpoints;
+ portal->numpoints = p->numpoints;
portal->plane.dist = -p->plane.dist;
VectorNegate(p->plane.normal, portal->plane.normal);
portal->here = (mleaf_t *)p->nodes[0];
// copy points
for (j = portal->numpoints - 1;j >= 0;j--)
{
- VectorCopy(p->winding->points[j], point->position);
+ VectorCopy(p->points + j*3, point->position);
point++;
}
PlaneClassify(&portal->plane);
// advance to next portal
portal++;
}
- Winding_Free(p->winding);
}
FreePortal(p);
p = pnext;
static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
{
- int side;
+ int i, side;
mnode_t *front, *back, *other_node;
mplane_t clipplane, *plane;
portal_t *portal, *nextportal, *nodeportal, *splitportal, *temp;
- winding_t *nodeportalwinding, *frontwinding, *backwinding;
+ int numfrontpoints, numbackpoints;
+ double frontpoints[3*MAX_PORTALPOINTS], backpoints[3*MAX_PORTALPOINTS];
// if a leaf, we're done
if (node->contents)
nodeportal = AllocPortal();
nodeportal->plane = *plane;
- nodeportalwinding = Winding_NewFromPlane(nodeportal->plane.normal[0], nodeportal->plane.normal[1], nodeportal->plane.normal[2], nodeportal->plane.dist);
+ PolygonD_QuadForPlane(nodeportal->points, nodeportal->plane.normal[0], nodeportal->plane.normal[1], nodeportal->plane.normal[2], nodeportal->plane.dist, 1024.0*1024.0*1024.0);
+ nodeportal->numpoints = 4;
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 = Winding_Clip(nodeportalwinding, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, true);
- if (!nodeportalwinding)
- {
- Con_Print("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal was clipped away\n");
+ for (i = 0;i < nodeportal->numpoints*3;i++)
+ frontpoints[i] = nodeportal->points[i];
+ PolygonD_Divide(nodeportal->numpoints, frontpoints, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, 1.0/32.0, MAX_PORTALPOINTS, nodeportal->points, &nodeportal->numpoints, 0, NULL, NULL);
+ if (nodeportal->numpoints <= 0 || nodeportal->numpoints >= MAX_PORTALPOINTS)
break;
- }
}
- if (nodeportalwinding)
+ if (nodeportal->numpoints < 3)
{
- // if the plane was not clipped on all sides, there was an error
- nodeportal->winding = nodeportalwinding;
- AddPortalToNodes(nodeportal, front, back);
+ Con_Print("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal was clipped away\n");
+ nodeportal->numpoints = 0;
}
-
- // split the portals of this node along this node's plane and assign them to the children of this node
- // (migrating the portals downward through the tree)
- for (portal = (portal_t *)node->portals;portal;portal = nextportal)
+ else if (nodeportal->numpoints >= MAX_PORTALPOINTS)
{
- if (portal->nodes[0] == portal->nodes[1])
- Host_Error("Mod_Q1BSP_RecursiveNodePortals: portal has same node on both sides(2)");
- if (portal->nodes[0] == node)
- side = 0;
- else if (portal->nodes[1] == node)
- side = 1;
- else
- Host_Error("Mod_Q1BSP_RecursiveNodePortals: mislinked portal");
- nextportal = portal->next[side];
-
- other_node = portal->nodes[!side];
- RemovePortalFromNodes(portal);
-
- // cut the portal into two portals, one on each side of the node plane
- Winding_Divide(portal->winding, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, &frontwinding, &backwinding);
+ Con_Print("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal has too many points\n");
+ nodeportal->numpoints = 0;
+ }
+ else
+ {
+ AddPortalToNodes(nodeportal, front, back);
- if (!frontwinding)
+ // split the portals of this node along this node's plane and assign them to the children of this node
+ // (migrating the portals downward through the tree)
+ for (portal = (portal_t *)node->portals;portal;portal = nextportal)
{
- if (side == 0)
- AddPortalToNodes(portal, back, other_node);
+ if (portal->nodes[0] == portal->nodes[1])
+ Host_Error("Mod_Q1BSP_RecursiveNodePortals: portal has same node on both sides(2)");
+ if (portal->nodes[0] == node)
+ side = 0;
+ else if (portal->nodes[1] == node)
+ side = 1;
else
- AddPortalToNodes(portal, other_node, back);
- continue;
- }
- if (!backwinding)
- {
+ Host_Error("Mod_Q1BSP_RecursiveNodePortals: mislinked portal");
+ nextportal = portal->next[side];
+
+ other_node = portal->nodes[!side];
+ RemovePortalFromNodes(portal);
+
+ // cut the portal into two portals, one on each side of the node plane
+ PolygonD_Divide(portal->numpoints, portal->points, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, 1.0/32.0, MAX_PORTALPOINTS, frontpoints, &numfrontpoints, MAX_PORTALPOINTS, backpoints, &numbackpoints);
+
+ if (!numfrontpoints)
+ {
+ if (side == 0)
+ AddPortalToNodes(portal, back, other_node);
+ else
+ AddPortalToNodes(portal, other_node, back);
+ continue;
+ }
+ if (!numbackpoints)
+ {
+ if (side == 0)
+ AddPortalToNodes(portal, front, other_node);
+ else
+ AddPortalToNodes(portal, other_node, front);
+ continue;
+ }
+
+ // the portal is split
+ splitportal = AllocPortal();
+ temp = splitportal->chain;
+ *splitportal = *portal;
+ splitportal->chain = temp;
+ for (i = 0;i < numbackpoints*3;i++)
+ splitportal->points[i] = backpoints[i];
+ splitportal->numpoints = numbackpoints;
+ for (i = 0;i < numfrontpoints*3;i++)
+ portal->points[i] = frontpoints[i];
+ portal->numpoints = numfrontpoints;
+
if (side == 0)
+ {
AddPortalToNodes(portal, front, other_node);
+ AddPortalToNodes(splitportal, back, other_node);
+ }
else
+ {
AddPortalToNodes(portal, other_node, front);
- continue;
- }
-
- // the winding is split
- splitportal = AllocPortal();
- temp = splitportal->chain;
- *splitportal = *portal;
- splitportal->chain = temp;
- splitportal->winding = backwinding;
- Winding_Free(portal->winding);
- portal->winding = frontwinding;
-
- if (side == 0)
- {
- AddPortalToNodes(portal, front, other_node);
- AddPortalToNodes(splitportal, back, other_node);
- }
- else
- {
- AddPortalToNodes(portal, other_node, front);
- AddPortalToNodes(splitportal, other_node, back);
+ AddPortalToNodes(splitportal, other_node, back);
+ }
}
}
msurface_t *surf;
int numshadowmeshtriangles;
- mod->type = mod_brush;
+ mod->type = mod_brushq1;
header = (dheader_t *)buffer;
// swap all the lumps
mod_base = (qbyte *)header;
- for (i = 0;i < (int) sizeof(dheader_t) / 4;i++)
- ((int *)header)[i] = LittleLong(((int *)header)[i]);
+ header->version = LittleLong(header->version);
+ 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);
+ }
// load into heap
// LordHavoc: this code was originally at the end of this loop, but
// has been transformed to something more readable at the start here.
- // LordHavoc: only register submodels if it is the world
- // (prevents external bsp models from replacing world submodels with
- // their own)
- if (loadmodel->isworldmodel && i)
+ if (i > 0)
{
char name[10];
+ // LordHavoc: only register submodels if it is the world
+ // (prevents external bsp models from replacing world submodels with
+ // their own)
+ if (!loadmodel->isworldmodel)
+ continue;
// duplicate the basic information
sprintf(name, "*%i", i);
mod = Mod_FindName(name);
{
q3dface_t *in;
q3msurface_t *out;
- int i, j, n, count, invalidelements, patchsize[2], finalwidth, finalheight, xlevel, ylevel, row0, row1, x, y, *e, finalvertices, finaltriangles;
+ int i, j, n, count, invalidelements, patchsize[2], finalwidth, finalheight, xlevel, ylevel, row0, row1, x, y, *e, finalvertices, finaltriangles, firstvertex, firstelement, type;
//int *originalelement3i;
//int *originalneighbor3i;
float *originalvertex3f;
for (i = 0;i < count;i++, in++, out++)
{
// check face type first
- out->type = LittleLong(in->type);
- if (out->type != Q3FACETYPE_POLYGON
- && out->type != Q3FACETYPE_PATCH
- && out->type != Q3FACETYPE_MESH
- && out->type != Q3FACETYPE_FLARE)
+ type = LittleLong(in->type);
+ if (type != Q3FACETYPE_POLYGON
+ && type != Q3FACETYPE_PATCH
+ && type != Q3FACETYPE_MESH
+ && type != Q3FACETYPE_FLARE)
{
- Con_DPrintf("Mod_Q3BSP_LoadFaces: face #%i: unknown face type %i\n", i, out->type);
+ Con_DPrintf("Mod_Q3BSP_LoadFaces: face #%i: unknown face type %i\n", i, type);
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
}
Con_DPrintf("Mod_Q3BSP_LoadFaces: face #%i: invalid textureindex %i (%i textures)\n", i, n, loadmodel->brushq3.num_textures);
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
n = 0;
}
else
out->lightmaptexture = loadmodel->brushq3.data_lightmaps[n];
- out->firstvertex = LittleLong(in->firstvertex);
+ firstvertex = LittleLong(in->firstvertex);
out->num_vertices = LittleLong(in->numvertices);
- out->firstelement = LittleLong(in->firstelement);
+ firstelement = LittleLong(in->firstelement);
out->num_triangles = LittleLong(in->numelements) / 3;
if (out->num_triangles * 3 != LittleLong(in->numelements))
{
Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): numelements %i is not a multiple of 3\n", i, out->texture->name, LittleLong(in->numelements));
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
}
- if (out->firstvertex < 0 || out->firstvertex + out->num_vertices > loadmodel->brushq3.num_vertices)
+ if (firstvertex < 0 || firstvertex + out->num_vertices > loadmodel->brushq3.num_vertices)
{
- Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): invalid vertex range %i : %i (%i vertices)\n", i, out->texture->name, out->firstvertex, out->firstvertex + out->num_vertices, loadmodel->brushq3.num_vertices);
+ Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): invalid vertex range %i : %i (%i vertices)\n", i, out->texture->name, firstvertex, firstvertex + out->num_vertices, loadmodel->brushq3.num_vertices);
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
}
- if (out->firstelement < 0 || out->firstelement + out->num_triangles * 3 > loadmodel->brushq3.num_triangles * 3)
+ if (firstelement < 0 || firstelement + out->num_triangles * 3 > loadmodel->brushq3.num_triangles * 3)
{
- Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): invalid element range %i : %i (%i elements)\n", i, out->texture->name, out->firstelement, out->firstelement + out->num_triangles * 3, loadmodel->brushq3.num_triangles * 3);
+ Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): invalid element range %i : %i (%i elements)\n", i, out->texture->name, firstelement, firstelement + out->num_triangles * 3, loadmodel->brushq3.num_triangles * 3);
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
}
- switch(out->type)
+ switch(type)
{
case Q3FACETYPE_POLYGON:
case Q3FACETYPE_MESH:
// no processing necessary
- out->data_vertex3f = loadmodel->brushq3.data_vertex3f + out->firstvertex * 3;
- 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;
- out->data_color4f = loadmodel->brushq3.data_color4f + out->firstvertex * 4;
- out->data_element3i = loadmodel->brushq3.data_element3i + out->firstelement;
- out->data_neighbor3i = loadmodel->brushq3.data_neighbor3i + out->firstelement;
+ out->data_vertex3f = loadmodel->brushq3.data_vertex3f + firstvertex * 3;
+ out->data_texcoordtexture2f = loadmodel->brushq3.data_texcoordtexture2f + firstvertex * 2;
+ out->data_texcoordlightmap2f = loadmodel->brushq3.data_texcoordlightmap2f + firstvertex * 2;
+ out->data_svector3f = loadmodel->brushq3.data_svector3f + firstvertex * 3;
+ out->data_tvector3f = loadmodel->brushq3.data_tvector3f + firstvertex * 3;
+ out->data_normal3f = loadmodel->brushq3.data_normal3f + firstvertex * 3;
+ out->data_color4f = loadmodel->brushq3.data_color4f + firstvertex * 4;
+ out->data_element3i = loadmodel->brushq3.data_element3i + firstelement;
+ out->data_neighbor3i = loadmodel->brushq3.data_neighbor3i + firstelement;
break;
case Q3FACETYPE_PATCH:
patchsize[0] = LittleLong(in->specific.patch.patchsize[0]);
Con_Printf("Mod_Q3BSP_LoadFaces: face #%i (texture \"%s\"): invalid patchsize %ix%i\n", i, out->texture->name, patchsize[0], patchsize[1]);
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0; // error
+ type = 0; // error
continue;
}
- originalvertex3f = loadmodel->brushq3.data_vertex3f + out->firstvertex * 3;
- //originalsvector3f = loadmodel->brushq3.data_svector3f + out->firstvertex * 3;
- //originaltvector3f = loadmodel->brushq3.data_tvector3f + out->firstvertex * 3;
- //originalnormal3f = loadmodel->brushq3.data_normal3f + out->firstvertex * 3;
- originaltexcoordtexture2f = loadmodel->brushq3.data_texcoordtexture2f + out->firstvertex * 2;
- originaltexcoordlightmap2f = loadmodel->brushq3.data_texcoordlightmap2f + out->firstvertex * 2;
- originalcolor4f = loadmodel->brushq3.data_color4f + out->firstvertex * 4;
- //originalelement3i = loadmodel->brushq3.data_element3i + out->firstelement;
- //originalneighbor3i = loadmodel->brushq3.data_neighbor3i + out->firstelement;
+ originalvertex3f = loadmodel->brushq3.data_vertex3f + firstvertex * 3;
+ //originalsvector3f = loadmodel->brushq3.data_svector3f + firstvertex * 3;
+ //originaltvector3f = loadmodel->brushq3.data_tvector3f + firstvertex * 3;
+ //originalnormal3f = loadmodel->brushq3.data_normal3f + firstvertex * 3;
+ originaltexcoordtexture2f = loadmodel->brushq3.data_texcoordtexture2f + firstvertex * 2;
+ originaltexcoordlightmap2f = loadmodel->brushq3.data_texcoordlightmap2f + firstvertex * 2;
+ originalcolor4f = loadmodel->brushq3.data_color4f + firstvertex * 4;
+ //originalelement3i = loadmodel->brushq3.data_element3i + firstelement;
+ //originalneighbor3i = loadmodel->brushq3.data_neighbor3i + firstelement;
/*
originalvertex3f = out->data_vertex3f;
//originalsvector3f = out->data_svector3f;
//originalneighbor3i = out->data_neighbor3i;
*/
// convert patch to Q3FACETYPE_MESH
- xlevel = QuadraticSplinePatchSubdivisionLevelOnX(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_tolerance.value, 10);
- ylevel = QuadraticSplinePatchSubdivisionLevelOnY(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_tolerance.value, 10);
+ xlevel = QuadraticBSplinePatchSubdivisionLevelOnX(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_tolerance.value, 10);
+ ylevel = QuadraticBSplinePatchSubdivisionLevelOnY(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_tolerance.value, 10);
// bound to user settings
xlevel = bound(r_subdivisions_minlevel.integer, xlevel, r_subdivisions_maxlevel.integer);
ylevel = bound(r_subdivisions_minlevel.integer, ylevel, r_subdivisions_maxlevel.integer);
out->data_texcoordlightmap2f = out->data_texcoordtexture2f + finalvertices * 2;
out->data_element3i = Mem_Alloc(loadmodel->mempool, sizeof(int[6]) * finaltriangles);
out->data_neighbor3i = out->data_element3i + finaltriangles * 3;
- out->type = Q3FACETYPE_MESH;
- out->firstvertex = -1;
+ type = Q3FACETYPE_MESH;
+ firstvertex = -1;
out->num_vertices = finalvertices;
- out->firstelement = -1;
+ firstelement = -1;
out->num_triangles = finaltriangles;
// generate geometry
// (note: normals are skipped because they get recalculated)
- QuadraticSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 3, originalvertex3f, out->data_vertex3f);
- QuadraticSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 2, originaltexcoordtexture2f, out->data_texcoordtexture2f);
- QuadraticSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 2, originaltexcoordlightmap2f, out->data_texcoordlightmap2f);
- QuadraticSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 4, originalcolor4f, out->data_color4f);
+ QuadraticBSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 3, originalvertex3f, out->data_vertex3f);
+ QuadraticBSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 2, originaltexcoordtexture2f, out->data_texcoordtexture2f);
+ QuadraticBSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 2, originaltexcoordlightmap2f, out->data_texcoordlightmap2f);
+ QuadraticBSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 4, originalcolor4f, out->data_color4f);
// generate elements
e = out->data_element3i;
for (y = 0;y < finalheight - 1;y++)
}
// q3map does not put in collision brushes for curves... ugh
// build the lower quality collision geometry
- out->collisions = true;
- xlevel = QuadraticSplinePatchSubdivisionLevelOnX(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_collision_tolerance.value, 10);
- ylevel = QuadraticSplinePatchSubdivisionLevelOnY(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_collision_tolerance.value, 10);
+ xlevel = QuadraticBSplinePatchSubdivisionLevelOnX(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_collision_tolerance.value, 10);
+ ylevel = QuadraticBSplinePatchSubdivisionLevelOnY(patchsize[0], patchsize[1], 3, originalvertex3f, r_subdivisions_collision_tolerance.value, 10);
// bound to user settings
xlevel = bound(r_subdivisions_collision_minlevel.integer, xlevel, r_subdivisions_collision_maxlevel.integer);
ylevel = bound(r_subdivisions_collision_minlevel.integer, ylevel, r_subdivisions_collision_maxlevel.integer);
out->data_collisionelement3i = Mem_Alloc(loadmodel->mempool, sizeof(int[3]) * finaltriangles);
out->num_collisionvertices = finalvertices;
out->num_collisiontriangles = finaltriangles;
- QuadraticSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 3, originalvertex3f, out->data_collisionvertex3f);
+ QuadraticBSplinePatchSubdivideFloatBuffer(patchsize[0], patchsize[1], xlevel, ylevel, 3, originalvertex3f, out->data_collisionvertex3f);
// generate elements
e = out->data_collisionelement3i;
for (y = 0;y < finalheight - 1;y++)
// don't render it
out->num_vertices = 0;
out->num_triangles = 0;
- out->type = 0;
+ type = 0;
break;
}
for (j = 0, invalidelements = 0;j < out->num_triangles * 3;j++)
invalidelements++;
if (invalidelements)
{
- 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->num_vertices, out->firstelement, out->num_triangles * 3);
+ 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, type, out->texture->name, out->texture->surfaceflags, out->texture->nativecontents, firstvertex, out->num_vertices, firstelement, out->num_triangles * 3);
for (j = 0;j < out->num_triangles * 3;j++)
{
Con_Printf(" %i", out->data_element3i[j]);
loadmodel->brushq3.data_leaffaces = out;
loadmodel->brushq3.num_leaffaces = count;
+ loadmodel->brushq3.data_leaffacenums = Mem_Alloc(loadmodel->mempool, count * sizeof(int));
+
for (i = 0;i < count;i++, in++, out++)
{
n = LittleLong(*in);
if (n < 0 || n >= loadmodel->brushq3.num_faces)
Host_Error("Mod_Q3BSP_LoadLeafFaces: invalid face index %i (%i faces)\n", n, loadmodel->brushq3.num_faces);
*out = loadmodel->brushq3.data_faces + n;
+ loadmodel->brushq3.data_leaffacenums[i] = n;
}
}
if (n < 0 || n + c > loadmodel->brushq3.num_leaffaces)
Host_Error("Mod_Q3BSP_LoadLeafs: invalid leafface range %i : %i (%i leaffaces)\n", n, n + c, loadmodel->brushq3.num_leaffaces);
out->firstleafface = loadmodel->brushq3.data_leaffaces + n;
+ out->firstleaffacenum = loadmodel->brushq3.data_leaffacenums + n;
out->numleaffaces = c;
n = LittleLong(in->firstleafbrush);
c = LittleLong(in->numleafbrushes);
for (i = 0;i < leaf->numleaffaces;i++)
{
face = leaf->firstleafface[i];
- if (face->collisions && face->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, face->mins, face->maxs))
+ if (face->num_collisiontriangles && face->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, face->mins, face->maxs))
{
face->collisionmarkframe = markframe;
Collision_TraceLineTriangleMeshFloat(trace, linestart, lineend, face->num_collisiontriangles, face->data_collisionelement3i, face->data_collisionvertex3f, face->texture->supercontents, segmentmins, segmentmaxs);
for (i = 0;i < leaf->numleaffaces;i++)
{
face = leaf->firstleafface[i];
- if (face->collisions && face->markframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, face->mins, face->maxs))
+ if (face->num_collisiontriangles && face->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, face->mins, face->maxs))
{
- face->markframe = markframe;
+ face->collisionmarkframe = markframe;
Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, face->num_collisiontriangles, face->data_collisionelement3i, face->data_collisionvertex3f, face->texture->supercontents, segmentmins, segmentmaxs);
}
}
for (i = 0;i < model->brushq3.data_thismodel->numfaces;i++)
{
face = model->brushq3.data_thismodel->firstface + i;
- if (face->collisions)
+ if (face->num_collisiontriangles)
Collision_TraceLineTriangleMeshFloat(trace, boxstartmins, boxendmins, face->num_collisiontriangles, face->data_collisionelement3i, face->data_collisionvertex3f, face->texture->supercontents, segmentmins, segmentmaxs);
}
}
for (i = 0;i < model->brushq3.data_thismodel->numfaces;i++)
{
face = model->brushq3.data_thismodel->firstface + i;
- if (face->collisions)
+ if (face->num_collisiontriangles)
Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, face->num_collisiontriangles, face->data_collisionelement3i, face->data_collisionvertex3f, face->texture->supercontents, segmentmins, segmentmaxs);
}
}
}
*/
+void Mod_Q3BSP_BuildTextureFaceLists(void)
+{
+ int i, j;
+ loadmodel->brushq3.data_texturefaces = Mem_Alloc(loadmodel->mempool, loadmodel->nummodelsurfaces * sizeof(q3msurface_t *));
+ loadmodel->brushq3.data_texturefacenums = Mem_Alloc(loadmodel->mempool, loadmodel->nummodelsurfaces * sizeof(int));
+ for (i = 0;i < loadmodel->brushq3.num_textures;i++)
+ loadmodel->brushq3.data_textures[i].numfaces = 0;
+ for (i = 0;i < loadmodel->nummodelsurfaces;i++)
+ loadmodel->brushq3.data_faces[loadmodel->surfacelist[i]].texture->numfaces++;
+ j = 0;
+ for (i = 0;i < loadmodel->brushq3.num_textures;i++)
+ {
+ loadmodel->brushq3.data_textures[i].facelist = loadmodel->brushq3.data_texturefaces + j;
+ loadmodel->brushq3.data_textures[i].facenumlist = loadmodel->brushq3.data_texturefacenums + j;
+ j += loadmodel->brushq3.data_textures[i].numfaces;
+ loadmodel->brushq3.data_textures[i].numfaces = 0;
+ }
+ for (i = 0;i < loadmodel->nummodelsurfaces;i++)
+ {
+ loadmodel->brushq3.data_faces[loadmodel->surfacelist[i]].texture->facenumlist[loadmodel->brushq3.data_faces[loadmodel->surfacelist[i]].texture->numfaces] = loadmodel->surfacelist[i];
+ loadmodel->brushq3.data_faces[loadmodel->surfacelist[i]].texture->facelist[loadmodel->brushq3.data_faces[loadmodel->surfacelist[i]].texture->numfaces++] = loadmodel->brushq3.data_faces + loadmodel->surfacelist[i];
+ }
+}
+
+void Mod_Q3BSP_RecursiveFindNumLeafs(q3mnode_t *node)
+{
+ int numleafs;
+ while (node->plane)
+ {
+ Mod_Q3BSP_RecursiveFindNumLeafs(node->children[0]);
+ node = node->children[1];
+ }
+ numleafs = ((q3mleaf_t *)node - loadmodel->brushq3.data_leafs) + 1;
+ if (loadmodel->brushq3.num_leafs < numleafs)
+ loadmodel->brushq3.num_leafs = numleafs;
+}
+
extern void R_Q3BSP_DrawSky(struct entity_render_s *ent);
extern void R_Q3BSP_Draw(struct entity_render_s *ent);
extern void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
mod_base = (qbyte *)header;
// swap all the lumps
- for (i = 0;i < (int) sizeof(*header) / 4;i++)
- ((int *)header)[i] = LittleLong(((int *)header)[i]);
+ header->ident = LittleLong(header->ident);
+ header->version = LittleLong(header->version);
+ for (i = 0;i < Q3HEADER_LUMPS;i++)
+ {
+ header->lumps[i].fileofs = LittleLong(header->lumps[i].fileofs);
+ header->lumps[i].filelen = LittleLong(header->lumps[i].filelen);
+ }
Mod_Q3BSP_LoadEntities(&header->lumps[Q3LUMP_ENTITIES]);
Mod_Q3BSP_LoadTextures(&header->lumps[Q3LUMP_TEXTURES]);
Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, face->data_vertex3f, NULL, NULL, NULL, NULL, face->num_triangles, face->data_element3i);
loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
-
+
+ loadmodel->brushq3.num_leafs = 0;
+ Mod_Q3BSP_RecursiveFindNumLeafs(loadmodel->brushq3.data_nodes);
+
+ mod = loadmodel;
for (i = 0;i < loadmodel->brushq3.num_models;i++)
{
- if (i == 0)
- mod = loadmodel;
- else
+ if (i > 0)
{
char name[10];
// LordHavoc: only register submodels if it is the world
- // (prevents bsp models from replacing world submodels)
+ // (prevents external bsp models from replacing world submodels with
+ // their own)
if (!loadmodel->isworldmodel)
continue;
// duplicate the basic information
if (j < mod->brushq3.data_thismodel->numfaces)
mod->DrawSky = R_Q3BSP_DrawSky;
}
+
+ Mod_Q3BSP_BuildTextureFaceLists();
}
void Mod_IBSP_Load(model_t *mod, void *buffer)