VOID PAL_FreeResources( VOID ) /*++ Purpose: Free all loaded resources. Parameters: None. Return value: None. --*/ { if (gpResources != NULL) { // // Free all loaded sprites // PAL_FreePlayerSprites(); PAL_FreeEventObjectSprites(); // // Free map // PAL_FreeMap(gpResources->lpMap); // // Delete the instance // free(gpResources); } gpResources = NULL; }
/*++ Free all loaded resources. --*/ VOID PAL_FreeResources(void) { if (gpResources != NULL) { // // Free all loaded sprites // PAL_FreePlayerSprites(); PAL_FreeEventObjectSprites(); // // Free map // PAL_FreeMap(gpResources->lpMap); // // Delete the instance // free(gpResources); } gpResources = NULL; }
VOID PAL_LoadResources( VOID ) /*++ Purpose: Load the game resources if needed. Parameters: None. Return value: None. --*/ { int i, index, l, n; WORD wPlayerID, wSpriteNum; if (gpResources == NULL || gpResources->bLoadFlags == 0) { return; } // // Load scene // if (gpResources->bLoadFlags & kLoadScene) { FILE *fpMAP, *fpGOP; fpMAP = UTIL_OpenRequiredFile("map.mkf"); fpGOP = UTIL_OpenRequiredFile("gop.mkf"); if (gpGlobals->fEnteringScene) { gpGlobals->wScreenWave = 0; gpGlobals->sWaveProgression = 0; } // // Free previous loaded scene (sprites and map) // PAL_FreeEventObjectSprites(); PAL_FreeMap(gpResources->lpMap); // // Load map // i = gpGlobals->wNumScene - 1; gpResources->lpMap = PAL_LoadMap(gpGlobals->g.rgScene[i].wMapNum, fpMAP, fpGOP); if (gpResources->lpMap == NULL) { fclose(fpMAP); fclose(fpGOP); TerminateOnError("PAL_LoadResources(): Fail to load map #%d (scene #%d) !", gpGlobals->g.rgScene[i].wMapNum, gpGlobals->wNumScene); } // // Load sprites // index = gpGlobals->g.rgScene[i].wEventObjectIndex; gpResources->nEventObject = gpGlobals->g.rgScene[i + 1].wEventObjectIndex; gpResources->nEventObject -= index; if (gpResources->nEventObject > 0) { gpResources->lppEventObjectSprites = (LPSPRITE *)UTIL_calloc(gpResources->nEventObject, sizeof(LPSPRITE)); } for (i = 0; i < gpResources->nEventObject; i++, index++) { n = gpGlobals->g.lprgEventObject[index].wSpriteNum; if (n == 0) { // // this event object has no sprite // gpResources->lppEventObjectSprites[i] = NULL; continue; } l = PAL_MKFGetDecompressedSize(n, gpGlobals->f.fpMGO); gpResources->lppEventObjectSprites[i] = (LPSPRITE)UTIL_malloc(l); if (PAL_MKFDecompressChunk(gpResources->lppEventObjectSprites[i], l, n, gpGlobals->f.fpMGO) > 0) { gpGlobals->g.lprgEventObject[index].nSpriteFramesAuto = PAL_SpriteGetNumFrames(gpResources->lppEventObjectSprites[i]); } } gpGlobals->partyoffset = PAL_XY(160, 112); fclose(fpGOP); fclose(fpMAP); } // // Load player sprites // if (gpResources->bLoadFlags & kLoadPlayerSprite) { // // Free previous loaded player sprites // PAL_FreePlayerSprites(); for (i = 0; i <= (short)gpGlobals->wMaxPartyMemberIndex; i++) { wPlayerID = gpGlobals->rgParty[i].wPlayerRole; assert(wPlayerID < MAX_PLAYER_ROLES); // // Load player sprite // wSpriteNum = gpGlobals->g.PlayerRoles.rgwSpriteNum[wPlayerID]; l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO); gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l); PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum, gpGlobals->f.fpMGO); } if (gpGlobals->nFollower > 0) { // // Load the follower sprite // wSpriteNum = gpGlobals->rgParty[i].wPlayerRole; l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO); gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l); PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum, gpGlobals->f.fpMGO); } } // // Clear all of the load flags // gpResources->bLoadFlags = 0; }