moved a number of msurface_t fields to a separate msurface_lightmapinfo_t structure...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Mar 2005 06:54:34 +0000 (06:54 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Mar 2005 06:54:34 +0000 (06:54 +0000)
moved collision triangles/vertices information out of surfmesh_t and into msurface_t

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

gl_rsurf.c
model_brush.c
model_brush.h
model_shared.c
model_shared.h

index 0524cf7..f4e8c46 100644 (file)
@@ -61,11 +61,11 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        // update cached lighting info
        surface->cached_dlight = 0;
 
-       smax = (surface->extents[0]>>4)+1;
-       tmax = (surface->extents[1]>>4)+1;
+       smax = (surface->lightmapinfo->extents[0]>>4)+1;
+       tmax = (surface->lightmapinfo->extents[1]>>4)+1;
        size = smax*tmax;
        size3 = size*3;
-       lightmap = surface->samples;
+       lightmap = surface->lightmapinfo->samples;
 
 // set to full bright if no light data
        bl = intblocklights;
@@ -83,13 +83,13 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
                if (lightmap)
                {
                        bl = intblocklights;
-                       for (maps = 0;maps < MAXLIGHTMAPS && surface->styles[maps] != 255;maps++, lightmap += size3)
-                               for (scale = d_lightstylevalue[surface->styles[maps]], i = 0;i < size3;i++)
+                       for (maps = 0;maps < MAXLIGHTMAPS && surface->lightmapinfo->styles[maps] != 255;maps++, lightmap += size3)
+                               for (scale = d_lightstylevalue[surface->lightmapinfo->styles[maps]], i = 0;i < size3;i++)
                                        bl[i] += lightmap[i] * scale;
                }
        }
 
-       stain = surface->stainsamples;
+       stain = surface->lightmapinfo->stainsamples;
        bl = intblocklights;
        out = templight;
        // the >> 16 shift adjusts down 8 bits to account for the stainmap
