]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
LoadTGA now loads colormapped and greyscale targas (as found in qe1m1 project)
[xonotic/darkplaces.git] / model_brush.c
index d3876cacc1b710719471cc37b3a1ca06685d3f32..c003fb2c5f3228311ab9979b0d87a34cf6361836 100644 (file)
@@ -383,10 +383,10 @@ static void Mod_LoadTextures (lump_t *l)
                                                        Image_Copy8bitRGBA(mtdata, basepixels, basepixels_width * basepixels_height, palette_nofullbrights);
                                                        if (!glowpixels)
                                                        {
-                                                               for (j = 0;j < tx->width*tx->height;j++)
+                                                               for (j = 0;j < (int)(tx->width*tx->height);j++)
                                                                        if (((qbyte *)&palette_onlyfullbrights[mtdata[j]])[3] > 0) // fullbright
                                                                                break;
-                                                               if (j < tx->width * tx->height)
+                                                               if (j < (int)(tx->width * tx->height))
                                                                {
                                                                        glowpixels_width = tx->width;
                                                                        glowpixels_height = tx->height;
@@ -511,8 +511,7 @@ static void Mod_LoadTextures (lump_t *l)
                }
 
                // start out with no animation
-               tx->currentframe[0] = tx;
-               tx->currentframe[1] = tx;
+               tx->currentframe = tx;
        }
 
        // sequence the animations
@@ -745,6 +744,7 @@ void Mod_LoadLightList(void)
        }
 }
 
