merged q3msurface_t into msurface_t
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 7 Mar 2005 23:28:42 +0000 (23:28 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 7 Mar 2005 23:28:42 +0000 (23:28 +0000)
renamed brushq1./brushq3. surface stuff to brush.
surface->texinfo->texture is now also copied into surface->texture for convenient access (and consistency with q3bsp)
the qc surface info extension has been made q3bsp friendly (however querying a surface's points won't give very sane results on q3bsp surfaces!)
a little cruft removal in some structures

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5051 d7cf8633-e32d-0410-b094-e92efae38249

gl_rsurf.c
model_brush.c
model_brush.h
model_shared.c
model_shared.h
portals.c
pr_cmds.c
r_light.c

index 1d9ae5e..fc144cd 100644 (file)
@@ -442,7 +442,7 @@ loc0:
                impact[2] = origin[2] - node->plane->normal[2] * ndist;
        }
 
-       for (surface = model->brushq1.surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
+       for (surface = model->brush.data_surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
        {
                if (surface->stainsamples)
                {
@@ -702,7 +702,7 @@ static int RSurf_LightSeparate_Vertex3f_Color4f(const matrix4x4_t *matrix, const
 static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
 {
        const entity_render_t *ent = calldata1;
-       const msurface_t *surface = ent->model->brushq1.surfaces + calldata2;
+       const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
        rmeshstate_t m;
        float currentalpha;
        float base, colorscale;
@@ -714,11 +714,11 @@ static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata
        R_Mesh_Matrix(&ent->matrix);
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
 
-       texture = surface->texinfo->texture;
+       texture = surface->texture;
        if (texture->animated)
                texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (r_refdef.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
        currentalpha = ent->alpha;
-       if (surface->flags & SURF_WATERALPHA)
+       if (texture->flags & SURF_WATERALPHA)
                currentalpha *= r_wateralpha.value;
 
        GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
@@ -741,12 +741,12 @@ static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata
                GL_DepthMask(!(ent->effects & EF_NODEPTHTEST));
        }
 
-       turb = (surface->flags & SURF_DRAWTURB) && r_waterscroll.value;
-       fullbright = !(ent->flags & RENDER_LIGHT) || (surface->flags & SURF_DRAWFULLBRIGHT) || !surface->samples;
+       turb = (texture->flags & SURF_DRAWTURB) && r_waterscroll.value;
+       fullbright = !(ent->flags & RENDER_LIGHT) || (texture->flags & SURF_DRAWFULLBRIGHT) || !surface->samples;
        base = fullbright ? 2.0f : r_ambient.value * (1.0f / 64.0f);
-       if (surface->flags & SURF_DRAWTURB)
+       if (texture->flags & SURF_DRAWTURB)
                base *= 0.5f;
-       if ((surface->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
+       if ((texture->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
        {
                // NVIDIA Geforce3 distortion texture shader on water
                GL_Color(1, 1, 1, currentalpha);
@@ -891,6 +891,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
 {
        int texturesurfaceindex;
        vec3_t center, modelorg;
+       msurface_t *surface;
        rmeshstate_t m;
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
        if (gl_lightmaps.integer)
@@ -902,7 +903,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                memset(&m, 0, sizeof(m));
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.tex[0] = R_GetTexture(surface->lightmaptexture);
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
@@ -917,13 +918,13 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                // transparent vertex shaded from lightmap
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        vec3_t tempcenter;
                        tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
                        tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
                        tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
                        Matrix4x4_Transform(&ent->matrix, tempcenter, center);
-                       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brushq1.surfaces);
+                       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brush.data_surfaces);
                }
        }
        else if (texture->flags & SURF_LIGHTMAP)
@@ -959,7 +960,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                                        doglow = false;
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
-                                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                                               surface = texturesurfacelist[texturesurfaceindex];
                                                m.tex[1] = R_GetTexture(surface->lightmaptexture);
                                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
@@ -976,7 +977,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                                {
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
-                                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                                               surface = texturesurfacelist[texturesurfaceindex];
                                                m.tex[1] = R_GetTexture(surface->lightmaptexture);
                                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
@@ -996,7 +997,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                                doglow = false;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
-                                       msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                                       surface = texturesurfacelist[texturesurfaceindex];
                                        m.tex[1] = R_GetTexture(surface->lightmaptexture);
                                        m.pointer_vertex = surface->mesh.data_vertex3f;
                                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
@@ -1024,7 +1025,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.base);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                                R_Mesh_State(&m);
@@ -1044,7 +1045,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.base);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.tex[0] = R_GetTexture(surface->lightmaptexture);
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
@@ -1064,7 +1065,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.base);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                                R_Mesh_State(&m);
@@ -1083,7 +1084,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.detail);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                                R_Mesh_State(&m);
@@ -1102,7 +1103,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.glow);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                                R_Mesh_State(&m);
@@ -1121,7 +1122,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        m.tex[0] = R_GetTexture(texture->skin.glow);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                if (m.tex[0])
                                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
@@ -1137,8 +1138,8 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
        {
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       msurface_t *surface = texturesurfacelist[texturesurfaceindex];
-                       RSurfShader_Transparent_Callback(ent, surface - ent->model->brushq1.surfaces);
+                       surface = texturesurfacelist[texturesurfaceindex];
+                       RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
                }
        }
        else if (texture->flags & SURF_DRAWSKY)
@@ -1172,7 +1173,7 @@ void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenums
                        memset(&m, 0, sizeof(m));
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                m.pointer_vertex = surface->mesh.data_vertex3f;
                                R_Mesh_State(&m);
                                GL_LockArrays(0, surface->mesh.num_vertices);
@@ -1202,7 +1203,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
        if (ent != r_refdef.worldentity)
        {
                // because bmodels can be reused, we have to clear dlightframe every time
-               surface = model->brushq1.surfaces + model->firstmodelsurface;
+               surface = model->brush.data_surfaces + model->firstmodelsurface;
                for (i = 0;i < model->nummodelsurfaces;i++, surface++)
                        surface->dlightframe = -1;
        }
@@ -1233,15 +1234,15 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
        {
                if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
                {
-                       surface = model->brushq1.surfaces + j;
-                       if (t != surface->texinfo->texture)
+                       surface = model->brush.data_surfaces + j;
+                       if (t != surface->texture)
                        {
                                if (numsurfacelist)
                                {
                                        R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
                                        numsurfacelist = 0;
                                }
-                               t = surface->texinfo->texture;
+                               t = surface->texture;
                                f = t->flags & flagsmask;
                                texture = t->currentframe;
                        }
@@ -1332,7 +1333,7 @@ void R_WorldVisibility(void)
        {
                int i, j;
                mleaf_t *leaf;
-               memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq3.num_faces);
+               memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brush.num_surfaces);
                for (j = 0, leaf = r_refdef.worldmodel->brush.data_leafs;j < r_refdef.worldmodel->brush.num_leafs;j++, leaf++)
                {
                        if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
@@ -1357,7 +1358,7 @@ void R_WorldVisibility(void)
                if (!viewleaf)
                        return;
 
-               memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq1.numsurfaces);
+               memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brush.num_surfaces);
                if (viewleaf->clusterindex < 0 || r_surfaceworldnode.integer)
                {
                        // equivilant to quake's RecursiveWorldNode but faster and more effective
@@ -1475,8 +1476,8 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
                                        surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
                                        if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
                                        {
-                                               surface = model->brushq1.surfaces + surfaceindex;
-                                               if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->flags & SURF_LIGHTMAP) && !surface->texinfo->texture->skin.fog)
+                                               surface = model->brush.data_surfaces + surfaceindex;
+                                               if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->texture->flags & SURF_LIGHTMAP) && !surface->texture->skin.fog)
                                                {
                                                        for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
                                                        {
@@ -1527,7 +1528,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
-                       surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
+                       surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
                        R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
                }
                R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
@@ -1554,17 +1555,17 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
                R_UpdateTextureInfo(ent);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
-                       surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
+                       surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
                        if (r_shadow_compilingrtlight)
                        {
                                // if compiling an rtlight, capture the mesh
-                               t = surface->texinfo->texture;
+                               t = surface->texture;
                                if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
-                                       Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texinfo->texture->skin.base, surface->texinfo->texture->skin.gloss, surface->texinfo->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
                        }
-                       else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surface - ent->model->brushq1.surfaces])
+                       else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surface - ent->model->brush.data_surfaces])
                        {
-                               t = surface->texinfo->texture->currentframe;
+                               t = surface->texture->currentframe;
                                // FIXME: transparent surfaces need to be lit later
                                if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
                                        R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
@@ -1587,7 +1588,7 @@ void R_DrawCollisionBrush(colbrushf_t *brush)
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *surface)
+void R_Q3BSP_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
 {
        int i;
        rmeshstate_t m;
@@ -1596,7 +1597,7 @@ void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *surface)
        memset(&m, 0, sizeof(m));
        m.pointer_vertex = surface->mesh.data_collisionvertex3f;
        R_Mesh_State(&m);
