GBA Input: Consolidate GBA_KEY_NONE and GBA_NO_MAPPING

This commit is contained in:
Jeffrey Pfau 2016-01-07 23:50:01 -08:00
parent a920eaa7f0
commit c732ea6a71
4 changed files with 20 additions and 9 deletions

View File

@ -53,6 +53,7 @@ Misc:
- 3DS: Update to new ctrulib API
- GBA RR: Add preliminary SRAM support for VBM loading
- GBA RR: Add support for resets in movies
- GBA Input: Consolidate GBA_KEY_NONE and GBA_NO_MAPPING
0.3.2: (2015-12-16)
Bugfixes:

View File

@ -95,7 +95,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t
map->numMaps = 1;
impl = &map->maps[0];
impl->type = type;
impl->map = calloc(GBA_KEY_MAX, sizeof(int));
impl->map = malloc(GBA_KEY_MAX * sizeof(int));
int i;
for (i = 0; i < GBA_KEY_MAX; ++i) {
impl->map[i] = GBA_KEY_NONE;
}
TableInit(&impl->axes, 2, free);
} else {
impl = _lookupMap(map, type);
@ -110,7 +114,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t
}
if (impl) {
impl->type = type;
impl->map = calloc(GBA_KEY_MAX, sizeof(int));
impl->map = malloc(GBA_KEY_MAX * sizeof(int));
int i;
for (i = 0; i < GBA_KEY_MAX; ++i) {
impl->map[i] = GBA_KEY_NONE;
}
} else {
map->maps = realloc(map->maps, sizeof(*map->maps) * map->numMaps * 2);
for (m = map->numMaps * 2 - 1; m > map->numMaps; --m) {
@ -120,7 +128,11 @@ static struct GBAInputMapImpl* _guaranteeMap(struct GBAInputMap* map, uint32_t t
map->numMaps *= 2;
impl = &map->maps[m];
impl->type = type;
impl->map = calloc(GBA_KEY_MAX, sizeof(int));
impl->map = malloc(GBA_KEY_MAX * sizeof(int));
int i;
for (i = 0; i < GBA_KEY_MAX; ++i) {
impl->map[i] = GBA_KEY_NONE;
}
}
TableInit(&impl->axes, 2, free);
}
@ -378,18 +390,18 @@ void GBAInputUnbindKey(struct GBAInputMap* map, uint32_t type, enum GBAKey input
return;
}
if (impl) {
impl->map[input] = GBA_NO_MAPPING;
impl->map[input] = GBA_KEY_NONE;
}
}
int GBAInputQueryBinding(const struct GBAInputMap* map, uint32_t type, enum GBAKey input) {
if (input >= GBA_KEY_MAX) {
return 0;
return GBA_KEY_NONE;
}
const struct GBAInputMapImpl* impl = _lookupMapConst(map, type);
if (!impl || !impl->map) {
return 0;
return GBA_KEY_NONE;
}
return impl->map[input];

View File

@ -22,8 +22,6 @@ struct GBAAxis {
int32_t deadLow;
};
#define GBA_NO_MAPPING -1
extern const char* GBAKeyNames[];
void GBAInputMapInit(struct GBAInputMap*);

View File

@ -249,7 +249,7 @@ void GBAKeyEditor::lookupBinding(const GBAInputMap* map, KeyEditor* keyEditor, G
#ifdef BUILD_SDL
if (m_type == SDL_BINDING_BUTTON) {
int value = GBAInputQueryBinding(map, m_type, key);
if (value != GBA_NO_MAPPING) {
if (value != GBA_KEY_NONE) {
keyEditor->setValueButton(value);
}
return;