]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
lighthalf related transpoly cleanup
[xonotic/darkplaces.git] / model_brush.c
index 4fa418f3710256877a559e7c94bebccab59ac885..03f9dc924accca934e7dac81a0d1701a7a66f711 100644 (file)
@@ -39,36 +39,7 @@ void Mod_BrushInit (void)
        memset (mod_novis, 0xff, sizeof(mod_novis));
 }
 
-/*
-===============
-Mod_PointInLeaf
-===============
-*/
-mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model)
-{
-       mnode_t         *node;
-       float           d;
-       mplane_t        *plane;
-       
-       if (!model || !model->nodes)
-               Sys_Error ("Mod_PointInLeaf: bad model");
-
-       node = model->nodes;
-       while (1)
-       {
-               if (node->contents < 0)
-                       return (mleaf_t *)node;
-               plane = node->plane;
-               d = DotProduct (p,plane->normal) - plane->dist;
-               if (d > 0)
-                       node = node->children[0];
-               else
-                       node = node->children[1];
-       }
-       
-       return NULL;    // never reached
-}
-
+// Mod_PointInLeaf moved to cpu_noasm.c
 
 /*
 ===================
@@ -122,7 +93,7 @@ byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model)
        return Mod_DecompressVis (leaf->compressed_vis, model);
 }
 
-byte   *mod_base;
+extern byte    *mod_base;
 
 extern cvar_t r_fullbrights;
 
@@ -166,7 +137,7 @@ void Mod_LoadTextures (lump_t *l)
                        mt->offsets[j] = LittleLong (mt->offsets[j]);
                
                if ( (mt->width & 15) || (mt->height & 15) )
-                       Sys_Error ("Texture %s is not 16 aligned", mt->name);
+                       Host_Error ("Texture %s is not 16 aligned", mt->name);
                // LordHavoc: rewriting the map texture loader for GLQuake
                tx = Hunk_AllocName (sizeof(texture_t), loadname );
                loadmodel->textures[i] = tx;
@@ -179,11 +150,12 @@ void Mod_LoadTextures (lump_t *l)
                freeimage = TRUE;
                bytesperpixel = 4;
                fullbrights = FALSE;
-               transparent = FALSE;
-               data = loadimagepixels(mt->name, FALSE, tx->width, tx->height);
+               transparent = TRUE;
+               data = loadimagepixels(mt->name, FALSE, 0, 0); //tx->width, tx->height);
                if (!data) // no external texture found
                {
                        freeimage = FALSE;
+                       transparent = FALSE;
                        bytesperpixel = 1;
                        if (!hlbsp && mt->offsets[0]) // texture included
                        {
@@ -206,14 +178,10 @@ void Mod_LoadTextures (lump_t *l)
                }
                else
                {
-                       for (j = 0;j < image_width*image_height;j++)
-                               if (data[j*4+3] < 255)
-                               {
-                                       transparent = TRUE;
-                                       break;
-                               }
+                       tx->width = image_width;
+                       tx->height = image_height;
                }
-               if (!hlbsp && !strncmp(mt->name,"sky",3)) // LordHavoc: HL sky textures are entirely unrelated
+               if (!hlbsp && !strncmp(mt->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
                {
                        tx->transparent = FALSE;
                        R_InitSky (data, bytesperpixel);
@@ -328,7 +296,7 @@ void Mod_LoadTextures (lump_t *l)
                                        altmax = num+1;
                        }
                        else
-                               Sys_Error ("Bad animating texture %s", tx->name);
+                               Host_Error ("Bad animating texture %s", tx->name);
                }
                
 #define        ANIM_CYCLE      2
@@ -337,7 +305,7 @@ void Mod_LoadTextures (lump_t *l)
                {
                        tx2 = anims[j];
                        if (!tx2)
-                               Sys_Error ("Missing frame %i of %s",j, tx->name);
+                               Host_Error ("Missing frame %i of %s",j, tx->name);
                        tx2->anim_total = max * ANIM_CYCLE;
                        tx2->anim_min = j * ANIM_CYCLE;
                        tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -349,7 +317,7 @@ void Mod_LoadTextures (lump_t *l)
                {
                        tx2 = altanims[j];
                        if (!tx2)
-                               Sys_Error ("Missing frame %i of %s",j, tx->name);
+                               Host_Error ("Missing frame %i of %s",j, tx->name);
                        tx2->anim_total = altmax * ANIM_CYCLE;
                        tx2->anim_min = j * ANIM_CYCLE;
                        tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -372,8 +340,6 @@ void Mod_LoadLighting (lump_t *l)
        byte d;
        char litfilename[1024];
        loadmodel->lightdata = NULL;
-       if (!l->filelen)
-               return;
        if (hlbsp) // LordHavoc: load the colored lighting data straight
        {
                loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
@@ -393,6 +359,7 @@ void Mod_LoadLighting (lump_t *l)
                                i = LittleLong(((int *)data)[1]);
                                if (i == 1)
                                {
+                                       Con_DPrintf("%s loaded", litfilename);
                                        loadmodel->lightdata = data + 8;
                                        return;
                                }
@@ -403,6 +370,8 @@ void Mod_LoadLighting (lump_t *l)
                                Con_Printf("Corrupt .lit file (old version?), ignoring\n");
                }
                // LordHavoc: oh well, expand the white lighting data
+               if (!l->filelen)
+                       return;
                loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
                in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
                out = loadmodel->lightdata;
@@ -471,7 +440,7 @@ void Mod_LoadVertexes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -499,7 +468,7 @@ void Mod_LoadSubmodels (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -535,7 +504,7 @@ void Mod_LoadEdges (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);   
 
@@ -564,7 +533,7 @@ void Mod_LoadTexinfo (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -600,19 +569,19 @@ void Mod_LoadTexinfo (lump_t *l)
                {
                        out->texture = r_notexture_mip; // checkerboard texture
                        out->flags = 0;
+                       out->texture->transparent = FALSE;
                }
                else
                {
                        if (miptex >= loadmodel->numtextures)
-                               Sys_Error ("miptex >= loadmodel->numtextures");
+                               Host_Error ("miptex >= loadmodel->numtextures");
                        out->texture = loadmodel->textures[miptex];
                        if (!out->texture)
                        {
                                out->texture = r_notexture_mip; // texture not found
                                out->flags = 0;
-                       }
-                       else
                                out->texture->transparent = FALSE;
+                       }
                }
        }
 }
@@ -666,7 +635,7 @@ void CalcSurfaceExtents (msurface_t *s)
                s->texturemins[i] = bmins[i] * 16;
                s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
                if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
-                       Sys_Error ("Bad surface extents");
+                       Host_Error ("Bad surface extents");
        }
 }
 
@@ -688,7 +657,7 @@ void Mod_LoadFaces (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -787,7 +756,7 @@ void Mod_LoadNodes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -834,7 +803,7 @@ void Mod_LoadLeafs (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -891,7 +860,7 @@ void Mod_LoadClipnodes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -927,6 +896,8 @@ void Mod_LoadClipnodes (lump_t *l)
                out->planenum = LittleLong(in->planenum);
                out->children[0] = LittleShort(in->children[0]);
                out->children[1] = LittleShort(in->children[1]);
+               if (out->children[0] >= count || out->children[1] >= count)
+                       Host_Error("Corrupt clipping hull (out of range child)\n");
        }
 }
 
@@ -982,7 +953,7 @@ void Mod_LoadMarksurfaces (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -993,7 +964,7 @@ void Mod_LoadMarksurfaces (lump_t *l)
        {
                j = LittleShort(in[i]);
                if (j >= loadmodel->numsurfaces)
-                       Sys_Error ("Mod_ParseMarksurfaces: bad surface number");
+                       Host_Error ("Mod_ParseMarksurfaces: bad surface number");
                out[i] = loadmodel->surfaces + j;
        }
 }
@@ -1010,7 +981,7 @@ void Mod_LoadSurfedges (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*sizeof(*out), loadname);   
 
@@ -1037,7 +1008,7 @@ void Mod_LoadPlanes (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
        out = Hunk_AllocName ( count*2*sizeof(*out), loadname); 
 
@@ -1077,8 +1048,8 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
        header = (dheader_t *)buffer;
 
        i = LittleLong (header->version);
-       if (i != BSPVERSION & i != 30)
-               Sys_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
+       if (i != BSPVERSION && i != 30)
+               Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
        hlbsp = i == 30;
        halflifebsp.value = hlbsp;