@@ -98,7 +98,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        // (0 = 0.0, 128 = 1.0, 256 = 2.0)
        if (ent->model->brushq1.lightmaprgba)
        {
-               stride = (surface->lightmaptexturestride - smax) * 4;
+               stride = (surface->lightmapinfo->lightmaptexturestride - smax) * 4;
                for (i = 0;i < tmax;i++, out += stride)
                {
                        for (j = 0;j < smax;j++)
@@ -112,7 +112,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        }
        else
        {
-               stride = (surface->lightmaptexturestride - smax) * 3;
+               stride = (surface->lightmapinfo->lightmaptexturestride - smax) * 3;
                for (i = 0;i < tmax;i++, out += stride)
                {
                        for (j = 0;j < smax;j++)
@@ -170,13 +170,13 @@ loc0:
 
        for (surface = model->brush.data_surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
        {
-               if (surface->stainsamples)
+               if (surface->lightmapinfo->stainsamples)
                {
-                       smax = (surface->extents[0] >> 4) + 1;
-                       tmax = (surface->extents[1] >> 4) + 1;
+                       smax = (surface->lightmapinfo->extents[0] >> 4) + 1;
+                       tmax = (surface->lightmapinfo->extents[1] >> 4) + 1;
 
-                       impacts = DotProduct (impact, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3] - surface->texturemins[0];
-                       impactt = DotProduct (impact, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3] - surface->texturemins[1];
+                       impacts = DotProduct (impact, surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3] - surface->lightmapinfo->texturemins[0];
+                       impactt = DotProduct (impact, surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3] - surface->lightmapinfo->texturemins[1];
 
                        s = bound(0, impacts, smax * 16) - impacts;
                        t = bound(0, impactt, tmax * 16) - impactt;
@@ -188,7 +188,7 @@ loc0:
                        for (s = 0, i = impacts; s < smax; s++, i -= 16)
                                sdtable[s] = i * i + dist2;
 
-                       bl = surface->stainsamples;
+                       bl = surface->lightmapinfo->stainsamples;
                        smax3 = smax * 3;
                        stained = false;
 
@@ -256,7 +256,7 @@ void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int
        entity_render_t *ent;
        model_t *model;
        vec3_t org;
-       if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brush.data_nodes)
+       if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brush.data_nodes || !r_refdef.worldmodel->brushq1.lightdata)
                return;
        fcolor[0] = cr1;
        fcolor[1] = cg1;
@@ -564,6 +564,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                b = ent->colormod[2] * colorscale;
                                a = texture->currentalpha;
                                base = r_ambient.value * (1.0f / 64.0f);
+                               // q3bsp has no lightmap updates, so the lightstylevalue that
+                               // would normally be baked into the lightmaptexture must be
+                               // applied to the color
+                               if (ent->model->brushq1.lightdata)
+                               {
+                                       float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
+                                       r *= scale;
+                                       g *= scale;
+                                       b *= scale;
+                               }
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
@@ -597,78 +607,29 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        {
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                R_Mesh_ColorPointer(varray_color4f);
-                                               if (surface->styles[0] != 255)
+                                               if (surface->mesh.data_lightmapcolor4f)
                                                {
-                                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                       for (i = 0, c = varray_color4f;i < surface->mesh.num_vertices;i++, c += 4)
                                                        {
-                                                               c[0] = 0;
-                                                               c[1] = 0;
-                                                               c[2] = 0;
-                                                               if (surface->styles[0] != 255)
-                                                               {
-                                                                       if (surface->mesh.data_lightmapcolor4f)
-                                                                       {
-                                                                               float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 128.0f);
-                                                                               VectorMA(c, scale, surface->mesh.data_lightmapcolor4f + i*4, c);
-                                                                       }
-                                                                       else if (surface->mesh.data_lightmapoffsets)
-                                                                       {
-                                                                               const qbyte *lm = surface->samples + surface->mesh.data_lightmapoffsets[i];
-                                                                               float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 32768.0f);
-                                                                               VectorMA(c, scale, lm, c);
-                                                                               if (surface->styles[1] != 255)
-                                                                               {
-                                                                                       int size3 = ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3;
-                                                                                       lm += size3;
-                                                                                       scale = d_lightstylevalue[surface->styles[1]] * (1.0f / 32768.0f);
-                                                                                       VectorMA(c, scale, lm, c);
-                                                                                       if (surface->styles[2] != 255)
-                                                                                       {
-                                                                                               lm += size3;
-                                                                                               scale = d_lightstylevalue[surface->styles[2]] * (1.0f / 32768.0f);
-                                                                                               VectorMA(c, scale, lm, c);
-                                                                                               if (surface->styles[3] != 255)
-                                                                                               {
-                                                                                                       lm += size3;
-                                                                                                       scale = d_lightstylevalue[surface->styles[3]] * (1.0f / 32768.0f);
-                                                                                                       VectorMA(c, scale, lm, c);
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       }
-                                                               }
-                                                               c[0] *= r;
-                                                               c[1] *= g;
-                                                               c[2] *= b;
-                                                               if (fogallpasses)
+                                                               c[0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
+                                                               c[1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
+                                                               c[2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
+                                                               c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                       }
+                                                       if (fogallpasses)
+                                                       {
+                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
                                                                        VectorScale(c, f, c);
                                                                }
-                                                               if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
-                                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
-                                                               else
-                                                                       c[3] = a;
                                                        }
                                                }
                                                else
                                                {
-                                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
-                                                       {
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
-                                                               {
-                                                                       c[0] = 0;
-                                                                       c[1] = 0;
-                                                                       c[2] = 0;
-                                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
-                                                               }
-                                                       }
-                                                       else
-                                                       {
-                                                               R_Mesh_ColorPointer(NULL);
-                                                               GL_Color(0, 0, 0, a);
-                                                       }
+                                                       R_Mesh_ColorPointer(NULL);
+                                                       GL_Color(0, 0, 0, a);
                                                }
                                        }
                                        GL_LockArrays(0, surface->mesh.num_vertices);
@@ -698,6 +659,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                a = texture->currentalpha;
                                if (dolightmap)
                                {
+                                       // q3bsp has no lightmap updates, so the lightstylevalue that
+                                       // would normally be baked into the lightmaptexture must be
+                                       // applied to the color
+                                       if (!ent->model->brushq1.lightdata)
+                                       {
+                                               float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
+                                               r *= scale;
+                                               g *= scale;
+                                               b *= scale;
+                                       }
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
@@ -709,35 +680,29 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        c[0] = 0;
                                                        c[1] = 0;
                                                        c[2] = 0;
-                                                       if (surface->styles[0] != 255)
+                                                       if (surface->mesh.data_lightmapcolor4f)
+                                                               VectorCopy(surface->mesh.data_lightmapcolor4f + i*4, c);
+                                                       else if (surface->lightmapinfo)
                                                        {
-                                                               if (surface->mesh.data_lightmapcolor4f)
-                                                               {
-                                                                       float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 128.0f);
-                                                                       VectorMA(c, scale, surface->mesh.data_lightmapcolor4f + i*4, c);
-                                                               }
-                                                               else if (surface->mesh.data_lightmapoffsets)
+                                                               const qbyte *lm = surface->lightmapinfo->samples + surface->mesh.data_lightmapoffsets[i];
+                                                               float scale = d_lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f);
+                                                               VectorMA(c, scale, lm, c);
+                                                               if (surface->lightmapinfo->styles[1] != 255)
                                                                {
-                                                                       const qbyte *lm = surface->samples + surface->mesh.data_lightmapoffsets[i];
-                                                                       float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 32768.0f);
+                                                                       int size3 = ((surface->lightmapinfo->extents[0]>>4)+1)*((surface->lightmapinfo->extents[1]>>4)+1)*3;
+                                                                       lm += size3;
+                                                                       scale = d_lightstylevalue[surface->lightmapinfo->styles[1]] * (1.0f / 32768.0f);
                                                                        VectorMA(c, scale, lm, c);
-                                                                       if (surface->styles[1] != 255)
+                                                                       if (surface->lightmapinfo->styles[2] != 255)
                                                                        {
-                                                                               int size3 = ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3;
                                                                                lm += size3;
-                                                                               scale = d_lightstylevalue[surface->styles[1]] * (1.0f / 32768.0f);
+                                                                               scale = d_lightstylevalue[surface->lightmapinfo->styles[2]] * (1.0f / 32768.0f);
                                                                                VectorMA(c, scale, lm, c);
-                                                                               if (surface->styles[2] != 255)
+                                                                               if (surface->lightmapinfo->styles[3] != 255)
                                                                                {
                                                                                        lm += size3;
-                                                                                       scale = d_lightstylevalue[surface->styles[2]] * (1.0f / 32768.0f);
+                                                                                       scale = d_lightstylevalue[surface->lightmapinfo->styles[3]] * (1.0f / 32768.0f);
                                                                                        VectorMA(c, scale, lm, c);
-                                                                                       if (surface->styles[3] != 255)
-                                                                                       {
-                                                                                               lm += size3;
-                                                                                               scale = d_lightstylevalue[surface->styles[3]] * (1.0f / 32768.0f);
-                                                                                               VectorMA(c, scale, lm, c);
-                                                                                       }
                                                                                }
                                                                        }
                                                                }
@@ -1396,7 +1361,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                        if (f && surface->mesh.num_triangles)
                        {
                                // if lightmap parameters changed, rebuild lightmap texture
-                               if (surface->cached_dlight && surface->samples)
+                               if (surface->cached_dlight && surface->lightmapinfo->samples)
                                        R_BuildLightMap(ent, surface);
                                // add face to draw list
                                surfacelist[numsurfacelist++] = surface;
@@ -1426,7 +1391,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                        if (f && surface->mesh.num_triangles)
                        {
                                // if lightmap parameters changed, rebuild lightmap texture
-                               if (surface->cached_dlight && surface->samples)
+                               if (surface->cached_dlight && surface->lightmapinfo->samples)
                                        R_BuildLightMap(ent, surface);
                                // add face to draw list
                                surfacelist[numsurfacelist++] = surface;
@@ -1517,15 +1482,15 @@ static void R_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
 {
        int i;
        rmeshstate_t m;
-       if (!surface->mesh.num_collisiontriangles)
+       if (!surface->num_collisiontriangles)
                return;
        memset(&m, 0, sizeof(m));
-       m.pointer_vertex = surface->mesh.data_collisionvertex3f;
+       m.pointer_vertex = surface->data_collisionvertex3f;
        R_Mesh_State(&m);
        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);
+       GL_LockArrays(0, surface->num_collisionvertices);
+       R_Mesh_Draw(surface->num_collisionvertices, surface->num_collisiontriangles, surface->data_collisionelement3i);
        GL_LockArrays(0, 0);
 }
 
@@ -1636,7 +1601,7 @@ void R_Q1BSP_Draw(entity_render_t *ent)
                        if (brush->colbrushf && brush->colbrushf->numtriangles)
                                R_DrawCollisionBrush(brush->colbrushf);
                for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
-                       if (surface->mesh.num_collisiontriangles)
+                       if (surface->num_collisiontriangles)
                                R_DrawCollisionSurface(ent, surface);
                qglPolygonOffset(0, 0);
        }
index 4664422..835098e 100644 (file)
@@ -788,26 +788,26 @@ loc0:
                        surface = r_refdef.worldmodel->brush.data_surfaces + node->firstsurface;
                        for (i = 0;i < node->numsurfaces;i++, surface++)
                        {
-                               if (!(surface->texture->basematerialflags & MATERIALFLAG_WALL) || !surface->samples)
+                               if (!(surface->texture->basematerialflags & MATERIALFLAG_WALL) || !surface->lightmapinfo->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];
-                               dt = (int) (x * surface->texinfo->vecs[1][0] + y * surface->texinfo->vecs[1][1] + mid * surface->texinfo->vecs[1][2] + surface->texinfo->vecs[1][3]) - surface->texturemins[1];
+                               ds = (int) (x * surface->lightmapinfo->texinfo->vecs[0][0] + y * surface->lightmapinfo->texinfo->vecs[0][1] + mid * surface->lightmapinfo->texinfo->vecs[0][2] + surface->lightmapinfo->texinfo->vecs[0][3]) - surface->lightmapinfo->texturemins[0];
+                               dt = (int) (x * surface->lightmapinfo->texinfo->vecs[1][0] + y * surface->lightmapinfo->texinfo->vecs[1][1] + mid * surface->lightmapinfo->texinfo->vecs[1][2] + surface->lightmapinfo->texinfo->vecs[1][3]) - surface->lightmapinfo->texturemins[1];
 
-                               if (ds >= 0 && ds < surface->extents[0] && dt >= 0 && dt < surface->extents[1])
+                               if (ds >= 0 && ds < surface->lightmapinfo->extents[0] && dt >= 0 && dt < surface->lightmapinfo->extents[1])
                                {
                                        qbyte *lightmap;
                                        int lmwidth, lmheight, maps, line3, size3, dsfrac = ds & 15, dtfrac = dt & 15, scale = 0, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
-                                       lmwidth = ((surface->extents[0]>>4)+1);
-                                       lmheight = ((surface->extents[1]>>4)+1);
+                                       lmwidth = ((surface->lightmapinfo->extents[0]>>4)+1);
+                                       lmheight = ((surface->lightmapinfo->extents[1]>>4)+1);
                                        line3 = lmwidth * 3; // LordHavoc: *3 for colored lighting
                                        size3 = lmwidth * lmheight * 3; // LordHavoc: *3 for colored lighting
 
-                                       lightmap = surface->samples + ((dt>>4) * lmwidth + (ds>>4))*3; // LordHavoc: *3 for colored lighting
+                                       lightmap = surface->lightmapinfo->samples + ((dt>>4) * lmwidth + (ds>>4))*3; // LordHavoc: *3 for colored lighting
 
-                                       for (maps = 0;maps < MAXLIGHTMAPS && surface->styles[maps] != 255;maps++)
+                                       for (maps = 0;maps < MAXLIGHTMAPS && surface->lightmapinfo->styles[maps] != 255;maps++)
                                        {
-                                               scale = d_lightstylevalue[surface->styles[maps]];
+                                               scale = d_lightstylevalue[surface->lightmapinfo->styles[maps]];
                                                r00 += lightmap[      0] * scale;g00 += lightmap[      1] * scale;b00 += lightmap[      2] * scale;
                                                r01 += lightmap[      3] * scale;g01 += lightmap[      4] * scale;b01 += lightmap[      5] * scale;
                                                r10 += lightmap[line3+0] * scale;g10 += lightmap[line3+1] * scale;b10 += lightmap[line3+2] * scale;
@@ -1754,8 +1754,8 @@ static void Mod_Q1BSP_GenerateWarpMesh(msurface_t *surface)
        for (i = 0, v = mesh->vertex;i < subdivpolyverts;i++, v++)
        {
                VectorCopy(subdivpolyvert[i], v->v);
-               v->st[0] = DotProduct(v->v, surface->texinfo->vecs[0]);
-               v->st[1] = DotProduct(v->v, surface->texinfo->vecs[1]);
+               v->st[0] = DotProduct(v->v, surface->lightmapinfo->texinfo->vecs[0]);
+               v->st[1] = DotProduct(v->v, surface->lightmapinfo->texinfo->vecs[1]);
        }
 }
 #endif
@@ -1772,6 +1772,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                Host_Error("Mod_Q1BSP_LoadFaces: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        loadmodel->brush.data_surfaces = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_t));
+       loadmodel->brush.data_surfaces_lightmapinfo = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_lightmapinfo_t));
 
        loadmodel->brush.num_surfaces = count;
 
@@ -1788,12 +1789,14 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
        // vertex limit
        loadmodel->nummeshes = 1;
        loadmodel->meshlist = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t *));
-       loadmodel->meshlist[0] = Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, 0, 0, true, true, false);
+       loadmodel->meshlist[0] = Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, true, true, false);
 
        totalverts = 0;
        totaltris = 0;
        for (surfacenum = 0, in = (void *)(mod_base + l->fileofs), surface = loadmodel->brush.data_surfaces;surfacenum < count;surfacenum++, in++, surface++)
        {
+               surface->lightmapinfo = loadmodel->brush.data_surfaces_lightmapinfo + surfacenum;
+
                // FIXME: validate edges, texinfo, etc?
                firstedge = LittleLong(in->firstedge);
                numedges = LittleShort(in->numedges);
@@ -1802,8 +1805,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                i = LittleShort(in->texinfo);
                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->texture = surface->texinfo->texture;
+               surface->lightmapinfo->texinfo = loadmodel->brushq1.texinfo + i;
+               surface->texture = surface->lightmapinfo->texinfo->texture;
 
                planenum = LittleShort(in->planenum);
                if ((unsigned int) planenum >= (unsigned int) loadmodel->brush.num_planes)
@@ -1838,8 +1841,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                                VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[lindex].v[0]].position, surface->mesh.data_vertex3f + i * 3);
                        else
                                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];
+                       s = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+                       t = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
                        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);