-       i = (int)(((size_t)surface) / sizeof(q3msurface_t));
+       i = (int)(((size_t)surface) / sizeof(msurface_t));
        GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
        GL_LockArrays(0, surface->mesh.num_collisionvertices);
        R_Mesh_Draw(surface->mesh.num_collisionvertices, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i);
@@ -1606,7 +1607,7 @@ void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *surface)
 void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int surfacenumber)
 {
        const entity_render_t *ent = voident;
-       q3msurface_t *surface = ent->model->brushq3.data_faces + surfacenumber;
+       msurface_t *surface = ent->model->brush.data_surfaces + surfacenumber;
        rmeshstate_t m;
        R_Mesh_Matrix(&ent->matrix);
        memset(&m, 0, sizeof(m));
@@ -1713,9 +1714,10 @@ void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int surfacenumber
                qglEnable(GL_CULL_FACE);
 }
 
-void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, q3msurface_t **texturesurfacelist)
+void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, msurface_t **texturesurfacelist)
 {
        int i, texturesurfaceindex;
+       msurface_t *surface;
        qboolean dolightmap;
        qboolean dobase;
        qboolean doambient;
@@ -1735,7 +1737,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                memset(&m, 0, sizeof(m));
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.tex[0] = R_GetTexture(surface->lightmaptexture);
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
                        if (surface->lightmaptexture)
@@ -1763,12 +1765,12 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                        return;
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        facecenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
                        facecenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
                        facecenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
                        Matrix4x4_Transform(&ent->matrix, facecenter, center);
-                       R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brushq3.data_faces);
+                       R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brush.data_surfaces);
                }
                return;
        }
@@ -1806,7 +1808,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                memset(&m, 0, sizeof(m));
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
                        GL_LockArrays(0, surface->mesh.num_vertices);
@@ -1838,7 +1840,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.tex[0] = R_GetTexture(t->skin.base);
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
@@ -1858,7 +1860,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                memset(&m, 0, sizeof(m));
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
                        GL_LockArrays(0, surface->mesh.num_vertices);
@@ -1880,7 +1882,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.pointer_color = NULL;
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        if (!surface->lightmaptexture)
                                continue;
                        m.tex[1] = R_GetTexture(surface->lightmaptexture);
