]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
Coordinates are now floats in network protocol (bloats it yes, but the accuracy allow...
[xonotic/darkplaces.git] / model_brush.c
index d5c8c3e386a1ddcd58e2572010025a0c803db5c5..e0bd20f40d7622e2995c646d50772273f9df67c0 100644 (file)
@@ -111,6 +111,7 @@ void Mod_LoadTextures (lump_t *l)
        texture_t       *altanims[10];
        dmiptexlump_t *m;
        byte    *data;
+       int             *dofs;
 
        if (!l->filelen)
        {
@@ -123,14 +124,16 @@ void Mod_LoadTextures (lump_t *l)
        m->nummiptex = LittleLong (m->nummiptex);
        
        loadmodel->numtextures = m->nummiptex;
-       loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
+       loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures), va("%s texture headers", loadname));
 
+       // just to work around bounds checking when debugging with it (array index out of bounds error thing)
+       dofs = m->dataofs;
        for (i=0 ; i<m->nummiptex ; i++)
        {
-               m->dataofs[i] = LittleLong(m->dataofs[i]);
-               if (m->dataofs[i] == -1)
+               dofs[i] = LittleLong(dofs[i]);
+               if (dofs[i] == -1)
                        continue;
-               mt = (miptex_t *)((byte *)m + m->dataofs[i]);
+               mt = (miptex_t *)((byte *)m + dofs[i]);
                mt->width = LittleLong (mt->width);
                mt->height = LittleLong (mt->height);
                for (j=0 ; j<MIPLEVELS ; j++)
@@ -139,7 +142,7 @@ void Mod_LoadTextures (lump_t *l)
                if ( (mt->width & 15) || (mt->height & 15) )
                        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 );
+               tx = Hunk_AllocName (sizeof(texture_t), va("%s textures", loadname));
                loadmodel->textures[i] = tx;
 
                // LordHavoc: force all names to lowercase and make sure they are terminated while copying
@@ -167,17 +170,44 @@ void Mod_LoadTextures (lump_t *l)
                        freeimage = FALSE;
                        transparent = FALSE;
                        bytesperpixel = 1;
-                       if (!hlbsp && mt->offsets[0]) // texture included
+                       if (mt->offsets[0]) // texture included
                        {
                                data = (byte *)((int) mt + mt->offsets[0]);
-                               if (r_fullbrights.value && tx->name[0] != '*')
+                               if (hlbsp)
+                               {
+                                       byte *in, *out, *pal;
+                                       int palsize, d, p;
+                                       bytesperpixel = 4;
+                                       freeimage = TRUE;
+                                       in = data;
+                                       data = out = qmalloc(mt->width * mt->height * 4);
+                                       pal = in + (((mt->width * mt->height) * 85) >> 6);
+                                       palsize = pal[1] * 0x100 + pal[0];
+                                       if (palsize >= 256)
+                                               palsize = 255;
+                                       pal += 2;
+                                       for (d = 0;d < mt->width * mt->height;d++)
+                                       {
+                                               p = (*in++) * 3;
+                                               out[0] = pal[p];
+                                               out[1] = pal[p+1];
+                                               out[2] = pal[p+2];
+                                               out[3] = 255;
+                                               if (out[0] == 255 && out[1] == 0 && out[2] == 0) // HL transparent color (pure blue)
+                                                       out[0] = out[1] = out[2] = out[3] = 0;
+                                               out += 4;
+                                       }
+                               }
+                               else if (r_fullbrights.value && tx->name[0] != '*')
                                {
                                        for (j = 0;j < tx->width*tx->height;j++)
+                                       {
                                                if (data[j] >= 224) // fullbright
                                                {
                                                        fullbrights = TRUE;
                                                        break;
                                                }
+                                       }
                                }
                        }
                        else // no texture, and no external replacement texture was found
@@ -198,30 +228,31 @@ void Mod_LoadTextures (lump_t *l)
                }
                else
                {
-                       tx->transparent = transparent;
                        if (fullbrights)
                        {
                                char name[64];
                                byte *data2;
-                               data2 = malloc(tx->width*tx->height);
+                               tx->transparent = false;
+                               data2 = qmalloc(tx->width*tx->height);
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
-                               tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
+                               tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
                                strcpy(name, tx->name);
                                strcat(name, "_glow");
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
-                               tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
-                               free(data2);
+                               tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
+                               qfree(data2);
                        }
                        else
                        {
+                               tx->transparent = transparent;
                                tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
                                tx->gl_glowtexturenum = 0;
                        }
                }
                if (freeimage)