@@ -1862,53 +1865,53 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                BoxFromPoints(surface->mins, surface->maxs, surface->mesh.num_vertices, surface->mesh.data_vertex3f);
 
                // generate surface extents information
-               texmins[0] = texmaxs[0] = DotProduct(surface->mesh.data_vertex3f, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3];
-               texmins[1] = texmaxs[1] = DotProduct(surface->mesh.data_vertex3f, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3];
+               texmins[0] = texmaxs[0] = DotProduct(surface->mesh.data_vertex3f, surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+               texmins[1] = texmaxs[1] = DotProduct(surface->mesh.data_vertex3f, surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
                for (i = 1;i < surface->mesh.num_vertices;i++)
                {
                        for (j = 0;j < 2;j++)
                        {
-                               val = DotProduct(surface->mesh.data_vertex3f + i * 3, surface->texinfo->vecs[j]) + surface->texinfo->vecs[j][3];
+                               val = DotProduct(surface->mesh.data_vertex3f + i * 3, surface->lightmapinfo->texinfo->vecs[j]) + surface->lightmapinfo->texinfo->vecs[j][3];
                                texmins[j] = min(texmins[j], val);
                                texmaxs[j] = max(texmaxs[j], val);
                        }
                }
                for (i = 0;i < 2;i++)
                {
-                       surface->texturemins[i] = (int) floor(texmins[i] / 16.0) * 16;
-                       surface->extents[i] = (int) ceil(texmaxs[i] / 16.0) * 16 - surface->texturemins[i];
+                       surface->lightmapinfo->texturemins[i] = (int) floor(texmins[i] / 16.0) * 16;
+                       surface->lightmapinfo->extents[i] = (int) ceil(texmaxs[i] / 16.0) * 16 - surface->lightmapinfo->texturemins[i];
                }
 
-               smax = surface->extents[0] >> 4;
-               tmax = surface->extents[1] >> 4;
-               ssize = (surface->extents[0] >> 4) + 1;
-               tsize = (surface->extents[1] >> 4) + 1;
+               smax = surface->lightmapinfo->extents[0] >> 4;
+               tmax = surface->lightmapinfo->extents[1] >> 4;
+               ssize = (surface->lightmapinfo->extents[0] >> 4) + 1;
+               tsize = (surface->lightmapinfo->extents[1] >> 4) + 1;
 
                // lighting info
                for (i = 0;i < MAXLIGHTMAPS;i++)
-                       surface->styles[i] = in->styles[i];
+                       surface->lightmapinfo->styles[i] = in->styles[i];
                // force lightmap upload on first time seeing the surface
                surface->cached_dlight = true;
-               surface->lightmaptexturestride = 0;
+               surface->lightmapinfo->lightmaptexturestride = 0;
                surface->lightmaptexture = NULL;
                i = LittleLong(in->lightofs);
                if (i == -1)
                {
-                       surface->samples = NULL;
+                       surface->lightmapinfo->samples = NULL;
                        // give non-lightmapped water a 1x white lightmap
-                       if ((surface->texture->basematerialflags & MATERIALFLAG_WATER) && (surface->texinfo->flags & TEX_SPECIAL) && ssize <= 256 && tsize <= 256)
+                       if ((surface->texture->basematerialflags & MATERIALFLAG_WATER) && (surface->lightmapinfo->texinfo->flags & TEX_SPECIAL) && ssize <= 256 && tsize <= 256)
                        {
-                               surface->samples = Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
-                               surface->styles[0] = 0;
-                               memset(surface->samples, 128, ssize * tsize * 3);
+                               surface->lightmapinfo->samples = Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
+                               surface->lightmapinfo->styles[0] = 0;
+                               memset(surface->lightmapinfo->samples, 128, ssize * tsize * 3);
                        }
                }
                else if (loadmodel->brush.ishlbsp) // LordHavoc: HalfLife map (bsp version 30)
-                       surface->samples = loadmodel->brushq1.lightdata + i;
+                       surface->lightmapinfo->samples = loadmodel->brushq1.lightdata + i;
                else // LordHavoc: white lighting (bsp version 29)
-                       surface->samples = loadmodel->brushq1.lightdata + (i * 3);
+                       surface->lightmapinfo->samples = loadmodel->brushq1.lightdata + (i * 3);
 
-               if (!(surface->texinfo->flags & TEX_SPECIAL) || surface->samples)
+               if (!(surface->lightmapinfo->texinfo->flags & TEX_SPECIAL) || surface->lightmapinfo->samples)
                {
                        int i, iu, iv;
                        float u, v, ubase, vbase, uscale, vscale;
@@ -1916,19 +1919,19 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                        if (ssize > 256 || tsize > 256)
                                Host_Error("Bad surface extents");
                        // stainmap for permanent marks on walls
-                       surface->stainsamples = Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
+                       surface->lightmapinfo->stainsamples = Mem_Alloc(loadmodel->mempool, ssize * tsize * 3);
                        // clear to white
-                       memset(surface->stainsamples, 255, ssize * tsize * 3);
+                       memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3);
 
                        if (r_miplightmaps.integer)
                        {
-                               surface->lightmaptexturestride = ssize;
-                               surface->lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, NULL, surface->lightmaptexturestride, tsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_MIPMAP | TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+                               surface->lightmapinfo->lightmaptexturestride = ssize;
+                               surface->lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, NULL, surface->lightmapinfo->lightmaptexturestride, tsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_MIPMAP | TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
                        }
                        else
                        {
-                               surface->lightmaptexturestride = R_CompatibleFragmentWidth(ssize, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, 0);
-                               surface->lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, NULL, surface->lightmaptexturestride, tsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FRAGMENT | TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+                               surface->lightmapinfo->lightmaptexturestride = R_CompatibleFragmentWidth(ssize, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, 0);
+                               surface->lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, NULL, surface->lightmapinfo->lightmaptexturestride, tsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FRAGMENT | TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
                        }
                        R_FragmentLocation(surface->lightmaptexture, NULL, NULL, &ubase, &vbase, &uscale, &vscale);
                        uscale = (uscale - ubase) / ssize;
@@ -1936,8 +1939,8 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
 
                        for (i = 0;i < surface->mesh.num_vertices;i++)
                        {
-                               u = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3]) + 8 - surface->texturemins[0]) * (1.0 / 16.0);
-                               v = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3]) + 8 - surface->texturemins[1]) * (1.0 / 16.0);
+                               u = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
+                               v = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
                                surface->mesh.data_texcoordlightmap2f[i * 2 + 0] = u * uscale + ubase;
                                surface->mesh.data_texcoordlightmap2f[i * 2 + 1] = v * vscale + vbase;
                                // LordHavoc: calc lightmap data offset for vertex lighting to use
