Load override.cfg from config dir to add or override menu controls
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3159 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.7:
|
Changes towards version 0.7:
|
||||||
|
- Load override.cfg from user's dir to add or override menu controls - Alex
|
||||||
- Allow addons to override any content by placing zips into their
|
- Allow addons to override any content by placing zips into their
|
||||||
'shadow-content' dir - Alex
|
'shadow-content' dir - Alex
|
||||||
- Content reorg: font chars now use hexadecimal numbering - Alex
|
- Content reorg: font chars now use hexadecimal numbering - Alex
|
||||||
|
|||||||
+2
-2
@@ -11,8 +11,8 @@ to be called the next iteration of the main game loop (which will occur
|
|||||||
when the current activity (IP, HyperSpace, Communication, Battle) changes.
|
when the current activity (IP, HyperSpace, Communication, Battle) changes.
|
||||||
By setting this, a function can be called from the main loop, thereby
|
By setting this, a function can be called from the main loop, thereby
|
||||||
eliminating threading issues that may otherwise arrise.
|
eliminating threading issues that may otherwise arrise.
|
||||||
The debug key can be specified in keys.cfg by adding a line with a text
|
The debug key can be specified in user's override.cfg by adding a line
|
||||||
similar to "Debug: key F11".
|
with a text similar to "debug.1 = STRING:key F12".
|
||||||
An interactive way to access various debugging code, similar to
|
An interactive way to access various debugging code, similar to
|
||||||
the uio debug mode (see below) is in the works.
|
the uio debug mode (see below) is in the works.
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ initKeyConfig (void)
|
|||||||
|
|
||||||
/* First, load in the menu keys */
|
/* First, load in the menu keys */
|
||||||
LoadResourceIndex (contentDir, "menu.key", "menu.");
|
LoadResourceIndex (contentDir, "menu.key", "menu.");
|
||||||
|
LoadResourceIndex (configDir, "override.cfg", "menu.");
|
||||||
for (i = 0; i < NUM_MENU_KEYS; i++)
|
for (i = 0; i < NUM_MENU_KEYS; i++)
|
||||||
{
|
{
|
||||||
if (!menu_res_names[i])
|
if (!menu_res_names[i])
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ res_GetResource (RESOURCE res)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (desc->resdata.ptr == NULL)
|
||||||
|
loadResourceDesc (desc);
|
||||||
if (desc->resdata.ptr != NULL)
|
if (desc->resdata.ptr != NULL)
|
||||||
return desc->resdata.ptr;
|
++desc->refcount;
|
||||||
|
|
||||||
loadResourceDesc (desc);
|
|
||||||
|
|
||||||
return desc->resdata.ptr;
|
return desc->resdata.ptr;
|
||||||
// May still be NULL, if the load failed.
|
// May still be NULL, if the load failed.
|
||||||
@@ -176,6 +176,13 @@ res_FreeResource (RESOURCE res)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (desc->refcount > 0)
|
||||||
|
--desc->refcount;
|
||||||
|
else
|
||||||
|
log_add (log_Debug, "Warning: freeing an unreferenced resource.");
|
||||||
|
if (desc->refcount > 0)
|
||||||
|
return; // Still references left
|
||||||
|
|
||||||
freeFun = desc->vtable->freeFun;
|
freeFun = desc->vtable->freeFun;
|
||||||
if (freeFun == NULL)
|
if (freeFun == NULL)
|
||||||
{
|
{
|
||||||
@@ -216,7 +223,7 @@ res_DetachResource (RESOURCE res)
|
|||||||
freeFun = desc->vtable->freeFun;
|
freeFun = desc->vtable->freeFun;
|
||||||
if (freeFun == NULL)
|
if (freeFun == NULL)
|
||||||
{
|
{
|
||||||
log_add (log_Debug, "Warning: trying to detatch from a non-heap resource.");
|
log_add (log_Debug, "Warning: trying to detach from a non-heap resource.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,8 +234,16 @@ res_DetachResource (RESOURCE res)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (desc->refcount > 1)
|
||||||
|
{
|
||||||
|
log_add (log_Debug, "Warning: trying to detach a resource referenced "
|
||||||
|
"%u times", desc->refcount);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
result = desc->resdata.ptr;
|
result = desc->resdata.ptr;
|
||||||
desc->resdata.ptr = NULL;
|
desc->resdata.ptr = NULL;
|
||||||
|
desc->refcount = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ typedef struct resource_desc
|
|||||||
char *fname;
|
char *fname;
|
||||||
ResourceHandlers *vtable;
|
ResourceHandlers *vtable;
|
||||||
RESOURCE_DATA resdata;
|
RESOURCE_DATA resdata;
|
||||||
|
// refcount is rudimentary as nothing really frees the descriptors
|
||||||
|
unsigned refcount;
|
||||||
} ResourceDesc;
|
} ResourceDesc;
|
||||||
|
|
||||||
struct resource_index_desc
|
struct resource_index_desc
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ newResourceDesc (const char *res_id, const char *resval)
|
|||||||
strncpy (result->fname, path, pathlen);
|
strncpy (result->fname, path, pathlen);
|
||||||
result->fname[pathlen] = '\0';
|
result->fname[pathlen] = '\0';
|
||||||
result->vtable = vtable;
|
result->vtable = vtable;
|
||||||
|
result->refcount = 0;
|
||||||
|
|
||||||
if (vtable->freeFun == NULL)
|
if (vtable->freeFun == NULL)
|
||||||
{
|
{
|
||||||
@@ -324,6 +325,9 @@ res_GetString (const char *key)
|
|||||||
ResourceDesc *desc = lookupResourceDesc (idx, key);
|
ResourceDesc *desc = lookupResourceDesc (idx, key);
|
||||||
if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING"))
|
if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
/* TODO: Work out exact STRING semantics, specifically, the lifetime of
|
||||||
|
* the returned value. If caller is allowed to reference the returned
|
||||||
|
* value forever, STRING has to be ref-counted. */
|
||||||
return (const char *)desc->resdata.ptr;
|
return (const char *)desc->resdata.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +428,8 @@ res_Remove (const char *key)
|
|||||||
{
|
{
|
||||||
if (oldDesc->resdata.ptr != NULL)
|
if (oldDesc->resdata.ptr != NULL)
|
||||||
{
|
{
|
||||||
log_add (log_Warning, "WARNING: Replacing '%s' while it is live", key);
|
if (oldDesc->refcount > 0)
|
||||||
|
log_add (log_Warning, "WARNING: Replacing '%s' while it is live", key);
|
||||||
if (oldDesc->vtable && oldDesc->vtable->freeFun)
|
if (oldDesc->vtable && oldDesc->vtable->freeFun)
|
||||||
{
|
{
|
||||||
oldDesc->vtable->freeFun(oldDesc->resdata.ptr);
|
oldDesc->vtable->freeFun(oldDesc->resdata.ptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user