texture_t *anims[10];
texture_t *altanims[10];
dmiptexlump_t *m;
- byte *data;
+ byte *data;
+ int *dofs;
if (!l->filelen)
{
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++)
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;
- memcpy (tx->name, mt->name, sizeof(tx->name));
+ // LordHavoc: force all names to lowercase and make sure they are terminated while copying
+ for (j = 0;mt->name[j] && j < 15;j++)
+ {
+ if (mt->name[j] >= 'A' && mt->name[j] <= 'Z')
+ tx->name[j] = mt->name[j] + ('a' - 'A');
+ else
+ tx->name[j] = mt->name[j];
+ }
+ for (;j < 16;j++)
+ tx->name[j] = 0;
+
tx->width = mt->width;
tx->height = mt->height;
for (j=0 ; j<MIPLEVELS ; j++)
bytesperpixel = 4;
fullbrights = FALSE;
transparent = TRUE;
- data = loadimagepixels(mt->name, FALSE, 0, 0); //tx->width, tx->height);
+ data = loadimagepixels(tx->name, FALSE, 0, 0); //tx->width, tx->height);
if (!data) // no external texture found
{
freeimage = FALSE;
if (!hlbsp && mt->offsets[0]) // texture included
{
data = (byte *)((int) mt + mt->offsets[0]);
- if (r_fullbrights.value && mt->name[0] != '*')
+ if (r_fullbrights.value && tx->name[0] != '*')
{
for (j = 0;j < tx->width*tx->height;j++)
if (data[j] >= 224) // fullbright
tx->width = image_width;
tx->height = image_height;
}
- if (!hlbsp && !strncmp(mt->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
+ if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
{
tx->transparent = FALSE;
R_InitSky (data, bytesperpixel);
{
char name[64];
byte *data2;
- data2 = malloc(tx->width*tx->height);
+ 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);
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);
+ qfree(data2);
}
else
{
}
}
if (freeimage)
- free(data);
-
- /*
- pixels = mt->width*mt->height/64*85;
- tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
- loadmodel->textures[i] = tx;
-
- memcpy (tx->name, mt->name, sizeof(tx->name));
- tx->width = mt->width;
- tx->height = mt->height;
- for (j=0 ; j<MIPLEVELS ; j++)
- tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
- // the pixels immediately follow the structures
- memcpy ( tx+1, mt+1, pixels);
-
-
- if (!strncmp(mt->name,"sky",3))
- R_InitSky (tx);
- else
- tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false, 1);
- */
+ qfree(data);
}
//
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);
+ 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)
i = LittleLong(((int *)data)[1]);
if (i == 1)
{
+ Con_DPrintf("%s loaded", litfilename);
loadmodel->lightdata = data + 8;
return;
}
Con_Printf("Corrupt .lit file (old version?), ignoring\n");
}
// LordHavoc: oh well, expand the white lighting data
- loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
+ if (!l->filelen)
+ return;
+ 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);
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);
}
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)
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;
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;
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;
{
texinfo_t *in;
mtexinfo_t *out;
- int i, j, count;
+ int i, j, k, count;
int miptex;
float len1, len2;
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;
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;
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;
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;
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;
- hull = &loadmodel->hulls[1];
- hull->clipnodes = out;
- hull->firstclipnode = 0;
- hull->lastclipnode = count-1;
- hull->planes = loadmodel->planes;
- hull->clip_mins[0] = -16;
- hull->clip_mins[1] = -16;
- hull->clip_mins[2] = -24;
- hull->clip_maxs[0] = 16;
- hull->clip_maxs[1] = 16;
- hull->clip_maxs[2] = 32;
-
- hull = &loadmodel->hulls[2];
- hull->clipnodes = out;
- hull->firstclipnode = 0;
- hull->lastclipnode = count-1;
- hull->planes = loadmodel->planes;
- hull->clip_mins[0] = -32;
- hull->clip_mins[1] = -32;
- hull->clip_mins[2] = -24;
- hull->clip_maxs[0] = 32;
- hull->clip_maxs[1] = 32;
- hull->clip_maxs[2] = 64;
+ if (hlbsp)
+ {
+ hull = &loadmodel->hulls[1];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -16;
+ hull->clip_mins[1] = -16;
+ hull->clip_mins[2] = -36;
+ hull->clip_maxs[0] = 16;
+ hull->clip_maxs[1] = 16;
+ hull->clip_maxs[2] = 36;
+
+ hull = &loadmodel->hulls[2];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -32;
+ hull->clip_mins[1] = -32;
+ hull->clip_mins[2] = -32;
+ hull->clip_maxs[0] = 32;
+ hull->clip_maxs[1] = 32;
+ hull->clip_maxs[2] = 32;
+
+ hull = &loadmodel->hulls[3];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -16;
+ hull->clip_mins[1] = -16;
+ hull->clip_mins[2] = -18;
+ hull->clip_maxs[0] = 16;
+ hull->clip_maxs[1] = 16;
+ hull->clip_maxs[2] = 18;
+ }
+ else
+ {
+ hull = &loadmodel->hulls[1];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -16;
+ hull->clip_mins[1] = -16;
+ hull->clip_mins[2] = -24;
+ hull->clip_maxs[0] = 16;
+ hull->clip_maxs[1] = 16;
+ hull->clip_maxs[2] = 32;
+
+ hull = &loadmodel->hulls[2];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -32;
+ hull->clip_mins[1] = -32;
+ hull->clip_mins[2] = -24;
+ hull->clip_maxs[0] = 32;
+ hull->clip_maxs[1] = 32;
+ hull->clip_maxs[2] = 64;
+ }
for (i=0 ; i<count ; i++, out++, in++)
{
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;
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;
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;
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;