]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
Patch from div0 to fix skyboxes in downloaded maps
[xonotic/darkplaces.git] / model_brush.c
index f367e4b7be0b831635079137e3f1e4fe33ebcf08..937924f53bef87edf7f41f1cf50b3ce24289cca6 100644 (file)
@@ -851,7 +851,7 @@ static void Mod_Q1BSP_TraceBox(struct model_s *model, int frame, trace_t *trace,
        Con_Printf("t(%f %f %f,%f %f %f,%i %f %f %f)", rhc.start[0], rhc.start[1], rhc.start[2], rhc.end[0], rhc.end[1], rhc.end[2], rhc.hull - model->brushq1.hulls, rhc.hull->clip_mins[0], rhc.hull->clip_mins[1], rhc.hull->clip_mins[2]);
        Mod_Q1BSP_RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
        {
-               
+
                double test[3];
                trace_t testtrace;
                VectorLerp(rhc.start, rhc.trace->fraction, rhc.end, test);
@@ -903,12 +903,12 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
        cbox_planes[3].normal[0] =  0;cbox_planes[3].normal[1] = -1;cbox_planes[3].normal[2] =  0;cbox_planes[3].dist = maxs[1] - cmins[1];
        cbox_planes[4].normal[0] =  0;cbox_planes[4].normal[1] =  0;cbox_planes[4].normal[2] =  1;cbox_planes[4].dist = cmaxs[2] - mins[2];
        cbox_planes[5].normal[0] =  0;cbox_planes[5].normal[1] =  0;cbox_planes[5].normal[2] = -1;cbox_planes[5].dist = maxs[2] - cmins[2];
-       cbox_planes[0].supercontents = boxsupercontents;cbox_planes[0].q3surfaceflags = boxq3surfaceflags;cbox_planes[0].texture = boxtexture;
-       cbox_planes[1].supercontents = boxsupercontents;cbox_planes[1].q3surfaceflags = boxq3surfaceflags;cbox_planes[1].texture = boxtexture;
-       cbox_planes[2].supercontents = boxsupercontents;cbox_planes[2].q3surfaceflags = boxq3surfaceflags;cbox_planes[2].texture = boxtexture;
-       cbox_planes[3].supercontents = boxsupercontents;cbox_planes[3].q3surfaceflags = boxq3surfaceflags;cbox_planes[3].texture = boxtexture;
-       cbox_planes[4].supercontents = boxsupercontents;cbox_planes[4].q3surfaceflags = boxq3surfaceflags;cbox_planes[4].texture = boxtexture;
-       cbox_planes[5].supercontents = boxsupercontents;cbox_planes[5].q3surfaceflags = boxq3surfaceflags;cbox_planes[5].texture = boxtexture;
+       cbox_planes[0].q3surfaceflags = boxq3surfaceflags;cbox_planes[0].texture = boxtexture;
+       cbox_planes[1].q3surfaceflags = boxq3surfaceflags;cbox_planes[1].texture = boxtexture;
+       cbox_planes[2].q3surfaceflags = boxq3surfaceflags;cbox_planes[2].texture = boxtexture;
+       cbox_planes[3].q3surfaceflags = boxq3surfaceflags;cbox_planes[3].texture = boxtexture;
+       cbox_planes[4].q3surfaceflags = boxq3surfaceflags;cbox_planes[4].texture = boxtexture;
+       cbox_planes[5].q3surfaceflags = boxq3surfaceflags;cbox_planes[5].texture = boxtexture;
        memset(trace, 0, sizeof(trace_t));
        trace->hitsupercontentsmask = hitsupercontentsmask;
        trace->fraction = 1;
@@ -1117,7 +1117,7 @@ middle sample (the one which was requested)
 
 void Mod_Q1BSP_LightPoint(model_t *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal)
 {
-       Mod_Q1BSP_LightPoint_RecursiveBSPNode(model, ambientcolor, diffusecolor, diffusenormal, model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, p[0], p[1], p[2], p[2] - 65536);
+       Mod_Q1BSP_LightPoint_RecursiveBSPNode(model, ambientcolor, diffusecolor, diffusenormal, model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, p[0], p[1], p[2] + 0.125, p[2] - 65536);
        VectorSet(diffusenormal, 0, 0, -1);
 }
 
@@ -1233,7 +1233,8 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
        texture_t *tx, *tx2, *anims[10], *altanims[10];
        dmiptexlump_t *m;
        unsigned char *data, *mtdata;
-       char name[MAX_QPATH];
+       const char *s;
+       char mapname[MAX_QPATH], name[MAX_QPATH];
 
        loadmodel->data_textures = NULL;
 
@@ -1278,6 +1279,11 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
        if (!m)
                return;
 
+       s = loadmodel->name;
+       if (!strncasecmp(s, "maps/", 5))
+               s += 5;
+       FS_StripExtension(s, mapname, sizeof(mapname));
+
        // just to work around bounds checking when debugging with it (array index out of bounds error thing)
        dofs = m->dataofs;
        // LordHavoc: mostly rewritten map texture loader
@@ -1346,7 +1352,8 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        }
                        else
                        {
-                               if (!Mod_LoadSkinFrame(&tx->skin, gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false, true))
+                               if (!Mod_LoadSkinFrame(&tx->skin, gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false, true)
+                                && !Mod_LoadSkinFrame(&tx->skin, gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false, true))
                                {
                                        // did not find external texture, load it from the bsp or wad3
                                        if (loadmodel->brush.ishlbsp)
@@ -4235,16 +4242,19 @@ static void Mod_Q3BSP_LoadShaders(void)
                                }
                        }
                        // identify if this is a blended terrain shader or similar
-                       shader->primarylayer = shader->layers + 0;
-                       if (shader->layers[1].blendfunc[0] == GL_SRC_ALPHA && shader->layers[1].blendfunc[1] == GL_ONE_MINUS_SRC_ALPHA)
+                       if (shader->numlayers)
                        {
-                               // terrain blending or other effects
-                               shader->backgroundlayer = shader->layers + 0;
-                               shader->primarylayer = shader->layers + 1;
+                               shader->primarylayer = shader->layers + 0;
+                               if (shader->layers[1].blendfunc[0] == GL_SRC_ALPHA && shader->layers[1].blendfunc[1] == GL_ONE_MINUS_SRC_ALPHA)
+                               {
+                                       // terrain blending or other effects
+                                       shader->backgroundlayer = shader->layers + 0;
+                                       shader->primarylayer = shader->layers + 1;
+                               }
+                               // now see if the lightmap came first, and if so choose the second texture instead
+                               if (!strcasecmp(shader->primarylayer->texturename, "$lightmap"))
+                                       shader->primarylayer = shader->layers + 1;
                        }
-                       // now see if the lightmap came first, and if so choose the second texture instead
-                       if (!strcasecmp(shader->primarylayer->texturename, "$lightmap"))
-                               shader->primarylayer = shader->layers + 1;
                }
                Mem_Free(f);
        }
