diff --git a/lib/gamelib/anim.c b/lib/gamelib/anim.c index 1b0f4140e..6298dec65 100644 --- a/lib/gamelib/anim.c +++ b/lib/gamelib/anim.c @@ -333,11 +333,11 @@ anim_SetVals( char szFileName[], UWORD uwAnimID ) /***************************************************************************/ // the playstation version uses sscanf's ... see animload.c -BASEANIM *anim_LoadFromBuffer(char *pBuffer, UDWORD size) +BASEANIM *anim_LoadFromFile(PHYSFS_file* fileHandle) { - if ( ParseResourceBuffer( pBuffer, size ) == FALSE ) + if ( ParseResourceFile( fileHandle ) == FALSE ) { - debug( LOG_ERROR, "anim_LoadFromBuffer: couldn't parse file\n" ); + debug( LOG_ERROR, "anim_LoadFromFile: couldn't parse file\n" ); abort(); return NULL; } diff --git a/lib/gamelib/anim.h b/lib/gamelib/anim.h index 3b6331125..c44ceb309 100644 --- a/lib/gamelib/anim.h +++ b/lib/gamelib/anim.h @@ -30,6 +30,8 @@ /***************************************************************************/ +#include + #include "lib/framework/types.h" #include "lib/ivis_common/imd.h" #include "maxpidef.h" @@ -129,6 +131,7 @@ ANIMGLOBALS; BOOL anim_Init( GETSHAPEFUNC ); BOOL anim_Shutdown( void ); BASEANIM * anim_LoadFromBuffer(char *pBuffer, UDWORD size); +BASEANIM * anim_LoadFromFile(PHYSFS_file* fileHandle); void anim_ReleaseAnim( BASEANIM *psAnim ); BOOL anim_Create3D( char szPieFileName[], UWORD uwFrames, UWORD uwFrameRate, UWORD uwObj, diff --git a/lib/gamelib/audp_lexer.l b/lib/gamelib/audp_lexer.l index 230c776e4..2d03d8d72 100644 --- a/lib/gamelib/audp_lexer.l +++ b/lib/gamelib/audp_lexer.l @@ -37,34 +37,20 @@ static BOOL g_bParsingSubFile; static FILE *g_fpOld; -/* Pointer to the input buffer */ -static char *pInputBuffer = NULL; -static char *pEndBuffer = NULL; - +/* Handle to the input file */ static PHYSFS_file* pReadFile = NULL; #define YY_INPUT(buf,result,max_size) \ - if (pReadFile == NULL) \ + if (PHYSFS_eof(pReadFile)) \ { \ - if (pInputBuffer != pEndBuffer) { \ - buf[0] = *(pInputBuffer++); result = 1; \ - } else { \ - buf[0] = EOF; result = YY_NULL; \ - } \ + buf[0] = EOF; result = YY_NULL; \ } \ - else \ - { \ - if (PHYSFS_eof(pReadFile)) \ + else { \ + result = PHYSFS_read(pReadFile, buf, 1, max_size); \ + if (result == -1) \ { \ buf[0] = EOF; result = YY_NULL; \ } \ - else { \ - result = PHYSFS_read(pReadFile, buf, 1, max_size); \ - if (result == -1) \ - { \ - buf[0] = EOF; result = YY_NULL; \ - } \ - } \ } void audp_error(char *pMessage,...); @@ -159,22 +145,12 @@ audp_wrap( void ) } /***************************************************************************/ -/* Set the current input buffer for the lexer */ +/* Set the current input file for the lexer */ /***************************************************************************/ -void parserSetInputBuffer(char *pBuffer, UDWORD size) -{ - pInputBuffer = pBuffer; - pEndBuffer = pBuffer + size; - - pReadFile = NULL; -} - void parserSetInputFile(PHYSFS_file* fileHandle) { pReadFile = fileHandle; - - pInputBuffer = pEndBuffer = NULL; } /***************************************************************************/ diff --git a/lib/gamelib/audp_parser.y b/lib/gamelib/audp_parser.y index 9a5619f3e..01de45b43 100644 --- a/lib/gamelib/audp_parser.y +++ b/lib/gamelib/audp_parser.y @@ -226,17 +226,6 @@ void audp_error(char *pMessage,...) /***************************************************************************/ /* Read a resource file */ - -BOOL ParseResourceBuffer(char *pData, UDWORD fileSize) -{ - // Tell lex about the input buffer - parserSetInputBuffer( pData, fileSize ); - - audp_parse(); - - return TRUE; -} - BOOL ParseResourceFile(PHYSFS_file* fileHandle) { // Tell lex about the input file diff --git a/lib/gamelib/parser.h b/lib/gamelib/parser.h index ae74997b1..dbd41e975 100644 --- a/lib/gamelib/parser.h +++ b/lib/gamelib/parser.h @@ -32,9 +32,7 @@ extern void IncludeFile( char szFileName[] ); extern BOOL ParseFile( char szFileName[] ); extern void IncludeFile( char szFileName[] ); -extern void parserSetInputBuffer(char *pBuffer, UDWORD size); extern void parserSetInputFile(PHYSFS_file* fileHandle); -extern BOOL ParseResourceBuffer(char *pData, UDWORD fileSize); extern BOOL ParseResourceFile(PHYSFS_file* fileHandle); extern BOOL ParsingBuffer( void ); extern void parseGetErrorData(int *pLine, char **ppText); diff --git a/src/data.c b/src/data.c index 3b7c32aa1..fc9fd4c4d 100644 --- a/src/data.c +++ b/src/data.c @@ -1012,34 +1012,39 @@ static BOOL dataAudioCfgLoad(const char* fileName, void **ppData) } /* Load an anim file */ -static BOOL dataAnimLoad(char *pBuffer, UDWORD size, void **ppData) +static BOOL dataAnimLoad(const char *fileName, void **ppData) { - BASEANIM *psAnim; - - if ( (psAnim = anim_LoadFromBuffer( pBuffer, size )) == NULL ) + PHYSFS_file* fileHandle = PHYSFS_openRead(fileName); + if (fileHandle == NULL) { + *ppData = NULL; return FALSE; } - /* copy anim for return */ - *ppData = psAnim; + *ppData = anim_LoadFromFile(fileHandle); + PHYSFS_close(fileHandle); - - return TRUE; + return *ppData != NULL; } - /* Load an audio config file */ -static BOOL dataAnimCfgLoad(char *pBuffer, UDWORD size, void **ppData) +static BOOL dataAnimCfgLoad(const char *fileName, void **ppData) { + BOOL success; + PHYSFS_file* fileHandle = PHYSFS_openRead(fileName); *ppData = NULL; - if ( ParseResourceBuffer( pBuffer, size ) == FALSE ) + + if (fileHandle == NULL) { return FALSE; } - return TRUE; + success = ParseResourceFile(fileHandle); + + PHYSFS_close(fileHandle); + + return success; } @@ -1183,8 +1188,6 @@ static const RES_TYPE_MIN_BUF BufferResourceTypes[] = {"IMGPAGE", dataIMGPAGELoad, dataIMGPAGERelease}, {"TERTILES", NULL, NULL}, // This version was used when running with the software renderer. {"HWTERTILES", dataHWTERTILESLoad, dataHWTERTILESRelease}, // freed by 3d shutdow},// Tertiles Files. This version used when running with hardware renderer. - {"ANI", dataAnimLoad, dataAnimRelease}, - {"ANIMCFG", dataAnimCfgLoad, NULL}, {"IMG", dataIMGLoad, dataIMGRelease}, {"TEXPAGE", bufferTexPageLoad, dataTexPageRelease}, {"IMD", dataIMDBufferLoad, (RES_FREE)iV_IMDRelease}, @@ -1201,6 +1204,8 @@ static const RES_TYPE_MIN_FILE FileResourceTypes[] = { {"WAV", dataAudioLoad, (RES_FREE)sound_ReleaseTrack}, {"AUDIOCFG", dataAudioCfgLoad, NULL}, + {"ANI", dataAnimLoad, dataAnimRelease}, + {"ANIMCFG", dataAnimCfgLoad, NULL}, }; /* Pass all the data loading functions to the framework library */