Re: [AD] New config function suggestion

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Wed, 2006-03-08 at 21:34 -0500, Ryan Patterson wrote:
> I have an idea for some new config file functions, and I would like to
> know if I wrote them if they would be eligible for inclusion in the
> current Allegro tree...
> 
> {get,set}_config_key - These do the same as config_int, except that
> they store the value as a string like KEY_A in the INI file, and
> automatically convert.

You already can do:

set_config_string("keys", "fire_key", scancode_to_name(KEY_SPACE));

and then a:

fire_key = name_to_scancode(get_config_string("keys", fire_key"));

would be simple to implement:

int name_to_scancode(char const *name)
{
    for (int k = 0; k < KEY_MAX; k++) {
        if (!ustrcmp(scancode_to_name(k), name)) return k;
    }
    return 0;
}

Of course, scancode_to_name uses internationalized and platform specific
names - so this is no use if you want to distribute the config files.
But neither would be the KEY_* names, since they also are
internationalized and platform specific. And so, having them as numbers
is better, to make clear it is only some internal values without
specific meaning. "KEY_Q" may be Q on a US keyboard, but is A on a
French keyboard under Windows (but Q under Linux). KEY_OPENBRACE doesn't
even exist on a German keyboard (and is mapped to some other random key
since there are only have 114 KEY_* constants). So in general, I don't
think we should promote use of the names over the numbers on config
files, since they simple are internal numbers. If there's a config file
in a game:

fire_key = KEY_Q
left_key = KEY_OPENBRACE

And then it doesn't work, since the first gets mapped to A, and the
other doesn't exist, it just makes your program look broken.

It's better practice to have:
fire_key = 17
left_key = 65

And you absolutely must provide a configure option in-game then, which
displays the key names (using scancode_to_name) and allows changing
them. With that, a French user would see the A key and maybe the Ù key,
then wonder why you made such odd default keys, but could change them
and play the game. The numbers in the config file would not matter.

Ah, well, I'm just annoyed at UAE and Vice who never let me properly
play games because they got the keyboard mapping all wrong and only work
on US layout. Dosbox and Mame OTOH have an in-game configuration of
keys, and it's possible to map keys there and play the games. So,
Allegro docs should make it clear that you need to do that, and that
KEY_* values are just numbers, and should not be used directly.

> {get,set}_config_color - These would read or set a color in the INI
> file. The color could be in the form of hex #ffffff, or decimal 255,
> 255, 255. (Conversion at call of function)

Maybe two functions color_to_string, string_to_color? It's two one
liners I have often written myself, and that constitutes they would be
useful.

> {get,set}_config_card - These would read or set a graphics card name
> in the INI file. It would appear in the ini file as (for instance)
> GFX_AUTODETECT, and automatically convert.

There's already get/set_config_id - if it doesn't work with AUTODETECT,
that should probably be fixed.

-- 
Elias Pschernig





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/