Refactored the ResourceIndex type to fit UQM's standard for opaque types
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2967 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -25,7 +25,9 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "libs/uio.h"
|
#include "libs/uio.h"
|
||||||
|
|
||||||
typedef struct resource_index *RESOURCE_INDEX;
|
typedef struct resource_index_desc RESOURCE_INDEX_DESC;
|
||||||
|
typedef RESOURCE_INDEX_DESC *RESOURCE_INDEX;
|
||||||
|
|
||||||
typedef const char *RESOURCE;
|
typedef const char *RESOURCE;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ const char *_cur_resfile_name;
|
|||||||
// At other times, it is NULL.
|
// At other times, it is NULL.
|
||||||
|
|
||||||
static ResourceDesc *
|
static ResourceDesc *
|
||||||
lookupResourceDesc (ResourceIndex *idx, RESOURCE res) {
|
lookupResourceDesc (RESOURCE_INDEX idx, RESOURCE res) {
|
||||||
return (ResourceDesc *) CharHashTable_find (idx->map, res);
|
return (ResourceDesc *) CharHashTable_find (idx->map, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc)
|
loadResourceDesc (RESOURCE_INDEX idx, ResourceDesc *desc)
|
||||||
{
|
{
|
||||||
desc->resdata = loadResource (desc->fname,
|
desc->resdata = loadResource (desc->fname,
|
||||||
idx->typeInfo.handlers[desc->restype].loadFun);
|
idx->typeInfo.handlers[desc->restype].loadFun);
|
||||||
@@ -79,7 +79,7 @@ err:
|
|||||||
void *
|
void *
|
||||||
res_GetResource (RESOURCE res)
|
res_GetResource (RESOURCE res)
|
||||||
{
|
{
|
||||||
ResourceIndex *resourceIndex;
|
RESOURCE_INDEX resourceIndex;
|
||||||
ResourceDesc *desc;
|
ResourceDesc *desc;
|
||||||
|
|
||||||
if (res == NULL_RESOURCE)
|
if (res == NULL_RESOURCE)
|
||||||
@@ -113,7 +113,7 @@ res_FreeResource (RESOURCE res)
|
|||||||
{
|
{
|
||||||
ResourceDesc *desc;
|
ResourceDesc *desc;
|
||||||
ResourceFreeFun *freeFun;
|
ResourceFreeFun *freeFun;
|
||||||
ResourceIndex *idx;
|
RESOURCE_INDEX idx;
|
||||||
|
|
||||||
desc = lookupResourceDesc (_get_current_index_header(), res);
|
desc = lookupResourceDesc (_get_current_index_header(), res);
|
||||||
if (desc == NULL)
|
if (desc == NULL)
|
||||||
|
|||||||
@@ -46,15 +46,12 @@ typedef struct
|
|||||||
ResourceHandlers *handlers;
|
ResourceHandlers *handlers;
|
||||||
} ResourceTypeInfo;
|
} ResourceTypeInfo;
|
||||||
|
|
||||||
struct resource_index
|
struct resource_index_desc
|
||||||
{
|
{
|
||||||
CharHashTable_HashTable *map;
|
CharHashTable_HashTable *map;
|
||||||
ResourceTypeInfo typeInfo;
|
ResourceTypeInfo typeInfo;
|
||||||
size_t numRes;
|
size_t numRes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* XXX: This should almost certainly be folded into RESOURCE_INDEX wherever possible */
|
|
||||||
typedef struct resource_index ResourceIndex;
|
|
||||||
|
|
||||||
#endif /* _INDEX_H */
|
#endif /* _INDEX_H */
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,15 @@
|
|||||||
|
|
||||||
#include "resintrn.h"
|
#include "resintrn.h"
|
||||||
|
|
||||||
static ResourceIndex *curResourceIndex;
|
static RESOURCE_INDEX curResourceIndex;
|
||||||
|
|
||||||
void
|
void
|
||||||
_set_current_index_header (ResourceIndex *newResourceIndex)
|
_set_current_index_header (RESOURCE_INDEX newResourceIndex)
|
||||||
{
|
{
|
||||||
curResourceIndex = newResourceIndex;
|
curResourceIndex = newResourceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceIndex *
|
RESOURCE_INDEX
|
||||||
_get_current_index_header (void)
|
_get_current_index_header (void)
|
||||||
{
|
{
|
||||||
return curResourceIndex;
|
return curResourceIndex;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
static RESOURCE_INDEX
|
static RESOURCE_INDEX
|
||||||
allocResourceIndex (void) {
|
allocResourceIndex (void) {
|
||||||
RESOURCE_INDEX ndx = HMalloc (sizeof (struct resource_index));
|
RESOURCE_INDEX ndx = HMalloc (sizeof (RESOURCE_INDEX_DESC));
|
||||||
ndx->typeInfo.numTypes = 0;
|
ndx->typeInfo.numTypes = 0;
|
||||||
ndx->typeInfo.handlers = NULL;
|
ndx->typeInfo.handlers = NULL;
|
||||||
ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, 0, 0.85, 0.9);
|
ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, 0, 0.85, 0.9);
|
||||||
@@ -69,7 +69,7 @@ newResourceDesc (const char *res_id, const char *resval)
|
|||||||
int pathlen;
|
int pathlen;
|
||||||
RES_TYPE resType;
|
RES_TYPE resType;
|
||||||
ResourceDesc *result;
|
ResourceDesc *result;
|
||||||
ResourceIndex *idx = _get_current_index_header ();
|
RESOURCE_INDEX idx = _get_current_index_header ();
|
||||||
|
|
||||||
path = strchr (resval, ':');
|
path = strchr (resval, ':');
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
@@ -164,7 +164,7 @@ process_resource_desc (const char *key, const char *value)
|
|||||||
RESOURCE_INDEX
|
RESOURCE_INDEX
|
||||||
InitResourceSystem (void)
|
InitResourceSystem (void)
|
||||||
{
|
{
|
||||||
ResourceIndex *ndx = allocResourceIndex ();
|
RESOURCE_INDEX ndx = allocResourceIndex ();
|
||||||
|
|
||||||
_set_current_index_header (ndx);
|
_set_current_index_header (ndx);
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ InstallResTypeVectors (RES_TYPE resType, ResourceLoadFun *loadFun,
|
|||||||
ResourceFreeFun *freeFun)
|
ResourceFreeFun *freeFun)
|
||||||
{
|
{
|
||||||
ResourceHandlers handlers;
|
ResourceHandlers handlers;
|
||||||
ResourceIndex *idx = _get_current_index_header ();
|
RESOURCE_INDEX idx = _get_current_index_header ();
|
||||||
handlers.loadFun = loadFun;
|
handlers.loadFun = loadFun;
|
||||||
handlers.freeFun = freeFun;
|
handlers.freeFun = freeFun;
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
#include "reslib.h"
|
#include "reslib.h"
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
|
|
||||||
void *loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc);
|
void *loadResourceDesc (RESOURCE_INDEX idx, ResourceDesc *desc);
|
||||||
void *loadResource(const char *path, ResourceLoadFun *loadFun);
|
void *loadResource(const char *path, ResourceLoadFun *loadFun);
|
||||||
|
|
||||||
void _set_current_index_header (ResourceIndex *newResourceIndex);
|
void _set_current_index_header (RESOURCE_INDEX newResourceIndex);
|
||||||
ResourceIndex *_get_current_index_header (void);
|
RESOURCE_INDEX _get_current_index_header (void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _RESINTRN_H */
|
#endif /* _RESINTRN_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user