models: fix cppcheck warnings

This commit is contained in:
Denis Pauk 2024-02-05 01:29:56 +02:00
parent 5ea0a76f76
commit 10cc304778
7 changed files with 99 additions and 85 deletions

View File

@ -43,6 +43,8 @@ Goals (finished):
* Add debug progress loading code for maps. * Add debug progress loading code for maps.
Goals (none of it finished): Goals (none of it finished):
* md5 improve load speed,
* md3 fix possible memory coruption,
* Single player support, * Single player support,
* modified ReRelease game code support with removed KEX only related code. * modified ReRelease game code support with removed KEX only related code.

View File

@ -33,9 +33,7 @@ static byte *s_bufferlights = NULL, *s_bufferlights_max = NULL;
static int static int
BSPX_LightGridSingleValue(const bspxlightgrid_t *grid, const lightstyle_t *lightstyles, int x, int y, int z, vec3_t res_diffuse) BSPX_LightGridSingleValue(const bspxlightgrid_t *grid, const lightstyle_t *lightstyles, int x, int y, int z, vec3_t res_diffuse)
{ {
int i;
unsigned int node; unsigned int node;
struct bspxlgsamp_s *samp;
node = grid->rootnode; node = grid->rootnode;
while (!(node & LGNODE_LEAF)) while (!(node & LGNODE_LEAF))
@ -52,6 +50,9 @@ BSPX_LightGridSingleValue(const bspxlightgrid_t *grid, const lightstyle_t *light
{ {
struct bspxlgleaf_s *leaf = &grid->leafs[node & ~LGNODE_LEAF]; struct bspxlgleaf_s *leaf = &grid->leafs[node & ~LGNODE_LEAF];
struct bspxlgsamp_s *samp;
int i;
x -= leaf->mins[0]; x -= leaf->mins[0];
y -= leaf->mins[1]; y -= leaf->mins[1];
z -= leaf->mins[2]; z -= leaf->mins[2];
@ -495,7 +496,7 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
{ {
int smax, tmax; int smax, tmax;
int r, g, b, a, max; int r, g, b, a, max;
int i, j, size, nummaps; int i, j, size, numlightmaps;
byte *lightmap; byte *lightmap;
float scale[4]; float scale[4];
float *bl; float *bl;
@ -529,15 +530,15 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
} }
/* count the # of maps */ /* count the # of maps */
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255; for (numlightmaps = 0; numlightmaps < MAXLIGHTMAPS && surf->styles[numlightmaps] != 255;
nummaps++) numlightmaps++)
{ {
} }
lightmap = surf->samples; lightmap = surf->samples;
/* add all the lightmaps */ /* add all the lightmaps */
if (nummaps == 1) if (numlightmaps == 1)
{ {
int maps; int maps;
@ -702,7 +703,7 @@ store:
} }
static void static void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount, R_MarkSurfaceLights(dlight_t *light, int bit, const mnode_t *node, int r_dlightframecount,
msurface_t *surfaces) msurface_t *surfaces)
{ {
msurface_t *surf; msurface_t *surf;

View File

@ -56,7 +56,7 @@ Mod_NumberLeafs(mleaf_t *leafs, mnode_t *node, int *r_leaftovis, int *r_vistolea
{ {
if (node->contents != CONTENTS_NODE) if (node->contents != CONTENTS_NODE)
{ {
mleaf_t *leaf; const mleaf_t *leaf;
int leafnum; int leafnum;
leaf = (mleaf_t *)node; leaf = (mleaf_t *)node;
@ -324,7 +324,8 @@ Mod_LoadLighting(byte **lightdata, int *size, const byte *mod_base, const lump_t
} }
void void
Mod_LoadSetSurfaceLighting(byte *lightdata, int size, msurface_t *out, byte *styles, int lightofs) Mod_LoadSetSurfaceLighting(byte *lightdata, int size, msurface_t *out,
const byte *styles, int lightofs)
{ {
int i; int i;
@ -349,7 +350,7 @@ Mod_LoadSetSurfaceLighting(byte *lightdata, int size, msurface_t *out, byte *sty
* Fills in s->texturemins[] and s->extents[] * Fills in s->texturemins[] and s->extents[]
*/ */
void void
Mod_CalcSurfaceExtents(int *surfedges, mvertex_t *vertexes, medge_t *edges, Mod_CalcSurfaceExtents(const int *surfedges, mvertex_t *vertexes, medge_t *edges,
msurface_t *s) msurface_t *s)
{ {
double mins[2], maxs[2]; double mins[2], maxs[2];
@ -588,8 +589,9 @@ void
Mod_LoadSurfedges(const char *name, int **surfedges, int *numsurfedges, Mod_LoadSurfedges(const char *name, int **surfedges, int *numsurfedges,
const byte *mod_base, const lump_t *l) const byte *mod_base, const lump_t *l)
{ {
const int *in;
int i, count; int i, count;
int *in, *out; int *out;
in = (void *)(mod_base + l->fileofs); in = (void *)(mod_base + l->fileofs);
@ -740,10 +742,12 @@ Mod_LoadBSPX(int filesize, const byte *mod_base)
int int
Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out) Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out)
{ {
int lmwidth, lmheight, i;
const dlminfo_t *lminfo; const dlminfo_t *lminfo;
unsigned short lmwidth, lmheight; float v0, v1;
if (lminfos == NULL) { if (lminfos == NULL)
{
return -1; return -1;
} }
@ -756,8 +760,12 @@ Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out)
return -1; return -1;
} }
for (int i = 0; i < 2; i++) { for (i = 0; i < 2; i++)
for (int j = 0; j < 4; j++) { {
int j;
for (j = 0; j < 4; j++)
{
out->lmvecs[i][j] = LittleFloat(lminfo->vecs[i][j]); out->lmvecs[i][j] = LittleFloat(lminfo->vecs[i][j]);
} }
} }
@ -768,10 +776,10 @@ Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out)
out->texturemins[0] = 0; out->texturemins[0] = 0;
out->texturemins[1] = 0; out->texturemins[1] = 0;
float v0 = VectorLength(out->lmvecs[0]); v0 = VectorLength(out->lmvecs[0]);
out->lmvlen[0] = v0 > 0.0f ? 1.0f / v0 : 0.0f; out->lmvlen[0] = v0 > 0.0f ? 1.0f / v0 : 0.0f;
float v1 = VectorLength(out->lmvecs[1]); v1 = VectorLength(out->lmvecs[1]);
out->lmvlen[1] = v1 > 0.0f ? 1.0f / v1 : 0.0f; out->lmvlen[1] = v1 > 0.0f ? 1.0f / v1 : 0.0f;
return LittleLong(lminfo->lightofs); return LittleLong(lminfo->lightofs);
@ -782,7 +790,7 @@ Mod_LoadMarksurfaces(const char *name, msurface_t ***marksurfaces, unsigned int
msurface_t *surfaces, int numsurfaces, const byte *mod_base, const lump_t *l) msurface_t *surfaces, int numsurfaces, const byte *mod_base, const lump_t *l)
{ {
int i, count; int i, count;
short *in; const short *in;
msurface_t **out; msurface_t **out;
in = (void *)(mod_base + l->fileofs); in = (void *)(mod_base + l->fileofs);
@ -820,7 +828,7 @@ Mod_LoadQMarksurfaces(const char *name, msurface_t ***marksurfaces, unsigned int
msurface_t *surfaces, int numsurfaces, const byte *mod_base, const lump_t *l) msurface_t *surfaces, int numsurfaces, const byte *mod_base, const lump_t *l)
{ {
int i, count; int i, count;
int *in; const int *in;
msurface_t **out; msurface_t **out;
in = (void *)(mod_base + l->fileofs); in = (void *)(mod_base + l->fileofs);

View File

@ -35,7 +35,7 @@ byte
R_CompressNormalMDL(const float *normal) R_CompressNormalMDL(const float *normal)
{ {
byte i, besti; byte i, besti;
float dot, bestdot; float bestdot;
bestdot = normal[0] * r_avertexnormals[0][0] + bestdot = normal[0] * r_avertexnormals[0][0] +
normal[1] * r_avertexnormals[0][1] + normal[1] * r_avertexnormals[0][1] +
@ -44,6 +44,8 @@ R_CompressNormalMDL(const float *normal)
for (i = 1; i < NUMVERTEXNORMALS; i++) for (i = 1; i < NUMVERTEXNORMALS; i++)
{ {
float dot;
dot = normal[0] * r_avertexnormals[i][0] + dot = normal[0] * r_avertexnormals[i][0] +
normal[1] * r_avertexnormals[i][1] + normal[1] * r_avertexnormals[i][1] +
normal[2] * r_avertexnormals[i][2]; normal[2] * r_avertexnormals[i][2];

View File

@ -35,7 +35,7 @@ load base s and t vertices (not used in gl version)
================= =================
*/ */
static void static void
Mod_LoadSTvertList(dmdx_t *pheader, dstvert_t *pinst) Mod_LoadSTvertList(dmdx_t *pheader, const dstvert_t *pinst)
{ {
dstvert_t *poutst; dstvert_t *poutst;
int i; int i;
@ -57,7 +57,7 @@ Load the glcmds
================= =================
*/ */
static void static void
Mod_LoadCmdList(const char *mod_name, dmdx_t *pheader, int *pincmd) Mod_LoadCmdList(const char *mod_name, dmdx_t *pheader, const int *pincmd)
{ {
int *poutcmd; int *poutcmd;
int i; int i;
@ -127,7 +127,7 @@ Load triangle lists
================= =================
*/ */
static void static void
Mod_LoadDTriangleList(dmdx_t *pheader, dtriangle_t *pintri) Mod_LoadDTriangleList(dmdx_t *pheader, const dtriangle_t *pintri)
{ {
dtriangle_t *pouttri; dtriangle_t *pouttri;
int i; int i;
@ -154,7 +154,7 @@ Load DKM triangle lists
================= =================
*/ */
static void static void
Mod_LoadDkmTriangleList(dmdx_t *pheader, dkmtriangle_t *pintri) Mod_LoadDkmTriangleList(dmdx_t *pheader, const dkmtriangle_t *pintri)
{ {
dtriangle_t *pouttri; dtriangle_t *pouttri;
int i; int i;
@ -183,7 +183,8 @@ Load the DKM glcmds
static void static void
Mod_LoadDKMCmdList(const char *mod_name, dmdx_t *pheader, int *pincmd) Mod_LoadDKMCmdList(const char *mod_name, dmdx_t *pheader, int *pincmd)
{ {
int *poutcmd, *pendcmd; const int *pendcmd;
int *poutcmd;
int i; int i;
poutcmd = (int *)((char*)pheader + pheader->ofs_glcmds); poutcmd = (int *)((char*)pheader + pheader->ofs_glcmds);
@ -413,7 +414,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
const byte *curr_pos; const byte *curr_pos;
mdl_triangle_t *triangles; mdl_triangle_t *triangles;
mdl_texcoord_t *texcoords; const mdl_texcoord_t *texcoords;
curr_pos = (byte*)buffer + sizeof(mdl_header_t); curr_pos = (byte*)buffer + sizeof(mdl_header_t);
@ -614,8 +615,11 @@ static void *
Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen, Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
struct image_s ***skins, int *numskins, modtype_t *type) struct image_s ***skins, int *numskins, modtype_t *type)
{ {
dmdx_t *pheader = NULL;
const int *baseglcmds;
md3_header_t pinmodel; md3_header_t pinmodel;
void *extradata; void *extradata;
int *pglcmds;
int i; int i;
if (modfilelen < sizeof(pinmodel)) if (modfilelen < sizeof(pinmodel))
@ -663,7 +667,7 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
byte * meshofs = (byte*)buffer + pinmodel.ofs_meshes; byte * meshofs = (byte*)buffer + pinmodel.ofs_meshes;
for (i = 0; i < pinmodel.num_meshes; i++) for (i = 0; i < pinmodel.num_meshes; i++)
{ {
md3_mesh_t *md3_mesh = (md3_mesh_t*)meshofs; const md3_mesh_t *md3_mesh = (md3_mesh_t*)meshofs;
num_xyz += LittleLong(md3_mesh->num_xyz); num_xyz += LittleLong(md3_mesh->num_xyz);
num_tris += LittleLong(md3_mesh->num_tris); num_tris += LittleLong(md3_mesh->num_tris);
@ -691,8 +695,6 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
int ofs_st = ofs_tris + num_tris * sizeof(dtriangle_t); int ofs_st = ofs_tris + num_tris * sizeof(dtriangle_t);
int ofs_end = ofs_st + num_tris * 3 * sizeof(dstvert_t); int ofs_end = ofs_st + num_tris * 3 * sizeof(dstvert_t);
dmdx_t *pheader = NULL;
*numskins = num_skins; *numskins = num_skins;
extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *)); extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(ofs_end); pheader = Hunk_Alloc(ofs_end);
@ -716,13 +718,10 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
pheader->ofs_glcmds = ofs_glcmds; pheader->ofs_glcmds = ofs_glcmds;
pheader->ofs_end = ofs_end; pheader->ofs_end = ofs_end;
meshofs = (byte*)buffer + pinmodel.ofs_meshes;
num_xyz = 0; num_xyz = 0;
num_tris = 0; num_tris = 0;
int *pglcmds, *baseglcmds; baseglcmds = pglcmds = (int *)((byte *)pheader + pheader->ofs_glcmds);
pglcmds = baseglcmds = (int *)((byte *)pheader + pheader->ofs_glcmds);
dmdxmesh_t *mesh_nodes = (dmdxmesh_t *)((byte *)pheader + pheader->ofs_meshes); dmdxmesh_t *mesh_nodes = (dmdxmesh_t *)((byte *)pheader + pheader->ofs_meshes);
dtriangle_t *tris = (dtriangle_t*)((byte *)pheader + pheader->ofs_tris); dtriangle_t *tris = (dtriangle_t*)((byte *)pheader + pheader->ofs_tris);
dstvert_t *st = (dstvert_t*)((byte *)pheader + pheader->ofs_st); dstvert_t *st = (dstvert_t*)((byte *)pheader + pheader->ofs_st);
@ -732,14 +731,14 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
meshofs = (byte*)buffer + pinmodel.ofs_meshes; meshofs = (byte*)buffer + pinmodel.ofs_meshes;
for (i = 0; i < pinmodel.num_meshes; i++) for (i = 0; i < pinmodel.num_meshes; i++)
{ {
int j; const md3_mesh_t *md3_mesh = (md3_mesh_t*)meshofs;
md3_mesh_t *md3_mesh = (md3_mesh_t*)meshofs;
const float *fst = (const float*)(meshofs + md3_mesh->ofs_st); const float *fst = (const float*)(meshofs + md3_mesh->ofs_st);
int j;
/* load shaders */ /* load shaders */
for (j = 0; j < md3_mesh->num_shaders; j++) for (j = 0; j < md3_mesh->num_shaders; j++)
{ {
md3_shader_t *md3_shader = (md3_shader_t*)(meshofs + md3_mesh->ofs_shaders) + j; const md3_shader_t *md3_shader = (md3_shader_t*)(meshofs + md3_mesh->ofs_shaders) + j;
strncpy(skin, md3_shader->name, MAX_SKINNAME - 1); strncpy(skin, md3_shader->name, MAX_SKINNAME - 1);
skin += MAX_SKINNAME; skin += MAX_SKINNAME;
@ -759,7 +758,7 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
for (j = 0; j < md3_mesh->num_tris * 3; j++) for (j = 0; j < md3_mesh->num_tris * 3; j++)
{ {
int vert_id; int vert_id;
vec2_t st; vec2_t cmdst;
/* count */ /* count */
if ((j % 3) == 0) if ((j % 3) == 0)
@ -769,9 +768,9 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
} }
/* st */ /* st */
st[0] = LittleFloat(fst[LittleLong(p[j]) * 2 + 0]); cmdst[0] = LittleFloat(fst[LittleLong(p[j]) * 2 + 0]);
st[1] = LittleFloat(fst[LittleLong(p[j]) * 2 + 1]); cmdst[1] = LittleFloat(fst[LittleLong(p[j]) * 2 + 1]);
memcpy(pglcmds, &st, sizeof(st)); memcpy(pglcmds, &cmdst, sizeof(cmdst));
pglcmds += 2; pglcmds += 2;
/* index */ /* index */
vert_id = LittleLong(p[j]) + num_xyz; vert_id = LittleLong(p[j]) + num_xyz;
@ -824,7 +823,7 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
{ {
daliasxframe_t *frame = (daliasxframe_t *)( daliasxframe_t *frame = (daliasxframe_t *)(
(byte *)pheader + pheader->ofs_frames + i * pheader->framesize); (byte *)pheader + pheader->ofs_frames + i * pheader->framesize);
md3_frameinfo_t *md3_frameinfo = (md3_frameinfo_t*)inframe; const md3_frameinfo_t *md3_frameinfo = (md3_frameinfo_t*)inframe;
strncpy(frame->name, md3_frameinfo->name, sizeof(frame->name) - 1); strncpy(frame->name, md3_frameinfo->name, sizeof(frame->name) - 1);
PrepareFrameVertex(vertx + i * pheader->num_xyz, PrepareFrameVertex(vertx + i * pheader->num_xyz,
@ -834,15 +833,16 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
} }
free(vertx); free(vertx);
/* TODO: make separate function */
for (i = 0; i < pheader->num_skins; i++) for (i = 0; i < pheader->num_skins; i++)
{ {
char *skin; char *skinname;
skin = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME; skinname = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME;
skin[MAX_SKINNAME - 1] = 0; skinname[MAX_SKINNAME - 1] = 0;
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n", R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n",
__func__, mod_name, i, skin); __func__, mod_name, i, skinname);
} }
*type = mod_alias; *type = mod_alias;
@ -859,16 +859,16 @@ static void *
Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen, Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
struct image_s ***skins, int *numskins, modtype_t *type) struct image_s ***skins, int *numskins, modtype_t *type)
{ {
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_glcmds, ofs_frames, ofs_end;
vec3_t translate = {0, 0, 0}; vec3_t translate = {0, 0, 0};
const dtriangle_t *pintri;
const dstvert_t *pinst;
const int *pincmd;
dmdl_t pinmodel; dmdl_t pinmodel;
dmdx_t *pheader; dmdx_t *pheader;
dtriangle_t *pintri;
dstvert_t *pinst;
dmdxmesh_t *mesh_nodes; dmdxmesh_t *mesh_nodes;
int *pincmd;
void *extradata; void *extradata;
int i, framesize; int i, framesize;
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_glcmds, ofs_frames, ofs_end;
if (modfilelen < sizeof(pinmodel)) if (modfilelen < sizeof(pinmodel))
{ {
@ -1087,13 +1087,14 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
modtype_t *type) modtype_t *type)
{ {
char *src = (char *)buffer; char *src = (char *)buffer;
int version, size, inframesize = 0; int inframesize = 0;
void *extradata = NULL; void *extradata = NULL;
dmdx_t *pheader = NULL; dmdx_t *pheader = NULL;
while (modfilelen > 0) while (modfilelen > 0)
{ {
char blockname[32]; char blockname[32];
int version, size;
memcpy(blockname, src, sizeof(blockname)); memcpy(blockname, src, sizeof(blockname));
@ -1106,9 +1107,9 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
if (Q_strncasecmp(blockname, "header", sizeof(blockname)) == 0) if (Q_strncasecmp(blockname, "header", sizeof(blockname)) == 0)
{ {
int framesize; const fmheader_t *header = (fmheader_t *)src;
dmdx_t dmdxheader; dmdx_t dmdxheader;
fmheader_t *header = (fmheader_t *)src; int framesize;
if (sizeof(fmheader_t) > size) if (sizeof(fmheader_t) > size)
{ {
@ -1515,9 +1516,10 @@ Mod_LoadSprite_SP2 (const char *mod_name, const void *buffer, int modfilelen,
struct image_s ***skins, int *numskins, struct image_s ***skins, int *numskins,
modtype_t *type) modtype_t *type)
{ {
dsprite_t *sprin, *sprout; const dsprite_t *sprin;
void *extradata; dsprite_t *sprout;
int i, numframes; int i, numframes;
void *extradata;
sprin = (dsprite_t *)buffer; sprin = (dsprite_t *)buffer;
numframes = LittleLong(sprin->numframes); numframes = LittleLong(sprin->numframes);
@ -1590,7 +1592,7 @@ Mod_LoadMinMaxUpdate(const char *mod_name, vec3_t mins, vec3_t maxs, void *extra
if (type == mod_alias) if (type == mod_alias)
{ {
daliasxframe_t *frame; daliasxframe_t *frame;
dmdx_t *pheader; const dmdx_t *pheader;
int i; int i;
pheader = (dmdx_t *)extradata; pheader = (dmdx_t *)extradata;
@ -1615,8 +1617,6 @@ Mod_LoadMinMaxUpdate(const char *mod_name, vec3_t mins, vec3_t maxs, void *extra
maxs[1] = -9999; maxs[1] = -9999;
maxs[2] = -9999; maxs[2] = -9999;
frame = (daliasxframe_t *)((char*)extradata + pheader->ofs_frames);
for (i = 0; i < pheader->num_frames; i++) for (i = 0; i < pheader->num_frames; i++)
{ {
int j; int j;
@ -1803,7 +1803,7 @@ Mod_LoadFileMD5Merge(const char *namewe, void **buffer)
sprintf(skins_list, "\nnumskins %d\n", numskins); sprintf(skins_list, "\nnumskins %d\n", numskins);
for(i = 0; i < numskins; i++) for(i = 0; i < numskins; i++)
{ {
char *skinname = skins + MAX_SKINNAME * i; const char *skinname = skins + MAX_SKINNAME * i;
if (!md5path) if (!md5path)
{ {

View File

@ -223,37 +223,37 @@ BuildFrameSkeleton(const md5_joint_info_t *jointInfos,
if (jointInfos[i].flags & 1) /* Tx */ if (jointInfos[i].flags & 1) /* Tx */
{ {
animatedPos[0] = animFrameData[jointInfos[i].startIndex + j]; animatedPos[0] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
if (jointInfos[i].flags & 2) /* Ty */ if (jointInfos[i].flags & 2) /* Ty */
{ {
animatedPos[1] = animFrameData[jointInfos[i].startIndex + j]; animatedPos[1] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
if (jointInfos[i].flags & 4) /* Tz */ if (jointInfos[i].flags & 4) /* Tz */
{ {
animatedPos[2] = animFrameData[jointInfos[i].startIndex + j]; animatedPos[2] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
if (jointInfos[i].flags & 8) /* Qx */ if (jointInfos[i].flags & 8) /* Qx */
{ {
animatedOrient[0] = animFrameData[jointInfos[i].startIndex + j]; animatedOrient[0] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
if (jointInfos[i].flags & 16) /* Qy */ if (jointInfos[i].flags & 16) /* Qy */
{ {
animatedOrient[1] = animFrameData[jointInfos[i].startIndex + j]; animatedOrient[1] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
if (jointInfos[i].flags & 32) /* Qz */ if (jointInfos[i].flags & 32) /* Qz */
{ {
animatedOrient[2] = animFrameData[jointInfos[i].startIndex + j]; animatedOrient[2] = animFrameData[jointInfos[i].startIndex + j];
++j; j++;
} }
/* Compute orient quaternion's w value */ /* Compute orient quaternion's w value */
@ -976,7 +976,7 @@ MD5_ComputeNormals(md5_model_t *md5file)
for(i = 0; i < md5file->num_frames; ++i) for(i = 0; i < md5file->num_frames; ++i)
{ {
md5_frame_t *frame_in; const md5_frame_t *frame_in;
int k, vert_step = 0; int k, vert_step = 0;
frame_in = md5file->skelFrames + i; frame_in = md5file->skelFrames + i;
@ -1033,11 +1033,13 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
int mesh_size, anim_size; int mesh_size, anim_size;
md5_model_t *md5file; md5_model_t *md5file;
void *extradata = NULL; void *extradata = NULL;
byte *startbuffer, *endbuffer; const byte *endbuffer;
byte *startbuffer;
int i, num_verts = 0, num_tris = 0, num_glcmds = 0; int i, num_verts = 0, num_tris = 0, num_glcmds = 0;
int framesize, ofs_skins, ofs_frames, ofs_glcmds, ofs_meshes, ofs_tris, ofs_st, ofs_end; int framesize, ofs_skins, ofs_frames, ofs_glcmds, ofs_meshes, ofs_tris, ofs_st, ofs_end;
dmdx_t *pheader = NULL; dmdx_t *pheader = NULL;
int *pglcmds, *baseglcmds; const int *baseglcmds;
int *pglcmds;
dmdxmesh_t *mesh_nodes; dmdxmesh_t *mesh_nodes;
dtriangle_t *tris; dtriangle_t *tris;
dstvert_t *st; dstvert_t *st;
@ -1064,9 +1066,9 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
return NULL; return NULL;
} }
if (md5file && anim_size > 0) if (anim_size > 0)
{ {
ReadMD5Anim(md5file, buffer + mesh_size + 1, anim_size); ReadMD5Anim(md5file, (char*)buffer + mesh_size + 1, anim_size);
} }
if (!md5file->num_frames) if (!md5file->num_frames)
@ -1150,7 +1152,7 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
num_tris = 0; num_tris = 0;
pglcmds = baseglcmds = (int *)((byte *)pheader + pheader->ofs_glcmds); baseglcmds = pglcmds = (int *)((byte *)pheader + pheader->ofs_glcmds);
mesh_nodes = (dmdxmesh_t *)((byte *)pheader + pheader->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((byte *)pheader + pheader->ofs_meshes);
tris = (dtriangle_t*)((byte *)pheader + pheader->ofs_tris); tris = (dtriangle_t*)((byte *)pheader + pheader->ofs_tris);
st = (dstvert_t*)((byte *)pheader + pheader->ofs_st); st = (dstvert_t*)((byte *)pheader + pheader->ofs_st);
@ -1211,11 +1213,9 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
__func__, mod_name, i, skin); __func__, mod_name, i, skin);
} }
if (md5file)
{
FreeModelMd5(md5file); FreeModelMd5(md5file);
free(md5file); free(md5file);
}
*type = mod_alias; *type = mod_alias;

View File

@ -347,9 +347,10 @@ extern void Mod_LoadQBSPEdges(const char *name, medge_t **edges, int *numedges,
extern void Mod_LoadVertexes(const char *name, mvertex_t **vertexes, int *numvertexes, extern void Mod_LoadVertexes(const char *name, mvertex_t **vertexes, int *numvertexes,
const byte *mod_base, const lump_t *l); const byte *mod_base, const lump_t *l);
extern void Mod_LoadLighting(byte **lightdata, int *size, const byte *mod_base, const lump_t *l); extern void Mod_LoadLighting(byte **lightdata, int *size, const byte *mod_base, const lump_t *l);
extern void Mod_LoadSetSurfaceLighting(byte *lightdata, int size, msurface_t *out, byte *styles, int lightofs); extern void Mod_LoadSetSurfaceLighting(byte *lightdata, int size, msurface_t *out,
extern void Mod_CalcSurfaceExtents(int *surfedges, mvertex_t *vertexes, medge_t *edges, const byte *styles, int lightofs);
msurface_t *s); extern void Mod_CalcSurfaceExtents(const int *surfedges, mvertex_t *vertexes,
medge_t *edges, msurface_t *s);
extern void Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo, extern void Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo,
const byte *mod_base, const lump_t *l, findimage_t find_image, const byte *mod_base, const lump_t *l, findimage_t find_image,
struct image_s *notexture); struct image_s *notexture);