-                       free(data);
+                       qfree(data);
        }
 
 //
@@ -332,7 +363,7 @@ void Mod_LoadLighting (lump_t *l)
        loadmodel->lightdata = NULL;
        if (hlbsp) // LordHavoc: load the colored lighting data straight
        {
-               loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
+               loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
                memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
        }
        else // LordHavoc: bsp version 29 (normal white lighting)
@@ -362,7 +393,7 @@ void Mod_LoadLighting (lump_t *l)
                // LordHavoc: oh well, expand the white lighting data
                if (!l->filelen)
                        return;
-               loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
+               loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
                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;
                memcpy (in, mod_base + l->fileofs, l->filelen);
@@ -389,7 +420,7 @@ void Mod_LoadVisibility (lump_t *l)
                loadmodel->visdata = NULL;
                return;
        }
-       loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);    
+       loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
        memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
 }
 
@@ -409,7 +440,7 @@ void Mod_LoadEntities (lump_t *l)
                loadmodel->entities = NULL;
                return;
        }
-       loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);   
+       loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
        memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
 
        if (isworldmodel)
@@ -432,7 +463,7 @@ void Mod_LoadVertexes (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s vertices", loadname));
 
        loadmodel->vertexes = out;
        loadmodel->numvertexes = count;
@@ -460,7 +491,7 @@ void Mod_LoadSubmodels (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
 
        loadmodel->submodels = out;
        loadmodel->numsubmodels = count;
@@ -496,7 +527,7 @@ void Mod_LoadEdges (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);   
+       out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
 
        loadmodel->edges = out;
        loadmodel->numedges = count;
@@ -517,7 +548,7 @@ void Mod_LoadTexinfo (lump_t *l)
 {
        texinfo_t *in;
        mtexinfo_t *out;
-       int     i, j, count;
+       int     i, j, k, count;
        int             miptex;
        float   len1, len2;
 
@@ -525,15 +556,16 @@ void Mod_LoadTexinfo (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
 
        loadmodel->texinfo = out;
        loadmodel->numtexinfo = count;
 
        for ( i=0 ; i<count ; i++, in++, out++)
        {
-               for (j=0 ; j<8 ; j++)
-                       out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
+               for (k=0 ; k<2 ; k++)
+                       for (j=0 ; j<4 ; j++)
+                               out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
                len1 = Length (out->vecs[0]);
                len2 = Length (out->vecs[1]);
                len1 = (len1 + len2)/2;
@@ -649,7 +681,7 @@ void Mod_LoadFaces (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
 
        loadmodel->surfaces = out;
        loadmodel->numsurfaces = count;
@@ -748,7 +780,7 @@ void Mod_LoadNodes (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
 
        loadmodel->nodes = out;
        loadmodel->numnodes = count;
@@ -795,7 +827,7 @@ void Mod_LoadLeafs (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
 
        loadmodel->leafs = out;
        loadmodel->numleafs = count;
@@ -852,7 +884,7 @@ void Mod_LoadClipnodes (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
 
        loadmodel->clipnodes = out;
        loadmodel->numclipnodes = count;
@@ -950,7 +982,7 @@ void Mod_MakeHull0 (void)
        
        in = loadmodel->nodes;
        count = loadmodel->numnodes;
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
 
        hull->clipnodes = out;
        hull->firstclipnode = 0;
@@ -986,7 +1018,7 @@ void Mod_LoadMarksurfaces (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
 
        loadmodel->marksurfaces = out;
        loadmodel->nummarksurfaces = count;
@@ -1014,7 +1046,7 @@ void Mod_LoadSurfedges (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
 
        loadmodel->surfedges = out;
        loadmodel->numsurfedges = count;
@@ -1041,7 +1073,7 @@ void Mod_LoadPlanes (lump_t *l)
        if (l->filelen % sizeof(*in))
                Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*2*sizeof(*out), loadname); 
+       out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
 
        loadmodel->planes = out;
        loadmodel->numplanes = count;