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:
mcmartin
2008-05-14 03:15:29 +00:00
parent ffd50ee6fd
commit 2ddc969faf
8 changed files with 78 additions and 36 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.7:
- ResourceLoadFun is now descriptor-based, not stream-based - Michael
- Removed RES_TYPE enum, folded into ResourceDesc - Michael
- Split STRTAB into STRTAB (strings) and BINTAB (color/xlat tables) - Michael
- Removed internal references to defunct resource types - Michael
+7 -1
View File
@@ -316,11 +316,17 @@ _ReleaseCodeResData (void *data)
return TRUE;
}
static void *
GetCodeFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, GetCodeResData);
}
BOOLEAN
InstallCodeResType ()
{
return (InstallResTypeVectors ("CODE",
GetCodeResData, _ReleaseCodeResData));
GetCodeFileData, _ReleaseCodeResData));
}
+14 -2
View File
@@ -18,12 +18,24 @@
#include "gfxintrn.h"
static void *
GetCelFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetCelData);
}
static void *
GetFontFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetFontData);
}
BOOLEAN
InstallGraphicResTypes (void)
{
InstallResTypeVectors ("GFXRES", _GetCelData, _ReleaseCelData);
InstallResTypeVectors ("FONTRES", _GetFontData, _ReleaseFontData);
InstallResTypeVectors ("GFXRES", GetCelFileData, _ReleaseCelData);
InstallResTypeVectors ("FONTRES", GetFontFileData, _ReleaseFontData);
return (TRUE);
}
+26 -25
View File
@@ -34,38 +34,39 @@ typedef const char *RESOURCE;
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);
extern uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename,
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);
typedef void *(ResourceLoadFileFun) (uio_Stream *fp, DWORD len);
extern RESOURCE_INDEX InitResourceSystem ();
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);
void *LoadResourceFromPath(const char *pathname, ResourceLoadFileFun fn);
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
extern BOOLEAN FreeResourceData (void *);
BOOLEAN FreeResourceData (void *);
#include "strlib.h"
+2 -3
View File
@@ -35,13 +35,12 @@ lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res) {
void *
loadResourceDesc (ResourceDesc *desc)
{
desc->resdata = loadResource (desc->fname,
desc->vtable->loadFun);
desc->resdata = desc->vtable->loadFun (desc->fname);
return desc->resdata;
}
void *
loadResource(const char *path, ResourceLoadFun *loadFun)
LoadResourceFromPath (const char *path, ResourceLoadFileFun *loadFun)
{
uio_Stream *stream;
long dataLen;
-1
View File
@@ -25,7 +25,6 @@
ResourceDesc *lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res);
void *loadResourceDesc (ResourceDesc *desc);
void *loadResource(const char *path, ResourceLoadFun *loadFun);
void _set_current_index_header (RESOURCE_INDEX newResourceIndex);
RESOURCE_INDEX _get_current_index_header (void);
+14 -2
View File
@@ -18,11 +18,23 @@
#include "sndintrn.h"
static void *
GetSoundBankFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetSoundBankData);
}
static void *
GetMusicFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetMusicData);
}
BOOLEAN
InstallAudioResTypes (void)
{
InstallResTypeVectors ("SNDRES", _GetSoundBankData, _ReleaseSoundBankData);
InstallResTypeVectors ("MUSICRES", _GetMusicData, _ReleaseMusicData);
InstallResTypeVectors ("SNDRES", GetSoundBankFileData, _ReleaseSoundBankData);
InstallResTypeVectors ("MUSICRES", GetMusicFileData, _ReleaseMusicData);
return (TRUE);
}
+14 -2
View File
@@ -18,11 +18,23 @@
#include "strintrn.h"
static void *
GetStringTableFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetStringData);
}
static void *
GetBinaryTableFileData (const char *pathname)
{
return LoadResourceFromPath (pathname, _GetBinaryTableData);
}
BOOLEAN
InstallStringTableResType (void)
{
InstallResTypeVectors ("STRTAB", _GetStringData, FreeResourceData);
InstallResTypeVectors ("BINTAB", _GetBinaryTableData, FreeResourceData);
InstallResTypeVectors ("STRTAB", GetStringTableFileData, FreeResourceData);
InstallResTypeVectors ("BINTAB", GetBinaryTableFileData, FreeResourceData);
return TRUE;
}