mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: mod_studio: implement loading sequence files on BE
This commit is contained in:
@@ -550,6 +550,38 @@ static void Mod_StudioCalcRotations( int boneused[], int numbones, const byte *p
|
||||
}
|
||||
|
||||
|
||||
static void Mod_SwapStudioSeqGroupAnims( studiohdr_t *phdr, mstudioseqdesc_t *pseq, byte *buf )
|
||||
{
|
||||
mstudioanim_t *panim = (mstudioanim_t *)( buf + pseq->animindex );
|
||||
int numanims = pseq->numblends * phdr->numbones;
|
||||
|
||||
for( int j = 0; j < numanims; j++, panim++ )
|
||||
{
|
||||
le_struct_swap( mstudioanim_swap, panim );
|
||||
|
||||
for( int k = 0; k < 6; k++ )
|
||||
{
|
||||
if( panim->offset[k] == 0 )
|
||||
continue;
|
||||
|
||||
mstudioanimvalue_t *panimvalue = (mstudioanimvalue_t *)((byte *)panim + panim->offset[k] );
|
||||
|
||||
int frames = pseq->numframes;
|
||||
while( frames > 0 )
|
||||
{
|
||||
int valid = panimvalue->num.valid;
|
||||
int total = panimvalue->num.total;
|
||||
|
||||
for( int l = 1; l <= valid; l++ )
|
||||
panimvalue[l].value = LittleShort( panimvalue[l].value );
|
||||
|
||||
panimvalue += valid + 1;
|
||||
frames -= total;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
StudioGetAnim
|
||||
@@ -558,17 +590,10 @@ StudioGetAnim
|
||||
*/
|
||||
void *R_StudioGetAnim( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc )
|
||||
{
|
||||
mstudioseqgroup_t *pseqgroup;
|
||||
cache_user_t *paSequences;
|
||||
fs_offset_t filesize;
|
||||
byte *buf;
|
||||
|
||||
pseqgroup = (mstudioseqgroup_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqgroupindex) + pseqdesc->seqgroup;
|
||||
if( pseqdesc->seqgroup == 0 )
|
||||
return ((byte *)m_pStudioHeader + pseqdesc->animindex);
|
||||
|
||||
paSequences = (cache_user_t *)m_pSubModel->submodels;
|
||||
|
||||
cache_user_t *paSequences = (cache_user_t *)m_pSubModel->submodels;
|
||||
if( paSequences == NULL )
|
||||
{
|
||||
paSequences = (cache_user_t *)Mem_Calloc( com_studiocache, MAXSTUDIOGROUPS * sizeof( cache_user_t ));
|
||||
@@ -578,23 +603,31 @@ void *R_StudioGetAnim( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstud
|
||||
// check for already loaded
|
||||
if( !Mod_CacheCheck(( cache_user_t *)&( paSequences[pseqdesc->seqgroup] )))
|
||||
{
|
||||
string filepath, modelname, modelpath;
|
||||
|
||||
string modelname;
|
||||
COM_FileBase( m_pSubModel->name, modelname, sizeof( modelname ));
|
||||
|
||||
string modelpath;
|
||||
COM_ExtractFilePath( m_pSubModel->name, modelpath );
|
||||
|
||||
// NOTE: here we build real sub-animation filename because stupid user may rename model without recompile
|
||||
string filepath;
|
||||
Q_snprintf( filepath, sizeof( filepath ), "%s/%s%i%i.mdl", modelpath, modelname, pseqdesc->seqgroup / 10, pseqdesc->seqgroup % 10 );
|
||||
|
||||
buf = FS_LoadFile( filepath, &filesize, false );
|
||||
if( !buf || !filesize ) Host_Error( "%s: can't load %s\n", __func__, filepath );
|
||||
if( IDSEQGRPHEADER != *(uint *)buf ) Host_Error( "%s: %s is corrupted\n", __func__, filepath );
|
||||
fs_offset_t filesize;
|
||||
byte *buf = FS_LoadFile( filepath, &filesize, false );
|
||||
if( !buf || !filesize )
|
||||
Host_Error( "%s: can't load %s\n", __func__, filepath );
|
||||
if( LittleLong( IDSEQGRPHEADER ) != *(uint *)buf )
|
||||
Host_Error( "%s: %s is corrupted\n", __func__, filepath );
|
||||
|
||||
Con_Printf( "loading: %s\n", filepath );
|
||||
|
||||
paSequences[pseqdesc->seqgroup].data = Mem_Calloc( com_studiocache, filesize );
|
||||
memcpy( paSequences[pseqdesc->seqgroup].data, buf, filesize );
|
||||
Mem_Free( buf );
|
||||
|
||||
Mod_SwapStudioSeqGroupAnims( m_pStudioHeader, pseqdesc,
|
||||
(byte *)paSequences[pseqdesc->seqgroup].data );
|
||||
}
|
||||
|
||||
return ((byte *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex);
|
||||
@@ -1023,34 +1056,7 @@ static qboolean Mod_SwapStudioModel( const char *name, void *buffer, size_t buff
|
||||
if( pseq->seqgroup != 0 )
|
||||
continue;
|
||||
|
||||
mstudioanim_t *panim = (mstudioanim_t *)( mod_base + pseq->animindex );
|
||||
int numanims = pseq->numblends * phdr->numbones;
|
||||
|
||||
for( int j = 0; j < numanims; j++, panim++ )
|
||||
{
|
||||
le_struct_swap( mstudioanim_swap, panim );
|
||||
|
||||
for( int k = 0; k < 6; k++ )
|
||||
{
|
||||
if( panim->offset[k] == 0 )
|
||||
continue;
|
||||
|
||||
mstudioanimvalue_t *panimvalue = (mstudioanimvalue_t *)((byte *)panim + panim->offset[k] );
|
||||
|
||||
int frames = pseq->numframes;
|
||||
while( frames > 0 )
|
||||
{
|
||||
int valid = panimvalue->num.valid;
|
||||
int total = panimvalue->num.total;
|
||||
|
||||
for( int l = 1; l <= valid; l++ )
|
||||
panimvalue[l].value = LittleShort( panimvalue[l].value );
|
||||
|
||||
panimvalue += valid + 1;
|
||||
frames -= total;
|
||||
}
|
||||
}
|
||||
}
|
||||
Mod_SwapStudioSeqGroupAnims( phdr, pseq, mod_base );
|
||||
}
|
||||
|
||||
for( int i = 0; i < phdr->numbodyparts; i++ )
|
||||
|
||||
Reference in New Issue
Block a user