+/*
 static int castshadowcount = 0;
 void Mod_ProcessLightList(void)
 {
@@ -783,8 +783,10 @@ void Mod_ProcessLightList(void)
                                                dist = -dist;
                                        if (dist > 0 && dist < e->cullradius)
                                        {
-                                               VectorSubtract(e->origin, surf->poly_center, temp);
-                                               if (DotProduct(temp, temp) - surf->poly_radius2 < e->cullradius2)
+                                               temp[0] = bound(surf->poly_mins[0], e->origin[0], surf->poly_maxs[0]) - e->origin[0];
+                                               temp[1] = bound(surf->poly_mins[1], e->origin[1], surf->poly_maxs[1]) - e->origin[1];
+                                               temp[2] = bound(surf->poly_mins[2], e->origin[2], surf->poly_maxs[2]) - e->origin[2];
+                                               if (DotProduct(temp, temp) < lightradius2)
                                                        loadmodel->surfacevisframes[*mark] = -2;
                                        }
                                }
@@ -845,7 +847,7 @@ void Mod_ProcessLightList(void)
                        float *verts = Mem_Alloc(loadmodel->mempool, maxverts * sizeof(float[3]));
                        float f, *v0, *v1, projectdistance;
 
-                       e->shadowvolume = Mod_ShadowMesh_Begin(loadmodel->mempool);
+                       e->shadowvolume = Mod_ShadowMesh_Begin(loadmodel->mempool, 1024);
 #if 0
                        {
                        vec3_t outermins, outermaxs, innermins, innermaxs;
@@ -998,6 +1000,7 @@ void Mod_ProcessLightList(void)
                }
        }
 }
+*/
 
 
 /*
@@ -1586,7 +1589,7 @@ void Mod_GenerateVertexMesh (msurface_t *surf)
 void Mod_GenerateSurfacePolygon (msurface_t *surf)
 {
        int i, lindex;
-       float *vec, *vert, mins[3], maxs[3], temp[3], dist;
+       float *vec, *vert, mins[3], maxs[3];
 
        // convert edges back to a normal polygon
        surf->poly_numverts = surf->numedges;
@@ -1605,29 +1608,17 @@ void Mod_GenerateSurfacePolygon (msurface_t *surf)
        VectorCopy(vert, mins);
        VectorCopy(vert, maxs);
        vert += 3;
-       for (i = 1;i < surf->poly_numverts;i++)
+       for (i = 1;i < surf->poly_numverts;i++, vert += 3)
        {
                if (mins[0] > vert[0]) mins[0] = vert[0];if (maxs[0] < vert[0]) maxs[0] = vert[0];
                if (mins[1] > vert[1]) mins[1] = vert[1];if (maxs[1] < vert[1]) maxs[1] = vert[1];
                if (mins[2] > vert[2]) mins[2] = vert[2];if (maxs[2] < vert[2]) maxs[2] = vert[2];
-               vert += 3;
        }
        VectorCopy(mins, surf->poly_mins);
        VectorCopy(maxs, surf->poly_maxs);
        surf->poly_center[0] = (mins[0] + maxs[0]) * 0.5f;
        surf->poly_center[1] = (mins[1] + maxs[1]) * 0.5f;
        surf->poly_center[2] = (mins[2] + maxs[2]) * 0.5f;
-       surf->poly_radius2 = 0;
-       vert = surf->poly_verts;
-       for (i = 0;i < surf->poly_numverts;i++)
-       {
-               VectorSubtract(vert, surf->poly_center, temp);
-               dist = DotProduct(temp, temp);
-               if (surf->poly_radius2 < dist)
-                       surf->poly_radius2 = dist;
-               vert += 3;
-       }
-       surf->poly_radius = sqrt(surf->poly_radius2);
 }
 
 /*
@@ -2702,16 +2693,18 @@ static void Mod_MakePortals(void)
 
 static void Mod_BuildSurfaceNeighbors (msurface_t *surfaces, int numsurfaces, mempool_t *mempool)
 {
-       int surfnum, vertnum, snum, vnum;
+#if 0
+       int surfnum, vertnum, vertnum2, snum, vnum, vnum2;
        msurface_t *surf, *s;
        float *v0, *v1, *v2, *v3;
        for (surf = surfaces, surfnum = 0;surfnum < numsurfaces;surf++, surfnum++)
-       {
                surf->neighborsurfaces = Mem_Alloc(mempool, surf->poly_numverts * sizeof(msurface_t *));
-               for (vertnum = 0;vertnum < surf->poly_numverts;vertnum++)
+       for (surf = surfaces, surfnum = 0;surfnum < numsurfaces;surf++, surfnum++)
+       {
+               for (vertnum = surf->poly_numverts - 1, vertnum2 = 0, v0 = surf->poly_verts + (surf->poly_numverts - 1) * 3, v1 = surf->poly_verts;vertnum2 < surf->poly_numverts;vertnum = vertnum2, vertnum2++, v0 = v1, v1 += 3)
                {
-                       v0 = surf->poly_verts + ((vertnum + 1) % surf->poly_numverts) * 3;
-                       v1 = surf->poly_verts + vertnum * 3;
+                       if (surf->neighborsurfaces[vertnum])
+                               continue;
                        surf->neighborsurfaces[vertnum] = NULL;
                        for (s = surfaces, snum = 0;snum < numsurfaces;s++, snum++)
                        {
@@ -2720,11 +2713,19 @@ static void Mod_BuildSurfaceNeighbors (msurface_t *surfaces, int numsurfaces, me
                                 || s->poly_mins[2] > (surf->poly_maxs[2] + 1) || s->poly_maxs[2] < (surf->poly_mins[2] - 1)
                                 || s == surf)
                                        continue;
-                               for (vnum = 0, v2 = s->poly_verts + (s->poly_numverts - 1) * 3, v3 = s->poly_verts;vnum < s->poly_numverts;vnum++, v2 = v3, v3 += 3)
+                               for (vnum = 0;vnum < s->poly_numverts;vnum++)
+                                       if (s->neighborsurfaces[vnum] == surf)
+                                               break;
+                               if (vnum < s->poly_numverts)
+                                       continue;
+                               for (vnum = s->poly_numverts - 1, vnum2 = 0, v2 = s->poly_verts + (s->poly_numverts - 1) * 3, v3 = s->poly_verts;vnum2 < s->poly_numverts;vnum = vnum2, vnum2++, v2 = v3, v3 += 3)
                                {
-                                       if (v0[0] == v2[0] && v0[1] == v2[1] && v0[2] == v2[2] && v1[0] == v3[0] && v1[1] == v3[1] && v1[2] == v3[2])
+                                       if (s->neighborsurfaces[vnum] == NULL
+                                        && ((v0[0] == v2[0] && v0[1] == v2[1] && v0[2] == v2[2] && v1[0] == v3[0] && v1[1] == v3[1] && v1[2] == v3[2])
+                                         || (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2] && v0[0] == v3[0] && v0[1] == v3[1] && v0[2] == v3[2])))
                                        {
                                                surf->neighborsurfaces[vertnum] = s;
+                                               s->neighborsurfaces[vnum] = surf;
                                                break;
                                        }
                                }
@@ -2733,6 +2734,7 @@ static void Mod_BuildSurfaceNeighbors (msurface_t *surfaces, int numsurfaces, me
                        }
                }
        }
+#endif
 }
 
 /*
@@ -2743,7 +2745,7 @@ Mod_LoadBrushModel
 extern void R_Model_Brush_DrawSky(entity_render_t *ent);
 extern void R_Model_Brush_Draw(entity_render_t *ent);
 extern void R_Model_Brush_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius);
-extern void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius2, float lightdistbias, float lightsubtract, float *lightcolor);
+extern void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor);
 void Mod_LoadBrushModel (model_t *mod, void *buffer)
 {
        int                     i, j;
@@ -2771,7 +2773,7 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
 // swap all the lumps
        mod_base = (qbyte *)header;
 
-       for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
+       for (i = 0;i < (int) sizeof(dheader_t) / 4;i++)
                ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
 
 // load into heap
@@ -2883,7 +2885,7 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
                        mod->radius2 = modelradius * modelradius;
                        // LordHavoc: build triangle meshs for entire model's geometry
                        // (only used for shadow volumes)
-                       mod->shadowmesh = Mod_ShadowMesh_Begin(originalloadmodel->mempool);
+                       mod->shadowmesh = Mod_ShadowMesh_Begin(originalloadmodel->mempool, 1024);
                        for (j = 0, surf = &mod->surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surf++)
                                if (surf->flags & SURF_SHADOWCAST)
                                        Mod_ShadowMesh_AddPolygon(originalloadmodel->mempool, mod->shadowmesh, surf->poly_numverts, surf->poly_verts);
@@ -2926,6 +2928,6 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
        }
 
        loadmodel = originalloadmodel;
-       Mod_ProcessLightList ();
+       //Mod_ProcessLightList ();
 }