SDL: Refactor GBASDLEvents and GBASDLPlayer into mSDLEvents and mSDLPlayer

This commit is contained in:
Jeffrey Pfau 2016-02-02 20:59:56 -08:00
parent 46590f98d8
commit a9ba3a2094
18 changed files with 229 additions and 155 deletions

View File

@ -42,6 +42,8 @@ struct mCore {
void (*step)(struct mCore*); void (*step)(struct mCore*);
void (*setKeys)(struct mCore*, uint32_t keys); void (*setKeys)(struct mCore*, uint32_t keys);
void (*addKeys)(struct mCore*, uint32_t keys);
void (*clearKeys)(struct mCore*, uint32_t keys);
int32_t (*frameCounter)(struct mCore*); int32_t (*frameCounter)(struct mCore*);
int32_t (*frameCycles)(struct mCore*); int32_t (*frameCycles)(struct mCore*);

View File

@ -46,4 +46,8 @@ struct mRTCGenericSource {
void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core); void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
struct mRumble {
void (*setRumble)(struct mRumble*, int enable);
};
#endif #endif

View File

@ -98,6 +98,16 @@ static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) {
gbcore->keys = keys; gbcore->keys = keys;
} }
static void _GBCoreAddKeys(struct mCore* core, uint32_t keys) {
struct GBCore* gbcore = (struct GBCore*) core;
gbcore->keys |= keys;
}
static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) {
struct GBCore* gbcore = (struct GBCore*) core;
gbcore->keys &= ~keys;
}
static int32_t _GBCoreFrameCounter(struct mCore* core) { static int32_t _GBCoreFrameCounter(struct mCore* core) {
struct GB* gb = core->board; struct GB* gb = core->board;
return gb->video.frameCounter; return gb->video.frameCounter;
@ -136,6 +146,8 @@ struct mCore* GBCoreCreate(void) {
core->runLoop = _GBCoreRunLoop; core->runLoop = _GBCoreRunLoop;
core->step = _GBCoreStep; core->step = _GBCoreStep;
core->setKeys = _GBCoreSetKeys; core->setKeys = _GBCoreSetKeys;
core->addKeys = _GBCoreAddKeys;
core->clearKeys = _GBCoreClearKeys;
core->frameCounter = _GBCoreFrameCounter; core->frameCounter = _GBCoreFrameCounter;
core->frameCycles = _GBCoreFrameCycles; core->frameCycles = _GBCoreFrameCycles;
core->frequency = _GBCoreFrequency; core->frequency = _GBCoreFrequency;

View File

@ -99,7 +99,7 @@ struct GBA {
struct mRotationSource* rotationSource; struct mRotationSource* rotationSource;
struct GBALuminanceSource* luminanceSource; struct GBALuminanceSource* luminanceSource;
struct mRTCSource* rtcSource; struct mRTCSource* rtcSource;
struct GBARumble* rumble; struct mRumble* rumble;
struct GBARRContext* rr; struct GBARRContext* rr;
void* pristineRom; void* pristineRom;

View File

@ -364,7 +364,7 @@ void GBAHardwareInitRumble(struct GBACartridgeHardware* hw) {
} }
void _rumbleReadPins(struct GBACartridgeHardware* hw) { void _rumbleReadPins(struct GBACartridgeHardware* hw) {
struct GBARumble* rumble = hw->p->rumble; struct mRumble* rumble = hw->p->rumble;
if (!rumble) { if (!rumble) {
return; return;
} }

View File

@ -76,10 +76,6 @@ struct GBARTC {
}; };
#pragma pack(pop) #pragma pack(pop)
struct GBARumble {
void (*setRumble)(struct GBARumble*, int enable);
};
struct GBAGBPKeyCallback { struct GBAGBPKeyCallback {
struct mKeyCallback d; struct mKeyCallback d;
struct GBACartridgeHardware* p; struct GBACartridgeHardware* p;

View File

@ -29,7 +29,7 @@ static retro_set_rumble_state_t rumbleCallback;
static void GBARetroLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args); static void GBARetroLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
static void _postAudioBuffer(struct GBAAVStream*, struct GBAAudio* audio); static void _postAudioBuffer(struct GBAAVStream*, struct GBAAudio* audio);
static void _setRumble(struct GBARumble* rumble, int enable); static void _setRumble(struct mRumble* rumble, int enable);
static uint8_t _readLux(struct GBALuminanceSource* lux); static uint8_t _readLux(struct GBALuminanceSource* lux);
static void _updateLux(struct GBALuminanceSource* lux); static void _updateLux(struct GBALuminanceSource* lux);
@ -41,7 +41,7 @@ static void* savedata;
static struct GBAAVStream stream; static struct GBAAVStream stream;
static int rumbleLevel; static int rumbleLevel;
static struct CircleBuffer rumbleHistory; static struct CircleBuffer rumbleHistory;
static struct GBARumble rumble; static struct mRumble rumble;
static struct GBALuminanceSource lux; static struct GBALuminanceSource lux;
static int luxLevel; static int luxLevel;
static struct GBACheatDevice cheats; static struct GBACheatDevice cheats;
@ -470,7 +470,7 @@ static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio)
audioCallback(samples, SAMPLES); audioCallback(samples, SAMPLES);
} }
static void _setRumble(struct GBARumble* rumble, int enable) { static void _setRumble(struct mRumble* rumble, int enable) {
UNUSED(rumble); UNUSED(rumble);
if (!rumbleCallback) { if (!rumbleCallback) {
return; return;

View File

@ -22,7 +22,7 @@ using namespace QGBA;
#ifdef BUILD_SDL #ifdef BUILD_SDL
int InputController::s_sdlInited = 0; int InputController::s_sdlInited = 0;
GBASDLEvents InputController::s_sdlEvents; mSDLEvents InputController::s_sdlEvents;
#endif #endif
InputController::InputController(int playerId, QWidget* topLevel, QObject* parent) InputController::InputController(int playerId, QWidget* topLevel, QObject* parent)
@ -41,11 +41,11 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
#ifdef BUILD_SDL #ifdef BUILD_SDL
if (s_sdlInited == 0) { if (s_sdlInited == 0) {
GBASDLInitEvents(&s_sdlEvents); mSDLInitEvents(&s_sdlEvents);
} }
++s_sdlInited; ++s_sdlInited;
m_sdlPlayer.bindings = &m_inputMap; m_sdlPlayer.bindings = &m_inputMap;
GBASDLInitBindings(&m_inputMap); mSDLInitBindingsGBA(&m_inputMap);
updateJoysticks(); updateJoysticks();
#endif #endif
@ -75,12 +75,12 @@ InputController::~InputController() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
if (m_playerAttached) { if (m_playerAttached) {
GBASDLDetachPlayer(&s_sdlEvents, &m_sdlPlayer); mSDLDetachPlayer(&s_sdlEvents, &m_sdlPlayer);
} }
--s_sdlInited; --s_sdlInited;
if (s_sdlInited == 0) { if (s_sdlInited == 0) {
GBASDLDeinitEvents(&s_sdlEvents); mSDLDeinitEvents(&s_sdlEvents);
} }
#endif #endif
} }
@ -90,9 +90,9 @@ void InputController::setConfiguration(ConfigController* config) {
setAllowOpposing(config->getOption("allowOpposingDirections").toInt()); setAllowOpposing(config->getOption("allowOpposingDirections").toInt());
loadConfiguration(KEYBOARD); loadConfiguration(KEYBOARD);
#ifdef BUILD_SDL #ifdef BUILD_SDL
GBASDLEventsLoadConfig(&s_sdlEvents, config->input()); mSDLEventsLoadConfig(&s_sdlEvents, config->input());
if (!m_playerAttached) { if (!m_playerAttached) {
m_playerAttached = GBASDLAttachPlayer(&s_sdlEvents, &m_sdlPlayer); m_playerAttached = mSDLAttachPlayer(&s_sdlEvents, &m_sdlPlayer);
} }
loadConfiguration(SDL_BINDING_BUTTON); loadConfiguration(SDL_BINDING_BUTTON);
loadProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON)); loadProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON));
@ -103,7 +103,7 @@ void InputController::loadConfiguration(uint32_t type) {
mInputMapLoad(&m_inputMap, type, m_config->input()); mInputMapLoad(&m_inputMap, type, m_config->input());
#ifdef BUILD_SDL #ifdef BUILD_SDL
if (m_playerAttached) { if (m_playerAttached) {
GBASDLPlayerLoadConfig(&m_sdlPlayer, m_config->input()); mSDLPlayerLoadConfig(&m_sdlPlayer, m_config->input());
} }
#endif #endif
} }
@ -126,7 +126,7 @@ void InputController::saveConfiguration() {
saveConfiguration(SDL_BINDING_BUTTON); saveConfiguration(SDL_BINDING_BUTTON);
saveProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON)); saveProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON));
if (m_playerAttached) { if (m_playerAttached) {
GBASDLPlayerSaveConfig(&m_sdlPlayer, m_config->input()); mSDLPlayerSaveConfig(&m_sdlPlayer, m_config->input());
} }
m_config->write(); m_config->write();
#endif #endif
@ -194,7 +194,7 @@ int InputController::gamepad(uint32_t type) const {
void InputController::setGamepad(uint32_t type, int index) { void InputController::setGamepad(uint32_t type, int index) {
#ifdef BUILD_SDL #ifdef BUILD_SDL
if (type == SDL_BINDING_BUTTON) { if (type == SDL_BINDING_BUTTON) {
GBASDLPlayerChangeJoystick(&s_sdlEvents, &m_sdlPlayer, index); mSDLPlayerChangeJoystick(&s_sdlEvents, &m_sdlPlayer, index);
} }
#endif #endif
} }
@ -206,7 +206,7 @@ void InputController::setPreferredGamepad(uint32_t type, const QString& device)
mInputSetPreferredDevice(m_config->input(), "gba", type, m_playerId, device.toUtf8().constData()); mInputSetPreferredDevice(m_config->input(), "gba", type, m_playerId, device.toUtf8().constData());
} }
GBARumble* InputController::rumble() { mRumble* InputController::rumble() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (m_playerAttached) { if (m_playerAttached) {
@ -285,7 +285,7 @@ void InputController::bindKey(uint32_t type, int key, GBAKey gbaKey) {
void InputController::updateJoysticks() { void InputController::updateJoysticks() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
GBASDLUpdateJoysticks(&s_sdlEvents); mSDLUpdateJoysticks(&s_sdlEvents);
#endif #endif
} }
@ -513,7 +513,7 @@ bool InputController::hasPendingEvent(GBAKey key) const {
void InputController::suspendScreensaver() { void InputController::suspendScreensaver() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLSuspendScreensaver(&s_sdlEvents); mSDLSuspendScreensaver(&s_sdlEvents);
#endif #endif
#endif #endif
} }
@ -521,7 +521,7 @@ void InputController::suspendScreensaver() {
void InputController::resumeScreensaver() { void InputController::resumeScreensaver() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLResumeScreensaver(&s_sdlEvents); mSDLResumeScreensaver(&s_sdlEvents);
#endif #endif
#endif #endif
} }
@ -529,7 +529,7 @@ void InputController::resumeScreensaver() {
void InputController::setScreensaverSuspendable(bool suspendable) { void InputController::setScreensaverSuspendable(bool suspendable) {
#ifdef BUILD_SDL #ifdef BUILD_SDL
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLSetScreensaverSuspendable(&s_sdlEvents, suspendable); mSDLSetScreensaverSuspendable(&s_sdlEvents, suspendable);
#endif #endif
#endif #endif
} }

View File

@ -79,7 +79,7 @@ public:
void stealFocus(QWidget* focus); void stealFocus(QWidget* focus);
void releaseFocus(QWidget* focus); void releaseFocus(QWidget* focus);
GBARumble* rumble(); mRumble* rumble();
mRotationSource* rotationSource(); mRotationSource* rotationSource();
signals: signals:
@ -108,8 +108,8 @@ private:
#ifdef BUILD_SDL #ifdef BUILD_SDL
static int s_sdlInited; static int s_sdlInited;
static GBASDLEvents s_sdlEvents; static mSDLEvents s_sdlEvents;
GBASDLPlayer m_sdlPlayer; mSDLPlayer m_sdlPlayer;
bool m_playerAttached; bool m_playerAttached;
#endif #endif

View File

@ -69,7 +69,7 @@ void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user) {
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &renderer->player, &event); mSDLHandleEventGBA(context, &renderer->player, &event);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
// Event handling can change the size of the screen // Event handling can change the size of the screen
if (renderer->player.windowUpdated) { if (renderer->player.windowUpdated) {
@ -132,32 +132,15 @@ void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user) {
UNUSED(user); UNUSED(user);
SDL_Event event; SDL_Event event;
struct VideoBackend* v = &renderer->gl.d; struct VideoBackend* v = &renderer->gl.d;
int activeKeys = 0;
renderer->audio.psg = &((struct GB*) renderer->core->board)->audio; renderer->audio.psg = &((struct GB*) renderer->core->board)->audio;
while (true) { while (true) {
renderer->core->runFrame(renderer->core); renderer->core->runFrame(renderer->core);
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
// TODO: Refactor out mSDLHandleEvent(renderer->core, &renderer->player, &event);
if (event.type == SDL_KEYUP || event.type == SDL_KEYDOWN) {
int key;
#if !defined(BUILD_PANDORA) && SDL_VERSION_ATLEAST(2, 0, 0)
key = mInputMapKey(renderer->player.bindings, SDL_BINDING_KEY, event.key.keysym.scancode);
#else
key = mInputMapKey(renderer->player.bindings, SDL_BINDING_KEY, event.key.keysym.sym);
#endif
if (key != GBA_KEY_NONE) {
if (event.type == SDL_KEYDOWN) {
activeKeys |= 1 << key;
} else {
activeKeys &= ~(1 << key);
}
}
}
if (event.type == SDL_QUIT) { if (event.type == SDL_QUIT) {
return; return;
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
// Event handling can change the size of the screen // Event handling can change the size of the screen
if (renderer->player.windowUpdated) { if (renderer->player.windowUpdated) {
@ -167,7 +150,6 @@ void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user) {
} }
#endif #endif
} }
renderer->core->setKeys(renderer->core, activeKeys);
v->postFrame(v, renderer->outputBuffer); v->postFrame(v, renderer->outputBuffer);
v->drawFrame(v); v->drawFrame(v);

View File

@ -112,7 +112,7 @@ void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user) {
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &renderer->player, &event); mSDLHandleEventGBA(context, &renderer->player, &event);
} }
if (mCoreSyncWaitFrameStart(&context->sync)) { if (mCoreSyncWaitFrameStart(&context->sync)) {

View File

@ -188,11 +188,11 @@ int main(int argc, char** argv) {
} }
renderer.player.bindings = &inputMap; renderer.player.bindings = &inputMap;
GBASDLInitBindings(&inputMap); mSDLInitBindingsGBA(&inputMap);
GBASDLInitEvents(&renderer.events); mSDLInitEvents(&renderer.events);
GBASDLEventsLoadConfig(&renderer.events, mCoreConfigGetInput(&config)); mSDLEventsLoadConfig(&renderer.events, mCoreConfigGetInput(&config));
GBASDLAttachPlayer(&renderer.events, &renderer.player); mSDLAttachPlayer(&renderer.events, &renderer.player);
GBASDLPlayerLoadConfig(&renderer.player, mCoreConfigGetInput(&config)); mSDLPlayerLoadConfig(&renderer.player, mCoreConfigGetInput(&config));
int ret; int ret;
@ -207,7 +207,7 @@ int main(int argc, char** argv) {
ret = 1; ret = 1;
break; break;
} }
GBASDLDetachPlayer(&renderer.events, &renderer.player); mSDLDetachPlayer(&renderer.events, &renderer.player);
mInputMapDeinit(&inputMap); mInputMapDeinit(&inputMap);
mSDLDeinit(&renderer); mSDLDeinit(&renderer);
@ -245,8 +245,8 @@ int mSDLRunGBA(struct mSDLRenderer* renderer, struct GBAArguments* args, struct
if (!didFail) { if (!didFail) {
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLSetScreensaverSuspendable(&renderer->events, opts->suspendScreensaver); mSDLSetScreensaverSuspendable(&renderer->events, opts->suspendScreensaver);
GBASDLSuspendScreensaver(&renderer->events); mSDLSuspendScreensaver(&renderer->events);
#endif #endif
if (GBAThreadStart(&context)) { if (GBAThreadStart(&context)) {
renderer->audio.psg = &context.gba->audio.psg; renderer->audio.psg = &context.gba->audio.psg;
@ -259,8 +259,8 @@ int mSDLRunGBA(struct mSDLRenderer* renderer, struct GBAArguments* args, struct
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLResumeScreensaver(&renderer->events); mSDLResumeScreensaver(&renderer->events);
GBASDLSetScreensaverSuspendable(&renderer->events, false); mSDLSetScreensaverSuspendable(&renderer->events, false);
#endif #endif
if (GBAThreadHasCrashed(&context)) { if (GBAThreadHasCrashed(&context)) {
@ -315,7 +315,7 @@ static bool mSDLInit(struct mSDLRenderer* renderer) {
} }
static void mSDLDeinit(struct mSDLRenderer* renderer) { static void mSDLDeinit(struct mSDLRenderer* renderer) {
GBASDLDeinitEvents(&renderer->events); mSDLDeinitEvents(&renderer->events);
GBSDLDeinitAudio(&renderer->audio); GBSDLDeinitAudio(&renderer->audio);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_DestroyWindow(renderer->window); SDL_DestroyWindow(renderer->window);

View File

@ -49,8 +49,8 @@ struct mSDLRenderer {
struct GBAVideoSoftwareRenderer d; struct GBAVideoSoftwareRenderer d;
#endif #endif
struct GBSDLAudio audio; struct GBSDLAudio audio;
struct GBASDLEvents events; struct mSDLEvents events;
struct GBASDLPlayer player; struct mSDLPlayer player;
bool (*init)(struct mSDLRenderer* renderer); bool (*init)(struct mSDLRenderer* renderer);
void (*runloop)(struct mSDLRenderer* renderer, void* user); void (*runloop)(struct mSDLRenderer* renderer, void* user);

View File

@ -16,23 +16,23 @@
#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
#endif #endif
static bool GBASDLInit(struct SDLSoftwareRenderer* renderer); static bool mSDLInit(struct SDLSoftwareRenderer* renderer);
static void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer); static void mSDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer);
static void GBASDLDeinit(struct SDLSoftwareRenderer* renderer); static void mSDLDeinit(struct SDLSoftwareRenderer* renderer);
void GBASDLGLCreate(struct SDLSoftwareRenderer* renderer) { void mSDLGLCreate(struct SDLSoftwareRenderer* renderer) {
renderer->init = GBASDLInit; renderer->init = mSDLInit;
renderer->deinit = GBASDLDeinit; renderer->deinit = mSDLDeinit;
renderer->runloop = GBASDLRunloop; renderer->runloop = mSDLRunloop;
} }
void GBASDLSWCreate(struct SDLSoftwareRenderer* renderer) { void mSDLSWCreate(struct SDLSoftwareRenderer* renderer) {
renderer->init = GBASDLInit; renderer->init = mSDLInit;
renderer->deinit = GBASDLDeinit; renderer->deinit = mSDLDeinit;
renderer->runloop = GBASDLRunloop; renderer->runloop = mSDLRunloop;
} }
bool GBASDLInit(struct SDLSoftwareRenderer* renderer) { bool mSDLInit(struct SDLSoftwareRenderer* renderer) {
SDL_SetVideoMode(800, 480, 16, SDL_FULLSCREEN); SDL_SetVideoMode(800, 480, 16, SDL_FULLSCREEN);
renderer->odd = 0; renderer->odd = 0;
@ -83,12 +83,12 @@ bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
return true; return true;
} }
void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) { void mSDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) {
SDL_Event event; SDL_Event event;
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &renderer->player, &event); mSDLHandleEventGBA(context, &renderer->player, &event);
} }
if (mCoreSyncWaitFrameStart(&context->sync)) { if (mCoreSyncWaitFrameStart(&context->sync)) {
@ -107,7 +107,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
} }
} }
void GBASDLDeinit(struct SDLSoftwareRenderer* renderer) { void mSDLDeinit(struct SDLSoftwareRenderer* renderer) {
munmap(renderer->base[0], VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); munmap(renderer->base[0], VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
struct omapfb_plane_info plane; struct omapfb_plane_info plane;

View File

@ -5,10 +5,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "sdl-events.h" #include "sdl-events.h"
#include "core/input.h"
#include "debugger/debugger.h" #include "debugger/debugger.h"
#include "gba/input.h"
#include "gba/io.h" #include "gba/io.h"
#include "gba/rr/rr.h" #include "gba/rr/rr.h"
#include "gba/serialize.h" #include "gba/serialize.h"
#include "gba/supervisor/thread.h"
#include "gba/video.h" #include "gba/video.h"
#include "gba/renderers/video-software.h" #include "gba/renderers/video-software.h"
#include "util/configuration.h" #include "util/configuration.h"
@ -27,14 +30,14 @@
DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo); DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
static void _GBASDLSetRumble(struct GBARumble* rumble, int enable); static void _mSDLSetRumble(struct mRumble* rumble, int enable);
#endif #endif
static int32_t _GBASDLReadTiltX(struct mRotationSource* rumble); static int32_t _mSDLReadTiltX(struct mRotationSource* rumble);
static int32_t _GBASDLReadTiltY(struct mRotationSource* rumble); static int32_t _mSDLReadTiltY(struct mRotationSource* rumble);
static int32_t _GBASDLReadGyroZ(struct mRotationSource* rumble); static int32_t _mSDLReadGyroZ(struct mRotationSource* rumble);
static void _GBASDLRotationSample(struct mRotationSource* source); static void _mSDLRotationSample(struct mRotationSource* source);
bool GBASDLInitEvents(struct GBASDLEvents* context) { bool mSDLInitEvents(struct mSDLEvents* context) {
#if SDL_VERSION_ATLEAST(2, 0, 4) #if SDL_VERSION_ATLEAST(2, 0, 4)
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif #endif
@ -56,7 +59,7 @@ bool GBASDLInitEvents(struct GBASDLEvents* context) {
int nJoysticks = SDL_NumJoysticks(); int nJoysticks = SDL_NumJoysticks();
SDL_JoystickListInit(&context->joysticks, nJoysticks); SDL_JoystickListInit(&context->joysticks, nJoysticks);
if (nJoysticks > 0) { if (nJoysticks > 0) {
GBASDLUpdateJoysticks(context); mSDLUpdateJoysticks(context);
} }
context->playersAttached = 0; context->playersAttached = 0;
@ -74,7 +77,7 @@ bool GBASDLInitEvents(struct GBASDLEvents* context) {
return true; return true;
} }
void GBASDLDeinitEvents(struct GBASDLEvents* context) { void mSDLDeinitEvents(struct mSDLEvents* context) {
size_t i; size_t i;
for (i = 0; i < SDL_JoystickListSize(&context->joysticks); ++i) { for (i = 0; i < SDL_JoystickListSize(&context->joysticks); ++i) {
struct SDL_JoystickCombo* joystick = SDL_JoystickListGetPointer(&context->joysticks, i); struct SDL_JoystickCombo* joystick = SDL_JoystickListGetPointer(&context->joysticks, i);
@ -87,14 +90,14 @@ void GBASDLDeinitEvents(struct GBASDLEvents* context) {
SDL_QuitSubSystem(SDL_INIT_JOYSTICK); SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
} }
void GBASDLEventsLoadConfig(struct GBASDLEvents* context, const struct Configuration* config) { void mSDLEventsLoadConfig(struct mSDLEvents* context, const struct Configuration* config) {
context->preferredJoysticks[0] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 0); context->preferredJoysticks[0] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 0);
context->preferredJoysticks[1] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 1); context->preferredJoysticks[1] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 1);
context->preferredJoysticks[2] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 2); context->preferredJoysticks[2] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 2);
context->preferredJoysticks[3] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 3); context->preferredJoysticks[3] = mInputGetPreferredDevice(config, "gba", SDL_BINDING_BUTTON, 3);
} }
void GBASDLInitBindings(struct mInputMap* inputMap) { void mSDLInitBindingsGBA(struct mInputMap* inputMap) {
#ifdef BUILD_PANDORA #ifdef BUILD_PANDORA
mInputBindKey(inputMap, SDL_BINDING_KEY, SDLK_PAGEDOWN, GBA_KEY_A); mInputBindKey(inputMap, SDL_BINDING_KEY, SDLK_PAGEDOWN, GBA_KEY_A);
mInputBindKey(inputMap, SDL_BINDING_KEY, SDLK_END, GBA_KEY_B); mInputBindKey(inputMap, SDL_BINDING_KEY, SDLK_END, GBA_KEY_B);
@ -147,7 +150,7 @@ void GBASDLInitBindings(struct mInputMap* inputMap) {
mInputBindAxis(inputMap, SDL_BINDING_BUTTON, 1, &description); mInputBindAxis(inputMap, SDL_BINDING_BUTTON, 1, &description);
} }
bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player) { bool mSDLAttachPlayer(struct mSDLEvents* events, struct mSDLPlayer* player) {
player->joystick = 0; player->joystick = 0;
if (events->playersAttached >= MAX_PLAYERS) { if (events->playersAttached >= MAX_PLAYERS) {
@ -155,16 +158,16 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
player->rumble.d.setRumble = _GBASDLSetRumble; player->rumble.d.setRumble = _mSDLSetRumble;
CircleBufferInit(&player->rumble.history, RUMBLE_PWM); CircleBufferInit(&player->rumble.history, RUMBLE_PWM);
player->rumble.level = 0; player->rumble.level = 0;
player->rumble.p = player; player->rumble.p = player;
#endif #endif
player->rotation.d.readTiltX = _GBASDLReadTiltX; player->rotation.d.readTiltX = _mSDLReadTiltX;
player->rotation.d.readTiltY = _GBASDLReadTiltY; player->rotation.d.readTiltY = _mSDLReadTiltY;
player->rotation.d.readGyroZ = _GBASDLReadGyroZ; player->rotation.d.readGyroZ = _mSDLReadGyroZ;
player->rotation.d.sample = _GBASDLRotationSample; player->rotation.d.sample = _mSDLRotationSample;
player->rotation.axisX = 2; player->rotation.axisX = 2;
player->rotation.axisY = 3; player->rotation.axisY = 3;
player->rotation.gyroSensitivity = 2.2e9f; player->rotation.gyroSensitivity = 2.2e9f;
@ -228,7 +231,7 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
return true; return true;
} }
void GBASDLDetachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player) { void mSDLDetachPlayer(struct mSDLEvents* events, struct mSDLPlayer* player) {
if (player != events->players[player->playerId]) { if (player != events->players[player->playerId]) {
return; return;
} }
@ -245,7 +248,7 @@ void GBASDLDetachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
CircleBufferDeinit(&player->rotation.zHistory); CircleBufferDeinit(&player->rotation.zHistory);
} }
void GBASDLPlayerLoadConfig(struct GBASDLPlayer* context, const struct Configuration* config) { void mSDLPlayerLoadConfig(struct mSDLPlayer* context, const struct Configuration* config) {
mInputMapLoad(context->bindings, SDL_BINDING_KEY, config); mInputMapLoad(context->bindings, SDL_BINDING_KEY, config);
if (context->joystick) { if (context->joystick) {
mInputMapLoad(context->bindings, SDL_BINDING_BUTTON, config); mInputMapLoad(context->bindings, SDL_BINDING_BUTTON, config);
@ -298,7 +301,7 @@ void GBASDLPlayerLoadConfig(struct GBASDLPlayer* context, const struct Configura
} }
} }
void GBASDLPlayerSaveConfig(const struct GBASDLPlayer* context, struct Configuration* config) { void mSDLPlayerSaveConfig(const struct mSDLPlayer* context, struct Configuration* config) {
if (context->joystick) { if (context->joystick) {
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
const char* name = SDL_JoystickName(context->joystick->joystick); const char* name = SDL_JoystickName(context->joystick->joystick);
@ -319,14 +322,14 @@ void GBASDLPlayerSaveConfig(const struct GBASDLPlayer* context, struct Configura
} }
} }
void GBASDLPlayerChangeJoystick(struct GBASDLEvents* events, struct GBASDLPlayer* player, size_t index) { void mSDLPlayerChangeJoystick(struct mSDLEvents* events, struct mSDLPlayer* player, size_t index) {
if (player->playerId >= MAX_PLAYERS || index >= SDL_JoystickListSize(&events->joysticks)) { if (player->playerId >= MAX_PLAYERS || index >= SDL_JoystickListSize(&events->joysticks)) {
return; return;
} }
player->joystick = SDL_JoystickListGetPointer(&events->joysticks, index); player->joystick = SDL_JoystickListGetPointer(&events->joysticks, index);
} }
void GBASDLUpdateJoysticks(struct GBASDLEvents* events) { void mSDLUpdateJoysticks(struct mSDLEvents* events) {
// Pump SDL joystick events without eating the rest of the events // Pump SDL joystick events without eating the rest of the events
SDL_JoystickUpdate(); SDL_JoystickUpdate();
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
@ -376,7 +379,7 @@ static void _pauseAfterFrame(struct GBAThread* context) {
GBAThreadPauseFromThread(context); GBAThreadPauseFromThread(context);
} }
static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const struct SDL_KeyboardEvent* event) { static void _mSDLHandleKeypressGBA(struct GBAThread* context, struct mSDLPlayer* sdlContext, const struct SDL_KeyboardEvent* event) {
enum GBAKey key = GBA_KEY_NONE; enum GBAKey key = GBA_KEY_NONE;
if (!event->keysym.mod) { if (!event->keysym.mod) {
#if !defined(BUILD_PANDORA) && SDL_VERSION_ATLEAST(2, 0, 0) #if !defined(BUILD_PANDORA) && SDL_VERSION_ATLEAST(2, 0, 0)
@ -493,7 +496,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLPlayer
} }
} }
static void _GBASDLHandleJoyButton(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) { static void _mSDLHandleJoyButtonGBA(struct GBAThread* context, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) {
enum GBAKey key = 0; enum GBAKey key = 0;
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_BUTTON, event->button); key = mInputMapKey(sdlContext->bindings, SDL_BINDING_BUTTON, event->button);
if (key == GBA_KEY_NONE) { if (key == GBA_KEY_NONE) {
@ -507,7 +510,7 @@ static void _GBASDLHandleJoyButton(struct GBAThread* context, struct GBASDLPlaye
} }
} }
static void _GBASDLHandleJoyHat(struct GBAThread* context, const struct SDL_JoyHatEvent* event) { static void _mSDLHandleJoyHatGBA(struct GBAThread* context, const struct SDL_JoyHatEvent* event) {
enum GBAKey key = 0; enum GBAKey key = 0;
if (event->value & SDL_HAT_UP) { if (event->value & SDL_HAT_UP) {
@ -527,21 +530,67 @@ static void _GBASDLHandleJoyHat(struct GBAThread* context, const struct SDL_JoyH
context->activeKeys |= key; context->activeKeys |= key;
} }
static void _GBASDLHandleJoyAxis(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const struct SDL_JoyAxisEvent* event) { static void _mSDLHandleJoyAxisGBA(struct GBAThread* context, struct mSDLPlayer* sdlContext, const struct SDL_JoyAxisEvent* event) {
int keys = context->activeKeys; int keys = context->activeKeys;
keys = mInputClearAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, keys); keys = mInputClearAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, keys);
enum GBAKey key = mInputMapAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, event->value); enum GBAKey key = mInputMapAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, event->value);
if (key != GBA_KEY_NONE) { if (key != -1) {
keys |= 1 << key; keys |= 1 << key;
} }
context->activeKeys = keys; context->activeKeys = keys;
} }
static void _mSDLHandleKeypress(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_KeyboardEvent* event) {
int key = -1;
if (!event->keysym.mod) {
#if !defined(BUILD_PANDORA) && SDL_VERSION_ATLEAST(2, 0, 0)
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_KEY, event->keysym.scancode);
#else
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_KEY, event->keysym.sym);
#endif
}
if (key != -1) {
if (event->type == SDL_KEYDOWN) {
core->addKeys(core, 1 << key);
} else {
core->clearKeys(core, 1 << key);
}
return;
}
// TODO: Put back events
}
static void _mSDLHandleJoyButton(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) {
int key = 0;
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_BUTTON, event->button);
if (key == -1) {
return;
}
if (event->type == SDL_JOYBUTTONDOWN) {
core->addKeys(core, 1 << key);
} else {
core->clearKeys(core, 1 << key);
}
}
static void _mSDLHandleJoyAxis(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyAxisEvent* event) {
int clearKeys = ~mInputClearAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, -1);
int newKeys = 0;
int key = mInputMapAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, event->value);
if (key != -1) {
newKeys |= 1 << key;
}
clearKeys &= ~newKeys;
core->clearKeys(core, clearKeys);
core->addKeys(core, newKeys);
}
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
static void _GBASDLHandleWindowEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const struct SDL_WindowEvent* event) { static void _mSDLHandleWindowEvent(struct mSDLPlayer* sdlContext, const struct SDL_WindowEvent* event) {
UNUSED(context);
switch (event->event) { switch (event->event) {
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
sdlContext->windowUpdated = 1; sdlContext->windowUpdated = 1;
@ -550,36 +599,63 @@ static void _GBASDLHandleWindowEvent(struct GBAThread* context, struct GBASDLPla
} }
#endif #endif
void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event) { void mSDLHandleEventGBA(struct GBAThread* context, struct mSDLPlayer* sdlContext, const union SDL_Event* event) {
switch (event->type) { switch (event->type) {
case SDL_QUIT: case SDL_QUIT:
GBAThreadEnd(context); GBAThreadEnd(context);
break; break;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
_GBASDLHandleWindowEvent(context, sdlContext, &event->window); _mSDLHandleWindowEvent(sdlContext, &event->window);
break; break;
#endif #endif
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
_GBASDLHandleKeypress(context, sdlContext, &event->key); _mSDLHandleKeypressGBA(context, sdlContext, &event->key);
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
_GBASDLHandleJoyButton(context, sdlContext, &event->jbutton); _mSDLHandleJoyButtonGBA(context, sdlContext, &event->jbutton);
break; break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
_GBASDLHandleJoyHat(context, &event->jhat); _mSDLHandleJoyHatGBA(context, &event->jhat);
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
_GBASDLHandleJoyAxis(context, sdlContext, &event->jaxis); _mSDLHandleJoyAxisGBA(context, sdlContext, &event->jaxis);
break;
}
}
void mSDLHandleEvent(struct mCore* core, struct mSDLPlayer* sdlContext, const union SDL_Event* event) {
switch (event->type) {
case SDL_QUIT:
// TODO
break;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_WINDOWEVENT:
_mSDLHandleWindowEvent(sdlContext, &event->window);
break;
#endif
case SDL_KEYDOWN:
case SDL_KEYUP:
_mSDLHandleKeypress(core, sdlContext, &event->key);
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
_mSDLHandleJoyButton(core, sdlContext, &event->jbutton);
break;
case SDL_JOYHATMOTION:
// TODO
break;
case SDL_JOYAXISMOTION:
_mSDLHandleJoyAxis(core, sdlContext, &event->jaxis);
break; break;
} }
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
static void _GBASDLSetRumble(struct GBARumble* rumble, int enable) { static void _mSDLSetRumble(struct mRumble* rumble, int enable) {
struct GBASDLRumble* sdlRumble = (struct GBASDLRumble*) rumble; struct mSDLRumble* sdlRumble = (struct mSDLRumble*) rumble;
if (!sdlRumble->p->joystick->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->joystick->haptic)) { if (!sdlRumble->p->joystick->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->joystick->haptic)) {
return; return;
} }
@ -598,31 +674,31 @@ static void _GBASDLSetRumble(struct GBARumble* rumble, int enable) {
} }
#endif #endif
static int32_t _readTilt(struct GBASDLPlayer* player, int axis) { static int32_t _readTilt(struct mSDLPlayer* player, int axis) {
if (!player->joystick) { if (!player->joystick) {
return 0; return 0;
} }
return SDL_JoystickGetAxis(player->joystick->joystick, axis) * 0x3800; return SDL_JoystickGetAxis(player->joystick->joystick, axis) * 0x3800;
} }
static int32_t _GBASDLReadTiltX(struct mRotationSource* source) { static int32_t _mSDLReadTiltX(struct mRotationSource* source) {
struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; struct mSDLRotation* rotation = (struct mSDLRotation*) source;
return _readTilt(rotation->p, rotation->axisX); return _readTilt(rotation->p, rotation->axisX);
} }
static int32_t _GBASDLReadTiltY(struct mRotationSource* source) { static int32_t _mSDLReadTiltY(struct mRotationSource* source) {
struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; struct mSDLRotation* rotation = (struct mSDLRotation*) source;
return _readTilt(rotation->p, rotation->axisY); return _readTilt(rotation->p, rotation->axisY);
} }
static int32_t _GBASDLReadGyroZ(struct mRotationSource* source) { static int32_t _mSDLReadGyroZ(struct mRotationSource* source) {
struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; struct mSDLRotation* rotation = (struct mSDLRotation*) source;
float z = rotation->zDelta; float z = rotation->zDelta;
return z * rotation->gyroSensitivity; return z * rotation->gyroSensitivity;
} }
static void _GBASDLRotationSample(struct mRotationSource* source) { static void _mSDLRotationSample(struct mRotationSource* source) {
struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; struct mSDLRotation* rotation = (struct mSDLRotation*) source;
SDL_JoystickUpdate(); SDL_JoystickUpdate();
if (!rotation->p->joystick) { if (!rotation->p->joystick) {
return; return;
@ -653,21 +729,21 @@ static void _GBASDLRotationSample(struct mRotationSource* source) {
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
void GBASDLSuspendScreensaver(struct GBASDLEvents* events) { void mSDLSuspendScreensaver(struct mSDLEvents* events) {
if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) { if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) {
SDL_DisableScreenSaver(); SDL_DisableScreenSaver();
} }
++events->screensaverSuspendDepth; ++events->screensaverSuspendDepth;
} }
void GBASDLResumeScreensaver(struct GBASDLEvents* events) { void mSDLResumeScreensaver(struct mSDLEvents* events) {
--events->screensaverSuspendDepth; --events->screensaverSuspendDepth;
if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) { if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) {
SDL_EnableScreenSaver(); SDL_EnableScreenSaver();
} }
} }
void GBASDLSetScreensaverSuspendable(struct GBASDLEvents* events, bool suspendable) { void mSDLSetScreensaverSuspendable(struct mSDLEvents* events, bool suspendable) {
bool wasSuspendable = events->screensaverSuspendable; bool wasSuspendable = events->screensaverSuspendable;
events->screensaverSuspendable = suspendable; events->screensaverSuspendable = suspendable;
if (events->screensaverSuspendDepth > 0) { if (events->screensaverSuspendDepth > 0) {

View File

@ -7,11 +7,11 @@
#define SDL_EVENTS_H #define SDL_EVENTS_H
#include "util/common.h" #include "util/common.h"
#include "core/interface.h"
#include "util/circle-buffer.h" #include "util/circle-buffer.h"
#include "util/vector.h" #include "util/vector.h"
#include "gba/supervisor/thread.h"
#include <SDL.h> #include <SDL.h>
#define SDL_BINDING_KEY 0x53444C4BU #define SDL_BINDING_KEY 0x53444C4BU
@ -19,7 +19,6 @@
#define MAX_PLAYERS 4 #define MAX_PLAYERS 4
struct GBAVideoSoftwareRenderer;
struct Configuration; struct Configuration;
struct SDL_JoystickCombo { struct SDL_JoystickCombo {
@ -33,20 +32,19 @@ struct SDL_JoystickCombo {
DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo); DECLARE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
struct GBASDLPlayer; struct mSDLPlayer;
struct mSDLEvents {
struct GBASDLEvents {
struct SDL_JoystickList joysticks; struct SDL_JoystickList joysticks;
const char* preferredJoysticks[MAX_PLAYERS]; const char* preferredJoysticks[MAX_PLAYERS];
int playersAttached; int playersAttached;
struct GBASDLPlayer* players[MAX_PLAYERS]; struct mSDLPlayer* players[MAX_PLAYERS];
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
int screensaverSuspendDepth; int screensaverSuspendDepth;
bool screensaverSuspendable; bool screensaverSuspendable;
#endif #endif
}; };
struct GBASDLPlayer { struct mSDLPlayer {
size_t playerId; size_t playerId;
struct mInputMap* bindings; struct mInputMap* bindings;
struct SDL_JoystickCombo* joystick; struct SDL_JoystickCombo* joystick;
@ -55,18 +53,18 @@ struct GBASDLPlayer {
int fullscreen; int fullscreen;
int windowUpdated; int windowUpdated;
struct GBASDLRumble { struct mSDLRumble {
struct GBARumble d; struct mRumble d;
struct GBASDLPlayer* p; struct mSDLPlayer* p;
int level; int level;
struct CircleBuffer history; struct CircleBuffer history;
} rumble; } rumble;
#endif #endif
struct GBASDLRotation { struct mSDLRotation {
struct mRotationSource d; struct mRotationSource d;
struct GBASDLPlayer* p; struct mSDLPlayer* p;
// Tilt // Tilt
int axisX; int axisX;
@ -83,25 +81,29 @@ struct GBASDLPlayer {
} rotation; } rotation;
}; };
bool GBASDLInitEvents(struct GBASDLEvents*); bool mSDLInitEvents(struct mSDLEvents*);
void GBASDLDeinitEvents(struct GBASDLEvents*); void mSDLDeinitEvents(struct mSDLEvents*);
bool GBASDLAttachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*); bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
void GBASDLDetachPlayer(struct GBASDLEvents*, struct GBASDLPlayer*); void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
void GBASDLEventsLoadConfig(struct GBASDLEvents*, const struct Configuration*); void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
void GBASDLPlayerChangeJoystick(struct GBASDLEvents*, struct GBASDLPlayer*, size_t index); void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
void GBASDLUpdateJoysticks(struct GBASDLEvents* events); void mSDLUpdateJoysticks(struct mSDLEvents* events);
void GBASDLInitBindings(struct mInputMap* inputMap); void mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
void GBASDLPlayerLoadConfig(struct GBASDLPlayer*, const struct Configuration*); void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event); struct GBAThread;
void mSDLInitBindingsGBA(struct mInputMap* inputMap);
void mSDLHandleEventGBA(struct GBAThread* context, struct mSDLPlayer* sdlContext, const union SDL_Event* event);
struct mCore;
void mSDLHandleEvent(struct mCore* core, struct mSDLPlayer* sdlContext, const union SDL_Event* event);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
void GBASDLSuspendScreensaver(struct GBASDLEvents*); void mSDLSuspendScreensaver(struct mSDLEvents*);
void GBASDLResumeScreensaver(struct GBASDLEvents*); void mSDLResumeScreensaver(struct mSDLEvents*);
void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable); void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable);
#endif #endif
#endif #endif

View File

@ -91,7 +91,7 @@ void mSDLSWRunloopGBA(struct mSDLRenderer* renderer, void* user) {
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &renderer->player, &event); mSDLHandleEventGBA(context, &renderer->player, &event);
} }
if (mCoreSyncWaitFrameStart(&context->sync)) { if (mCoreSyncWaitFrameStart(&context->sync)) {

View File

@ -50,7 +50,7 @@ enum FilterMode {
static void _retraceCallback(u32 count); static void _retraceCallback(u32 count);
static void _audioDMA(void); static void _audioDMA(void);
static void _setRumble(struct GBARumble* rumble, int enable); static void _setRumble(struct mRumble* rumble, int enable);
static void _sampleRotation(struct mRotationSource* source); static void _sampleRotation(struct mRotationSource* source);
static int32_t _readTiltX(struct mRotationSource* source); static int32_t _readTiltX(struct mRotationSource* source);
static int32_t _readTiltY(struct mRotationSource* source); static int32_t _readTiltY(struct mRotationSource* source);
@ -74,7 +74,7 @@ static s8 WPAD_StickX(u8 chan, u8 right);
static s8 WPAD_StickY(u8 chan, u8 right); static s8 WPAD_StickY(u8 chan, u8 right);
static struct GBAVideoSoftwareRenderer renderer; static struct GBAVideoSoftwareRenderer renderer;
static struct GBARumble rumble; static struct mRumble rumble;
static struct mRotationSource rotation; static struct mRotationSource rotation;
static GXRModeObj* vmode; static GXRModeObj* vmode;
static Mtx model, view, modelview; static Mtx model, view, modelview;
@ -717,7 +717,7 @@ uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
return keys; return keys;
} }
void _setRumble(struct GBARumble* rumble, int enable) { void _setRumble(struct mRumble* rumble, int enable) {
UNUSED(rumble); UNUSED(rumble);
WPAD_Rumble(0, enable); WPAD_Rumble(0, enable);
if (enable) { if (enable) {