@@ -2741,7 +2744,7 @@ static void Mod_Q1BSP_BuildLightmapUpdateChains(mempool_t *mempool, model_t *mod
        {
                surface = model->brush.data_surfaces + model->firstmodelsurface + i;
                for (j = 0;j < MAXLIGHTMAPS;j++)
-                       stylecounts[surface->styles[j]]++;
+                       stylecounts[surface->lightmapinfo->styles[j]]++;
        }
        totalcount = 0;
        model->brushq1.light_styles = 0;
@@ -2773,8 +2776,8 @@ static void Mod_Q1BSP_BuildLightmapUpdateChains(mempool_t *mempool, model_t *mod
        {
                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;
+                       if (surface->lightmapinfo->styles[j] != 255)
+                               *model->brushq1.light_styleupdatechains[remapstyles[surface->lightmapinfo->styles[j]]]++ = surface;
        }
        j = 0;
        for (i = 0;i < model->brushq1.light_styles;i++)
@@ -4247,7 +4250,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                i = oldi;
                in = oldin;
                out = oldout;
-               mesh = tempmeshlist[meshnum] = Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, 0, 0, false, false, true);
+               mesh = tempmeshlist[meshnum] = Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, false, true);
                meshvertices = 0;
                meshtriangles = 0;
                for (;i < count && meshvertices + out->mesh.num_vertices <= mesh->num_vertices;i++, in++, out++)
