From: <av...@us...> - 2009-06-30 00:08:35
|
Revision: 3159 http://sc2.svn.sourceforge.net/sc2/?rev=3159&view=rev Author: avolkov Date: 2009-06-30 00:07:20 +0000 (Tue, 30 Jun 2009) Log Message: ----------- Load override.cfg from config dir to add or override menu controls Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/doc/devel/debug trunk/sc2/src/sc2code/libs/input/sdl/input.c trunk/sc2/src/sc2code/libs/resource/getres.c trunk/sc2/src/sc2code/libs/resource/index.h trunk/sc2/src/sc2code/libs/resource/resinit.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/ChangeLog 2009-06-30 00:07:20 UTC (rev 3159) @@ -1,4 +1,5 @@ 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 'shadow-content' dir - Alex - Content reorg: font chars now use hexadecimal numbering - Alex Modified: trunk/sc2/doc/devel/debug =================================================================== --- trunk/sc2/doc/devel/debug 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/doc/devel/debug 2009-06-30 00:07:20 UTC (rev 3159) @@ -11,8 +11,8 @@ when the current activity (IP, HyperSpace, Communication, Battle) changes. By setting this, a function can be called from the main loop, thereby eliminating threading issues that may otherwise arrise. -The debug key can be specified in keys.cfg by adding a line with a text -similar to "Debug: key F11". +The debug key can be specified in user's override.cfg by adding a line +with a text similar to "debug.1 = STRING:key F12". An interactive way to access various debugging code, similar to the uio debug mode (see below) is in the works. Modified: trunk/sc2/src/sc2code/libs/input/sdl/input.c =================================================================== --- trunk/sc2/src/sc2code/libs/input/sdl/input.c 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/src/sc2code/libs/input/sdl/input.c 2009-06-30 00:07:20 UTC (rev 3159) @@ -150,6 +150,7 @@ /* First, load in the menu keys */ LoadResourceIndex (contentDir, "menu.key", "menu."); + LoadResourceIndex (configDir, "override.cfg", "menu."); for (i = 0; i < NUM_MENU_KEYS; i++) { if (!menu_res_names[i]) Modified: trunk/sc2/src/sc2code/libs/resource/getres.c =================================================================== --- trunk/sc2/src/sc2code/libs/resource/getres.c 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/src/sc2code/libs/resource/getres.c 2009-06-30 00:07:20 UTC (rev 3159) @@ -121,11 +121,11 @@ return NULL; } + if (desc->resdata.ptr == NULL) + loadResourceDesc (desc); if (desc->resdata.ptr != NULL) - return desc->resdata.ptr; + ++desc->refcount; - loadResourceDesc (desc); - return desc->resdata.ptr; // May still be NULL, if the load failed. } @@ -176,6 +176,13 @@ 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; if (freeFun == NULL) { @@ -216,7 +223,7 @@ freeFun = desc->vtable->freeFun; 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; } @@ -227,8 +234,16 @@ 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; desc->resdata.ptr = NULL; + desc->refcount = 0; return result; } Modified: trunk/sc2/src/sc2code/libs/resource/index.h =================================================================== --- trunk/sc2/src/sc2code/libs/resource/index.h 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/src/sc2code/libs/resource/index.h 2009-06-30 00:07:20 UTC (rev 3159) @@ -37,6 +37,8 @@ char *fname; ResourceHandlers *vtable; RESOURCE_DATA resdata; + // refcount is rudimentary as nothing really frees the descriptors + unsigned refcount; } ResourceDesc; struct resource_index_desc Modified: trunk/sc2/src/sc2code/libs/resource/resinit.c =================================================================== --- trunk/sc2/src/sc2code/libs/resource/resinit.c 2009-06-29 05:05:48 UTC (rev 3158) +++ trunk/sc2/src/sc2code/libs/resource/resinit.c 2009-06-30 00:07:20 UTC (rev 3159) @@ -106,6 +106,7 @@ strncpy (result->fname, path, pathlen); result->fname[pathlen] = '\0'; result->vtable = vtable; + result->refcount = 0; if (vtable->freeFun == NULL) { @@ -324,6 +325,9 @@ ResourceDesc *desc = lookupResourceDesc (idx, key); if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING")) 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; } @@ -424,7 +428,8 @@ { 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) { oldDesc->vtable->freeFun(oldDesc->resdata.ptr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |