Resource loader now descriptor-based, not filestream-based.
This will allow for non-file resources, and eventual merging of configuration and other data into the resource system. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2970 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.7:
|
Changes towards version 0.7:
|
||||||
|
- ResourceLoadFun is now descriptor-based, not stream-based - Michael
|
||||||
- Removed RES_TYPE enum, folded into ResourceDesc - Michael
|
- Removed RES_TYPE enum, folded into ResourceDesc - Michael
|
||||||
- Split STRTAB into STRTAB (strings) and BINTAB (color/xlat tables) - Michael
|
- Split STRTAB into STRTAB (strings) and BINTAB (color/xlat tables) - Michael
|
||||||
- Removed internal references to defunct resource types - Michael
|
- Removed internal references to defunct resource types - Michael
|
||||||
|
|||||||
@@ -316,11 +316,17 @@ _ReleaseCodeResData (void *data)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetCodeFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, GetCodeResData);
|
||||||
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
InstallCodeResType ()
|
InstallCodeResType ()
|
||||||
{
|
{
|
||||||
return (InstallResTypeVectors ("CODE",
|
return (InstallResTypeVectors ("CODE",
|
||||||
GetCodeResData, _ReleaseCodeResData));
|
GetCodeFileData, _ReleaseCodeResData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,24 @@
|
|||||||
|
|
||||||
#include "gfxintrn.h"
|
#include "gfxintrn.h"
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetCelFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetCelData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetFontFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetFontData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
InstallGraphicResTypes (void)
|
InstallGraphicResTypes (void)
|
||||||
{
|
{
|
||||||
InstallResTypeVectors ("GFXRES", _GetCelData, _ReleaseCelData);
|
InstallResTypeVectors ("GFXRES", GetCelFileData, _ReleaseCelData);
|
||||||
InstallResTypeVectors ("FONTRES", _GetFontData, _ReleaseFontData);
|
InstallResTypeVectors ("FONTRES", GetFontFileData, _ReleaseFontData);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,38 +34,39 @@ typedef const char *RESOURCE;
|
|||||||
|
|
||||||
extern const char *_cur_resfile_name;
|
extern const char *_cur_resfile_name;
|
||||||
|
|
||||||
typedef void *(ResourceLoadFun) (uio_Stream *fp, DWORD len);
|
typedef void *(ResourceLoadFun) (const char *pathname);
|
||||||
typedef BOOLEAN (ResourceFreeFun) (void *handle);
|
typedef BOOLEAN (ResourceFreeFun) (void *handle);
|
||||||
|
|
||||||
extern uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename,
|
typedef void *(ResourceLoadFileFun) (uio_Stream *fp, DWORD len);
|
||||||
const char *mode);
|
|
||||||
extern int ReadResFile (void *lpBuf, COUNT size, COUNT count, uio_Stream *fp);
|
|
||||||
extern int WriteResFile (const void *lpBuf, COUNT size, COUNT count,
|
|
||||||
uio_Stream *fp);
|
|
||||||
extern int GetResFileChar (uio_Stream *fp);
|
|
||||||
extern int PutResFileChar (char ch, uio_Stream *fp);
|
|
||||||
extern int PutResFileNewline (uio_Stream *fp);
|
|
||||||
extern long SeekResFile (uio_Stream *fp, long offset, int whence);
|
|
||||||
extern long TellResFile (uio_Stream *fp);
|
|
||||||
extern long LengthResFile (uio_Stream *fp);
|
|
||||||
extern BOOLEAN res_CloseResFile (uio_Stream *fp);
|
|
||||||
extern BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename);
|
|
||||||
|
|
||||||
extern RESOURCE_INDEX InitResourceSystem ();
|
void *LoadResourceFromPath(const char *pathname, ResourceLoadFileFun fn);
|
||||||
extern void UninitResourceSystem (void);
|
|
||||||
extern BOOLEAN InstallResTypeVectors (const char *res_type,
|
|
||||||
ResourceLoadFun *loadFun, ResourceFreeFun *freeFun);
|
|
||||||
extern void *res_GetResource (RESOURCE res);
|
|
||||||
extern void *res_DetachResource (RESOURCE res);
|
|
||||||
extern BOOLEAN FreeResource (RESOURCE res);
|
|
||||||
extern COUNT CountResourceTypes (void);
|
|
||||||
|
|
||||||
extern void LoadResourceIndex (uio_DirHandle *dir, const char *filename);
|
uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename, const char *mode);
|
||||||
|
int ReadResFile (void *lpBuf, COUNT size, COUNT count, uio_Stream *fp);
|
||||||
|
int WriteResFile (const void *lpBuf, COUNT size, COUNT count, uio_Stream *fp);
|
||||||
|
int GetResFileChar (uio_Stream *fp);
|
||||||
|
int PutResFileChar (char ch, uio_Stream *fp);
|
||||||
|
int PutResFileNewline (uio_Stream *fp);
|
||||||
|
long SeekResFile (uio_Stream *fp, long offset, int whence);
|
||||||
|
long TellResFile (uio_Stream *fp);
|
||||||
|
long LengthResFile (uio_Stream *fp);
|
||||||
|
BOOLEAN res_CloseResFile (uio_Stream *fp);
|
||||||
|
BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename);
|
||||||
|
|
||||||
extern void *GetResourceData (uio_Stream *fp, DWORD length);
|
RESOURCE_INDEX InitResourceSystem ();
|
||||||
|
void UninitResourceSystem (void);
|
||||||
|
BOOLEAN InstallResTypeVectors (const char *res_type, ResourceLoadFun *loadFun, ResourceFreeFun *freeFun);
|
||||||
|
void *res_GetResource (RESOURCE res);
|
||||||
|
void *res_DetachResource (RESOURCE res);
|
||||||
|
BOOLEAN FreeResource (RESOURCE res);
|
||||||
|
COUNT CountResourceTypes (void);
|
||||||
|
|
||||||
|
void LoadResourceIndex (uio_DirHandle *dir, const char *filename);
|
||||||
|
|
||||||
|
void *GetResourceData (uio_Stream *fp, DWORD length);
|
||||||
|
|
||||||
#define AllocResourceData HMalloc
|
#define AllocResourceData HMalloc
|
||||||
extern BOOLEAN FreeResourceData (void *);
|
BOOLEAN FreeResourceData (void *);
|
||||||
|
|
||||||
#include "strlib.h"
|
#include "strlib.h"
|
||||||
|
|
||||||
|
|||||||
@@ -35,13 +35,12 @@ lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res) {
|
|||||||
void *
|
void *
|
||||||
loadResourceDesc (ResourceDesc *desc)
|
loadResourceDesc (ResourceDesc *desc)
|
||||||
{
|
{
|
||||||
desc->resdata = loadResource (desc->fname,
|
desc->resdata = desc->vtable->loadFun (desc->fname);
|
||||||
desc->vtable->loadFun);
|
|
||||||
return desc->resdata;
|
return desc->resdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
loadResource(const char *path, ResourceLoadFun *loadFun)
|
LoadResourceFromPath (const char *path, ResourceLoadFileFun *loadFun)
|
||||||
{
|
{
|
||||||
uio_Stream *stream;
|
uio_Stream *stream;
|
||||||
long dataLen;
|
long dataLen;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
ResourceDesc *lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res);
|
ResourceDesc *lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res);
|
||||||
void *loadResourceDesc (ResourceDesc *desc);
|
void *loadResourceDesc (ResourceDesc *desc);
|
||||||
void *loadResource(const char *path, ResourceLoadFun *loadFun);
|
|
||||||
|
|
||||||
void _set_current_index_header (RESOURCE_INDEX newResourceIndex);
|
void _set_current_index_header (RESOURCE_INDEX newResourceIndex);
|
||||||
RESOURCE_INDEX _get_current_index_header (void);
|
RESOURCE_INDEX _get_current_index_header (void);
|
||||||
|
|||||||
@@ -18,11 +18,23 @@
|
|||||||
|
|
||||||
#include "sndintrn.h"
|
#include "sndintrn.h"
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetSoundBankFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetSoundBankData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetMusicFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetMusicData);
|
||||||
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
InstallAudioResTypes (void)
|
InstallAudioResTypes (void)
|
||||||
{
|
{
|
||||||
InstallResTypeVectors ("SNDRES", _GetSoundBankData, _ReleaseSoundBankData);
|
InstallResTypeVectors ("SNDRES", GetSoundBankFileData, _ReleaseSoundBankData);
|
||||||
InstallResTypeVectors ("MUSICRES", _GetMusicData, _ReleaseMusicData);
|
InstallResTypeVectors ("MUSICRES", GetMusicFileData, _ReleaseMusicData);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,23 @@
|
|||||||
|
|
||||||
#include "strintrn.h"
|
#include "strintrn.h"
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetStringTableFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetStringData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
GetBinaryTableFileData (const char *pathname)
|
||||||
|
{
|
||||||
|
return LoadResourceFromPath (pathname, _GetBinaryTableData);
|
||||||
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
InstallStringTableResType (void)
|
InstallStringTableResType (void)
|
||||||
{
|
{
|
||||||
InstallResTypeVectors ("STRTAB", _GetStringData, FreeResourceData);
|
InstallResTypeVectors ("STRTAB", GetStringTableFileData, FreeResourceData);
|
||||||
InstallResTypeVectors ("BINTAB", _GetBinaryTableData, FreeResourceData);
|
InstallResTypeVectors ("BINTAB", GetBinaryTableFileData, FreeResourceData);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user