Endian fixes to the Q3 model loader.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1204 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Mark Olsen 2005-08-07 02:21:20 +00:00
parent 83cc102208
commit 4cf65db4b7

View file

@ -3625,17 +3625,17 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
min[0] = min[1] = min[2] = 0; min[0] = min[1] = min[2] = 0;
max[0] = max[1] = max[2] = 0; max[0] = max[1] = max[2] = 0;
surf = (md3Surface_t *)((qbyte *)header + header->ofsSurfaces); surf = (md3Surface_t *)((qbyte *)header + LittleLong(header->ofsSurfaces));
for (s = 0; s < header->numSurfaces; s++) for (s = 0; s < LittleLong(header->numSurfaces); s++)
{ {
if (surf->ident != MD3_IDENT) if (LittleLong(surf->ident) != MD3_IDENT)
Con_Printf("Warning: md3 sub-surface doesn't match ident\n"); Con_Printf("Warning: md3 sub-surface doesn't match ident\n");
size = sizeof(galiasinfo_t) + sizeof(galiasgroup_t)*header->numFrames; size = sizeof(galiasinfo_t) + sizeof(galiasgroup_t)*LittleLong(header->numFrames);
galias = Hunk_Alloc(size); galias = Hunk_Alloc(size);
galias->groupofs = sizeof(*galias); //frame groups galias->groupofs = sizeof(*galias); //frame groups
galias->groups = header->numFrames; galias->groups = LittleLong(header->numFrames);
galias->numverts = surf->numVerts; galias->numverts = LittleLong(surf->numVerts);
galias->numindexes = surf->numTriangles*3; galias->numindexes = LittleLong(surf->numTriangles)*3;
if (parent) if (parent)
parent->nextsurf = (qbyte *)galias - (qbyte *)parent; parent->nextsurf = (qbyte *)galias - (qbyte *)parent;
else else
@ -3645,42 +3645,42 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
#ifndef SERVERONLY #ifndef SERVERONLY
st_array = Hunk_Alloc(sizeof(vec2_t)*galias->numindexes); st_array = Hunk_Alloc(sizeof(vec2_t)*galias->numindexes);
galias->ofs_st_array = (qbyte*)st_array - (qbyte*)galias; galias->ofs_st_array = (qbyte*)st_array - (qbyte*)galias;
inst = (md3St_t*)((qbyte*)surf + surf->ofsSt); inst = (md3St_t*)((qbyte*)surf + LittleLong(surf->ofsSt));
for (i = 0; i < galias->numverts; i++) for (i = 0; i < galias->numverts; i++)
{ {
st_array[i][0] = inst[i].s; st_array[i][0] = LittleFloat(inst[i].s);
st_array[i][1] = inst[i].t; st_array[i][1] = LittleFloat(inst[i].t);
} }
#endif #endif
indexes = Hunk_Alloc(sizeof(*indexes)*galias->numindexes); indexes = Hunk_Alloc(sizeof(*indexes)*galias->numindexes);
galias->ofs_indexes = (qbyte*)indexes - (qbyte*)galias; galias->ofs_indexes = (qbyte*)indexes - (qbyte*)galias;
intris = (md3Triangle_t *)((qbyte*)surf + surf->ofsTriangles); intris = (md3Triangle_t *)((qbyte*)surf + LittleLong(surf->ofsTriangles));
for (i = 0; i < surf->numTriangles; i++) for (i = 0; i < LittleLong(surf->numTriangles); i++)
{ {
indexes[i*3+0] = intris[i].indexes[0]; indexes[i*3+0] = LittleLong(intris[i].indexes[0]);
indexes[i*3+1] = intris[i].indexes[1]; indexes[i*3+1] = LittleLong(intris[i].indexes[1]);
indexes[i*3+2] = intris[i].indexes[2]; indexes[i*3+2] = LittleLong(intris[i].indexes[2]);
} }
group = (galiasgroup_t *)(galias+1); group = (galiasgroup_t *)(galias+1);
invert = (md3XyzNormal_t *)((qbyte*)surf + surf->ofsXyzNormals); invert = (md3XyzNormal_t *)((qbyte*)surf + LittleLong(surf->ofsXyzNormals));
for (i = 0; i < surf->numFrames; i++) for (i = 0; i < LittleLong(surf->numFrames); i++)
{ {
pose = (galiaspose_t *)Hunk_Alloc(sizeof(galiaspose_t) + sizeof(vec3_t)*surf->numVerts pose = (galiaspose_t *)Hunk_Alloc(sizeof(galiaspose_t) + sizeof(vec3_t)*LittleLong(surf->numVerts)
#ifndef SERVERONLY #ifndef SERVERONLY
+ sizeof(vec3_t)*surf->numVerts + sizeof(vec3_t)*LittleLong(surf->numVerts)
#endif #endif
); );
verts = (vec3_t*)(pose+1); verts = (vec3_t*)(pose+1);
pose->ofsverts = (qbyte*)verts - (qbyte*)pose; pose->ofsverts = (qbyte*)verts - (qbyte*)pose;
#ifndef SERVERONLY #ifndef SERVERONLY
normals = verts + surf->numVerts; normals = verts + LittleLong(surf->numVerts);
pose->ofsnormals = (qbyte*)normals - (qbyte*)pose; pose->ofsnormals = (qbyte*)normals - (qbyte*)pose;
#endif #endif
for (j = 0; j < surf->numVerts; j++) for (j = 0; j < LittleLong(surf->numVerts); j++)
{ {
#ifndef SERVERONLY #ifndef SERVERONLY
lat = (float)invert[j].latlong[0] * (2 * M_PI)*(1.0 / 255.0); lat = (float)invert[j].latlong[0] * (2 * M_PI)*(1.0 / 255.0);
@ -3691,7 +3691,7 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
#endif #endif
for (d = 0; d < 3; d++) for (d = 0; d < 3; d++)
{ {
verts[j][d] = invert[j].xyz[d]/64.0f; verts[j][d] = LittleShort(invert[j].xyz[d])/64.0f;
if (verts[j][d]<min[d]) if (verts[j][d]<min[d])
min[d] = verts[j][d]; min[d] = verts[j][d];
if (verts[j][d]>max[d]) if (verts[j][d]>max[d])
@ -3712,11 +3712,11 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
group->poseofs = (qbyte*)pose - (qbyte*)group; group->poseofs = (qbyte*)pose - (qbyte*)group;
group++; group++;
invert += surf->numVerts; invert += LittleLong(surf->numVerts);
} }
#ifndef SERVERONLY #ifndef SERVERONLY
if (surf->numShaders+externalskins) if (LittleLong(surf->numShaders)+externalskins)
{ {
#ifndef Q3SHADERS #ifndef Q3SHADERS
char name[1024]; char name[1024];
@ -3724,11 +3724,11 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
#endif #endif
char shadname[1024]; char shadname[1024];
skin = Hunk_Alloc((surf->numShaders+externalskins)*((sizeof(galiasskin_t)+sizeof(galiastexnum_t)))); skin = Hunk_Alloc((LittleLong(surf->numShaders)+externalskins)*((sizeof(galiasskin_t)+sizeof(galiastexnum_t))));
galias->ofsskins = (qbyte *)skin - (qbyte *)galias; galias->ofsskins = (qbyte *)skin - (qbyte *)galias;
texnum = (galiastexnum_t *)(skin + surf->numShaders+externalskins); texnum = (galiastexnum_t *)(skin + LittleLong(surf->numShaders)+externalskins);
inshader = (md3Shader_t *)((qbyte *)surf + surf->ofsShaders); inshader = (md3Shader_t *)((qbyte *)surf + LittleLong(surf->ofsShaders));
for (i = 0; i < surf->numShaders+externalskins; i++) for (i = 0; i < LittleLong(surf->numShaders)+externalskins; i++)
{ {
skin->texnums = 1; skin->texnums = 1;
skin->ofstexnums = (qbyte *)texnum - (qbyte *)skin; skin->ofstexnums = (qbyte *)texnum - (qbyte *)skin;
@ -3737,7 +3737,7 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
skin->skinheight = 0; skin->skinheight = 0;
skin->skinspeed = 0; skin->skinspeed = 0;
if (i >= surf->numShaders) if (i >= LittleLong(surf->numShaders))
shadname[0] = 0; shadname[0] = 0;
else else
strcpy(shadname, inshader->name); strcpy(shadname, inshader->name);
@ -3823,21 +3823,47 @@ void GL_LoadQ3Model(model_t *mod, void *buffer)
if (r_shadows.value) if (r_shadows.value)
{ {
int *neighbours; int *neighbours;
neighbours = Hunk_Alloc(sizeof(int)*3*surf->numTriangles); neighbours = Hunk_Alloc(sizeof(int)*3*LittleLong(surf->numTriangles));
galias->ofs_trineighbours = (qbyte *)neighbours - (qbyte *)galias; galias->ofs_trineighbours = (qbyte *)neighbours - (qbyte *)galias;
R_BuildTriangleNeighbours(neighbours, indexes, surf->numTriangles); R_BuildTriangleNeighbours(neighbours, indexes, LittleLong(surf->numTriangles));
} }
#endif #endif
surf = (md3Surface_t *)((qbyte *)surf + surf->ofsEnd); surf = (md3Surface_t *)((qbyte *)surf + LittleLong(surf->ofsEnd));
} }
if (!root) if (!root)
root = Hunk_Alloc(sizeof(galiasinfo_t)); root = Hunk_Alloc(sizeof(galiasinfo_t));
root->numtagframes = header->numFrames; root->numtagframes = LittleLong(header->numFrames);
root->numtags = header->numTags; root->numtags = LittleLong(header->numTags);
root->ofstags = (char*)Hunk_Alloc(header->numTags*sizeof(md3tag_t)*header->numFrames) - (char*)root; root->ofstags = (char*)Hunk_Alloc(LittleLong(header->numTags)*sizeof(md3tag_t)*LittleLong(header->numFrames)) - (char*)root;
memcpy((char*)root+root->ofstags, (char*)header+header->ofsTags, header->numTags*sizeof(md3tag_t)*header->numFrames);
{
md3tag_t *src;
md3tag_t *dst;
src = (md3tag_t *)(((unsigned int)header)+LittleLong(header->ofsTags));
dst = (md3tag_t *)(((unsigned int)root)+root->ofstags);
for(i=0;i<LittleLong(header->numTags)*LittleLong(header->numFrames);i++)
{
memcpy(dst->name, src->name, sizeof(dst->name));
for(j=0;j<3;j++)
{
dst->org[j] = LittleFloat(src->org[j]);
}
for(j=0;j<3;j++)
{
for(s=0;s<3;s++)
{
dst->ang[j][s] = LittleFloat(src->ang[j][s]);
}
}
src++;
dst++;
}
}
// //
// move the complete, relocatable alias model to the cache // move the complete, relocatable alias model to the cache