diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 841dfdd8f..748731cf9 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.7: +- .cfg files are now kept as subtrees of the resource map - Michael +- Flight control data no longer unnecessarily copied to config directory - Michael - Index loading/saving now can operate on subtrees - Michael - Videos vs. slide now controlled by a '3dovideo' addon - Michael - New video resource type for 3DO videos - Michael diff --git a/sc2/content/menu.key b/sc2/content/menu.key index f702d0d0f..89b721d46 100644 --- a/sc2/content/menu.key +++ b/sc2/content/menu.key @@ -6,79 +6,79 @@ # Menu controls. Both sets of arrow keys, basically. Paging controls # moving quickly through the file lists in Super Melee. Zooming # controls zoom controls in the starmap. "Cancel" is also used to get -# you into menu mode to begin with. There is a "menu.Special" command +# you into menu mode to begin with. There is a "Special" command # currently unused by the game. It seems to have been originally used # to call up details on starships in the Super Melee selection screen. # Arrow key controls... -menu.up.1 = key Up -menu.down.1 = key Down -menu.right.1 = key Right -menu.left.1 = key Left -menu.pageup.1 = key PageUp -menu.pagedown.1 = key PageDown -menu.home.1 = key Home -menu.end.1 = key End -menu.zoomin.1 = key PageUp -menu.zoomout.1 = key PageDown -menu.select.1 = key Return -menu.select.2 = key RightControl -menu.cancel.1 = key Space -menu.cancel.2 = key RightShift +up.1 = STRING:key Up +down.1 = STRING:key Down +right.1 = STRING:key Right +left.1 = STRING:key Left +pageup.1 = STRING:key PageUp +pagedown.1 = STRING:key PageDown +home.1 = STRING:key Home +end.1 = STRING:key End +zoomin.1 = STRING:key PageUp +zoomout.1 = STRING:key PageDown +select.1 = STRING:key Return +select.2 = STRING:key RightControl +cancel.1 = STRING:key Space +cancel.2 = STRING:key RightShift # ... and the number pad. Note that zoom controls on the starmap are # different from the paging controls in Super Melee. -menu.up.2 = key Keypad-8 -menu.down.2 = key Keypad-2 -menu.left.2 = key Keypad-4 -menu.right.2 = key Keypad-6 -menu.pageup.2 = key Keypad-9 -menu.pagedown.2 = key Keypad-3 -menu.home.2 = key Keypad-7 -menu.end.2 = key Keypad-1 -menu.zoomin.2 = key Keypad-+ -menu.zoomout.2 = key Keypad-- -menu.select.3 = key Keypad-Enter -menu.cancel.3 = key Keypad-0 +up.2 = STRING:key Keypad-8 +down.2 = STRING:key Keypad-2 +left.2 = STRING:key Keypad-4 +right.2 = STRING:key Keypad-6 +pageup.2 = STRING:key Keypad-9 +pagedown.2 = STRING:key Keypad-3 +home.2 = STRING:key Keypad-7 +end.2 = STRING:key Keypad-1 +zoomin.2 = STRING:key Keypad-+ +zoomout.2 = STRING:key Keypad-- +select.3 = STRING:key Keypad-Enter +cancel.3 = STRING:key Keypad-0 # System utility keys. -menu.delete.1 = key Delete -menu.delete.2 = key Keypad-. -menu.backspace.1 = key Backspace -menu.editcancel.1 = key Escape -menu.search.1 = key / -menu.next.1 = key Tab -menu.pause.1 = key Pause -menu.pause.2 = key F1 -menu.exit.1 = key F10 -menu.fullscreen.1 = key F11 -menu.special.1 = key LeftAlt -menu.special.2 = key RightAlt +delete.1 = STRING:key Delete +delete.2 = STRING:key Keypad-. +backspace.1 = STRING:key Backspace +editcancel.1 = STRING:key Escape +search.1 = STRING:key / +next.1 = STRING:key Tab +pause.1 = STRING:key Pause +pause.2 = STRING:key F1 +exit.1 = STRING:key F10 +fullscreen.1 = STRING:key F11 +special.1 = STRING:key LeftAlt +special.2 = STRING:key RightAlt # Joystick controls, for both port 1 and 2. -menu.up.3 = joystick 0 axis 1 negative -menu.down.3 = joystick 0 axis 1 positive -menu.left.3 = joystick 0 axis 0 negative -menu.right.3 = joystick 0 axis 0 positive +up.3 = STRING:joystick 0 axis 1 negative +down.3 = STRING:joystick 0 axis 1 positive +left.3 = STRING:joystick 0 axis 0 negative +right.3 = STRING:joystick 0 axis 0 positive -menu.up.4 = joystick 0 hat 0 up -menu.down.4 = joystick 0 hat 0 down -menu.left.4 = joystick 0 hat 0 left -menu.right.4 = joystick 0 hat 0 right +up.4 = STRING:joystick 0 hat 0 up +down.4 = STRING:joystick 0 hat 0 down +left.4 = STRING:joystick 0 hat 0 left +right.4 = STRING:joystick 0 hat 0 right -menu.cancel.4 = joystick 0 button 1 -menu.select.4 = joystick 0 button 0 +cancel.4 = STRING:joystick 0 button 1 +select.4 = STRING:joystick 0 button 0 -menu.up.5 = joystick 1 axis 1 negative -menu.down.5 = joystick 1 axis 1 positive -menu.left.5 = joystick 1 axis 0 negative -menu.right.5 = joystick 1 axis 0 positive +up.5 = STRING:joystick 1 axis 1 negative +down.5 = STRING:joystick 1 axis 1 positive +left.5 = STRING:joystick 1 axis 0 negative +right.5 = STRING:joystick 1 axis 0 positive -menu.up.6 = joystick 1 hat 0 up -menu.down.6 = joystick 1 hat 0 down -menu.left.6 = joystick 1 hat 0 left -menu.right.6 = joystick 1 hat 0 right +up.6 = STRING:joystick 1 hat 0 up +down.6 = STRING:joystick 1 hat 0 down +left.6 = STRING:joystick 1 hat 0 left +right.6 = STRING:joystick 1 hat 0 right -menu.cancel.5 = joystick 1 button 1 -menu.select.5 = joystick 1 button 0 +cancel.5 = STRING:joystick 1 button 1 +select.5 = STRING:joystick 1 button 0 diff --git a/sc2/content/uqm.key b/sc2/content/uqm.key index a4d0fbb99..5308ae4f0 100644 --- a/sc2/content/uqm.key +++ b/sc2/content/uqm.key @@ -1,71 +1,71 @@ -keys.1.name = Arrows -keys.1.up.1 = key Up -keys.1.down.1 = key Down -keys.1.left.1 = key Left -keys.1.right.1 = key Right -keys.1.weapon.1 = key RightControl -keys.1.special.1 = key RightShift -keys.1.up.2 = key Keypad-8 -keys.1.down.2 = key Keypad-2 -keys.1.left.2 = key Keypad-4 -keys.1.right.2 = key Keypad-6 -keys.1.weapon.2 = key Return -keys.1.special.2 = key Keypad-0 -keys.1.escape.1 = key Escape +1.name = STRING:Arrows +1.up.1 = STRING:key Up +1.down.1 = STRING:key Down +1.left.1 = STRING:key Left +1.right.1 = STRING:key Right +1.weapon.1 = STRING:key RightControl +1.special.1 = STRING:key RightShift +1.up.2 = STRING:key Keypad-8 +1.down.2 = STRING:key Keypad-2 +1.left.2 = STRING:key Keypad-4 +1.right.2 = STRING:key Keypad-6 +1.weapon.2 = STRING:key Return +1.special.2 = STRING:key Keypad-0 +1.escape.1 = STRING:key Escape -keys.2.name = WASD -keys.2.up.1 = key w -keys.2.down.1 = key s -keys.2.left.1 = key a -keys.2.right.1 = key d -keys.2.weapon.1 = key v -keys.2.special.1 = key b -keys.2.escape.1 = key Escape +2.name = STRING:WASD +2.up.1 = STRING:key w +2.down.1 = STRING:key s +2.left.1 = STRING:key a +2.right.1 = STRING:key d +2.weapon.1 = STRING:key v +2.special.1 = STRING:key b +2.escape.1 = STRING:key Escape -keys.3.name = Arrows (2) -keys.3.up.1 = key Up -keys.3.down.1 = key Down -keys.3.left.1 = key Left -keys.3.right.1 = key Right -keys.3.up.2 = key Keypad-8 -keys.3.down.2 = key Keypad-2 -keys.3.left.2 = key Keypad-4 -keys.3.right.2 = key Keypad-6 -keys.3.weapon.1 = key ] -keys.3.special.1 = key [ -keys.3.escape.1 = key Escape +3.name = STRING:Arrows (2) +3.up.1 = STRING:key Up +3.down.1 = STRING:key Down +3.left.1 = STRING:key Left +3.right.1 = STRING:key Right +3.up.2 = STRING:key Keypad-8 +3.down.2 = STRING:key Keypad-2 +3.left.2 = STRING:key Keypad-4 +3.right.2 = STRING:key Keypad-6 +3.weapon.1 = STRING:key ] +3.special.1 = STRING:key [ +3.escape.1 = STRING:key Escape -keys.4.name = ESDF -keys.4.up.1 = key e -keys.4.down.1 = key d -keys.4.left.1 = key s -keys.4.right.1 = key f -keys.4.weapon.1 = key q -keys.4.special.1 = key a -keys.4.escape.1 = key Escape +4.name = STRING:ESDF +4.up.1 = STRING:key e +4.down.1 = STRING:key d +4.left.1 = STRING:key s +4.right.1 = STRING:key f +4.weapon.1 = STRING:key q +4.special.1 = STRING:key a +4.escape.1 = STRING:key Escape -keys.5.name = Joystick 1 -keys.5.up.1 = joystick 0 axis 1 negative -keys.5.down.1 = joystick 0 axis 1 positive -keys.5.left.1 = joystick 0 axis 0 negative -keys.5.right.1 = joystick 0 axis 0 positive -keys.5.up.2 = joystick 0 hat 0 up -keys.5.down.2 = joystick 0 hat 0 down -keys.5.left.2 = joystick 0 hat 0 left -keys.5.right.2 = joystick 0 hat 0 right -keys.5.weapon.1 = joystick 0 button 0 -keys.5.special.1 = joystick 0 button 1 -keys.5.escape.1 = key Escape +5.name = STRING:Joystick 1 +5.up.1 = STRING:joystick 0 axis 1 negative +5.down.1 = STRING:joystick 0 axis 1 positive +5.left.1 = STRING:joystick 0 axis 0 negative +5.right.1 = STRING:joystick 0 axis 0 positive +5.up.2 = STRING:joystick 0 hat 0 up +5.down.2 = STRING:joystick 0 hat 0 down +5.left.2 = STRING:joystick 0 hat 0 left +5.right.2 = STRING:joystick 0 hat 0 right +5.weapon.1 = STRING:joystick 0 button 0 +5.special.1 = STRING:joystick 0 button 1 +5.escape.1 = STRING:key Escape -keys.6.name = Joystick 2 -keys.6.up.1 = joystick 1 axis 1 negative -keys.6.down.1 = joystick 1 axis 1 positive -keys.6.left.1 = joystick 1 axis 0 negative -keys.6.right.1 = joystick 1 axis 0 positive -keys.6.up.2 = joystick 1 hat 0 up -keys.6.down.2 = joystick 1 hat 0 down -keys.6.left.2 = joystick 1 hat 0 left -keys.6.right.2 = joystick 1 hat 0 right -keys.6.weapon.1 = joystick 1 button 0 -keys.6.special.1 = joystick 1 button 1 -keys.6.escape.1 = key Escape +6.name = STRING:Joystick 2 +6.up.1 = STRING:joystick 1 axis 1 negative +6.down.1 = STRING:joystick 1 axis 1 positive +6.left.1 = STRING:joystick 1 axis 0 negative +6.right.1 = STRING:joystick 1 axis 0 positive +6.up.2 = STRING:joystick 1 hat 0 up +6.down.2 = STRING:joystick 1 hat 0 down +6.left.2 = STRING:joystick 1 hat 0 left +6.right.2 = STRING:joystick 1 hat 0 right +6.weapon.1 = STRING:joystick 1 button 0 +6.special.1 = STRING:joystick 1 button 1 +6.escape.1 = STRING:key Escape diff --git a/sc2/src/sc2code/libs/input/sdl/input.c b/sc2/src/sc2code/libs/input/sdl/input.c index ad0da589e..7050e9ce7 100644 --- a/sc2/src/sc2code/libs/input/sdl/input.c +++ b/sc2/src/sc2code/libs/input/sdl/input.c @@ -146,11 +146,10 @@ register_flight_controls (void) static void initKeyConfig (void) { - uio_Stream *fp; int i; /* First, load in the menu keys */ - res_LoadFilename (contentDir, "menu.key", NULL); + LoadResourceIndex (contentDir, "menu.key", "menu."); for (i = 0; i < NUM_MENU_KEYS; i++) { if (!menu_res_names[i]) @@ -158,30 +157,15 @@ initKeyConfig (void) register_menu_controls (i); } - fp = res_OpenResFile (configDir, "flight.cfg", "rt"); - if (!fp) + LoadResourceIndex (configDir, "flight.cfg", "keys."); + if (!res_HasKey ("keys.1.name")) { - if (copyFile (contentDir, "uqm.key", - configDir, "flight.cfg") == -1) - { - log_add (log_Fatal, "Error: Could not copy default key config " - "to user config dir: %s.", strerror (errno)); - exit (EXIT_FAILURE); - } - log_add (log_Info, "Copying default key config file to user " - "config dir."); - - if ((fp = res_OpenResFile (configDir, "flight.cfg", "rt")) == NULL) - { - log_add (log_Fatal, "Error: Could not open flight.cfg"); - exit (EXIT_FAILURE); - } + /* Either flight.cfg doesn't exist, or we're using an old version + of flight.cfg, and thus we wound up loading untyped values into + 'keys.keys.1.name' and such. Load the defaults from the content + directory. */ + LoadResourceIndex (contentDir, "uqm.key", "keys."); } - - res_LoadFile (fp, NULL); - // TODO RES070 - // res_LoadFile (fp, "keys."); - res_CloseResFile (fp); register_flight_controls (); @@ -454,16 +438,7 @@ RebindInputState (int template, int control, int index) void SaveKeyConfiguration (uio_DirHandle *path, const char *fname) { - uio_Stream *f; - - f = res_OpenResFile (path, fname, "wb"); - if (f) - { - res_SaveFile (f, "keys.", FALSE); - // TODO RES070 - // res_SaveFile (f, "keys.", TRUE); - res_CloseResFile (f); - } + SaveResourceIndex (path, fname, "keys.", TRUE); } void diff --git a/sc2/src/sc2code/libs/reslib.h b/sc2/src/sc2code/libs/reslib.h index e6963889c..f69e3128b 100644 --- a/sc2/src/sc2code/libs/reslib.h +++ b/sc2/src/sc2code/libs/reslib.h @@ -59,7 +59,6 @@ long LengthResFile (uio_Stream *fp); BOOLEAN res_CloseResFile (uio_Stream *fp); BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename); -RESOURCE_INDEX InitResourceSystem (); void UninitResourceSystem (void); BOOLEAN InstallResTypeVectors (const char *res_type, ResourceLoadFun *loadFun, ResourceFreeFun *freeFun, ResourceStringFun *stringFun); void *res_GetResource (RESOURCE res); @@ -99,13 +98,6 @@ extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, #define GetDirEntryContents GetStringContents /* Key-Value resources */ -void res_ClearTables (void); - -void res_LoadFilename (uio_DirHandle *path, const char *fname, const char *prefix); -void res_SaveFilename (uio_DirHandle *path, const char *fname, const char *root, BOOLEAN strip_root); - -void res_LoadFile (uio_Stream *fname, const char *prefix); -void res_SaveFile (uio_Stream *fname, const char *root, BOOLEAN strip_root); BOOLEAN res_HasKey (const char *key); diff --git a/sc2/src/sc2code/libs/resource/Makeinfo b/sc2/src/sc2code/libs/resource/Makeinfo index 40632db20..9359322a6 100644 --- a/sc2/src/sc2code/libs/resource/Makeinfo +++ b/sc2/src/sc2code/libs/resource/Makeinfo @@ -1,2 +1,2 @@ -uqm_CFILES="direct.c filecntl.c getres.c loadres.c mapres.c - propfile.c resdata.c resinit.c stringbank.c" +uqm_CFILES="direct.c filecntl.c getres.c loadres.c stringbank.c + propfile.c resinit.c" diff --git a/sc2/src/sc2code/libs/resource/mapres.c b/sc2/src/sc2code/libs/resource/mapres.c deleted file mode 100644 index 123d7bcaf..000000000 --- a/sc2/src/sc2code/libs/resource/mapres.c +++ /dev/null @@ -1,250 +0,0 @@ -/* mapres.c, Copyright (c) 2005 Michael C. Martin */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope thta it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include -#include -#include "libs/reslib.h" -#include "libs/log.h" -#include "libs/uio/charhashtable.h" -#include "propfile.h" -#include "stringbank.h" - -/* The CharHashTable owns its keys, but not its values. We will keep the - values in a StringBank. */ - -static CharHashTable_HashTable *map = NULL; -static stringbank *bank = NULL; - -static void -check_map_init (void) -{ - if (map == NULL) { - map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, 0, 0.85, 0.9); - } - if (bank == NULL) { - bank = StringBank_Create (); - } -} - -void -res_ClearTables (void) -{ - if (map != NULL) { - CharHashTable_deleteHashTable (map); - map = NULL; - } - if (bank != NULL) { - StringBank_Free (bank); - bank = NULL; - } -} - -BOOLEAN -res_Remove (const char *key) -{ - return CharHashTable_remove (map, key); -} - -/* Type conversion routines. */ -static const char * -bool2str (BOOLEAN b) -{ - return b ? "yes" : "no"; -} - -static const char * -int2str (int i) { - char buf[20]; - sprintf (buf, "%d", i); - return StringBank_AddOrFindString (bank, buf); -} - -static int -str2int (const char *s) { - return atoi(s); -} - -static BOOLEAN -str2bool (const char *s) { - if (!strcasecmp (s, "yes") || - !strcasecmp (s, "true") || - !strcasecmp (s, "1") ) - return TRUE; - return FALSE; -} - -BOOLEAN -res_IsBoolean (const char *key) -{ - const char *d; - check_map_init (); - - d = res_GetString (key); - if (!d) return 0; - - return !strcasecmp (d, "yes") || - !strcasecmp (d, "no") || - !strcasecmp (d, "true") || - !strcasecmp (d, "false") || - !strcasecmp (d, "0") || - !strcasecmp (d, "1") || - !strcasecmp (d, ""); -} - -BOOLEAN -res_IsInteger (const char *key) -{ - const char *d; - check_map_init (); - - d = res_GetString (key); - while (*d) { - if (!isdigit (*d)) - return 0; - d++; - } - return 1; -} - -const char * -res_GetString (const char *key) -{ - check_map_init (); - return CharHashTable_find (map, key); -} - -void -res_PutString (const char *key, const char *value) -{ - check_map_init (); - - value = StringBank_AddOrFindString (bank, value); - if (!CharHashTable_add (map, key, (void *)value)) - { - CharHashTable_remove (map, key); - CharHashTable_add (map, key, (void *)value); - } -} - -int -res_GetInteger (const char *key) -{ - check_map_init (); - return str2int (res_GetString (key)); -} - -void -res_PutInteger (const char *key, int value) -{ - check_map_init (); - res_PutString (key, int2str(value)); -} - -BOOLEAN -res_GetBoolean (const char *key) -{ - check_map_init (); - return str2bool (res_GetString (key)); -} - -void -res_PutBoolean (const char *key, BOOLEAN value) -{ - check_map_init (); - res_PutString (key, bool2str(value)); -} - -BOOLEAN -res_HasKey (const char *key) -{ - check_map_init (); - return (res_GetString (key) != NULL); -} - -void -res_LoadFile (uio_Stream *s, const char *prefix) -{ - check_map_init (); - - if (!map) - { - return; - } - - PropFile_from_file (s, res_PutString, prefix); -} - -void -res_LoadFilename (uio_DirHandle *path, const char *fname, const char *prefix) -{ - check_map_init (); - - if (!map) - { - return; - } - - PropFile_from_filename (path, fname, res_PutString, prefix); -} - -void -res_SaveFile (uio_Stream *f, const char *prefix, BOOLEAN strip_root) -{ - CharHashTable_Iterator *i; - int prefix_len = 0; - - if (prefix) - prefix_len = strlen (prefix); - - check_map_init (); - - i = CharHashTable_getIterator (map); - while (!CharHashTable_iteratorDone (i)) - { - const char *key = CharHashTable_iteratorKey (i); - const char *value = (const char *)CharHashTable_iteratorValue (i); - if (!prefix || !strncmp (prefix, key, prefix_len)) { - if (prefix && strip_root) { - WriteResFile (key+prefix_len, 1, strlen (key) - prefix_len, f); - } else { - WriteResFile (key, 1, strlen (key), f); - } - PutResFileChar(' ', f); - PutResFileChar('=', f); - PutResFileChar(' ', f); - WriteResFile (value, 1, strlen (value), f); - PutResFileNewline(f); - } - i = CharHashTable_iteratorNext (i); - } - CharHashTable_freeIterator (i); -} - -void -res_SaveFilename (uio_DirHandle *path, const char *fname, const char *prefix, BOOLEAN strip_root) -{ - uio_Stream *f; - - check_map_init (); - f = res_OpenResFile (path, fname, "wb"); - if (f) { - res_SaveFile (f, prefix, strip_root); - res_CloseResFile (f); - } -} diff --git a/sc2/src/sc2code/libs/resource/resdata.c b/sc2/src/sc2code/libs/resource/resdata.c deleted file mode 100644 index 09f888046..000000000 --- a/sc2/src/sc2code/libs/resource/resdata.c +++ /dev/null @@ -1,34 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "resintrn.h" - -static RESOURCE_INDEX curResourceIndex; - -void -_set_current_index_header (RESOURCE_INDEX newResourceIndex) -{ - curResourceIndex = newResourceIndex; -} - -RESOURCE_INDEX -_get_current_index_header (void) -{ - return curResourceIndex; -} - diff --git a/sc2/src/sc2code/libs/resource/resinit.c b/sc2/src/sc2code/libs/resource/resinit.c index 22fb3d935..ad76b3b27 100644 --- a/sc2/src/sc2code/libs/resource/resinit.c +++ b/sc2/src/sc2code/libs/resource/resinit.c @@ -23,6 +23,7 @@ #include "types.h" #include "libs/log.h" #include "libs/gfxlib.h" +#include "libs/reslib.h" #include "libs/sndlib.h" #include "libs/vidlib.h" #include "coderes.h" @@ -127,18 +128,7 @@ process_resource_desc (const char *key, const char *value) { if (!CharHashTable_add (map, key, newDesc)) { - ResourceDesc *oldDesc = (ResourceDesc *)CharHashTable_find (map, key); - if (oldDesc != NULL) - { - if (newDesc->resdata.ptr != NULL) - { - /* XXX: It might be nice to actually clean it up properly */ - log_add (log_Warning, "LEAK WARNING: Replaced '%s' while it was live", key); - } - HFree (oldDesc->fname); - HFree (oldDesc); - } - CharHashTable_remove (map, key); + res_Remove (key); CharHashTable_add (map, key, newDesc); } } @@ -188,9 +178,20 @@ BooleanToString (RESOURCE_DATA *resdata, char *buf, unsigned int size) snprintf (buf, size, "%s", resdata->num ? "true" : "false"); } +static RESOURCE_INDEX curResourceIndex; + +void +_set_current_index_header (RESOURCE_INDEX newResourceIndex) +{ + curResourceIndex = newResourceIndex; +} + RESOURCE_INDEX InitResourceSystem (void) { + if (curResourceIndex) { + return curResourceIndex; + } RESOURCE_INDEX ndx = allocResourceIndex (); _set_current_index_header (ndx); @@ -208,6 +209,15 @@ InitResourceSystem (void) return ndx; } +RESOURCE_INDEX +_get_current_index_header (void) +{ + if (!curResourceIndex) { + InitResourceSystem (); + } + return curResourceIndex; +} + void LoadResourceIndex (uio_DirHandle *dir, const char *rmpfile, const char *prefix) { @@ -304,3 +314,123 @@ InstallResTypeVectors (const char *resType, ResourceLoadFun *loadFun, map = _get_current_index_header ()->map; return CharHashTable_add (map, key, result) != 0; } + +/* These replace the mapres.c calls and probably should be split out at some point. */ +const char * +res_GetString (const char *key) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING")) + return NULL; + return (const char *)desc->resdata.ptr; +} + +void +res_PutString (const char *key, const char *value) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + int srclen, dstlen; + if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING")) + { + /* TODO: This is kind of roundabout. We can do better by refactoring newResourceDesc */ + process_resource_desc(key, "STRING:undefined"); + desc = lookupResourceDesc (idx, key); + } + srclen = strlen (value); + dstlen = strlen (desc->resdata.ptr); + if (srclen > dstlen) { + char *newValue = HMalloc(srclen + 1); + char *oldValue = desc->fname; + log_add(log_Warning, "Reallocating string space for '%s'", key); + strncpy (newValue, value, srclen + 1); + desc->resdata.ptr = newValue; + desc->fname = newValue; + HFree (oldValue); + } else { + strncpy (desc->resdata.ptr, value, srclen + 1); + } +} + +int +res_GetInteger (const char *key) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + if (!desc || strcmp(desc->vtable->resType, "INT32")) + { + // TODO: Better error handling + return 0; + } + return desc->resdata.num; +} + +void +res_PutInteger (const char *key, int value) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + if (!desc || strcmp(desc->vtable->resType, "INT32")) + { + /* TODO: This is kind of roundabout. We can do better by refactoring newResourceDesc */ + process_resource_desc(key, "INT32:0"); + desc = lookupResourceDesc (idx, key); + } + desc->resdata.num = value; +} + +BOOLEAN +res_GetBoolean (const char *key) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + if (!desc || strcmp(desc->vtable->resType, "BOOLEAN")) + { + // TODO: Better error handling + return FALSE; + } + return desc->resdata.num ? TRUE : FALSE; +} + +void +res_PutBoolean (const char *key, BOOLEAN value) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + ResourceDesc *desc = lookupResourceDesc (idx, key); + if (!desc || strcmp(desc->vtable->resType, "BOOLEAN")) + { + /* TODO: This is kind of roundabout. We can do better by refactoring newResourceDesc */ + process_resource_desc(key, "BOOLEAN:false"); + desc = lookupResourceDesc (idx, key); + } + desc->resdata.num = value; +} + +BOOLEAN +res_HasKey (const char *key) +{ + RESOURCE_INDEX idx = _get_current_index_header (); + return (lookupResourceDesc(idx, key) != NULL); +} + +BOOLEAN +res_Remove (const char *key) +{ + CharHashTable_HashTable *map = _get_current_index_header ()->map; + ResourceDesc *oldDesc = (ResourceDesc *)CharHashTable_find (map, key); + if (oldDesc != NULL) + { + if (oldDesc->resdata.ptr != NULL) + { + log_add (log_Warning, "WARNING: Replacing '%s' while it is live", key); + if (oldDesc->vtable && oldDesc->vtable->freeFun) + { + oldDesc->vtable->freeFun(oldDesc->resdata.ptr); + } + } + HFree (oldDesc->fname); + HFree (oldDesc); + } + return CharHashTable_remove (map, key); +} diff --git a/sc2/src/sc2code/setupmenu.c b/sc2/src/sc2code/setupmenu.c index d1041fc33..a27130d60 100644 --- a/sc2/src/sc2code/setupmenu.c +++ b/sc2/src/sc2code/setupmenu.c @@ -328,6 +328,7 @@ do_editkeys (WIDGET *self, int event) static void change_template (WIDGET_CHOICE *self, int oldval) { + (void) oldval; populate_editkeys (self->selected); } @@ -517,8 +518,6 @@ OnTextEntryChange (TEXTENTRY_STATE *pTES) static BOOLEAN OnTextEntryFrame (TEXTENTRY_STATE *pTES) { - WIDGET_TEXTENTRY *widget = (WIDGET_TEXTENTRY *) pTES->CbParam; - redraw_menu (); SleepThreadUntil (pTES->NextTime); @@ -1371,8 +1370,6 @@ SetGlobalOptions (GLOBALOPTS *opts) res_PutString ("keys.5.name", input_templates[4].name); res_PutString ("keys.6.name", input_templates[5].name); - res_SaveFilename (configDir, "uqm.cfg", "config.", FALSE); - // TODO RES070 - // res_SaveFilename (configDir, "uqm.cfg", "config.", TRUE); + SaveResourceIndex (configDir, "uqm.cfg", "config.", TRUE); SaveKeyConfiguration (configDir, "flight.cfg"); } diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 569991d7b..3b64393d8 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -103,6 +103,7 @@ static int parseIntOption (const char *str, int *result, const char *optName); static int parseFloatOption (const char *str, float *f, const char *optName); +static void parseIntVolume (int intVol, float *vol); static int parseVolume (const char *str, float *vol, const char *optName); static int InvalidArgument (const char *supplied, const char *opt_name); static int Check_PC_3DO_opt (const char *value, DWORD mask, const char *opt, @@ -210,9 +211,7 @@ main (int argc, char *argv[]) PlayerControls[1] = CONTROL_TEMPLATE_JOY_1; // Fill in the options struct based on uqm.cfg - res_LoadFilename (configDir, "uqm.cfg", NULL); - // TODO RES070 - // res_LoadFilename (configDir, "uqm.cfg", "config."); + LoadResourceIndex (configDir, "uqm.cfg", "config."); if (res_HasKey ("config.reswidth")) { @@ -381,18 +380,18 @@ main (int argc, char *argv[]) } if (res_HasKey ("config.musicvol")) { - parseVolume (res_GetString ("config.musicvol"), - &options.musicVolumeScale, "music volume"); + parseIntVolume (res_GetInteger ("config.musicvol"), + &options.musicVolumeScale); } if (res_HasKey ("config.sfxvol")) { - parseVolume (res_GetString ("config.sfxvol"), - &options.sfxVolumeScale, "SFX volume"); + parseIntVolume (res_GetInteger ("config.sfxvol"), + &options.sfxVolumeScale); } if (res_HasKey ("config.speechvol")) { - parseVolume (res_GetString ("config.speechvol"), - &options.speechVolumeScale, "speech volume"); + parseIntVolume (res_GetInteger ("config.speechvol"), + &options.speechVolumeScale); } { /* remove old control template names */ @@ -907,6 +906,25 @@ parseOptions (int argc, char *argv[], struct options_struct *options) return EXIT_SUCCESS; } +static void +parseIntVolume (int intVol, float *vol) +{ + if (intVol < 0) + { + *vol = 0.0f; + return; + } + + if (intVol > 100) + { + *vol = 1.0f; + return; + } + + *vol = intVol / 100.0f; + return; +} + static int parseVolume (const char *str, float *vol, const char *optName) { @@ -925,20 +943,7 @@ parseVolume (const char *str, float *vol, const char *optName) "for '%s'.", optName); return -1; } - - if (intVol < 0) - { - *vol = 0.0f; - return 0; - } - - if (intVol > 100) - { - *vol = 1.0f; - return 0; - } - - *vol = intVol / 100.0f; + parseIntVolume (intVol, vol); return 0; } diff --git a/sc2/src/uqmversion.h b/sc2/src/uqmversion.h index 77e981622..fb0c33aec 100644 --- a/sc2/src/uqmversion.h +++ b/sc2/src/uqmversion.h @@ -21,8 +21,8 @@ #define UQM_MAJOR_VERSION_S "0" #define UQM_MINOR_VERSION 6 #define UQM_MINOR_VERSION_S "6" -#define UQM_PATCH_VERSION 4 -#define UQM_PATCH_VERSION_S "4" +#define UQM_PATCH_VERSION 5 +#define UQM_PATCH_VERSION_S "5" #define UQM_EXTRA_VERSION "" /* The final version is interpreted as: * printf ("%d.%d.%d%s", UQM_MAJOR_VERSION, UQM_MINOR_VERSION,