@@ -4356,21 +4359,21 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                finalvertices = finalwidth * finalheight;
                                finaltriangles = (finalwidth - 1) * (finalheight - 1) * 2;
 
-                               out->mesh.data_collisionvertex3f = Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * finalvertices);
-                               out->mesh.data_collisionelement3i = Mem_Alloc(loadmodel->mempool, sizeof(int[3]) * finaltriangles);
-                               out->mesh.num_collisionvertices = finalvertices;
-                               out->mesh.num_collisiontriangles = finaltriangles;
-                               Q3PatchTesselateFloat(3, sizeof(float[3]), out->mesh.data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
-                               Q3PatchTriangleElements(out->mesh.data_collisionelement3i, finalwidth, finalheight);
+                               out->data_collisionvertex3f = Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * finalvertices);
+                               out->data_collisionelement3i = Mem_Alloc(loadmodel->mempool, sizeof(int[3]) * finaltriangles);
+                               out->num_collisionvertices = finalvertices;
+                               out->num_collisiontriangles = finaltriangles;
+                               Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
+                               Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight);
 
                                //Mod_SnapVertices(3, out->mesh.num_vertices, out->mesh.data_vertex3f, 0.25);
-                               Mod_SnapVertices(3, out->mesh.num_collisionvertices, out->mesh.data_collisionvertex3f, 1);
+                               Mod_SnapVertices(3, out->num_collisionvertices, out->data_collisionvertex3f, 1);
 
                                oldnumtriangles = out->mesh.num_triangles;
