Core: Refactor several input callbacks

This commit is contained in:
Jeffrey Pfau 2016-01-29 22:30:33 -08:00
parent 811d8281c3
commit bc1a094bea
14 changed files with 75 additions and 62 deletions

34
src/core/interface.h Normal file
View File

@ -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

View File

@ -96,9 +96,9 @@ struct GBA {
int springIRQ; int springIRQ;
uint32_t biosChecksum; uint32_t biosChecksum;
int* keySource; int* keySource;
struct GBARotationSource* rotationSource; struct mRotationSource* rotationSource;
struct GBALuminanceSource* luminanceSource; struct GBALuminanceSource* luminanceSource;
struct GBARTCSource* rtcSource; struct mRTCSource* rtcSource;
struct GBARumble* rumble; struct GBARumble* rumble;
struct GBARRContext* rr; struct GBARRContext* rr;
@ -114,8 +114,8 @@ struct GBA {
GBALogHandler logHandler; GBALogHandler logHandler;
enum GBALogLevel logLevel; enum GBALogLevel logLevel;
struct GBAAVStream* stream; struct GBAAVStream* stream;
struct GBAKeyCallback* keyCallback; struct mKeyCallback* keyCallback;
struct GBAStopCallback* stopCallback; struct mStopCallback* stopCallback;
enum GBAIdleLoopOptimization idleOptimization; enum GBAIdleLoopOptimization idleOptimization;
uint32_t idleLoop; uint32_t idleLoop;

View File

@ -21,7 +21,7 @@ static void _rtcProcessByte(struct GBACartridgeHardware* hw);
static void _rtcUpdateClock(struct GBACartridgeHardware* hw); static void _rtcUpdateClock(struct GBACartridgeHardware* hw);
static unsigned _rtcBCD(unsigned value); 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); static void _gyroReadPins(struct GBACartridgeHardware* hw);
@ -29,7 +29,7 @@ static void _rumbleReadPins(struct GBACartridgeHardware* hw);
static void _lightReadPins(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 uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value);
static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles); static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles);
@ -271,7 +271,7 @@ unsigned _rtcOutput(struct GBACartridgeHardware* hw) {
void _rtcUpdateClock(struct GBACartridgeHardware* hw) { void _rtcUpdateClock(struct GBACartridgeHardware* hw) {
time_t t; time_t t;
struct GBARTCSource* rtc = hw->p->rtcSource; struct mRTCSource* rtc = hw->p->rtcSource;
if (rtc) { if (rtc) {
if (rtc->sample) { if (rtc->sample) {
rtc->sample(rtc); rtc->sample(rtc);
@ -302,7 +302,7 @@ unsigned _rtcBCD(unsigned value) {
return counter; return counter;
} }
time_t _rtcGenericCallback(struct GBARTCSource* source) { time_t _rtcGenericCallback(struct mRTCSource* source) {
struct GBARTCGenericSource* rtc = (struct GBARTCGenericSource*) source; struct GBARTCGenericSource* rtc = (struct GBARTCGenericSource*) source;
switch (rtc->override) { switch (rtc->override) {
case RTC_NO_OVERRIDE: case RTC_NO_OVERRIDE:
@ -332,7 +332,7 @@ void GBAHardwareInitGyro(struct GBACartridgeHardware* hw) {
} }
void _gyroReadPins(struct GBACartridgeHardware* hw) { void _gyroReadPins(struct GBACartridgeHardware* hw) {
struct GBARotationSource* gyro = hw->p->rotationSource; struct mRotationSource* gyro = hw->p->rotationSource;
if (!gyro || !gyro->readGyroZ) { if (!gyro || !gyro->readGyroZ) {
return; return;
} }
@ -428,7 +428,7 @@ void GBAHardwareTiltWrite(struct GBACartridgeHardware* hw, uint32_t address, uin
case 0x8100: case 0x8100:
if (value == 0xAA && hw->tiltState == 1) { if (value == 0xAA && hw->tiltState == 1) {
hw->tiltState = 0; hw->tiltState = 0;
struct GBARotationSource* rotationSource = hw->p->rotationSource; struct mRotationSource* rotationSource = hw->p->rotationSource;
if (!rotationSource || !rotationSource->readTiltX || !rotationSource->readTiltY) { if (!rotationSource || !rotationSource->readTiltX || !rotationSource->readTiltY) {
return; 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; struct GBAGBPKeyCallback* gbpCallback = (struct GBAGBPKeyCallback*) callback;
if (gbpCallback->p->gbpInputsPosted == 2) { if (gbpCallback->p->gbpInputsPosted == 2) {
return 0x30F; return 0x30F;

View File

@ -16,7 +16,7 @@
#define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL) #define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL)
struct GBARTCGenericSource { struct GBARTCGenericSource {
struct GBARTCSource d; struct mRTCSource d;
struct GBA* p; struct GBA* p;
enum { enum {
RTC_NO_OVERRIDE, RTC_NO_OVERRIDE,
@ -85,7 +85,7 @@ struct GBARumble {
}; };
struct GBAGBPKeyCallback { struct GBAGBPKeyCallback {
struct GBAKeyCallback d; struct mKeyCallback d;
struct GBACartridgeHardware* p; struct GBACartridgeHardware* p;
}; };

View File

@ -8,6 +8,8 @@
#include "util/common.h" #include "util/common.h"
#include "core/interface.h"
enum GBALogLevel { enum GBALogLevel {
GBA_LOG_FATAL = 0x01, GBA_LOG_FATAL = 0x01,
GBA_LOG_ERROR = 0x02, GBA_LOG_ERROR = 0x02,
@ -62,23 +64,6 @@ struct GBAAVStream {
void (*postAudioBuffer)(struct GBAAVStream*, struct GBAAudio*); 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]; extern const int GBA_LUX_LEVELS[10];
struct GBALuminanceSource { struct GBALuminanceSource {
@ -87,12 +72,6 @@ struct GBALuminanceSource {
uint8_t (*readLuminance)(struct GBALuminanceSource*); uint8_t (*readLuminance)(struct GBALuminanceSource*);
}; };
struct GBARTCSource {
void (*sample)(struct GBARTCSource*);
time_t (*unixTime)(struct GBARTCSource*);
};
struct GBASIODriver { struct GBASIODriver {
struct GBASIO* p; struct GBASIO* p;

View File

@ -128,11 +128,11 @@ static void _pauseThread(struct GBAThread* threadContext, bool onThread) {
} }
struct GBAThreadStop { struct GBAThreadStop {
struct GBAStopCallback d; struct mStopCallback d;
struct GBAThread* p; struct GBAThread* p;
}; };
static void _stopCallback(struct GBAStopCallback* stop) { static void _stopCallback(struct mStopCallback* stop) {
struct GBAThreadStop* callback = (struct GBAThreadStop*) stop; struct GBAThreadStop* callback = (struct GBAThreadStop*) stop;
if (callback->p->stopCallback(callback->p)) { if (callback->p->stopCallback(callback->p)) {
_changeState(callback->p, THREAD_EXITING, false); _changeState(callback->p, THREAD_EXITING, false);

View File

@ -39,7 +39,7 @@ static enum ScreenMode {
FS_Archive sdmcArchive; FS_Archive sdmcArchive;
static struct GBA3DSRotationSource { static struct GBA3DSRotationSource {
struct GBARotationSource d; struct mRotationSource d;
accelVector accel; accelVector accel;
angularRate gyro; angularRate gyro;
} rotation; } rotation;

View File

@ -41,7 +41,7 @@ static vita2d_texture* tex;
static vita2d_texture* screenshot; static vita2d_texture* screenshot;
static Thread audioThread; static Thread audioThread;
static struct GBASceRotationSource { static struct GBASceRotationSource {
struct GBARotationSource d; struct mRotationSource d;
struct SceMotionSensorState state; struct SceMotionSensorState state;
} rotation; } rotation;

View File

@ -217,7 +217,7 @@ GBARumble* InputController::rumble() {
return nullptr; return nullptr;
} }
GBARotationSource* InputController::rotationSource() { mRotationSource* InputController::rotationSource() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
if (m_playerAttached) { if (m_playerAttached) {
return &m_sdlPlayer.rotation.d; return &m_sdlPlayer.rotation.d;

View File

@ -80,7 +80,7 @@ public:
void releaseFocus(QWidget* focus); void releaseFocus(QWidget* focus);
GBARumble* rumble(); GBARumble* rumble();
GBARotationSource* rotationSource(); mRotationSource* rotationSource();
signals: signals:
void profileLoaded(const QString& profile); void profileLoaded(const QString& profile);

View File

@ -13,7 +13,7 @@
#include "ui_SensorView.h" #include "ui_SensorView.h"
struct GBARotationSource; struct mRotationSource;
namespace QGBA { namespace QGBA {
@ -43,7 +43,7 @@ private:
std::function<void(int)> m_jiggered; std::function<void(int)> m_jiggered;
GameController* m_controller; GameController* m_controller;
InputController* m_input; InputController* m_input;
GBARotationSource* m_rotation; mRotationSource* m_rotation;
QTimer m_timer; QTimer m_timer;
void jiggerer(QAbstractButton*, void (InputController::*)(int)); void jiggerer(QAbstractButton*, void (InputController::*)(int));

View File

@ -29,10 +29,10 @@ 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 _GBASDLSetRumble(struct GBARumble* rumble, int enable);
#endif #endif
static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble); static int32_t _GBASDLReadTiltX(struct mRotationSource* rumble);
static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble); static int32_t _GBASDLReadTiltY(struct mRotationSource* rumble);
static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble); static int32_t _GBASDLReadGyroZ(struct mRotationSource* rumble);
static void _GBASDLRotationSample(struct GBARotationSource* source); static void _GBASDLRotationSample(struct mRotationSource* source);
bool GBASDLInitEvents(struct GBASDLEvents* context) { bool GBASDLInitEvents(struct GBASDLEvents* context) {
#if SDL_VERSION_ATLEAST(2, 0, 4) #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; 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; struct GBASDLRotation* rotation = (struct GBASDLRotation*) source;
return _readTilt(rotation->p, rotation->axisX); 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; struct GBASDLRotation* rotation = (struct GBASDLRotation*) source;
return _readTilt(rotation->p, rotation->axisY); 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; struct GBASDLRotation* rotation = (struct GBASDLRotation*) source;
float z = rotation->zDelta; float z = rotation->zDelta;
return z * rotation->gyroSensitivity; return z * rotation->gyroSensitivity;
} }
static void _GBASDLRotationSample(struct GBARotationSource* source) { static void _GBASDLRotationSample(struct mRotationSource* source) {
struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; struct GBASDLRotation* rotation = (struct GBASDLRotation*) source;
SDL_JoystickUpdate(); SDL_JoystickUpdate();
if (!rotation->p->joystick) { if (!rotation->p->joystick) {

View File

@ -65,7 +65,7 @@ struct GBASDLPlayer {
#endif #endif
struct GBASDLRotation { struct GBASDLRotation {
struct GBARotationSource d; struct mRotationSource d;
struct GBASDLPlayer* p; struct GBASDLPlayer* p;
// Tilt // Tilt

View File

@ -51,10 +51,10 @@ 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 GBARumble* rumble, int enable);
static void _sampleRotation(struct GBARotationSource* source); static void _sampleRotation(struct mRotationSource* source);
static int32_t _readTiltX(struct GBARotationSource* source); static int32_t _readTiltX(struct mRotationSource* source);
static int32_t _readTiltY(struct GBARotationSource* source); static int32_t _readTiltY(struct mRotationSource* source);
static int32_t _readGyroZ(struct GBARotationSource* source); static int32_t _readGyroZ(struct mRotationSource* source);
static void _drawStart(void); static void _drawStart(void);
static void _drawEnd(void); static void _drawEnd(void);
@ -75,7 +75,7 @@ static s8 WPAD_StickY(u8 chan, u8 right);
static struct GBAVideoSoftwareRenderer renderer; static struct GBAVideoSoftwareRenderer renderer;
static struct GBARumble rumble; static struct GBARumble rumble;
static struct GBARotationSource rotation; static struct mRotationSource rotation;
static GXRModeObj* vmode; static GXRModeObj* vmode;
static Mtx model, view, modelview; static Mtx model, view, modelview;
static uint16_t* texmem; 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); UNUSED(source);
vec3w_t accel; vec3w_t accel;
WPAD_Accel(0, &accel); WPAD_Accel(0, &accel);
@ -749,17 +749,17 @@ void _sampleRotation(struct GBARotationSource* source) {
gyroZ <<= 18; gyroZ <<= 18;
} }
int32_t _readTiltX(struct GBARotationSource* source) { int32_t _readTiltX(struct mRotationSource* source) {
UNUSED(source); UNUSED(source);
return tiltX; return tiltX;
} }
int32_t _readTiltY(struct GBARotationSource* source) { int32_t _readTiltY(struct mRotationSource* source) {
UNUSED(source); UNUSED(source);
return tiltY; return tiltY;
} }
int32_t _readGyroZ(struct GBARotationSource* source) { int32_t _readGyroZ(struct mRotationSource* source) {
UNUSED(source); UNUSED(source);
return gyroZ; return gyroZ;
} }