2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-09-25 09:46:28 -07:00
|
|
|
/*! \file frameresource.h
|
|
|
|
* \brief Resource file processing functions
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _resource_h
|
|
|
|
#define _resource_h
|
|
|
|
|
|
|
|
/* Maximum number of characters in a resource type */
|
|
|
|
#define RESTYPE_MAXCHAR 20
|
|
|
|
|
|
|
|
/* Maximum number of characters in a resource ID */
|
|
|
|
#define RESID_MAXCHAR 40
|
|
|
|
|
|
|
|
/* Function pointer for a function that loads from a memory buffer */
|
2006-08-12 09:52:37 -07:00
|
|
|
typedef BOOL (*RES_BUFFERLOAD)(char *pBuffer, UDWORD size, void **pData);
|
2007-04-08 14:39:24 -07:00
|
|
|
/* Function pointer for a function that loads from a filename */
|
|
|
|
typedef BOOL (*RES_FILELOAD)(const char *pFile, void **pData);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Function pointer for releasing a resource loaded by the above functions */
|
|
|
|
typedef void (*RES_FREE)(void *pData);
|
|
|
|
|
|
|
|
/* callback type for resload display callback*/
|
|
|
|
typedef void (*RESLOAD_CALLBACK)(void);
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct res_data
|
|
|
|
{
|
2007-04-08 14:39:24 -07:00
|
|
|
const char *aID; // ID of the resource - filename from the .wrf - e.g. "TRON.PIE"
|
2007-06-28 10:47:08 -07:00
|
|
|
void *pData; // pointer to the acutal data
|
|
|
|
SDWORD blockID; // which of the blocks is it in (so we can clear some of them...)
|
|
|
|
|
|
|
|
UDWORD HashedID; // hashed version of the name of the id
|
|
|
|
struct res_data *psNext; // next entry - most likely to be following on!
|
2006-07-04 06:35:01 -07:00
|
|
|
UDWORD usage;
|
2007-06-28 10:47:08 -07:00
|
|
|
} RES_DATA;
|
|
|
|
|
|
|
|
|
|
|
|
// New reduced resource type ... specially for PSX
|
|
|
|
// These types are statically defined in data.c
|
|
|
|
typedef struct _res_type
|
|
|
|
{
|
|
|
|
// type is still needed on psx ... strings are defined in source - data.c (yak!)
|
2006-11-03 13:35:50 -08:00
|
|
|
char aType[RESTYPE_MAXCHAR]; // type string (e.g. "PIE" - just for debug use only, only aplicable when loading from wrf (not wdg)
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-07-04 06:35:01 -07:00
|
|
|
RES_BUFFERLOAD buffLoad; // routine to process the data for this type
|
2007-06-28 10:47:08 -07:00
|
|
|
RES_FREE release; // routine to release the data (NULL indicates none)
|
|
|
|
|
|
|
|
// we must have a pointer to the data here so that we can do a resGetData();
|
|
|
|
RES_DATA *psRes; // Linked list of data items of this type
|
|
|
|
UDWORD HashedType; // hashed version of the name of the id - // a null hashedtype indicates end of list
|
2006-07-04 06:35:01 -07:00
|
|
|
|
2007-04-08 14:39:24 -07:00
|
|
|
RES_FILELOAD fileLoad; // This isn't really used any more ?
|
2007-06-28 10:47:08 -07:00
|
|
|
struct _res_type *psNext;
|
|
|
|
} RES_TYPE;
|
|
|
|
|
|
|
|
|
|
|
|
/* set the function to call when loading files with resloadfile*/
|
2006-09-13 02:09:05 -07:00
|
|
|
extern void resSetLoadCallback(RESLOAD_CALLBACK funcToCall);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Initialise the resource module */
|
|
|
|
extern BOOL resInitialise(void);
|
|
|
|
|
|
|
|
/* Shutdown the resource module */
|
|
|
|
extern void resShutDown(void);
|
|
|
|
|
|
|
|
// set the base resource directory
|
2006-11-03 13:35:50 -08:00
|
|
|
extern void resSetBaseDir(char *pResDir);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Parse the res file */
|
2006-09-24 12:11:34 -07:00
|
|
|
BOOL resLoad(const char *pResFile, SDWORD blockID,
|
2007-04-03 03:33:26 -07:00
|
|
|
char *pLoadBuffer, SDWORD bufferSize);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Release all the resources currently loaded and the resource load functions */
|
|
|
|
extern void resReleaseAll(void);
|
|
|
|
|
|
|
|
// release the data for a particular block ID
|
|
|
|
extern void resReleaseBlockData(SDWORD blockID);
|
|
|
|
|
|
|
|
/* Release all the resources currently loaded but keep the resource load functions */
|
|
|
|
extern void resReleaseAllData(void);
|
|
|
|
|
|
|
|
/* Add a buffer load and release function for a file type */
|
2006-11-03 13:35:50 -08:00
|
|
|
extern BOOL resAddBufferLoad(const char *pType, RES_BUFFERLOAD buffLoad,
|
2007-06-28 10:47:08 -07:00
|
|
|
RES_FREE release);
|
|
|
|
|
2007-04-08 14:39:24 -07:00
|
|
|
/* Add a file name load and release function for a file type */
|
|
|
|
extern BOOL resAddFileLoad(const char *pType, RES_FILELOAD fileLoad,
|
|
|
|
RES_FREE release);
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Call the load function for a file */
|
2007-04-08 14:39:24 -07:00
|
|
|
extern BOOL resLoadFile(const char *pType, const char *pFile);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Add data to the resource system
|
2006-11-03 13:35:50 -08:00
|
|
|
extern BOOL resAddData(char *pType, char *pID, void *pData);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Return the resource for a type and ID */
|
2006-11-03 13:35:50 -08:00
|
|
|
extern void *resGetDataFromHash(const char *pType, UDWORD HashedID);
|
|
|
|
extern void *resGetData(const char *pType, const char *pID);
|
|
|
|
extern BOOL resPresent(const char *pType, const char *pID);
|
|
|
|
void resToLower(char *pStr);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// return the HashedID string for a piece of data
|
2006-11-03 13:35:50 -08:00
|
|
|
extern BOOL resGetHashfromData(const char *pType, const void *pData, UDWORD *pHash);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
//return last imd resource
|
|
|
|
char *GetLastResourceFilename(void);
|
|
|
|
// Set the resource name of the last resource file loaded
|
|
|
|
void SetLastResourceFilename(char *pName);
|
|
|
|
|
|
|
|
// Returns the filename of the last resource file loaded
|
|
|
|
UDWORD GetLastHashName(void);
|
|
|
|
// Set the resource name of the last resource file loaded
|
|
|
|
void SetLastHashName(UDWORD HashName);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|