@@ -1897,7 +1899,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                {
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                if (surface->lightmaptexture)
                                        continue;
                                m.tex[1] = R_GetTexture(surface->lightmaptexture);
@@ -1916,7 +1918,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                {
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
-                               q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                               surface = texturesurfacelist[texturesurfaceindex];
                                if (surface->lightmaptexture)
                                        continue;
                                m.tex[1] = R_GetTexture(surface->lightmaptexture);
@@ -1948,7 +1950,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                memset(&m, 0, sizeof(m));
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.tex[0] = R_GetTexture(surface->lightmaptexture);
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
                        if (surface->lightmaptexture)
@@ -1972,7 +1974,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.tex[0] = R_GetTexture(t->skin.base);
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
@@ -1991,7 +1993,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.tex[0] = R_GetTexture(t->skin.base);
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
@@ -2010,7 +2012,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.tex[0] = R_GetTexture(t->skin.glow);
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                        m.pointer_vertex = surface->mesh.data_vertex3f;
                        R_Mesh_State(&m);
@@ -2032,7 +2034,7 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
                m.pointer_color = varray_color4f;
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
-                       q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+                       surface = texturesurfacelist[texturesurfaceindex];
                        if (m.tex[0])
                                m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
                        m.pointer_vertex = surface->mesh.data_vertex3f;
@@ -2050,12 +2052,12 @@ void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurf
 void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
 {
        int i, j, f, flagsmask, flags;
-       q3msurface_t *surface;
+       msurface_t *surface;
        model_t *model = ent->model;
        texture_t *t;
        const int maxfaces = 1024;
        int numsurfaces = 0;
-       q3msurface_t *surfacelist[1024];
+       msurface_t *surfacelist[1024];
        R_Mesh_Matrix(&ent->matrix);
        flagsmask = Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY;
        if (skyfaces)
@@ -2069,7 +2071,7 @@ void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
        {
                if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
                {
-                       surface = model->brushq3.data_faces + j;
+                       surface = model->brush.data_surfaces + j;
                        if (t != surface->texture)
                        {
                                if (numsurfaces)
@@ -2111,7 +2113,7 @@ void R_Q3BSP_Draw(entity_render_t *ent)
        {
                int i;
                model_t *model = ent->model;
-               q3msurface_t *surface;
+               msurface_t *surface;
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                GL_DepthMask(false);
                GL_DepthTest(true);
@@ -2121,7 +2123,7 @@ void R_Q3BSP_Draw(entity_render_t *ent)
                                R_DrawCollisionBrush(model->brushq3.data_models[model->brush.submodel].firstbrush[i].colbrushf);
                for (i = 0, surface = model->brushq3.data_models[model->brush.submodel].firstsurface;i < model->brushq3.data_models[model->brush.submodel].numsurfaces;i++, surface++)
                        if (surface->mesh.num_collisiontriangles)
-                               R_Q3BSP_DrawCollisionFace(ent, surface);
+                               R_Q3BSP_DrawCollisionSurface(ent, surface);
                qglPolygonOffset(0, 0);
        }
 }
@@ -2133,7 +2135,7 @@ void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
        int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
        const int *e;
        const float *v[3];
-       q3msurface_t *surface;
+       msurface_t *surface;
        mleaf_t *leaf;
        const qbyte *pvs;
        lightmins[0] = relativelightorigin[0] - lightradius;
@@ -2182,7 +2184,7 @@ void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
                                for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
                                {
                                        surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
-                                       surface = model->brushq3.data_faces + surfaceindex;
+                                       surface = model->brush.data_surfaces + surfaceindex;
                                        if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
                                        {
                                                if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->mesh.num_triangles)
@@ -2240,7 +2242,7 @@ void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
 {
        model_t *model = ent->model;
        vec3_t lightmins, lightmaxs;
-       q3msurface_t *surface;
+       msurface_t *surface;
        int surfacelistindex;
        if (r_drawcollisionbrushes.integer < 2)
        {
@@ -2254,7 +2256,7 @@ void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
-                       surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
+                       surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
                        // FIXME: check some manner of surface->rendermode here?
                        if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
                                R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
@@ -2267,7 +2269,7 @@ void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
 {
        model_t *model = ent->model;
        vec3_t lightmins, lightmaxs, modelorg;
-       q3msurface_t *surface;
+       msurface_t *surface;
        int surfacelistindex;
        if (r_drawcollisionbrushes.integer < 2)
        {
@@ -2281,7 +2283,7 @@ void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
                Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
-                       surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
+                       surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
                        if (r_shadow_compilingrtlight)
                        {
                                // if compiling an rtlight, capture the mesh
index 758231a..2367c0c 100644 (file)
@@ -178,7 +178,7 @@ static void Mod_Q1BSP_FindNonSolidLocation_r_Leaf(findnonsolidlocationinfo_t *in
        msurface_t *surface;
        for (surfacenum = 0, mark = leaf->firstleafsurface;surfacenum < leaf->numleafsurfaces;surfacenum++, mark++)
        {
-               surface = info->model->brushq1.surfaces + *mark;
+               surface = info->model->brush.data_surfaces + *mark;
                if (surface->flags & SURF_SOLIDCLIP)
                {
 #if 0
@@ -768,10 +768,10 @@ loc0:
                        int i, ds, dt;
                        msurface_t *surface;
 
-                       surface = r_refdef.worldmodel->brushq1.surfaces + node->firstsurface;
+                       surface = r_refdef.worldmodel->brush.data_surfaces + node->firstsurface;
                        for (i = 0;i < node->numsurfaces;i++, surface++)
                        {
-                               if (!(surface->flags & SURF_LIGHTMAP) || !surface->samples)
+                               if (!(surface->texture->flags & SURF_LIGHTMAP) || !surface->samples)
                                        continue;       // no lightmaps
 
                                ds = (int) (x * surface->texinfo->vecs[0][0] + y * surface->texinfo->vecs[0][1] + mid * surface->texinfo->vecs[0][2] + surface->texinfo->vecs[0][3]) - surface->texturemins[0];
@@ -1732,9 +1732,9 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error("Mod_Q1BSP_LoadFaces: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       loadmodel->brushq1.surfaces = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_t));
+       loadmodel->brush.data_surfaces = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_t));
 
-       loadmodel->brushq1.numsurfaces = count;
+       loadmodel->brush.num_surfaces = count;
 
        totalverts = 0;
        totaltris = 0;
@@ -1753,9 +1753,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
 
        totalverts = 0;
        totaltris = 0;
-       for (surfacenum = 0, in = (void *)(mod_base + l->fileofs), surface = loadmodel->brushq1.surfaces;surfacenum < count;surfacenum++, in++, surface++)
+       for (surfacenum = 0, in = (void *)(mod_base + l->fileofs), surface = loadmodel->brush.data_surfaces;surfacenum < count;surfacenum++, in++, surface++)
        {
-               surface->number = surfacenum;
                // FIXME: validate edges, texinfo, etc?
                firstedge = LittleLong(in->firstedge);
                numedges = LittleShort(in->numedges);
@@ -1765,7 +1764,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                if ((unsigned int) i >= (unsigned int) loadmodel->brushq1.numtexinfo)
                        Host_Error("Mod_Q1BSP_LoadFaces: invalid texinfo index %i(model has %i texinfos)\n", i, loadmodel->brushq1.numtexinfo);
                surface->texinfo = loadmodel->brushq1.texinfo + i;
-               surface->flags = surface->texinfo->texture->flags;
+               surface->texture = surface->texinfo->texture;
+               surface->flags = surface->texture->flags;
 
                planenum = LittleShort(in->planenum);
                if ((unsigned int) planenum >= (unsigned int) loadmodel->brush.num_planes)
@@ -1802,8 +1802,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                                VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, surface->mesh.data_vertex3f + i * 3);
                        s = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3];
                        t = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3];
-                       surface->mesh.data_texcoordtexture2f[i * 2 + 0] = s / surface->texinfo->texture->width;
-                       surface->mesh.data_texcoordtexture2f[i * 2 + 1] = t / surface->texinfo->texture->height;
+                       surface->mesh.data_texcoordtexture2f[i * 2 + 0] = s / surface->texture->width;
+                       surface->mesh.data_texcoordtexture2f[i * 2 + 1] = t / surface->texture->height;
                        surface->mesh.data_texcoorddetail2f[i * 2 + 0] = s * (1.0f / 16.0f);
                        surface->mesh.data_texcoorddetail2f[i * 2 + 1] = t * (1.0f / 16.0f);
                        surface->mesh.data_texcoordlightmap2f[i * 2 + 0] = 0;
@@ -1861,7 +1861,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                else // LordHavoc: white lighting (bsp version 29)
                        surface->samples = loadmodel->brushq1.lightdata + (i * 3);
 
-               if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+               if (surface->texture->flags & SURF_LIGHTMAP)
                {
                        if (ssize > 256 || tsize > 256)
                                Host_Error("Bad surface extents");
@@ -1871,7 +1871,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                        memset(surface->stainsamples, 255, ssize * tsize * 3);
                }
 
-               if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+               if (surface->texture->flags & SURF_LIGHTMAP)
                {
                        int i, iu, iv;
                        float u, v, ubase, vbase, uscale, vscale;
@@ -2154,7 +2154,7 @@ static void Mod_Q1BSP_LoadLeaffaces(lump_t *l)
        for (i = 0;i < loadmodel->brush.num_leafsurfaces;i++)
        {
                j = (unsigned) LittleShort(in[i]);
-               if (j >= loadmodel->brushq1.numsurfaces)
+               if (j >= loadmodel->brush.num_surfaces)
                        Host_Error("Mod_Q1BSP_LoadLeaffaces: bad surface number");
                loadmodel->brush.data_leafsurfaces[i] = j;
        }
@@ -2693,7 +2693,7 @@ static void Mod_Q1BSP_BuildLightmapUpdateChains(mempool_t *mempool, model_t *mod
        memset(stylecounts, 0, sizeof(stylecounts));
        for (i = 0;i < model->nummodelsurfaces;i++)
        {
-               surface = model->brushq1.surfaces + model->firstmodelsurface + i;
+               surface = model->brush.data_surfaces + model->firstmodelsurface + i;
                for (j = 0;j < MAXLIGHTMAPS;j++)
                        stylecounts[surface->styles[j]]++;
        }
@@ -2725,7 +2725,7 @@ static void Mod_Q1BSP_BuildLightmapUpdateChains(mempool_t *mempool, model_t *mod
        }
        for (i = 0;i < model->nummodelsurfaces;i++)
        {
-               surface = model->brushq1.surfaces + model->firstmodelsurface + i;
+               surface = model->brush.data_surfaces + model->firstmodelsurface + i;
                for (j = 0;j < MAXLIGHTMAPS;j++)
                        if (surface->styles[j] != 255)
                                *model->brushq1.light_styleupdatechains[remapstyles[surface->styles[j]]]++ = surface;
@@ -2853,7 +2853,7 @@ void Mod_Q1BSP_RecursiveGetVisible(mnode_t *node, model_t *model, const vec3_t p
                {
                        for (leafsurfacenum = 0;leafsurfacenum < leaf->numleafsurfaces;leafsurfacenum++)
                        {
-                               surface = model->brushq1.surfaces + leaf->firstleafsurface[leafsurfacenum];
+                               surface = model->brush.data_surfaces + leaf->firstleafsurface[leafsurfacenum];
                                if (surface->shadowmark != shadowmarkcount)
                                {
                                        surface->shadowmark = shadowmarkcount;
@@ -2969,13 +2969,13 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
 
        // make a single combined shadow mesh to allow optimized shadow volume creation
        numshadowmeshtriangles = 0;
-       for (j = 0, surface = loadmodel->brushq1.surfaces;j < loadmodel->brushq1.numsurfaces;j++, surface++)
+       for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
        {
                surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
                numshadowmeshtriangles += surface->mesh.num_triangles;
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
-       for (j = 0, surface = loadmodel->brushq1.surfaces;j < loadmodel->brushq1.numsurfaces;j++, surface++)
+       for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
                Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.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);
@@ -3066,13 +3066,13 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
                        mod->normalmaxs[0] = mod->normalmaxs[1] = mod->normalmaxs[2] = -1000000000.0f;
                        modelyawradius = 0;
                        modelradius = 0;
-                       for (j = 0, surface = &mod->brushq1.surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surface++)
+                       for (j = 0, surface = &mod->brush.data_surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surface++)
                        {
                                // we only need to have a drawsky function if it is used(usually only on world model)
-                               if (surface->texinfo->texture->flags & SURF_DRAWSKY)
+                               if (surface->texture->flags & SURF_DRAWSKY)
                                        mod->DrawSky = R_Q1BSP_DrawSky;
                                // LordHavoc: submodels always clip, even if water
-                               if (mod->brush.numsubmodels - 1)
+                               if (i)
                                        surface->flags |= SURF_SOLIDCLIP;
                                // calculate bounding shapes
                                for (k = 0, vec = surface->mesh.data_vertex3f;k < surface->mesh.num_vertices;k++, vec += 3)
@@ -3114,7 +3114,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
        //Mod_Q1BSP_ProcessLightList();
 
        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->brush.num_nodes, loadmodel->brush.num_leafs, mod->brushq1.submodels[i].visleafs, loadmodel->brush.num_portals);
+               Con_Printf("Some stats for q1bsp model \"%s\": %i faces, %i nodes, %i leafs, %i visleafs, %i visleafportals\n", loadmodel->name, loadmodel->brush.num_surfaces, loadmodel->brush.num_nodes, loadmodel->brush.num_leafs, mod->brushq1.submodels[i].visleafs, loadmodel->brush.num_portals);
 }
 
 static void Mod_Q2BSP_LoadEntities(lump_t *l)
@@ -4067,7 +4067,7 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l)
 static void Mod_Q3BSP_LoadFaces(lump_t *l)
 {
        q3dface_t *in, *oldin;
-       q3msurface_t *out, *oldout;
+       msurface_t *out, *oldout;
        int i, oldi, j, n, count, invalidelements, patchsize[2], finalwidth, finalheight, xtess, ytess, finalvertices, finaltriangles, firstvertex, firstelement, type, oldnumtriangles, oldnumtriangles2, meshnum, meshvertices, meshtriangles, numvertices, numtriangles;
        //int *originalelement3i;
        //int *originalneighbor3i;
@@ -4087,8 +4087,8 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
        count = l->filelen / sizeof(*in);
        out = Mem_Alloc(loadmodel->mempool, count * sizeof(*out));
 
-       loadmodel->brushq3.data_faces = out;
-       loadmodel->brushq3.num_faces = count;
+       loadmodel->brush.data_surfaces = out;
+       loadmodel->brush.num_surfaces = count;
 
        i = 0;
        for (meshnum = 0;i < count;meshnum++)
@@ -4434,9 +4434,9 @@ static void Mod_Q3BSP_LoadModels(lump_t *l)
                }
                n = LittleLong(in->firstface);
                c = LittleLong(in->numfaces);
-               if (n < 0 || n + c > loadmodel->brushq3.num_faces)
-                       Host_Error("Mod_Q3BSP_LoadModels: invalid face range %i : %i (%i faces)\n", n, n + c, loadmodel->brushq3.num_faces);
-               out->firstsurface = loadmodel->brushq3.data_faces + n;
+               if (n < 0 || n + c > loadmodel->brush.num_surfaces)
+                       Host_Error("Mod_Q3BSP_LoadModels: invalid face range %i : %i (%i faces)\n", n, n + c, loadmodel->brush.num_surfaces);
+               out->firstsurface = loadmodel->brush.data_surfaces + n;
                out->numsurfaces = c;
                n = LittleLong(in->firstbrush);
                c = LittleLong(in->numbrushes);
@@ -4489,8 +4489,8 @@ static void Mod_Q3BSP_LoadLeafFaces(lump_t *l)
        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);
+               if (n < 0 || n >= loadmodel->brush.num_surfaces)
+                       Host_Error("Mod_Q3BSP_LoadLeafFaces: invalid face index %i (%i faces)\n", n, loadmodel->brush.num_surfaces);
                *out = n;
        }
 }
@@ -4787,7 +4787,7 @@ static void Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace_t *trace, model_t *model,
        int i, startside, endside;
        float dist1, dist2, midfrac, mid[3], nodesegmentmins[3], nodesegmentmaxs[3];
        mleaf_t *leaf;
-       q3msurface_t *surface;
+       msurface_t *surface;
        colbrushf_t *brush;
        if (startfrac > trace->realfraction)
                return;
@@ -4852,7 +4852,7 @@ static void Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace_t *trace, model_t *model,
                // line trace the curves
                for (i = 0;i < leaf->numleafsurfaces;i++)
                {
-                       surface = model->brushq3.data_faces + leaf->firstleafsurface[i];
+                       surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
                        if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
                        {
                                surface->collisionmarkframe = markframe;
@@ -4871,7 +4871,7 @@ static void Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace_t *trace, model_t *model
        float nodesegmentmins[3], nodesegmentmaxs[3];
        mleaf_t *leaf;
        colbrushf_t *brush;
-       q3msurface_t *surface;
+       msurface_t *surface;
        /*
                // find which nodes the line is in and recurse for them
                while (node->plane)
@@ -5232,7 +5232,7 @@ static void Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace_t *trace, model_t *model
        {
                for (i = 0;i < leaf->numleafsurfaces;i++)
                {
-                       surface = model->brushq3.data_faces + leaf->firstleafsurface[i];
+                       surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
                        if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
                        {
                                surface->collisionmarkframe = markframe;
@@ -5249,7 +5249,7 @@ static void Mod_Q3BSP_TraceBox(model_t *model, int frame, trace_t *trace, const
        colbrushf_t *thisbrush_start, *thisbrush_end;
        matrix4x4_t startmatrix, endmatrix;
        static int markframe = 0;
-       q3msurface_t *surface;
+       msurface_t *surface;
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
        trace->realfraction = 1;
@@ -5499,7 +5499,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
        int i, j, numshadowmeshtriangles;
        q3dheader_t *header;
        float corner[3], yawradius, modelradius;
-       q3msurface_t *surface;
+       msurface_t *surface;
 
        mod->type = mod_brushq3;
        mod->numframes = 2; // although alternate textures are not supported it is annoying to complain about no such frame 1
@@ -5560,13 +5560,13 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
 
        // make a single combined shadow mesh to allow optimized shadow volume creation
        numshadowmeshtriangles = 0;
-       for (j = 0, surface = loadmodel->brushq3.data_faces;j < loadmodel->brushq3.num_faces;j++, surface++)
+       for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
        {
                surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
                numshadowmeshtriangles += surface->mesh.num_triangles;
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
-       for (j = 0, surface = loadmodel->brushq3.data_faces;j < loadmodel->brushq3.num_faces;j++, surface++)
+       for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
                Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.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);
@@ -5602,7 +5602,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
                mod->brush.submodel = i;
 
                // make the model surface list (used by shadowing/lighting)
-               mod->firstmodelsurface = mod->brushq3.data_models[i].firstsurface - mod->brushq3.data_faces;
+               mod->firstmodelsurface = mod->brushq3.data_models[i].firstsurface - mod->brush.data_surfaces;
                mod->nummodelsurfaces = mod->brushq3.data_models[i].numsurfaces;
                mod->surfacelist = Mem_Alloc(loadmodel->mempool, mod->nummodelsurfaces * sizeof(*mod->surfacelist));
                for (j = 0;j < mod->nummodelsurfaces;j++)
index 67d2a51..9412d77 100644 (file)
@@ -134,59 +134,48 @@ typedef struct
 }
 mtexinfo_t;
 
+struct q3meffect_s;
 typedef struct msurface_s
 {
        // bounding box for onscreen checks
        vec3_t mins;
        vec3_t maxs;
-
-       // the node plane this is on, backwards if SURF_PLANEBACK flag set
-       mplane_t *plane;
-       // SURF_ flags
-       int flags;
-       // texture mapping properties used by this surface
-       mtexinfo_t *texinfo;
-
+       // the texture to use on the surface
+       texture_t *texture;
        // the lightmap texture fragment to use on the rendering mesh
        rtexture_t *lightmaptexture;
        // mesh for rendering
        surfmesh_t mesh;
-       // if lightmap settings changed, this forces update
-       int cached_dlight;
-
-       // surface number, to avoid having to do a divide to find the number of a surface from it's address
-       int number;
+       // index into model->brush.shadowmesh
+       int num_firstshadowmeshtriangle;
 
+       // the node plane this is on, backwards if SURF_PLANEBACK flag set
+       mplane_t *plane; // q1bsp
+       // SURF_ flags
+       int flags; // q1bsp
+       // texture mapping properties used by this surface
+       mtexinfo_t *texinfo; // q1bsp
+       // if lightmap settings changed, this forces update
+       int cached_dlight; // q1bsp
        // index into d_lightstylevalue array, 255 means not used (black)
-       qbyte styles[MAXLIGHTMAPS];
+       qbyte styles[MAXLIGHTMAPS]; // q1bsp
        // RGB lighting data [numstyles][height][width][3]
-       qbyte *samples;
+       qbyte *samples; // q1bsp
        // stain to apply on lightmap (soot/dirt/blood/whatever)
-       qbyte *stainsamples;
+       qbyte *stainsamples; // q1bsp
        // the stride when building lightmaps to comply with fragment update
-       int lightmaptexturestride;
-       int texturemins[2];
-       int extents[2];
-
+       int lightmaptexturestride; // q1bsp
+       int texturemins[2]; // q1bsp
+       int extents[2]; // q1bsp
        // if this == r_framecount there are dynamic lights on the surface
-       int dlightframe;
+       int dlightframe; // q1bsp
        // which dynamic lights are touching this surface
        // (only access this if dlightframe is current)
-       int dlightbits[8];
-       // avoid redundent addition of dlights
-       int lightframe;
-
-       // avoid multiple collision traces with a surface polygon
-       int colframe;
-
-       // index into model->brush.shadowmesh
-       int num_firstshadowmeshtriangle;
+       int dlightbits[8]; // q1bsp
 
-       // currently used only for generating static shadow volumes
-       int lighttemp_castshadow;
-
-       // avoid redundent surface shadows
-       int shadowmark;
+       struct q3meffect_s *effect; // q3bsp
+       // FIXME: collisionmarkframe should be kept in a separate array
+       int collisionmarkframe; // q3bsp // don't collide twice in one trace
 }
 msurface_t;
 
@@ -772,14 +761,12 @@ q3dpvs_t;
 #define Q3TEXTUREFLAG_AUTOSPRITE2 32
 #define Q3TEXTUREFLAG_ALPHATEST 64
 
-struct q3msurface_s;
-
 typedef struct q3mmodel_s
 {
        vec3_t mins;
        vec3_t maxs;
        int numsurfaces;
-       struct q3msurface_s *firstsurface;
+       struct msurface_s *firstsurface;
        int numbrushes;
        struct q3mbrush_s *firstbrush;
 }
@@ -809,30 +796,6 @@ typedef struct q3meffect_s
 }
 q3meffect_t;
 
-typedef struct q3msurface_s
-{
-       // bounding box for culling
-       vec3_t mins;
-       vec3_t maxs;
-
-       // FIXME: collisionmarkframe should be kept in a separate array
-       // FIXME: shadowmark should be kept in a separate array
-
-       struct texture_s *texture;
-       struct q3meffect_s *effect;
-       rtexture_t *lightmaptexture;
-       int collisionmarkframe; // don't collide twice in one trace
-
-       surfmesh_t mesh;
-
-       // index into model->brush.shadowmesh
-       int num_firstshadowmeshtriangle;
-
-       // used for shadow volume generation
-       int shadowmark;
-}
-q3msurface_t;
-
 #define CHECKPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] & (1 << ((b) & 7))) : false)
 #define SETPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] |= (1 << ((b) & 7))) : false)
 #define CLEARPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] &= ~(1 << ((b) & 7))) : false)
index 326fa95..825e983 100644 (file)
@@ -204,9 +204,9 @@ static void mod_newmap(void)
        {
                if (mod_known[i].name[0] && mod_known[i].type == mod_brushq1)
                {
-                       for (surfacenum = 0, surface = mod_known[i].brushq1.surfaces;surfacenum < mod_known[i].brushq1.numsurfaces;surfacenum++, surface++)
+                       for (surfacenum = 0, surface = mod_known[i].brush.data_surfaces;surfacenum < mod_known[i].brush.num_surfaces;surfacenum++, surface++)
                        {
-                               if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+                               if (surface->texture->flags & SURF_LIGHTMAP)
                                {
                                        ssize = (surface->extents[0] >> 4) + 1;
                                        tsize = (surface->extents[1] >> 4) + 1;
index 20f2b06..b73deb5 100644 (file)
@@ -213,6 +213,9 @@ typedef struct model_brush_s
        int num_textures;
        texture_t *data_textures;
 
+       int num_surfaces;
+       msurface_t *data_surfaces;
+
        // pvs
        int num_pvsclusters;
        int num_pvsclusterbytes;
@@ -259,10 +262,6 @@ typedef struct model_brushq1_s
        int                             numtexinfo;
        mtexinfo_t              *texinfo;
 
-       int                             numsurfaces;
-       msurface_t              *surfaces;
-       msurface_t              *surfacepvsnext;
-
        int                             numsurfedges;
        int                             *surfedges;
 
@@ -323,9 +322,6 @@ typedef struct model_brushq3_s
        int num_effects;
        q3meffect_t *data_effects;
 
-       int num_faces;
-       q3msurface_t *data_faces;
-
        // lightmap textures
        int num_lightmaps;
        rtexture_t **data_lightmaps;
index a90ef26..ddd9bda 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -344,45 +344,27 @@ void Portal_RecursiveFlow_ExactLeafFaces(portalrecursioninfo_t *info, int *mark,
                if (!info->surfacemark[*mark])
                {
                        // FIXME?  this assumes q1bsp polygon surfaces
-                       surface = info->model->brushq1.surfaces + *mark;
-                       if (surface->mesh.num_vertices)
+                       surface = info->model->brush.data_surfaces + *mark;
+                       for (j = 0, elements = surface->mesh.data_element3i;j < surface->mesh.num_triangles;j++, elements += 3)
                        {
-                               if (surface->flags & SURF_PLANEBACK)
+                               VectorCopy((surface->mesh.data_vertex3f + elements[0] * 3), trianglepoints[0]);
+                               VectorCopy((surface->mesh.data_vertex3f + elements[1] * 3), trianglepoints[1]);
+                               VectorCopy((surface->mesh.data_vertex3f + elements[2] * 3), trianglepoints[2]);
+                               if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]))
                                {
-                                       if (DotProduct(info->eye, surface->plane->normal) > surface->plane->dist)
-                                               continue;
+                                       trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0]));
+                                       trimaxs[0] = max(trianglepoints[0][0], max(trianglepoints[1][0], trianglepoints[2][0]));
+                                       trimins[1] = min(trianglepoints[0][1], min(trianglepoints[1][1], trianglepoints[2][1]));
+                                       trimaxs[1] = max(trianglepoints[0][1], max(trianglepoints[1][1], trianglepoints[2][1]));
+                                       trimins[2] = min(trianglepoints[0][2], min(trianglepoints[1][2], trianglepoints[2][2]));
+                                       trimaxs[2] = max(trianglepoints[0][2], max(trianglepoints[1][2], trianglepoints[2][2]));
+                                       if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs))
+                                               if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3)
+                                                       break;
                                }
-                               else
-                               {
-                                       if (DotProduct(info->eye, surface->plane->normal) < surface->plane->dist)
-                                               continue;
-                               }
-                               if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, surface->mesh.data_vertex3f, surface->mesh.num_vertices, &portaltemppoints2[0][0], 256) < 3)
-                                       continue;
-                       }
-                       else
-                       {
-                               for (j = 0, elements = surface->mesh.data_element3i;j < surface->mesh.num_triangles;j++, elements += 3)
-                               {
-                                       VectorCopy((surface->mesh.data_vertex3f + elements[0] * 3), trianglepoints[0]);
-                                       VectorCopy((surface->mesh.data_vertex3f + elements[1] * 3), trianglepoints[1]);
-                                       VectorCopy((surface->mesh.data_vertex3f + elements[2] * 3), trianglepoints[2]);
-                                       if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]))
-                                       {
-                                               trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0]));
-                                               trimaxs[0] = max(trianglepoints[0][0], max(trianglepoints[1][0], trianglepoints[2][0]));
-                                               trimins[1] = min(trianglepoints[0][1], min(trianglepoints[1][1], trianglepoints[2][1]));
-                                               trimaxs[1] = max(trianglepoints[0][1], max(trianglepoints[1][1], trianglepoints[2][1]));
-                                               trimins[2] = min(trianglepoints[0][2], min(trianglepoints[1][2], trianglepoints[2][2]));
-                                               trimaxs[2] = max(trianglepoints[0][2], max(trianglepoints[1][2], trianglepoints[2][2]));
-                                               if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs))
-                                                       if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3)
-                                                               break;
-                                       }
-                               }
-                               if (j == surface->mesh.num_triangles)
-                                       continue;
                        }
+                       if (j == surface->mesh.num_triangles)
+                               continue;
                        info->surfacemark[*mark] = true;
                }
        }
index 925fa93..500f57f 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -2602,25 +2602,35 @@ void PF_te_plasmaburn (void)
 
 static void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
 {
-       int i, j;
-       vec3_t v1, clipplanenormal, normal;
-       vec_t clipplanedist, clipdist;
+       int i, j, k;
+       float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
+       bestdist = 1000000000;
        VectorCopy(p, out);
-       if (surface->flags & SURF_PLANEBACK)
-               VectorNegate(surface->plane->normal, normal);
-       else
-               VectorCopy(surface->plane->normal, normal);
-       for (i = 0, j = surface->mesh.num_vertices - 1;i < surface->mesh.num_vertices;j = i, i++)
-       {
-               VectorSubtract(&surface->mesh.data_vertex3f[j * 3], &surface->mesh.data_vertex3f[i * 3], v1);
-               VectorNormalizeFast(v1);
-               CrossProduct(v1, normal, clipplanenormal);
-               clipplanedist = DotProduct(&surface->mesh.data_vertex3f[i * 3], clipplanenormal);
-               clipdist = DotProduct(out, clipplanenormal) - clipplanedist;
-               if (clipdist > 0)
+       for (i = 0;i < surface->mesh.num_triangles;i++)
+       {
+               // clip original point to each triangle of the surface and find the
+               // triangle that is closest
+               v[0] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 0] * 3;
+               v[1] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 1] * 3;
+               v[2] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 2] * 3;
+               TriangleNormal(v[0], v[1], v[2], facenormal);
+               VectorNormalize(facenormal);
+               offsetdist = DotProduct(v[0], facenormal) - DotProduct(p, facenormal);
+               VectorMA(p, offsetdist, facenormal, temp);
+               for (j = 0, k = 2;j < 3;k = j, j++)
+               {
+                       VectorSubtract(v[k], v[j], edgenormal);
+                       CrossProduct(edgenormal, facenormal, sidenormal);
+                       VectorNormalize(sidenormal);
+                       offsetdist = DotProduct(v[k], sidenormal) - DotProduct(temp, sidenormal);
+                       if (offsetdist < 0)
+                               VectorMA(temp, offsetdist, sidenormal, temp);
+               }
+               dist = VectorDistance2(temp, p);
+               if (bestdist > dist)
                {
-                       clipdist = -clipdist;
-                       VectorMA(out, clipdist, clipplanenormal, out);
+                       bestdist = dist;
+                       VectorCopy(temp, out);
                }
        }
 }
@@ -2637,7 +2647,7 @@ static msurface_t *getsurface(edict_t *ed, int surfacenum)
        model = sv.models[modelindex];
        if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
                return NULL;
-       return model->brushq1.surfaces + surfacenum + model->firstmodelsurface;
+       return model->brush.data_surfaces + surfacenum + model->firstmodelsurface;
 }
 
 
@@ -2652,6 +2662,7 @@ void PF_getsurfacenumpoints(void)
                return;
        }
 
+       // note: this (incorrectly) assumes it is a simple polygon
        G_FLOAT(OFS_RETURN) = surface->mesh.num_vertices;
 }
 //PF_getsurfacepoint,     // #435 vector(entity e, float s, float n) getsurfacepoint = #435;
@@ -2666,6 +2677,7 @@ void PF_getsurfacepoint(void)
                return;
        if (!(surface = getsurface(ed, G_FLOAT(OFS_PARM1))))
                return;
+       // note: this (incorrectly) assumes it is a simple polygon
        pointnum = G_FLOAT(OFS_PARM2);
        if (pointnum < 0 || pointnum >= surface->mesh.num_vertices)
                return;
@@ -2676,14 +2688,17 @@ void PF_getsurfacepoint(void)
 void PF_getsurfacenormal(void)
 {
        msurface_t *surface;
+       vec3_t normal;
        VectorClear(G_VECTOR(OFS_RETURN));
        if (!(surface = getsurface(G_EDICT(OFS_PARM0), G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
-       if (surface->flags & SURF_PLANEBACK)
-               VectorNegate(surface->plane->normal, G_VECTOR(OFS_RETURN));
-       else
-               VectorCopy(surface->plane->normal, G_VECTOR(OFS_RETURN));
+       // note: this (incorrectly) assumes it is a simple polygon
+       // note: this only returns the first triangle, so it doesn't work very
+       // well for curved surfaces or arbitrary meshes
+       TriangleNormal(surface->mesh.data_vertex3f, surface->mesh.data_vertex3f + 3, surface->mesh.data_vertex3f + 6, normal);
+       VectorNormalize(normal);
+       VectorCopy(normal, G_VECTOR(OFS_RETURN));
 }
 //PF_getsurfacetexture,   // #437 string(entity e, float s) getsurfacetexture = #437;
 void PF_getsurfacetexture(void)
@@ -2692,7 +2707,7 @@ void PF_getsurfacetexture(void)
        G_INT(OFS_RETURN) = 0;
        if (!(surface = getsurface(G_EDICT(OFS_PARM0), G_FLOAT(OFS_PARM1))))
                return;
-       G_INT(OFS_RETURN) = PR_SetString(surface->texinfo->texture->name);
+       G_INT(OFS_RETURN) = PR_SetString(surface->texture->name);
 }
 //PF_getsurfacenearpoint, // #438 float(entity e, vector p) getsurfacenearpoint = #438;
 void PF_getsurfacenearpoint(void)
@@ -2714,7 +2729,7 @@ void PF_getsurfacenearpoint(void)
        if (modelindex < 1 || modelindex >= MAX_MODELS)
                return;
        model = sv.models[modelindex];
-       if (!model->brushq1.numsurfaces)
+       if (!model->brush.num_surfaces)
                return;
 
        // FIXME: implement rotation/scaling
@@ -2723,16 +2738,21 @@ void PF_getsurfacenearpoint(void)
        bestdist = 1000000000;
        for (surfacenum = 0;surfacenum < model->nummodelsurfaces;surfacenum++)
        {
-               surface = model->brushq1.surfaces + surfacenum + model->firstmodelsurface;
-               dist = PlaneDiff(p, surface->plane);
-               dist = dist * dist;
+               surface = model->brush.data_surfaces + surfacenum + model->firstmodelsurface;
+               // first see if the nearest point on the surface's box is closer than the previous match
+               clipped[0] = bound(surface->mins[0], p[0], surface->maxs[0]) - p[0];
+               clipped[1] = bound(surface->mins[1], p[1], surface->maxs[1]) - p[1];
+               clipped[2] = bound(surface->mins[2], p[2], surface->maxs[2]) - p[2];
+               dist = VectorLength2(clipped);
                if (dist < bestdist)
                {
+                       // it is, check the nearest point on the actual geometry
                        clippointtosurface(surface, p, clipped);
                        VectorSubtract(clipped, p, clipped);
-                       dist += DotProduct(clipped, clipped);
+                       dist += VectorLength2(clipped);
                        if (dist < bestdist)
                        {
+                               // that's closer too, store it as the best match
                                best = surfacenum;
                                bestdist = dist;
                        }
index b24c4d3..7b3ed2a 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -211,12 +211,12 @@ static void R_RecursiveMarkLights(entity_render_t *ent, vec3_t lightorigin, dlig
                {
                        if (ent == r_refdef.worldentity && !r_worldsurfacevisible[leaf->firstleafsurface[i]])
                                continue;
-                       surface = ent->model->brushq1.surfaces + leaf->firstleafsurface[i];
+                       surface = ent->model->brush.data_surfaces + leaf->firstleafsurface[i];
                        dist = sdist = PlaneDiff(lightorigin, surface->plane);
                        if (surface->flags & SURF_PLANEBACK)
                                dist = -dist;
 
-                       if (dist < -0.25f && !(surface->flags & SURF_LIGHTBOTHSIDES))
+                       if (dist < -0.25f && !(surface->texture->flags & SURF_LIGHTBOTHSIDES))
                                continue;
 
                        dist2 = dist * dist;