@@ -4299,7 +4309,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
                                        dpsnprintf(loadmodel->brush.skybox, sizeof(loadmodel->brush.skybox), "%s_", shader->skyboxname);
                                }
                        }
-                       else if ((shader->surfaceparms & Q3SURFACEPARM_NODRAW) || shader->numlayers == 0)
+                       else if ((out->surfaceflags & Q3SURFACEFLAG_NODRAW) || shader->numlayers == 0)
                                out->basematerialflags |= MATERIALFLAG_NODRAW;
                        else if (shader->surfaceparms & Q3SURFACEPARM_LAVA)
                                out->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_FULLBRIGHT;
@@ -4483,12 +4493,11 @@ static void Mod_Q3BSP_LoadBrushes(lump_t *l)
                {
                        VectorCopy(out->firstbrushside[j].plane->normal, planes[j].normal);
                        planes[j].dist = out->firstbrushside[j].plane->dist;
-                       planes[j].supercontents = out->firstbrushside[j].texture->supercontents;
                        planes[j].q3surfaceflags = out->firstbrushside[j].texture->surfaceflags;
                        planes[j].texture = out->firstbrushside[j].texture;
                }
                // make the colbrush from the planes
-               out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes);
+               out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes, out->texture->supercontents);
        }
        if (planes)
                Mem_Free(planes);