-                               oldnumtriangles2 = out->mesh.num_collisiontriangles;
-                               out->mesh.num_collisiontriangles = Mod_RemoveDegenerateTriangles(out->mesh.num_collisiontriangles, out->mesh.data_collisionelement3i, out->mesh.data_collisionelement3i, out->mesh.data_collisionvertex3f);
+                               oldnumtriangles2 = out->num_collisiontriangles;
+                               out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(out->num_collisiontriangles, out->data_collisionelement3i, out->data_collisionelement3i, out->data_collisionvertex3f);
                                if (developer.integer)
-                                       Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve became %i:%i vertices / %i:%i triangles (%i:%i degenerate)\n", patchsize[0], patchsize[1], out->mesh.num_vertices, out->mesh.num_collisionvertices, oldnumtriangles, oldnumtriangles2, oldnumtriangles - out->mesh.num_triangles, oldnumtriangles2 - out->mesh.num_collisiontriangles);
+                                       Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve became %i:%i vertices / %i:%i triangles (%i:%i degenerate)\n", patchsize[0], patchsize[1], out->mesh.num_vertices, out->num_collisionvertices, oldnumtriangles, oldnumtriangles2, oldnumtriangles - out->mesh.num_triangles, oldnumtriangles2 - out->num_collisiontriangles);
                                break;
                        default:
                                break;
