]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
added fogging info to rsurface state so model scaling applies to fog
[xonotic/darkplaces.git] / model_brush.c
index a245384bde33b5a40b8e96cff154f797161c8d45..dd6c0dbfcc69fd9414914174ac4a5d2e2aa5acf8 100644 (file)
@@ -1022,6 +1022,8 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
 #if 1
        colbrushf_t cbox;
        colplanef_t cbox_planes[6];
+       cbox.isaabb = true;
+       cbox.hasaabbplanes = true;
        cbox.supercontents = boxsupercontents;
        cbox.numplanes = 6;
        cbox.numpoints = 0;
@@ -1321,8 +1323,11 @@ A sky texture is 256*128, with the right side being a masked overlay
 */
 void R_Q1BSP_LoadSplitSky (unsigned char *src, int width, int height, int bytesperpixel)
 {
-       int i, j;
-       unsigned solidpixels[128*128], alphapixels[128*128];
+       int x, y;
+       int w = width/2;
+       int h = height;
+       unsigned *solidpixels = Mem_Alloc(tempmempool, w*h*sizeof(unsigned char[4]));
+       unsigned *alphapixels = Mem_Alloc(tempmempool, w*h*sizeof(unsigned char[4]));
 
        // allocate a texture pool if we need it
        if (loadmodel->texturepool == NULL && cls.state != ca_dedicated)
@@ -1330,12 +1335,12 @@ void R_Q1BSP_LoadSplitSky (unsigned char *src, int width, int height, int bytesp
 
        if (bytesperpixel == 4)
        {
-               for (i = 0;i < 128;i++)
+               for (y = 0;y < h;y++)
                {
-                       for (j = 0;j < 128;j++)
+                       for (x = 0;x < w;x++)
                        {
-                               solidpixels[(i*128) + j] = ((unsigned *)src)[i*256+j+128];
-                               alphapixels[(i*128) + j] = ((unsigned *)src)[i*256+j];
+                               solidpixels[y*w+x] = ((unsigned *)src)[y*width+x+w];
+                               alphapixels[y*w+x] = ((unsigned *)src)[y*width+x];
                        }
                }
        }
@@ -1351,33 +1356,35 @@ void R_Q1BSP_LoadSplitSky (unsigned char *src, int width, int height, int bytesp
                }
                bgra;
                r = g = b = 0;
-               for (i = 0;i < 128;i++)
+               for (y = 0;y < h;y++)
                {
-                       for (j = 0;j < 128;j++)
+                       for (x = 0;x < w;x++)
                        {
-                               p = src[i*256 + j + 128];
+                               p = src[x*width+y+w];
                                r += palette_rgb[p][0];
                                g += palette_rgb[p][1];
                                b += palette_rgb[p][2];
                        }
                }
-               bgra.b[2] = r/(128*128);
-               bgra.b[1] = g/(128*128);
-               bgra.b[0] = b/(128*128);
+               bgra.b[2] = r/(w*h);
+               bgra.b[1] = g/(w*h);
+               bgra.b[0] = b/(w*h);
                bgra.b[3] = 0;
-               for (i = 0;i < 128;i++)
+               for (y = 0;y < h;y++)
                {
-                       for (j = 0;j < 128;j++)
+                       for (x = 0;x < w;x++)
                        {
-                               solidpixels[(i*128) + j] = palette_bgra_complete[src[i*256 + j + 128]];
-                               p = src[i*256 + j];
-                               alphapixels[(i*128) + j] = p ? palette_bgra_complete[p] : bgra.i;
+                               solidpixels[y*w+x] = palette_bgra_complete[src[y*width+x+w]];
+                               p = src[y*width+x];
+                               alphapixels[y*w+x] = p ? palette_bgra_complete[p] : bgra.i;
                        }
                }
        }
 
-       loadmodel->brush.solidskytexture = R_LoadTexture2D(loadmodel->texturepool, "sky_solidtexture", 128, 128, (unsigned char *) solidpixels, TEXTYPE_BGRA, TEXF_PRECACHE, NULL);
-       loadmodel->brush.alphaskytexture = R_LoadTexture2D(loadmodel->texturepool, "sky_alphatexture", 128, 128, (unsigned char *) alphapixels, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
+       loadmodel->brush.solidskytexture = R_LoadTexture2D(loadmodel->texturepool, "sky_solidtexture", w, h, (unsigned char *) solidpixels, TEXTYPE_BGRA, TEXF_PRECACHE, NULL);
+       loadmodel->brush.alphaskytexture = R_LoadTexture2D(loadmodel->texturepool, "sky_alphatexture", w, h, (unsigned char *) alphapixels, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
+       Mem_Free(solidpixels);
+       Mem_Free(alphapixels);
 }
 
 static void Mod_Q1BSP_LoadTextures(lump_t *l)
@@ -1556,10 +1563,10 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                if (cls.state != ca_dedicated)
                {
                        // LordHavoc: HL sky textures are entirely different than quake
-                       if (!loadmodel->brush.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == 256 && mtheight == 128)
+                       if (!loadmodel->brush.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == mtheight * 2)
                        {
                                data = loadimagepixelsbgra(tx->name, false, false);
-                               if (data && image_width == 256 && image_height == 128)
+                               if (data && image_width == image_height * 2)
                                {
                                        R_Q1BSP_LoadSplitSky(data, image_width, image_height, 4);
                                        Mem_Free(data);
@@ -4431,7 +4438,7 @@ static void Mod_Q3BSP_LoadBrushes(lump_t *l)
                        q3surfaceflags |= planes[j].q3surfaceflags;
                }
                // make the colbrush from the planes
-               out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes, out->texture->supercontents, q3surfaceflags, out->texture);
+               out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes, out->texture->supercontents, q3surfaceflags, out->texture, true);
 
                // this whole loop can take a while (e.g. on redstarrepublic4)
                CL_KeepaliveMessage(false);
@@ -5917,7 +5924,7 @@ static void Mod_Q3BSP_TraceBox(dp_model_t *model, int frame, trace_t *trace, con
        float segmentmins[3], segmentmaxs[3];
        msurface_t *surface;
        q3mbrush_t *brush;
-       colbrushf_t *thisbrush_start, *thisbrush_end;
+       colboxbrushf_t thisbrush_start, thisbrush_end;
        vec3_t boxstartmins, boxstartmaxs, boxendmins, boxendmaxs;
 
        if (mod_q3bsp_optimizedtraceline.integer && VectorCompare(boxmins, boxmaxs))
@@ -5950,20 +5957,20 @@ static void Mod_Q3BSP_TraceBox(dp_model_t *model, int frame, trace_t *trace, con
        VectorAdd(start, boxmaxs, boxstartmaxs);
        VectorAdd(end, boxmins, boxendmins);
        VectorAdd(end, boxmaxs, boxendmaxs);
-       thisbrush_start = Collision_BrushForBox(&identitymatrix, boxstartmins, boxstartmaxs, 0, 0, NULL);
-       thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs, 0, 0, NULL);
+       Collision_BrushForBox(&thisbrush_start, boxstartmins, boxstartmaxs, 0, 0, NULL);
+       Collision_BrushForBox(&thisbrush_end, boxendmins, boxendmaxs, 0, 0, NULL);
        if (model->brush.submodel)
        {
                for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
                        if (brush->colbrushf)
-                               Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, brush->colbrushf, brush->colbrushf);
+                               Collision_TraceBrushBrushFloat(trace, &thisbrush_start.brush, &thisbrush_end.brush, brush->colbrushf, brush->colbrushf);
                if (mod_q3bsp_curves_collisions.integer)
                        for (i = 0, surface = model->data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
                                if (surface->num_collisiontriangles)
-                                       Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->num_collisionbboxstride, surface->data_collisionbbox6f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
+                                       Collision_TraceBrushTriangleMeshFloat(trace, &thisbrush_start.brush, &thisbrush_end.brush, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->num_collisionbboxstride, surface->data_collisionbbox6f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
        }
        else
-               Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, model, model->brush.data_nodes, thisbrush_start, thisbrush_end, ++markframe, segmentmins, segmentmaxs);
+               Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, model, model->brush.data_nodes, &thisbrush_start.brush, &thisbrush_end.brush, ++markframe, segmentmins, segmentmaxs);
 }
 
 static int Mod_Q3BSP_PointSuperContents(struct model_s *model, int frame, const vec3_t point)