64-bit compatible MD3 loading.

git-svn-id: https://svn.eduke32.com/eduke32@738 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2008-05-24 06:53:56 +00:00
parent 0189cf6064
commit dd7983a4e8
2 changed files with 37 additions and 20 deletions

View file

@ -115,25 +115,42 @@ typedef struct
char nam[64]; //ascz surface name char nam[64]; //ascz surface name
int flags; //? int flags; //?
int numframes, numshaders, numverts, numtris; //numframes same as md3head,max shade=~256,vert=~4096,tri=~8192 int numframes, numshaders, numverts, numtris; //numframes same as md3head,max shade=~256,vert=~4096,tri=~8192
md3tri_t *tris; //file format: rel offs from md3surf int ofstris;
md3shader_t *shaders; //file format: rel offs from md3surf int ofsshaders;
md3uv_t *uv; //file format: rel offs from md3surf int ofsuv;
md3xyzn_t *xyzn; //file format: rel offs from md3surf int ofsxyzn;
int ofsend; int ofsend;
// DO NOT read directly to this structure
// the following block is NOT in the file format
// be sure to use the SIZEOF_MD3SURF_T macro
md3tri_t *tris;
md3shader_t *shaders;
md3uv_t *uv;
md3xyzn_t *xyzn;
} md3surf_t; } md3surf_t;
#define SIZEOF_MD3SURF_T (sizeof(md3surf_t)-4*sizeof(void*))
typedef struct typedef struct
{ {
int id, vers; //id=IDP3(0x33806873), vers=15 int id, vers; //id=IDP3(0x33806873), vers=15
char nam[64]; //ascz path in PK3 char nam[64]; //ascz path in PK3
int flags; //? int flags; //?
int numframes, numtags, numsurfs, numskins; //max=~1024,~16,~32,numskins=artifact of MD2; use shader field instead int numframes, numtags, numsurfs, numskins; //max=~1024,~16,~32,numskins=artifact of MD2; use shader field instead
md3frame_t *frames; //file format: abs offs int ofsframes;
md3tag_t *tags; //file format: abs offs int ofstags;
md3surf_t *surfs; //file format: abs offs int ofssurfs;
int eof; //file format: abs offs int eof;
// DO NOT read directly to this structure
// the following block is NOT in the file format
// be sure to use the SIZEOF_MD3HEAD_T macro
md3frame_t *frames;
md3tag_t *tags;
md3surf_t *surfs;
} md3head_t; } md3head_t;
#define SIZEOF_MD3HEAD_T (sizeof(md3head_t)-3*sizeof(void*))
typedef struct typedef struct
{ {
//WARNING: This top block is a union between md2model&md3model: Make sure it matches! //WARNING: This top block is a union between md2model&md3model: Make sure it matches!

View file

@ -1277,12 +1277,12 @@ static md3model *md3load(int fil)
m->muladdframes = NULL; m->muladdframes = NULL;
kread(fil,&m->head,sizeof(md3head_t)); kread(fil,&m->head,SIZEOF_MD3HEAD_T);
m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers); m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers);
m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes); m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes);
m->head.numtags = B_LITTLE32(m->head.numtags); m->head.numsurfs = B_LITTLE32(m->head.numsurfs); m->head.numtags = B_LITTLE32(m->head.numtags); m->head.numsurfs = B_LITTLE32(m->head.numsurfs);
m->head.numskins = B_LITTLE32(m->head.numskins); m->head.frames = (md3frame_t*)B_LITTLE32((int)m->head.frames); m->head.numskins = B_LITTLE32(m->head.numskins); m->head.ofsframes = B_LITTLE32(m->head.ofsframes);
m->head.tags = (md3tag_t*)B_LITTLE32((int)m->head.tags); m->head.surfs = (md3surf_t*)B_LITTLE32((int)m->head.surfs); m->head.ofstags = B_LITTLE32(m->head.ofstags); m->head.ofssurfs = B_LITTLE32(m->head.ofssurfs);
m->head.eof = B_LITTLE32(m->head.eof); m->head.eof = B_LITTLE32(m->head.eof);
if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { free(m); return(0); } //"IDP3" if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { free(m); return(0); } //"IDP3"
@ -1290,21 +1290,21 @@ static md3model *md3load(int fil)
m->numskins = m->head.numskins; //<- dead code? m->numskins = m->head.numskins; //<- dead code?
m->numframes = m->head.numframes; m->numframes = m->head.numframes;
ofsurf = (int)m->head.surfs; ofsurf = (int)m->head.ofssurfs;
klseek(fil,(int)m->head.frames,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t); klseek(fil,m->head.ofsframes,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t);
m->head.frames = (md3frame_t *)malloc(i); if (!m->head.frames) { free(m); return(0); } m->head.frames = (md3frame_t *)malloc(i); if (!m->head.frames) { free(m); return(0); }
kread(fil,m->head.frames,i); kread(fil,m->head.frames,i);
if (m->head.numtags == 0) m->head.tags = NULL; if (m->head.numtags == 0) m->head.tags = NULL;
else else
{ {
klseek(fil,(int)m->head.tags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t); klseek(fil,m->head.ofstags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t);
m->head.tags = (md3tag_t *)malloc(i); if (!m->head.tags) { free(m->head.frames); free(m); return(0); } m->head.tags = (md3tag_t *)malloc(i); if (!m->head.tags) { free(m->head.frames); free(m); return(0); }
kread(fil,m->head.tags,i); kread(fil,m->head.tags,i);
} }
klseek(fil,(int)m->head.surfs,SEEK_SET); i = m->head.numsurfs*sizeof(md3surf_t); klseek(fil,m->head.ofssurfs,SEEK_SET); i = m->head.numsurfs*sizeof(md3surf_t);
m->head.surfs = (md3surf_t *)malloc(i); if (!m->head.surfs) { if (m->head.tags) free(m->head.tags); free(m->head.frames); free(m); return(0); } m->head.surfs = (md3surf_t *)malloc(i); if (!m->head.surfs) { if (m->head.tags) free(m->head.tags); free(m->head.frames); free(m); return(0); }
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
@ -1330,7 +1330,7 @@ static md3model *md3load(int fil)
for (surfi=0;surfi<m->head.numsurfs;surfi++) for (surfi=0;surfi<m->head.numsurfs;surfi++)
{ {
s = &m->head.surfs[surfi]; s = &m->head.surfs[surfi];
klseek(fil,ofsurf,SEEK_SET); kread(fil,s,sizeof(md3surf_t)); klseek(fil,ofsurf,SEEK_SET); kread(fil,s,SIZEOF_MD3SURF_T);
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
{ {
@ -1341,10 +1341,10 @@ static md3model *md3load(int fil)
} }
#endif #endif
offs[0] = ofsurf+((int)(s->tris)); leng[0] = s->numtris*sizeof(md3tri_t); offs[0] = ofsurf+s->ofstris; leng[0] = s->numtris*sizeof(md3tri_t);
offs[1] = ofsurf+((int)(s->shaders)); leng[1] = s->numshaders*sizeof(md3shader_t); offs[1] = ofsurf+s->ofsshaders; leng[1] = s->numshaders*sizeof(md3shader_t);
offs[2] = ofsurf+((int)(s->uv)); leng[2] = s->numverts*sizeof(md3uv_t); offs[2] = ofsurf+s->ofsuv; leng[2] = s->numverts*sizeof(md3uv_t);
offs[3] = ofsurf+((int)(s->xyzn)); leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t); offs[3] = ofsurf+s->ofsxyzn; leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t);
//memoryusage += (s->numverts * s->numframes * sizeof(md3xyzn_t)); //memoryusage += (s->numverts * s->numframes * sizeof(md3xyzn_t));
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage); //OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);