Move the configure and keyconfig data into subtrees of the resource map. As a side effect, default key configurations are read directly from the content directory.

THIS IS AN INCOMPATIBLE CHANGE TO THE CONFIG FILES. Update content as well as src when upgrading here. Old configurations will be lost but the upgrade should otherwise be automatic.

Bumped version to 0.6.5 to commemorate the incompatible change.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3108 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2009-02-16 00:40:42 +00:00
parent f2e4a8e223
commit c4f404af0a
12 changed files with 312 additions and 495 deletions
+2
View File
@@ -1,4 +1,6 @@
Changes towards version 0.7: 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 - Index loading/saving now can operate on subtrees - Michael
- Videos vs. slide now controlled by a '3dovideo' addon - Michael - Videos vs. slide now controlled by a '3dovideo' addon - Michael
- New video resource type for 3DO videos - Michael - New video resource type for 3DO videos - Michael
+59 -59
View File
@@ -6,79 +6,79 @@
# Menu controls. Both sets of arrow keys, basically. Paging controls # Menu controls. Both sets of arrow keys, basically. Paging controls
# moving quickly through the file lists in Super Melee. Zooming # moving quickly through the file lists in Super Melee. Zooming
# controls zoom controls in the starmap. "Cancel" is also used to get # 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 # currently unused by the game. It seems to have been originally used
# to call up details on starships in the Super Melee selection screen. # to call up details on starships in the Super Melee selection screen.
# Arrow key controls... # Arrow key controls...
menu.up.1 = key Up up.1 = STRING:key Up
menu.down.1 = key Down down.1 = STRING:key Down
menu.right.1 = key Right right.1 = STRING:key Right
menu.left.1 = key Left left.1 = STRING:key Left
menu.pageup.1 = key PageUp pageup.1 = STRING:key PageUp
menu.pagedown.1 = key PageDown pagedown.1 = STRING:key PageDown
menu.home.1 = key Home home.1 = STRING:key Home
menu.end.1 = key End end.1 = STRING:key End
menu.zoomin.1 = key PageUp zoomin.1 = STRING:key PageUp
menu.zoomout.1 = key PageDown zoomout.1 = STRING:key PageDown
menu.select.1 = key Return select.1 = STRING:key Return
menu.select.2 = key RightControl select.2 = STRING:key RightControl
menu.cancel.1 = key Space cancel.1 = STRING:key Space
menu.cancel.2 = key RightShift cancel.2 = STRING:key RightShift
# ... and the number pad. Note that zoom controls on the starmap are # ... and the number pad. Note that zoom controls on the starmap are
# different from the paging controls in Super Melee. # different from the paging controls in Super Melee.
menu.up.2 = key Keypad-8 up.2 = STRING:key Keypad-8
menu.down.2 = key Keypad-2 down.2 = STRING:key Keypad-2
menu.left.2 = key Keypad-4 left.2 = STRING:key Keypad-4
menu.right.2 = key Keypad-6 right.2 = STRING:key Keypad-6
menu.pageup.2 = key Keypad-9 pageup.2 = STRING:key Keypad-9
menu.pagedown.2 = key Keypad-3 pagedown.2 = STRING:key Keypad-3
menu.home.2 = key Keypad-7 home.2 = STRING:key Keypad-7
menu.end.2 = key Keypad-1 end.2 = STRING:key Keypad-1
menu.zoomin.2 = key Keypad-+ zoomin.2 = STRING:key Keypad-+
menu.zoomout.2 = key Keypad-- zoomout.2 = STRING:key Keypad--
menu.select.3 = key Keypad-Enter select.3 = STRING:key Keypad-Enter
menu.cancel.3 = key Keypad-0 cancel.3 = STRING:key Keypad-0
# System utility keys. # System utility keys.
menu.delete.1 = key Delete delete.1 = STRING:key Delete
menu.delete.2 = key Keypad-. delete.2 = STRING:key Keypad-.
menu.backspace.1 = key Backspace backspace.1 = STRING:key Backspace
menu.editcancel.1 = key Escape editcancel.1 = STRING:key Escape
menu.search.1 = key / search.1 = STRING:key /
menu.next.1 = key Tab next.1 = STRING:key Tab
menu.pause.1 = key Pause pause.1 = STRING:key Pause
menu.pause.2 = key F1 pause.2 = STRING:key F1
menu.exit.1 = key F10 exit.1 = STRING:key F10
menu.fullscreen.1 = key F11 fullscreen.1 = STRING:key F11
menu.special.1 = key LeftAlt special.1 = STRING:key LeftAlt
menu.special.2 = key RightAlt special.2 = STRING:key RightAlt
# Joystick controls, for both port 1 and 2. # Joystick controls, for both port 1 and 2.
menu.up.3 = joystick 0 axis 1 negative up.3 = STRING:joystick 0 axis 1 negative
menu.down.3 = joystick 0 axis 1 positive down.3 = STRING:joystick 0 axis 1 positive
menu.left.3 = joystick 0 axis 0 negative left.3 = STRING:joystick 0 axis 0 negative
menu.right.3 = joystick 0 axis 0 positive right.3 = STRING:joystick 0 axis 0 positive
menu.up.4 = joystick 0 hat 0 up up.4 = STRING:joystick 0 hat 0 up
menu.down.4 = joystick 0 hat 0 down down.4 = STRING:joystick 0 hat 0 down
menu.left.4 = joystick 0 hat 0 left left.4 = STRING:joystick 0 hat 0 left
menu.right.4 = joystick 0 hat 0 right right.4 = STRING:joystick 0 hat 0 right
menu.cancel.4 = joystick 0 button 1 cancel.4 = STRING:joystick 0 button 1
menu.select.4 = joystick 0 button 0 select.4 = STRING:joystick 0 button 0
menu.up.5 = joystick 1 axis 1 negative up.5 = STRING:joystick 1 axis 1 negative
menu.down.5 = joystick 1 axis 1 positive down.5 = STRING:joystick 1 axis 1 positive
menu.left.5 = joystick 1 axis 0 negative left.5 = STRING:joystick 1 axis 0 negative
menu.right.5 = joystick 1 axis 0 positive right.5 = STRING:joystick 1 axis 0 positive
menu.up.6 = joystick 1 hat 0 up up.6 = STRING:joystick 1 hat 0 up
menu.down.6 = joystick 1 hat 0 down down.6 = STRING:joystick 1 hat 0 down
menu.left.6 = joystick 1 hat 0 left left.6 = STRING:joystick 1 hat 0 left
menu.right.6 = joystick 1 hat 0 right right.6 = STRING:joystick 1 hat 0 right
menu.cancel.5 = joystick 1 button 1 cancel.5 = STRING:joystick 1 button 1
menu.select.5 = joystick 1 button 0 select.5 = STRING:joystick 1 button 0
+66 -66
View File
@@ -1,71 +1,71 @@
keys.1.name = Arrows 1.name = STRING:Arrows
keys.1.up.1 = key Up 1.up.1 = STRING:key Up
keys.1.down.1 = key Down 1.down.1 = STRING:key Down
keys.1.left.1 = key Left 1.left.1 = STRING:key Left
keys.1.right.1 = key Right 1.right.1 = STRING:key Right
keys.1.weapon.1 = key RightControl 1.weapon.1 = STRING:key RightControl
keys.1.special.1 = key RightShift 1.special.1 = STRING:key RightShift
keys.1.up.2 = key Keypad-8 1.up.2 = STRING:key Keypad-8
keys.1.down.2 = key Keypad-2 1.down.2 = STRING:key Keypad-2
keys.1.left.2 = key Keypad-4 1.left.2 = STRING:key Keypad-4
keys.1.right.2 = key Keypad-6 1.right.2 = STRING:key Keypad-6
keys.1.weapon.2 = key Return 1.weapon.2 = STRING:key Return
keys.1.special.2 = key Keypad-0 1.special.2 = STRING:key Keypad-0
keys.1.escape.1 = key Escape 1.escape.1 = STRING:key Escape
keys.2.name = WASD 2.name = STRING:WASD
keys.2.up.1 = key w 2.up.1 = STRING:key w
keys.2.down.1 = key s 2.down.1 = STRING:key s
keys.2.left.1 = key a 2.left.1 = STRING:key a
keys.2.right.1 = key d 2.right.1 = STRING:key d
keys.2.weapon.1 = key v 2.weapon.1 = STRING:key v
keys.2.special.1 = key b 2.special.1 = STRING:key b
keys.2.escape.1 = key Escape 2.escape.1 = STRING:key Escape
keys.3.name = Arrows (2) 3.name = STRING:Arrows (2)
keys.3.up.1 = key Up 3.up.1 = STRING:key Up
keys.3.down.1 = key Down 3.down.1 = STRING:key Down
keys.3.left.1 = key Left 3.left.1 = STRING:key Left
keys.3.right.1 = key Right 3.right.1 = STRING:key Right
keys.3.up.2 = key Keypad-8 3.up.2 = STRING:key Keypad-8
keys.3.down.2 = key Keypad-2 3.down.2 = STRING:key Keypad-2
keys.3.left.2 = key Keypad-4 3.left.2 = STRING:key Keypad-4
keys.3.right.2 = key Keypad-6 3.right.2 = STRING:key Keypad-6
keys.3.weapon.1 = key ] 3.weapon.1 = STRING:key ]
keys.3.special.1 = key [ 3.special.1 = STRING:key [
keys.3.escape.1 = key Escape 3.escape.1 = STRING:key Escape
keys.4.name = ESDF 4.name = STRING:ESDF
keys.4.up.1 = key e 4.up.1 = STRING:key e
keys.4.down.1 = key d 4.down.1 = STRING:key d
keys.4.left.1 = key s 4.left.1 = STRING:key s
keys.4.right.1 = key f 4.right.1 = STRING:key f
keys.4.weapon.1 = key q 4.weapon.1 = STRING:key q
keys.4.special.1 = key a 4.special.1 = STRING:key a
keys.4.escape.1 = key Escape 4.escape.1 = STRING:key Escape
keys.5.name = Joystick 1 5.name = STRING:Joystick 1
keys.5.up.1 = joystick 0 axis 1 negative 5.up.1 = STRING:joystick 0 axis 1 negative
keys.5.down.1 = joystick 0 axis 1 positive 5.down.1 = STRING:joystick 0 axis 1 positive
keys.5.left.1 = joystick 0 axis 0 negative 5.left.1 = STRING:joystick 0 axis 0 negative
keys.5.right.1 = joystick 0 axis 0 positive 5.right.1 = STRING:joystick 0 axis 0 positive
keys.5.up.2 = joystick 0 hat 0 up 5.up.2 = STRING:joystick 0 hat 0 up
keys.5.down.2 = joystick 0 hat 0 down 5.down.2 = STRING:joystick 0 hat 0 down
keys.5.left.2 = joystick 0 hat 0 left 5.left.2 = STRING:joystick 0 hat 0 left
keys.5.right.2 = joystick 0 hat 0 right 5.right.2 = STRING:joystick 0 hat 0 right
keys.5.weapon.1 = joystick 0 button 0 5.weapon.1 = STRING:joystick 0 button 0
keys.5.special.1 = joystick 0 button 1 5.special.1 = STRING:joystick 0 button 1
keys.5.escape.1 = key Escape 5.escape.1 = STRING:key Escape
keys.6.name = Joystick 2 6.name = STRING:Joystick 2
keys.6.up.1 = joystick 1 axis 1 negative 6.up.1 = STRING:joystick 1 axis 1 negative
keys.6.down.1 = joystick 1 axis 1 positive 6.down.1 = STRING:joystick 1 axis 1 positive
keys.6.left.1 = joystick 1 axis 0 negative 6.left.1 = STRING:joystick 1 axis 0 negative
keys.6.right.1 = joystick 1 axis 0 positive 6.right.1 = STRING:joystick 1 axis 0 positive
keys.6.up.2 = joystick 1 hat 0 up 6.up.2 = STRING:joystick 1 hat 0 up
keys.6.down.2 = joystick 1 hat 0 down 6.down.2 = STRING:joystick 1 hat 0 down
keys.6.left.2 = joystick 1 hat 0 left 6.left.2 = STRING:joystick 1 hat 0 left
keys.6.right.2 = joystick 1 hat 0 right 6.right.2 = STRING:joystick 1 hat 0 right
keys.6.weapon.1 = joystick 1 button 0 6.weapon.1 = STRING:joystick 1 button 0
keys.6.special.1 = joystick 1 button 1 6.special.1 = STRING:joystick 1 button 1
keys.6.escape.1 = key Escape 6.escape.1 = STRING:key Escape
+9 -34
View File
@@ -146,11 +146,10 @@ register_flight_controls (void)
static void static void
initKeyConfig (void) initKeyConfig (void)
{ {
uio_Stream *fp;
int i; int i;
/* First, load in the menu keys */ /* 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++) for (i = 0; i < NUM_MENU_KEYS; i++)
{ {
if (!menu_res_names[i]) if (!menu_res_names[i])
@@ -158,30 +157,15 @@ initKeyConfig (void)
register_menu_controls (i); register_menu_controls (i);
} }
fp = res_OpenResFile (configDir, "flight.cfg", "rt"); LoadResourceIndex (configDir, "flight.cfg", "keys.");
if (!fp) if (!res_HasKey ("keys.1.name"))
{ {
if (copyFile (contentDir, "uqm.key", /* Either flight.cfg doesn't exist, or we're using an old version
configDir, "flight.cfg") == -1) of flight.cfg, and thus we wound up loading untyped values into
{ 'keys.keys.1.name' and such. Load the defaults from the content
log_add (log_Fatal, "Error: Could not copy default key config " directory. */
"to user config dir: %s.", strerror (errno)); LoadResourceIndex (contentDir, "uqm.key", "keys.");
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);
}
}
res_LoadFile (fp, NULL);
// TODO RES070
// res_LoadFile (fp, "keys.");
res_CloseResFile (fp);
register_flight_controls (); register_flight_controls ();
@@ -454,16 +438,7 @@ RebindInputState (int template, int control, int index)
void void
SaveKeyConfiguration (uio_DirHandle *path, const char *fname) SaveKeyConfiguration (uio_DirHandle *path, const char *fname)
{ {
uio_Stream *f; SaveResourceIndex (path, fname, "keys.", TRUE);
f = res_OpenResFile (path, fname, "wb");
if (f)
{
res_SaveFile (f, "keys.", FALSE);
// TODO RES070
// res_SaveFile (f, "keys.", TRUE);
res_CloseResFile (f);
}
} }
void void
-8
View File
@@ -59,7 +59,6 @@ long LengthResFile (uio_Stream *fp);
BOOLEAN res_CloseResFile (uio_Stream *fp); BOOLEAN res_CloseResFile (uio_Stream *fp);
BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename); BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename);
RESOURCE_INDEX InitResourceSystem ();
void UninitResourceSystem (void); void UninitResourceSystem (void);
BOOLEAN InstallResTypeVectors (const char *res_type, ResourceLoadFun *loadFun, ResourceFreeFun *freeFun, ResourceStringFun *stringFun); BOOLEAN InstallResTypeVectors (const char *res_type, ResourceLoadFun *loadFun, ResourceFreeFun *freeFun, ResourceStringFun *stringFun);
void *res_GetResource (RESOURCE res); void *res_GetResource (RESOURCE res);
@@ -99,13 +98,6 @@ extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle,
#define GetDirEntryContents GetStringContents #define GetDirEntryContents GetStringContents
/* Key-Value resources */ /* 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); BOOLEAN res_HasKey (const char *key);
+2 -2
View File
@@ -1,2 +1,2 @@
uqm_CFILES="direct.c filecntl.c getres.c loadres.c mapres.c uqm_CFILES="direct.c filecntl.c getres.c loadres.c stringbank.c
propfile.c resdata.c resinit.c stringbank.c" propfile.c resinit.c"
-250
View File
@@ -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 <stdlib.h>
#include <string.h>
#include <ctype.h>
#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);
}
}
-34
View File
@@ -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;
}
+142 -12
View File
@@ -23,6 +23,7 @@
#include "types.h" #include "types.h"
#include "libs/log.h" #include "libs/log.h"
#include "libs/gfxlib.h" #include "libs/gfxlib.h"
#include "libs/reslib.h"
#include "libs/sndlib.h" #include "libs/sndlib.h"
#include "libs/vidlib.h" #include "libs/vidlib.h"
#include "coderes.h" #include "coderes.h"
@@ -127,18 +128,7 @@ process_resource_desc (const char *key, const char *value)
{ {
if (!CharHashTable_add (map, key, newDesc)) if (!CharHashTable_add (map, key, newDesc))
{ {
ResourceDesc *oldDesc = (ResourceDesc *)CharHashTable_find (map, key); res_Remove (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);
CharHashTable_add (map, key, newDesc); 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"); snprintf (buf, size, "%s", resdata->num ? "true" : "false");
} }
static RESOURCE_INDEX curResourceIndex;
void
_set_current_index_header (RESOURCE_INDEX newResourceIndex)
{
curResourceIndex = newResourceIndex;
}
RESOURCE_INDEX RESOURCE_INDEX
InitResourceSystem (void) InitResourceSystem (void)
{ {
if (curResourceIndex) {
return curResourceIndex;
}
RESOURCE_INDEX ndx = allocResourceIndex (); RESOURCE_INDEX ndx = allocResourceIndex ();
_set_current_index_header (ndx); _set_current_index_header (ndx);
@@ -208,6 +209,15 @@ InitResourceSystem (void)
return ndx; return ndx;
} }
RESOURCE_INDEX
_get_current_index_header (void)
{
if (!curResourceIndex) {
InitResourceSystem ();
}
return curResourceIndex;
}
void void
LoadResourceIndex (uio_DirHandle *dir, const char *rmpfile, const char *prefix) 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; map = _get_current_index_header ()->map;
return CharHashTable_add (map, key, result) != 0; 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);
}
+2 -5
View File
@@ -328,6 +328,7 @@ do_editkeys (WIDGET *self, int event)
static void static void
change_template (WIDGET_CHOICE *self, int oldval) change_template (WIDGET_CHOICE *self, int oldval)
{ {
(void) oldval;
populate_editkeys (self->selected); populate_editkeys (self->selected);
} }
@@ -517,8 +518,6 @@ OnTextEntryChange (TEXTENTRY_STATE *pTES)
static BOOLEAN static BOOLEAN
OnTextEntryFrame (TEXTENTRY_STATE *pTES) OnTextEntryFrame (TEXTENTRY_STATE *pTES)
{ {
WIDGET_TEXTENTRY *widget = (WIDGET_TEXTENTRY *) pTES->CbParam;
redraw_menu (); redraw_menu ();
SleepThreadUntil (pTES->NextTime); SleepThreadUntil (pTES->NextTime);
@@ -1371,8 +1370,6 @@ SetGlobalOptions (GLOBALOPTS *opts)
res_PutString ("keys.5.name", input_templates[4].name); res_PutString ("keys.5.name", input_templates[4].name);
res_PutString ("keys.6.name", input_templates[5].name); res_PutString ("keys.6.name", input_templates[5].name);
res_SaveFilename (configDir, "uqm.cfg", "config.", FALSE); SaveResourceIndex (configDir, "uqm.cfg", "config.", TRUE);
// TODO RES070
// res_SaveFilename (configDir, "uqm.cfg", "config.", TRUE);
SaveKeyConfiguration (configDir, "flight.cfg"); SaveKeyConfiguration (configDir, "flight.cfg");
} }
+28 -23
View File
@@ -103,6 +103,7 @@ static int parseIntOption (const char *str, int *result,
const char *optName); const char *optName);
static int parseFloatOption (const char *str, float *f, static int parseFloatOption (const char *str, float *f,
const char *optName); const char *optName);
static void parseIntVolume (int intVol, float *vol);
static int parseVolume (const char *str, float *vol, const char *optName); static int parseVolume (const char *str, float *vol, const char *optName);
static int InvalidArgument (const char *supplied, const char *opt_name); static int InvalidArgument (const char *supplied, const char *opt_name);
static int Check_PC_3DO_opt (const char *value, DWORD mask, const char *opt, 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; PlayerControls[1] = CONTROL_TEMPLATE_JOY_1;
// Fill in the options struct based on uqm.cfg // Fill in the options struct based on uqm.cfg
res_LoadFilename (configDir, "uqm.cfg", NULL); LoadResourceIndex (configDir, "uqm.cfg", "config.");
// TODO RES070
// res_LoadFilename (configDir, "uqm.cfg", "config.");
if (res_HasKey ("config.reswidth")) if (res_HasKey ("config.reswidth"))
{ {
@@ -381,18 +380,18 @@ main (int argc, char *argv[])
} }
if (res_HasKey ("config.musicvol")) if (res_HasKey ("config.musicvol"))
{ {
parseVolume (res_GetString ("config.musicvol"), parseIntVolume (res_GetInteger ("config.musicvol"),
&options.musicVolumeScale, "music volume"); &options.musicVolumeScale);
} }
if (res_HasKey ("config.sfxvol")) if (res_HasKey ("config.sfxvol"))
{ {
parseVolume (res_GetString ("config.sfxvol"), parseIntVolume (res_GetInteger ("config.sfxvol"),
&options.sfxVolumeScale, "SFX volume"); &options.sfxVolumeScale);
} }
if (res_HasKey ("config.speechvol")) if (res_HasKey ("config.speechvol"))
{ {
parseVolume (res_GetString ("config.speechvol"), parseIntVolume (res_GetInteger ("config.speechvol"),
&options.speechVolumeScale, "speech volume"); &options.speechVolumeScale);
} }
{ /* remove old control template names */ { /* remove old control template names */
@@ -907,6 +906,25 @@ parseOptions (int argc, char *argv[], struct options_struct *options)
return EXIT_SUCCESS; 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 static int
parseVolume (const char *str, float *vol, const char *optName) 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); "for '%s'.", optName);
return -1; return -1;
} }
parseIntVolume (intVol, vol);
if (intVol < 0)
{
*vol = 0.0f;
return 0;
}
if (intVol > 100)
{
*vol = 1.0f;
return 0;
}
*vol = intVol / 100.0f;
return 0; return 0;
} }
+2 -2
View File
@@ -21,8 +21,8 @@
#define UQM_MAJOR_VERSION_S "0" #define UQM_MAJOR_VERSION_S "0"
#define UQM_MINOR_VERSION 6 #define UQM_MINOR_VERSION 6
#define UQM_MINOR_VERSION_S "6" #define UQM_MINOR_VERSION_S "6"
#define UQM_PATCH_VERSION 4 #define UQM_PATCH_VERSION 5
#define UQM_PATCH_VERSION_S "4" #define UQM_PATCH_VERSION_S "5"
#define UQM_EXTRA_VERSION "" #define UQM_EXTRA_VERSION ""
/* The final version is interpreted as: /* The final version is interpreted as:
* printf ("%d.%d.%d%s", UQM_MAJOR_VERSION, UQM_MINOR_VERSION, * printf ("%d.%d.%d%s", UQM_MAJOR_VERSION, UQM_MINOR_VERSION,