diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-02-24 17:55:57 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:21 +0200 |
| commit | 9eee43d3bb24000077602a62dfdfeee2606f1589 (patch) | |
| tree | 0e5f8efef62b068e252fe9c98c14fec723e0a7a3 /src/pad | |
| parent | 18717569acda82b26099c62410df3b398d596ba1 (diff) | |
| download | rts-9eee43d3bb24000077602a62dfdfeee2606f1589.tar.gz | |
Add support for keyboard and mouse
Diffstat (limited to 'src/pad')
| -rw-r--r-- | src/pad/CMakeLists.txt | 17 | ||||
| -rw-r--r-- | src/pad/inc/pad.h | 6 | ||||
| -rw-r--r-- | src/pad/sdl-1.2/inc/pad/port.h | 4 | ||||
| -rw-r--r-- | src/pad/sdl-1.2/src/pad.c | 69 |
4 files changed, 17 insertions, 79 deletions
diff --git a/src/pad/CMakeLists.txt b/src/pad/CMakeLists.txt index 4862c2b..e4aee5b 100644 --- a/src/pad/CMakeLists.txt +++ b/src/pad/CMakeLists.txt @@ -1,10 +1,15 @@ -add_library(pad "src/pad.c") -target_include_directories(pad PUBLIC "inc" PRIVATE "privinc") +set(inc "inc") +set(privinc "privinc") +set(src "src/pad.c") if(PS1_BUILD) - target_include_directories(pad PUBLIC "ps1/inc") - target_sources(pad PRIVATE "ps1/src/pad.c") + set(src ${src} "ps1/src/pad.c") + set(inc ${inc} "ps1/inc") elseif(SDL1_2_BUILD) - target_include_directories(pad PUBLIC "sdl-1.2/inc") - target_sources(pad PRIVATE "sdl-1.2/src/pad.c") + set(src ${src} "sdl-1.2/src/pad.c") + set(inc ${inc} "sdl-1.2/inc") + set(deps ${deps} SDL) endif() + +add_library(pad ${src}) +target_include_directories(pad PUBLIC ${inc} PRIVATE ${privinc}) diff --git a/src/pad/inc/pad.h b/src/pad/inc/pad.h index 2579c84..c8f6b31 100644 --- a/src/pad/inc/pad.h +++ b/src/pad/inc/pad.h @@ -19,13 +19,17 @@ extern "C" X(PAD_KEY_C) \ X(PAD_KEY_D) \ X(PAD_KEY_E) \ - X(PAD_KEY_OPTIONS) + X(PAD_KEY_OPTIONS) \ + X(PAD_KEY_FULL_SCREEN) \ + X(PAD_KEY_EXIT) enum pad_key { #define X(x) x, PAD_KEYS #undef X + + MAX_PAD_KEYS }; struct pad diff --git a/src/pad/sdl-1.2/inc/pad/port.h b/src/pad/sdl-1.2/inc/pad/port.h index b6ae85a..8334b6a 100644 --- a/src/pad/sdl-1.2/inc/pad/port.h +++ b/src/pad/sdl-1.2/inc/pad/port.h @@ -1,8 +1,6 @@ #ifndef PAD_SDL_1_2_H #define PAD_SDL_1_2_H -#include <stdbool.h> - #ifdef __cplusplus extern "C" { @@ -10,7 +8,7 @@ extern "C" struct pad_port { - bool exit; + int dummy; }; #ifdef __cplusplus diff --git a/src/pad/sdl-1.2/src/pad.c b/src/pad/sdl-1.2/src/pad.c index a062758..f6a96c1 100644 --- a/src/pad/sdl-1.2/src/pad.c +++ b/src/pad/sdl-1.2/src/pad.c @@ -2,77 +2,8 @@ #include <SDL/SDL.h> #include <stdio.h> -static void key_event(const SDL_KeyboardEvent *const key, struct pad *const p) -{ - static const int keys[] = - { - [PAD_KEY_LEFT] = SDLK_LEFT, - [PAD_KEY_RIGHT] = SDLK_RIGHT, - [PAD_KEY_UP] = SDLK_UP, - [PAD_KEY_DOWN] = SDLK_DOWN, - [PAD_KEY_A] = SDLK_x, - [PAD_KEY_B] = SDLK_d, - [PAD_KEY_C] = SDLK_w, - [PAD_KEY_D] = SDLK_a, - [PAD_KEY_E] = SDLK_q, - [PAD_KEY_OPTIONS] = SDLK_ESCAPE - }; - - for (size_t i = 0; i < sizeof keys / sizeof *keys; i++) - { - const SDLKey k = key->keysym.sym; - - if (k == keys[i]) - { - const int mask = 1 << i; - - if (key->type == SDL_KEYDOWN) - { - printf("%s pressed\n", pad_str(i)); - p->mask |= mask; - } - else - { - printf("%s released\n", pad_str(i)); - p->mask &= ~mask; - } - } - } -} - void pad_port_update(struct pad *const p) { - SDL_Event ev; - static const int masks[] = {SDL_KEYEVENTMASK}; - int n; - - while ((n = SDL_PeepEvents(&ev, 1, SDL_GETEVENT, - masks[p->player] | SDL_QUITMASK)) > 0) - { - switch (ev.type) - { - case SDL_KEYDOWN: - /* Fall through. */ - case SDL_KEYUP: - key_event(&ev.key, p); - break; - - case SDL_QUIT: - p->port.exit = true; - break; - - default: - fprintf(stderr, "%s: unexpected SDL_Event %d\n", - __func__, ev.type); - break; - } - } - - if (n < 0) - { - fprintf(stderr, "%s: SDL_PeepEvents: %s\n", __func__, SDL_GetError()); - return; - } } void pad_init(const int player, struct pad *const p) |
