From bc1a094bead8ffa1d9d03beebfa8676511d7ac0b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 29 Jan 2016 22:30:33 -0800 Subject: [PATCH] Core: Refactor several input callbacks --- src/core/interface.h | 34 +++++++++++++++++++++++++++++ src/gba/gba.h | 8 +++---- src/gba/hardware.c | 14 ++++++------ src/gba/hardware.h | 4 ++-- src/gba/interface.h | 25 ++------------------- src/gba/supervisor/thread.c | 4 ++-- src/platform/3ds/main.c | 2 +- src/platform/psp2/psp2-context.c | 2 +- src/platform/qt/InputController.cpp | 2 +- src/platform/qt/InputController.h | 2 +- src/platform/qt/SensorView.h | 4 ++-- src/platform/sdl/sdl-events.c | 16 +++++++------- src/platform/sdl/sdl-events.h | 2 +- src/platform/wii/main.c | 18 +++++++-------- 14 files changed, 75 insertions(+), 62 deletions(-) create mode 100644 src/core/interface.h diff --git a/src/core/interface.h b/src/core/interface.h new file mode 100644 index 000000000..547ea20da --- /dev/null +++ b/src/core/interface.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef CORE_INTERFACE_H +#define CORE_INTERFACE_H + +#include "util/common.h" + +struct mKeyCallback { + uint16_t (*readKeys)(struct mKeyCallback*); +}; + +struct mStopCallback { + void (*stop)(struct mStopCallback*); +}; + +struct mRotationSource { + void (*sample)(struct mRotationSource*); + + int32_t (*readTiltX)(struct mRotationSource*); + int32_t (*readTiltY)(struct mRotationSource*); + + int32_t (*readGyroZ)(struct mRotationSource*); +}; + +struct mRTCSource { + void (*sample)(struct mRTCSource*); + + time_t (*unixTime)(struct mRTCSource*); +}; + +#endif diff --git a/src/gba/gba.h b/src/gba/gba.h index 61acf4f7c..dbf1aa255 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -96,9 +96,9 @@ struct GBA { int springIRQ; uint32_t biosChecksum; int* keySource; - struct GBARotationSource* rotationSource; + struct mRotationSource* rotationSource; struct GBALuminanceSource* luminanceSource; - struct GBARTCSource* rtcSource; + struct mRTCSource* rtcSource; struct GBARumble* rumble; struct GBARRContext* rr; @@ -114,8 +114,8 @@ struct GBA { GBALogHandler logHandler; enum GBALogLevel logLevel; struct GBAAVStream* stream; - struct GBAKeyCallback* keyCallback; - struct GBAStopCallback* stopCallback; + struct mKeyCallback* keyCallback; + struct mStopCallback* stopCallback; enum GBAIdleLoopOptimization idleOptimization; uint32_t idleLoop; diff --git a/src/gba/hardware.c b/src/gba/hardware.c index a0e648d2e..de3e85cb4 100644 --- a/src/gba/hardware.c +++ b/src/gba/hardware.c @@ -21,7 +21,7 @@ static void _rtcProcessByte(struct GBACartridgeHardware* hw); static void _rtcUpdateClock(struct GBACartridgeHardware* hw); static unsigned _rtcBCD(unsigned value); -static time_t _rtcGenericCallback(struct GBARTCSource* source); +static time_t _rtcGenericCallback(struct mRTCSource* source); static void _gyroReadPins(struct GBACartridgeHardware* hw); @@ -29,7 +29,7 @@ static void _rumbleReadPins(struct GBACartridgeHardware* hw); static void _lightReadPins(struct GBACartridgeHardware* hw); -static uint16_t _gbpRead(struct GBAKeyCallback*); +static uint16_t _gbpRead(struct mKeyCallback*); static uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles); @@ -271,7 +271,7 @@ unsigned _rtcOutput(struct GBACartridgeHardware* hw) { void _rtcUpdateClock(struct GBACartridgeHardware* hw) { time_t t; - struct GBARTCSource* rtc = hw->p->rtcSource; + struct mRTCSource* rtc = hw->p->rtcSource; if (rtc) { if (rtc->sample) { rtc->sample(rtc); @@ -302,7 +302,7 @@ unsigned _rtcBCD(unsigned value) { return counter; } -time_t _rtcGenericCallback(struct GBARTCSource* source) { +time_t _rtcGenericCallback(struct mRTCSource* source) { struct GBARTCGenericSource* rtc = (struct GBARTCGenericSource*) source; switch (rtc->override) { case RTC_NO_OVERRIDE: @@ -332,7 +332,7 @@ void GBAHardwareInitGyro(struct GBACartridgeHardware* hw) { } void _gyroReadPins(struct GBACartridgeHardware* hw) { - struct GBARotationSource* gyro = hw->p->rotationSource; + struct mRotationSource* gyro = hw->p->rotationSource; if (!gyro || !gyro->readGyroZ) { return; } @@ -428,7 +428,7 @@ void GBAHardwareTiltWrite(struct GBACartridgeHardware* hw, uint32_t address, uin case 0x8100: if (value == 0xAA && hw->tiltState == 1) { hw->tiltState = 0; - struct GBARotationSource* rotationSource = hw->p->rotationSource; + struct mRotationSource* rotationSource = hw->p->rotationSource; if (!rotationSource || !rotationSource->readTiltX || !rotationSource->readTiltY) { return; } @@ -535,7 +535,7 @@ void GBAHardwarePlayerUpdate(struct GBA* gba) { } } -uint16_t _gbpRead(struct GBAKeyCallback* callback) { +uint16_t _gbpRead(struct mKeyCallback* callback) { struct GBAGBPKeyCallback* gbpCallback = (struct GBAGBPKeyCallback*) callback; if (gbpCallback->p->gbpInputsPosted == 2) { return 0x30F; diff --git a/src/gba/hardware.h b/src/gba/hardware.h index fa64a9075..eb2082fd7 100644 --- a/src/gba/hardware.h +++ b/src/gba/hardware.h @@ -16,7 +16,7 @@ #define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL) struct GBARTCGenericSource { - struct GBARTCSource d; + struct mRTCSource d; struct GBA* p; enum { RTC_NO_OVERRIDE, @@ -85,7 +85,7 @@ struct GBARumble { }; struct GBAGBPKeyCallback { - struct GBAKeyCallback d; + struct mKeyCallback d; struct GBACartridgeHardware* p; }; diff --git a/src/gba/interface.h b/src/gba/interface.h index 396f4b549..53cbf8b9b 100644 --- a/src/gba/interface.h +++ b/src/gba/interface.h @@ -8,6 +8,8 @@ #include "util/common.h" +#include "core/interface.h" + enum GBALogLevel { GBA_LOG_FATAL = 0x01, GBA_LOG_ERROR = 0x02, @@ -62,23 +64,6 @@ struct GBAAVStream { void (*postAudioBuffer)(struct GBAAVStream*, struct GBAAudio*); }; -struct GBAKeyCallback { - uint16_t (*readKeys)(struct GBAKeyCallback*); -}; - -struct GBAStopCallback { - void (*stop)(struct GBAStopCallback*); -}; - -struct GBARotationSource { - void (*sample)(struct GBARotationSource*); - - int32_t (*readTiltX)(struct GBARotationSource*); - int32_t (*readTiltY)(struct GBARotationSource*); - - int32_t (*readGyroZ)(struct GBARotationSource*); -}; - extern const int GBA_LUX_LEVELS[10]; struct GBALuminanceSource { @@ -87,12 +72,6 @@ struct GBALuminanceSource { uint8_t (*readLuminance)(struct GBALuminanceSource*); }; -struct GBARTCSource { - void (*sample)(struct GBARTCSource*); - - time_t (*unixTime)(struct GBARTCSource*); -}; - struct GBASIODriver { struct GBASIO* p; diff --git a/src/gba/supervisor/thread.c b/src/gba/supervisor/thread.c index 336ff9f5b..60316f417 100644 --- a/src/gba/supervisor/thread.c +++ b/src/gba/supervisor/thread.c @@ -128,11 +128,11 @@ static void _pauseThread(struct GBAThread* threadContext, bool onThread) { } struct GBAThreadStop { - struct GBAStopCallback d; + struct mStopCallback d; struct GBAThread* p; }; -static void _stopCallback(struct GBAStopCallback* stop) { +static void _stopCallback(struct mStopCallback* stop) { struct GBAThreadStop* callback = (struct GBAThreadStop*) stop; if (callback->p->stopCallback(callback->p)) { _changeState(callback->p, THREAD_EXITING, false); diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index bf94356a4..834d20361 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -39,7 +39,7 @@ static enum ScreenMode { FS_Archive sdmcArchive; static struct GBA3DSRotationSource { - struct GBARotationSource d; + struct mRotationSource d; accelVector accel; angularRate gyro; } rotation; diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index ef3a75819..2c7a5bece 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -41,7 +41,7 @@ static vita2d_texture* tex; static vita2d_texture* screenshot; static Thread audioThread; static struct GBASceRotationSource { - struct GBARotationSource d; + struct mRotationSource d; struct SceMotionSensorState state; } rotation; diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index ebadbab4a..b608440f9 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -217,7 +217,7 @@ GBARumble* InputController::rumble() { return nullptr; } -GBARotationSource* InputController::rotationSource() { +mRotationSource* InputController::rotationSource() { #ifdef BUILD_SDL if (m_playerAttached) { return &m_sdlPlayer.rotation.d; diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index d44078068..34c49fa44 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -80,7 +80,7 @@ public: void releaseFocus(QWidget* focus); GBARumble* rumble(); - GBARotationSource* rotationSource(); + mRotationSource* rotationSource(); signals: void profileLoaded(const QString& profile); diff --git a/src/platform/qt/SensorView.h b/src/platform/qt/SensorView.h index 1eb4416a8..666c37f41 100644 --- a/src/platform/qt/SensorView.h +++ b/src/platform/qt/SensorView.h @@ -13,7 +13,7 @@ #include "ui_SensorView.h" -struct GBARotationSource; +struct mRotationSource; namespace QGBA { @@ -43,7 +43,7 @@ private: std::function m_jiggered; GameController* m_controller; InputController* m_input; - GBARotationSource* m_rotation; + mRotationSource* m_rotation; QTimer m_timer; void jiggerer(QAbstractButton*, void (InputController::*)(int)); diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 323877e60..95528af29 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -29,10 +29,10 @@ DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo); #if SDL_VERSION_ATLEAST(2, 0, 0) static void _GBASDLSetRumble(struct GBARumble* rumble, int enable); #endif -static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble); -static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble); -static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble); -static void _GBASDLRotationSample(struct GBARotationSource* source); +static int32_t _GBASDLReadTiltX(struct mRotationSource* rumble); +static int32_t _GBASDLReadTiltY(struct mRotationSource* rumble); +static int32_t _GBASDLReadGyroZ(struct mRotationSource* rumble); +static void _GBASDLRotationSample(struct mRotationSource* source); bool GBASDLInitEvents(struct GBASDLEvents* context) { #if SDL_VERSION_ATLEAST(2, 0, 4) @@ -605,23 +605,23 @@ static int32_t _readTilt(struct GBASDLPlayer* player, int axis) { return SDL_JoystickGetAxis(player->joystick->joystick, axis) * 0x3800; } -static int32_t _GBASDLReadTiltX(struct GBARotationSource* source) { +static int32_t _GBASDLReadTiltX(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; return _readTilt(rotation->p, rotation->axisX); } -static int32_t _GBASDLReadTiltY(struct GBARotationSource* source) { +static int32_t _GBASDLReadTiltY(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; return _readTilt(rotation->p, rotation->axisY); } -static int32_t _GBASDLReadGyroZ(struct GBARotationSource* source) { +static int32_t _GBASDLReadGyroZ(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; float z = rotation->zDelta; return z * rotation->gyroSensitivity; } -static void _GBASDLRotationSample(struct GBARotationSource* source) { +static void _GBASDLRotationSample(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; SDL_JoystickUpdate(); if (!rotation->p->joystick) { diff --git a/src/platform/sdl/sdl-events.h b/src/platform/sdl/sdl-events.h index 015868f2e..c298cb871 100644 --- a/src/platform/sdl/sdl-events.h +++ b/src/platform/sdl/sdl-events.h @@ -65,7 +65,7 @@ struct GBASDLPlayer { #endif struct GBASDLRotation { - struct GBARotationSource d; + struct mRotationSource d; struct GBASDLPlayer* p; // Tilt diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index 69ce5a989..fb035634c 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -51,10 +51,10 @@ static void _retraceCallback(u32 count); static void _audioDMA(void); static void _setRumble(struct GBARumble* rumble, int enable); -static void _sampleRotation(struct GBARotationSource* source); -static int32_t _readTiltX(struct GBARotationSource* source); -static int32_t _readTiltY(struct GBARotationSource* source); -static int32_t _readGyroZ(struct GBARotationSource* source); +static void _sampleRotation(struct mRotationSource* source); +static int32_t _readTiltX(struct mRotationSource* source); +static int32_t _readTiltY(struct mRotationSource* source); +static int32_t _readGyroZ(struct mRotationSource* source); static void _drawStart(void); static void _drawEnd(void); @@ -75,7 +75,7 @@ static s8 WPAD_StickY(u8 chan, u8 right); static struct GBAVideoSoftwareRenderer renderer; static struct GBARumble rumble; -static struct GBARotationSource rotation; +static struct mRotationSource rotation; static GXRModeObj* vmode; static Mtx model, view, modelview; static uint16_t* texmem; @@ -731,7 +731,7 @@ void _setRumble(struct GBARumble* rumble, int enable) { } } -void _sampleRotation(struct GBARotationSource* source) { +void _sampleRotation(struct mRotationSource* source) { UNUSED(source); vec3w_t accel; WPAD_Accel(0, &accel); @@ -749,17 +749,17 @@ void _sampleRotation(struct GBARotationSource* source) { gyroZ <<= 18; } -int32_t _readTiltX(struct GBARotationSource* source) { +int32_t _readTiltX(struct mRotationSource* source) { UNUSED(source); return tiltX; } -int32_t _readTiltY(struct GBARotationSource* source) { +int32_t _readTiltY(struct mRotationSource* source) { UNUSED(source); return tiltY; } -int32_t _readGyroZ(struct GBARotationSource* source) { +int32_t _readGyroZ(struct mRotationSource* source) { UNUSED(source); return gyroZ; }