@@ -4419,10 +4422,10 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                out->maxs[2] += 1.0f;
                        }
                        // set lightmap styles for consistency with q1bsp
-                       out->styles[0] = 0;
-                       out->styles[1] = 255;
-                       out->styles[2] = 255;
-                       out->styles[3] = 255;
+                       //out->lightmapinfo->styles[0] = 0;
+                       //out->lightmapinfo->styles[1] = 255;
+                       //out->lightmapinfo->styles[2] = 255;
+                       //out->lightmapinfo->styles[3] = 255;
                }
        }
 
@@ -4872,10 +4875,10 @@ static void Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace_t *trace, model_t *model,
                for (i = 0;i < leaf->numleafsurfaces;i++)
                {
                        surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
-                       if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
+                       if (surface->num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
                        {
                                surface->collisionmarkframe = markframe;
-                               Collision_TraceLineTriangleMeshFloat(trace, linestart, lineend, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i, surface->mesh.data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+                               Collision_TraceLineTriangleMeshFloat(trace, linestart, lineend, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
                                if (startfrac > trace->realfraction)
                                        return;
                        }
@@ -5252,10 +5255,10 @@ static void Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace_t *trace, model_t *model
                for (i = 0;i < leaf->numleafsurfaces;i++)
                {
                        surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
-                       if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
+                       if (surface->num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
                        {
                                surface->collisionmarkframe = markframe;
-                               Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i, surface->mesh.data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+                               Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
                        }
                }
        }
@@ -5306,8 +5309,8 @@ static void Mod_Q3BSP_TraceBox(model_t *model, int frame, trace_t *trace, const
                                                Collision_TraceLineBrushFloat(trace, boxstartmins, boxendmins, brush->colbrushf, brush->colbrushf);
                                if (mod_q3bsp_curves_collisions.integer)
                                        for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
-                                               if (surface->mesh.num_collisiontriangles)
-                                                       Collision_TraceLineTriangleMeshFloat(trace, boxstartmins, boxendmins, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i, surface->mesh.data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+                                               if (surface->num_collisiontriangles)
+                                                       Collision_TraceLineTriangleMeshFloat(trace, boxstartmins, boxendmins, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
                        }
                        else
                                Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace, model, model->brush.data_nodes, boxstartmins, boxendmins, 0, 1, boxstartmins, boxendmins, ++markframe, segmentmins, segmentmaxs);
@@ -5325,8 +5328,8 @@ static void Mod_Q3BSP_TraceBox(model_t *model, int frame, trace_t *trace, const
                                        Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, brush->colbrushf, brush->colbrushf);
                        if (mod_q3bsp_curves_collisions.integer)
                                for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
-                                       if (surface->mesh.num_collisiontriangles)
-                                               Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i, surface->mesh.data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+                                       if (surface->num_collisiontriangles)
+                                               Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
                }
                else
                        Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, model, model->brush.data_nodes, thisbrush_start, thisbrush_end, ++markframe, segmentmins, segmentmaxs);
index 56f34e3..4613346 100644 (file)
@@ -148,6 +148,23 @@ typedef struct
 }
 mtexinfo_t;
 
+typedef struct msurface_lightmapinfo_s
+{
+       // texture mapping properties used by this surface
+       mtexinfo_t *texinfo; // q1bsp
+       // index into d_lightstylevalue array, 255 means not used (black)
+       qbyte styles[MAXLIGHTMAPS]; // q1bsp
+       // RGB lighting data [numstyles][height][width][3]
+       qbyte *samples; // q1bsp
+       // stain to apply on lightmap (soot/dirt/blood/whatever)
+       qbyte *stainsamples; // q1bsp
+       // the stride when building lightmaps to comply with fragment update
+       int lightmaptexturestride; // q1bsp
+       int texturemins[2]; // q1bsp
+       int extents[2]; // q1bsp
+}
+msurface_lightmapinfo_t;
+
 struct q3deffect_s;
 typedef struct msurface_s
 {
@@ -162,25 +179,16 @@ typedef struct msurface_s
        int cached_dlight; // q1bsp
        // mesh for rendering
        surfmesh_t mesh;
+
+       int num_collisiontriangles;
+       int *data_collisionelement3i;
+       int num_collisionvertices;
+       float *data_collisionvertex3f;
+
        // 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
-       // index into d_lightstylevalue array, 255 means not used (black)
-       qbyte styles[MAXLIGHTMAPS]; // q1bsp
-       // RGB lighting data [numstyles][height][width][3]
-       qbyte *samples; // q1bsp
-       // stain to apply on lightmap (soot/dirt/blood/whatever)
-       qbyte *stainsamples; // q1bsp
-       // the stride when building lightmaps to comply with fragment update
-       int lightmaptexturestride; // q1bsp
-       int texturemins[2]; // q1bsp
-       int extents[2]; // q1bsp
+       msurface_lightmapinfo_t *lightmapinfo;
 
        struct q3deffect_s *effect; // q3bsp
        // FIXME: collisionmarkframe should be kept in a separate array
index 50fb269..4c75e81 100644 (file)
@@ -178,17 +178,11 @@ static void mod_newmap(void)
                {
                        for (surfacenum = 0, surface = mod_known[i].brush.data_surfaces;surfacenum < mod_known[i].brush.num_surfaces;surfacenum++, surface++)
                        {
-                               if (surface->stainsamples)
+                               if (surface->lightmapinfo && surface->lightmapinfo->stainsamples)
                                {
-                                       ssize = (surface->extents[0] >> 4) + 1;
-                                       tsize = (surface->extents[1] >> 4) + 1;
-
-                                       if (ssize > 256 || tsize > 256)
-                                               Host_Error("Bad surface extents");
-
-                                       if (surface->stainsamples)
-                                               memset(surface->stainsamples, 255, ssize * tsize * 3);
-
+                                       ssize = (surface->lightmapinfo->extents[0] >> 4) + 1;
+                                       tsize = (surface->lightmapinfo->extents[1] >> 4) + 1;
+                                       memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3);
                                        surface->cached_dlight = true;
                                }
                        }
@@ -758,15 +752,13 @@ void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const flo
                        VectorNormalize(v);
 }
 
-surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, int numcollisionvertices, int numcollisiontriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors)
+surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors)
 {
        surfmesh_t *mesh;
        qbyte *data;
-       mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + 3) * sizeof(int) + numcollisionvertices * sizeof(float[3]) + numcollisiontriangles * sizeof(int[3]));
+       mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + 3) * sizeof(int));
        mesh->num_vertices = numvertices;
        mesh->num_triangles = numtriangles;
