if (center < 0.0f)
center = 0.0f;
center += 8388608.0f;
- i = *((long *)¢er) & 0x7FFFFF;
+ i = *((int *)¢er) & 0x7FFFFF;
i = min(i, (TRANSDEPTHRES - 1));
#endif
tri->next = buf_sorttranstri_list[i];
#if SLOWMATH
length = 3.0f / sqrt(number);
#else
- *((long *)&length) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&length) = 0x5f3759df - ((* (int *) &number) >> 1);
length = 3.0f * (length * (1.5f - (number * 0.5f * length * length)));
#endif
#if SLOWMATH
length = 3.0f / sqrt(number);
#else
- *((long *)&length) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&length) = 0x5f3759df - ((* (int *) &number) >> 1);
length = 3.0f * (length * (1.5f - (number * 0.5f * length * length)));
#endif
if (number == 0.0f)
return 0.0f;
- *((long *)&y) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
return y * (1.5f - (number * 0.5f * y * y));
}
if (number != 0.0)
{
- *((long *)&y) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
y = y * (1.5f - (number * 0.5f * y * y));
VectorScale(v, y, v);
Con_Printf("Mod_ConvertAliasVerts: \"%s\", %i invalid normal indices found\n", loadmodel->name, invalidnormals);
}
-static void Mod_MDL_LoadFrames (long datapointer, int inverts, int outverts, vec3_t scale, vec3_t translate)
+static void Mod_MDL_LoadFrames (qbyte * datapointer, int inverts, int outverts, vec3_t scale, vec3_t translate)
{
daliasframetype_t *pframetype;
daliasframe_t *pinframe;
daliasframetype_t *pinframetype;
daliasgroup_t *pinframegroup;
float scales, scalet, scale[3], translate[3], interval;
- long datapointer, startframes, startskins;
+ qbyte *datapointer, *startframes, *startskins;
char name[MAX_QPATH];
qbyte *skintemp = NULL;
modelyawradius = 0;
modelradius = 0;
- datapointer = (long) buffer;
+ datapointer = buffer;
pinmodel = (mdl_t *)datapointer;
datapointer += sizeof(mdl_t);
{
int *vertremap;
md2_t *pinmodel;
- long base;
+ qbyte *base;
int version, end;
int i, j, k, hashindex, num, numxyz, numst, xyz, st;
float *stverts, s, t;
float st[2];
}
*hash, **md2verthash, *md2verthashdata;
- long datapointer;
+ qbyte *datapointer;
md2frame_t *pinframe;
char *inskin;
md2triangle_t *intri;
int skinwidth, skinheight;
pinmodel = buffer;
- base = (long) buffer;
+ base = buffer;
version = LittleLong (pinmodel->version);
if (version != MD2ALIAS_VERSION)
if (mesh->numtriangles < 1)
Host_Error("Mod_GenerateWarpMesh: no triangles?\n");
mesh->index = Mem_Alloc(loadmodel->mempool, mesh->numtriangles * sizeof(int[3]) + mesh->numverts * sizeof(surfvertex_t));
- mesh->vertex = (surfvertex_t *)((long) mesh->index + mesh->numtriangles * sizeof(int[3]));
+ mesh->vertex = (surfvertex_t *)((qbyte *) mesh->index + mesh->numtriangles * sizeof(int[3]));
memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t));
for (i = 0;i < mesh->numtriangles;i++)
mesh->numverts = surf->poly_numverts;
mesh->numtriangles = surf->poly_numverts - 2;
mesh->index = Mem_Alloc(loadmodel->mempool, mesh->numtriangles * sizeof(int[3]) + mesh->numverts * sizeof(surfvertex_t));
- mesh->vertex = (surfvertex_t *)((long) mesh->index + mesh->numtriangles * sizeof(int[3]));
+ mesh->vertex = (surfvertex_t *)((qbyte *) mesh->index + mesh->numtriangles * sizeof(int[3]));
memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t));
index = mesh->index;
mesh->numverts = surf->poly_numverts;
mesh->numtriangles = surf->poly_numverts - 2;
mesh->index = Mem_Alloc(loadmodel->mempool, mesh->numtriangles * sizeof(int[3]) + mesh->numverts * sizeof(surfvertex_t));
- mesh->vertex = (surfvertex_t *)((long) mesh->index + mesh->numtriangles * sizeof(int[3]));
+ mesh->vertex = (surfvertex_t *)((qbyte *) mesh->index + mesh->numtriangles * sizeof(int[3]));
memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t));
index = mesh->index;
mesh->numverts = surf->poly_numverts;
mesh->numtriangles = surf->poly_numverts - 2;
mesh->index = Mem_Alloc(loadmodel->mempool, mesh->numtriangles * sizeof(int[3]) + mesh->numverts * sizeof(surfvertex_t));
- mesh->vertex = (surfvertex_t *)((long) mesh->index + mesh->numtriangles * sizeof(int[3]));
+ mesh->vertex = (surfvertex_t *)((qbyte *) mesh->index + mesh->numtriangles * sizeof(int[3]));
memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t));
index = mesh->index;
a = *((const msurface_t **)voida);
b = *((const msurface_t **)voidb);
if (a->shader != b->shader)
- return (long) a->shader - (long) b->shader;
+ return (qbyte *) a->shader - (qbyte *) b->shader;
if (a->texinfo->texture != b->texinfo->texture);
return a->texinfo->texture - b->texinfo->texture;
return 0;
}
loadmodel->portals = Mem_Alloc(loadmodel->mempool, numportals * sizeof(mportal_t) + numpoints * sizeof(mvertex_t));
loadmodel->numportals = numportals;
- loadmodel->portalpoints = (void *) ((long) loadmodel->portals + numportals * sizeof(mportal_t));
+ loadmodel->portalpoints = (void *) ((qbyte *) loadmodel->portals + numportals * sizeof(mportal_t));
loadmodel->numportalpoints = numpoints;
// clear all leaf portal chains
for (i = 0;i < loadmodel->numleafs;i++)
#include "quakedef.h"
-model_t *loadmodel;
+model_t *loadmodel;
// LordHavoc: increased from 512 to 2048
#define MAX_MOD_KNOWN 2048
*out++ = 0;
}
-void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
+void Mod_Sprite_SharedSetup(qbyte *datapointer, int version, int *palette)
{
int i, j, k, groupframes, realframes, x, y, origin[2], width, height;
dspriteframetype_t *pinframetype;
float modelradius, interval;
char tempname[MAX_QPATH], name[MAX_QPATH];
qbyte *pixbuf;
- long startframes;
+ void *startframes;
modelradius = 0;
Mod_Sprite_StripExtension(loadmodel->name, tempname);
{
pixbuf = Mem_Alloc(tempmempool, width*height*4);
if (version == SPRITE32_VERSION)
- memcpy(pixbuf, (qbyte *)datapointer, width*height*4);
+ memcpy(pixbuf, datapointer, width*height*4);
else //if (version == SPRITE_VERSION || version == SPRITEHL_VERSION)
- Image_Copy8bitRGBA((qbyte *)datapointer, pixbuf, width*height, palette);
+ Image_Copy8bitRGBA(datapointer, pixbuf, width*height, palette);
loadmodel->sprdata_frames[realframes].texture = R_LoadTexture (loadmodel->texturepool, name, width, height, pixbuf, TEXTYPE_RGBA, TEXF_ALPHA | (r_mipsprites.integer ? TEXF_MIPMAP : 0) | TEXF_PRECACHE);
*/
void Mod_LoadSpriteModel (model_t *mod, void *buffer)
{
- int version;
+ int version, i, rendermode;
+ qbyte palette[256][4], *in;
+ dsprite_t *pinqsprite;
+ dspritehl_t *pinhlsprite;
+ qbyte *datapointer;
+
+ datapointer = buffer;
+
loadmodel->SERAddEntity = Mod_Sprite_SERAddEntity;
loadmodel->Draw = R_DrawSpriteModel;
loadmodel->DrawSky = NULL;
version = LittleLong(((dsprite_t *)buffer)->version);
if (version == SPRITE_VERSION || SPRITE32_VERSION)
{
- dsprite_t *pinsprite;
- long datapointer;
-
- datapointer = (long) buffer;
-
- pinsprite = (dsprite_t *)datapointer;
+ pinqsprite = (dsprite_t *)datapointer;
datapointer += sizeof(dsprite_t);
- loadmodel->numframes = LittleLong (pinsprite->numframes);
- loadmodel->sprnum_type = LittleLong (pinsprite->type);
- loadmodel->synctype = LittleLong (pinsprite->synctype);
+ loadmodel->numframes = LittleLong (pinqsprite->numframes);
+ loadmodel->sprnum_type = LittleLong (pinqsprite->type);
+ loadmodel->synctype = LittleLong (pinqsprite->synctype);
- Mod_Sprite_SharedSetup(datapointer, LittleLong (pinsprite->version), d_8to24table);
+ Mod_Sprite_SharedSetup(datapointer, LittleLong (pinqsprite->version), d_8to24table);
}
else if (version == SPRITEHL_VERSION)
{
- int i, rendermode;
- qbyte palette[256][4], *in;
- dspritehl_t *pinsprite;
- long datapointer;
-
- datapointer = (long) buffer;
-
- pinsprite = (dspritehl_t *)datapointer;
+ pinhlsprite = (dspritehl_t *)datapointer;
datapointer += sizeof(dspritehl_t);
- loadmodel->numframes = LittleLong (pinsprite->numframes);
- loadmodel->sprnum_type = LittleLong (pinsprite->type);
- loadmodel->synctype = LittleLong (pinsprite->synctype);
- rendermode = pinsprite->rendermode;
+ loadmodel->numframes = LittleLong (pinhlsprite->numframes);
+ loadmodel->sprnum_type = LittleLong (pinhlsprite->type);
+ loadmodel->synctype = LittleLong (pinhlsprite->synctype);
+ rendermode = pinhlsprite->rendermode;
- in = (qbyte *)datapointer;
+ in = datapointer;
datapointer += 2;
i = in[0] + in[1] * 256;
if (i != 256)
Host_Error ("Mod_LoadHLSprite: unexpected number of palette colors %i (should be 256)", i);
- in = (qbyte *)datapointer;
+ in = datapointer;
datapointer += 768;
switch(rendermode)
{
return;
}
- Mod_Sprite_SharedSetup(datapointer, LittleLong (pinsprite->version), (int *)(&palette[0][0]));
+ Mod_Sprite_SharedSetup(datapointer, LittleLong (pinhlsprite->version), (int *)(&palette[0][0]));
}
else
Host_Error ("Mod_LoadSpriteModel: %s has wrong version number (%i should be 1 (quake) or 32 (sprite32) or 2 (halflife)", loadmodel->name, version);
number = DotProduct(p->normal, p->normal);
if (number >= 0.1f)
{
- *((long *)&y) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
y = y * (1.5f - (number * 0.5f * y * y));
VectorScale(p->normal, y, p->normal);
p->dist = DotProduct(point1, p->normal);
t = 1.0f / sqrt(dist2);
#else
number = DotProduct(v, v);
- *((long *)&t) = 0x5f3759df - ((* (long *) &number) >> 1);
+ *((int *)&t) = 0x5f3759df - ((* (int *) &number) >> 1);
t = t * (1.5f - (number * 0.5f * t * t));
#endif
// DotProduct(avn,v) * t is dotproduct with a normalized v,
clump->largestavailable = MEMBITS - needed;
j = 0;
choseclump:
- mem = (memheader_t *)((long) clump->block + j * MEMUNIT);
+ mem = (memheader_t *)((qbyte *) clump->block + j * MEMUNIT);
mem->clump = clump;
clump->blocksinuse += needed;
for (i = j + needed;j < i;j++)
mem->fileline = fileline;
mem->size = size;
mem->pool = pool;
- mem->sentinel1 = MEMHEADER_SENTINEL;
- *((int *)((long) mem + sizeof(memheader_t) + mem->size)) = MEMHEADER_SENTINEL;
+ mem->sentinel1 = MEMHEADER_SENTINEL1;
+ // we have to use only a single byte for this sentinel, because it may not be aligned, and some platforms can't use unaligned accesses
+ *((qbyte *) mem + sizeof(memheader_t) + mem->size) = MEMHEADER_SENTINEL2;
// append to head of list
mem->chain = pool->chain;
pool->chain = mem;
- memset((void *)((long) mem + sizeof(memheader_t)), 0, mem->size);
- return (void *)((long) mem + sizeof(memheader_t));
+ memset((void *)((qbyte *) mem + sizeof(memheader_t)), 0, mem->size);
+ return (void *)((qbyte *) mem + sizeof(memheader_t));
}
void _Mem_Free(void *data, char *filename, int fileline)
Sys_Error("Mem_Free: data == NULL (called at %s:%i)", filename, fileline);
- mem = (memheader_t *)((long) data - sizeof(memheader_t));
- if (mem->sentinel1 != MEMHEADER_SENTINEL)
+ mem = (memheader_t *)((qbyte *) data - sizeof(memheader_t));
+ if (mem->sentinel1 != MEMHEADER_SENTINEL1)
Sys_Error("Mem_Free: trashed header sentinel 1 (alloc at %s:%i, free at %s:%i)", mem->filename, mem->fileline, filename, fileline);
- if (*((int *)((long) mem + sizeof(memheader_t) + mem->size)) != MEMHEADER_SENTINEL)
+ if (*((qbyte *) mem + sizeof(memheader_t) + mem->size) != MEMHEADER_SENTINEL2)
Sys_Error("Mem_Free: trashed header sentinel 2 (alloc at %s:%i, free at %s:%i)", mem->filename, mem->fileline, filename, fileline);
pool = mem->pool;
Con_DPrintf("Mem_Free: pool %s, alloc %s:%i, free %s:%i, size %i bytes\n", pool->name, mem->filename, mem->fileline, filename, fileline, mem->size);
Sys_Error("Mem_Free: trashed clump sentinel 1 (free at %s:%i)", filename, fileline);
if (clump->sentinel2 != MEMCLUMP_SENTINEL)
Sys_Error("Mem_Free: trashed clump sentinel 2 (free at %s:%i)", filename, fileline);
- firstblock = ((long) mem - (long) clump->block);
+ firstblock = ((qbyte *) mem - (qbyte *) clump->block);
if (firstblock & (MEMUNIT - 1))
Sys_Error("Mem_Free: address not valid in clump (free at %s:%i)", filename, fileline);
firstblock /= MEMUNIT;
// free memory owned by the pool
while ((*pool)->chain)
- Mem_Free((void *)((long) (*pool)->chain + sizeof(memheader_t)));
+ Mem_Free((void *)((qbyte *) (*pool)->chain + sizeof(memheader_t)));
// free the pool itself
memset(*pool, 0xBF, sizeof(mempool_t));
// free memory owned by the pool
while (pool->chain)
- Mem_Free((void *)((long) pool->chain + sizeof(memheader_t)));
+ Mem_Free((void *)((qbyte *) pool->chain + sizeof(memheader_t)));
}
void _Mem_CheckSentinels(void *data, char *filename, int fileline)
if (data == NULL)
Sys_Error("Mem_CheckSentinels: data == NULL (sentinel check at %s:%i)", filename, fileline);
- mem = (memheader_t *)((long) data - sizeof(memheader_t));
- if (mem->sentinel1 != MEMHEADER_SENTINEL)
+ mem = (memheader_t *)((qbyte *) data - sizeof(memheader_t));
+ if (mem->sentinel1 != MEMHEADER_SENTINEL1)
Sys_Error("Mem_CheckSentinels: trashed header sentinel 1 (block allocated at %s:%i, sentinel check at %s:%i)", mem->filename, mem->fileline, filename, fileline);
- if (*((int *)((long) mem + sizeof(memheader_t) + mem->size)) != MEMHEADER_SENTINEL)
+ if (*((qbyte *) mem + sizeof(memheader_t) + mem->size) != MEMHEADER_SENTINEL2)
Sys_Error("Mem_CheckSentinels: trashed header sentinel 2 (block allocated at %s:%i, sentinel check at %s:%i)", mem->filename, mem->fileline, filename, fileline);
}
for (pool = poolchain;pool;pool = pool->next)
{
for (mem = pool->chain;mem;mem = mem->chain)
- _Mem_CheckSentinels((void *)((long) mem + sizeof(memheader_t)), filename, fileline);
+ _Mem_CheckSentinels((void *)((qbyte *) mem + sizeof(memheader_t)), filename, fileline);
for (clump = pool->clumpchain;clump;clump = clump->chain)
_Mem_CheckClumpSentinels(clump, filename, fileline);
}
#define MEMBITS (MEMCLUMPSIZE / MEMUNIT)
#define MEMBITINTS (MEMBITS / 32)
-#define MEMHEADER_SENTINEL 0xABADCAFE
-#define MEMCLUMP_SENTINEL 0xDEADF00D
+#define MEMHEADER_SENTINEL1 0xDEADF00D
+#define MEMHEADER_SENTINEL2 0xDF
+#define MEMCLUMP_SENTINEL 0xABADCAFE
typedef struct memheader_s
{
// file name and line where Mem_Alloc was called
char *filename;
int fileline;
- // should always be MEMHEADER_SENTINEL
+ // should always be MEMHEADER_SENTINEL1
int sentinel1;
- // immediately followed by data, which is followed by another MEMHEADER_SENTINEL
+ // immediately followed by data, which is followed by a MEMHEADER_SENTINEL2 byte
}
memheader_t;