key input
This commit is contained in:
parent
e9eec9f97e
commit
d5f29beb8f
39
main.c
39
main.c
|
@ -2,6 +2,7 @@
|
||||||
#include "SDL3/SDL_blendmode.h"
|
#include "SDL3/SDL_blendmode.h"
|
||||||
#include "SDL3/SDL_error.h"
|
#include "SDL3/SDL_error.h"
|
||||||
#include "SDL3/SDL_init.h"
|
#include "SDL3/SDL_init.h"
|
||||||
|
#include "SDL3/SDL_keycode.h"
|
||||||
#include "SDL3/SDL_log.h"
|
#include "SDL3/SDL_log.h"
|
||||||
#include "SDL3/SDL_main.h"
|
#include "SDL3/SDL_main.h"
|
||||||
#include "SDL3/SDL_pixels.h"
|
#include "SDL3/SDL_pixels.h"
|
||||||
|
@ -41,6 +42,7 @@ static SDL_Surface* filtered[NUM_CHANNELS] = { NULL, NULL, NULL };
|
||||||
static SDL_Surface* screens[NUM_CHANNELS] = { NULL, NULL, NULL };
|
static SDL_Surface* screens[NUM_CHANNELS] = { NULL, NULL, NULL };
|
||||||
|
|
||||||
static struct mCore* cores[NUM_CHANNELS] = { NULL, NULL, NULL };
|
static struct mCore* cores[NUM_CHANNELS] = { NULL, NULL, NULL };
|
||||||
|
static unsigned keys = 0;
|
||||||
|
|
||||||
enum mColorFormat pixfmt_sdl_to_mgba(uint32_t sdl_fmt) {
|
enum mColorFormat pixfmt_sdl_to_mgba(uint32_t sdl_fmt) {
|
||||||
switch (sdl_fmt) {
|
switch (sdl_fmt) {
|
||||||
|
@ -340,12 +342,32 @@ int SDL_AppEvent(const SDL_Event *event) {
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case SDL_EVENT_KEY_DOWN: {
|
case SDL_EVENT_KEY_DOWN: {
|
||||||
const SDL_Keycode sym = event->key.keysym.sym;
|
const SDL_Keycode sym = event->key.keysym.sym;
|
||||||
if (sym == SDLK_ESCAPE || sym == SDLK_AC_BACK) {
|
switch (sym) {
|
||||||
SDL_Log("Key : Escape!");
|
case SDLK_ESCAPE: case SDLK_AC_BACK: return 1;
|
||||||
return 1;
|
case SDLK_SPACE: FlipCamera(); break;
|
||||||
} else if (sym == SDLK_SPACE) {
|
case SDLK_UP: keys |= 0x40; break;
|
||||||
FlipCamera();
|
case SDLK_DOWN: keys |= 0x80; break;
|
||||||
return 0;
|
case SDLK_LEFT: keys |= 0x20; break;
|
||||||
|
case SDLK_RIGHT: keys |= 0x10; break;
|
||||||
|
case SDLK_a: case SDLK_z: keys |= 1; break;
|
||||||
|
case SDLK_b: case SDLK_x: keys |= 2; break;
|
||||||
|
case SDLK_RETURN: keys |= 8; break;
|
||||||
|
case SDLK_BACKSPACE: keys |= 4; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SDL_EVENT_KEY_UP: {
|
||||||
|
const SDL_Keycode sym = event->key.keysym.sym;
|
||||||
|
switch (sym) {
|
||||||
|
case SDLK_UP: keys &= ~0x40; break;
|
||||||
|
case SDLK_DOWN: keys &= ~0x80; break;
|
||||||
|
case SDLK_LEFT: keys &= ~0x20; break;
|
||||||
|
case SDLK_RIGHT: keys &= ~0x10; break;
|
||||||
|
case SDLK_a: case SDLK_z: keys &= ~1; break;
|
||||||
|
case SDLK_b: case SDLK_x: keys &= ~2; break;
|
||||||
|
case SDLK_RETURN: keys &= ~8; break;
|
||||||
|
case SDLK_BACKSPACE: keys &= ~4; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -417,8 +439,13 @@ int SDL_AppIterate(void) {
|
||||||
if (since_last_present < FRAMESKIP_LIMIT) {
|
if (since_last_present < FRAMESKIP_LIMIT) {
|
||||||
for (i = 0; i < NUM_CHANNELS; i++) {
|
for (i = 0; i < NUM_CHANNELS; i++) {
|
||||||
struct mCore* core = cores[i];
|
struct mCore* core = cores[i];
|
||||||
|
core->setKeys(core, keys);
|
||||||
core->runFrame(core);
|
core->runFrame(core);
|
||||||
}
|
}
|
||||||
|
/*hack*/
|
||||||
|
if (keys && since_last_present < FRAMESKIP_LIMIT - 8) {
|
||||||
|
since_last_present = FRAMESKIP_LIMIT - 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!texture_updated) {
|
if (!texture_updated) {
|
||||||
|
|
Loading…
Reference in New Issue