-       mesh->num_collisionvertices = numcollisionvertices;
-       mesh->num_collisiontriangles = numcollisiontriangles;
        data = (qbyte *)(mesh + 1);
        if (mesh->num_vertices)
        {
@@ -788,10 +780,6 @@ surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriang
                mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
                mesh->data_neighbor3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
        }
-       if (mesh->num_collisionvertices)
-               mesh->data_collisionvertex3f = (float *)data, data += sizeof(float[3]) * mesh->num_collisionvertices;
-       if (mesh->num_collisiontriangles)
-               mesh->data_collisionelement3i = (int *)data, data += sizeof(int[3]) * mesh->num_collisiontriangles;
        return mesh;
 }
 
index 5379bd5..c540460 100644 (file)
@@ -76,24 +76,19 @@ overridetagnameset_t;
 // LordHavoc: replaces glpoly, triangle mesh
 typedef struct surfmesh_s
 {
-       int num_vertices; // number of vertices in the mesh
        int num_triangles; // number of triangles in the mesh
-       float *data_vertex3f; // float[verts*3] vertex locations
        int *data_element3i; // int[tris*3] triangles of the mesh, 3 indices into vertex arrays for each
+       int *data_neighbor3i; // int[tris*3] neighboring triangle on each edge (-1 if none)
+       int num_vertices; // number of vertices in the mesh
+       float *data_vertex3f; // float[verts*3] vertex locations
        float *data_texcoordtexture2f; // float[verts*2] texcoords for surface texture
        float *data_texcoordlightmap2f; // float[verts*2] texcoords for lightmap texture
        float *data_lightmapcolor4f;
        float *data_svector3f; // float[verts*3] direction of 'S' (right) texture axis for each vertex
        float *data_tvector3f; // float[verts*3] direction of 'T' (down) texture axis for each vertex
        float *data_normal3f; // float[verts*3] direction of 'R' (out) texture axis for each vertex
-       int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting
        float *data_texcoorddetail2f; // float[verts*2] texcoords for detail texture
-       int *data_neighbor3i; // int[tris*3] neighboring triangle on each edge (-1 if none)
-
-       int num_collisionvertices;
-       int num_collisiontriangles;
-       float *data_collisionvertex3f;
-       int *data_collisionelement3i;
+       int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting
 }
 surfmesh_t;
 
@@ -215,6 +210,7 @@ typedef struct model_brush_s
 
        int num_surfaces;
        msurface_t *data_surfaces;
+       msurface_lightmapinfo_t *data_surfaces_lightmapinfo;
 
        int num_brushes;
        q3mbrush_t *data_brushes;
@@ -468,7 +464,7 @@ void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, c
 void Mod_BuildNormals(int numverts, int numtriangles, const float *vertex3f, const int *elements, float *normal3f);
 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
 
-surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, int numcollisionvertices, int numcollisiontriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors);
+surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors);
 
 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable);
 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh, int light, int neighbors);