mirror of https://github.com/mgba-emu/mgba.git
Libretro: Reduce rumble callbacks
This commit is contained in:
parent
1bf29ae362
commit
a8d991e24f
1
CHANGES
1
CHANGES
|
@ -127,6 +127,7 @@ Misc:
|
||||||
- Wii: Stretch now sets pixel-accurate mode size cap
|
- Wii: Stretch now sets pixel-accurate mode size cap
|
||||||
- Qt: Ensure camera image is valid
|
- Qt: Ensure camera image is valid
|
||||||
- GB: Improved SGB2 support
|
- GB: Improved SGB2 support
|
||||||
|
- Libretro: Reduce rumble callbacks
|
||||||
|
|
||||||
0.7 beta 1: (2018-09-24)
|
0.7 beta 1: (2018-09-24)
|
||||||
- Initial beta for 0.7
|
- Initial beta for 0.7
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <mgba/gba/interface.h>
|
#include <mgba/gba/interface.h>
|
||||||
#include <mgba/internal/gba/gba.h>
|
#include <mgba/internal/gba/gba.h>
|
||||||
#endif
|
#endif
|
||||||
#include <mgba-util/circle-buffer.h>
|
|
||||||
#include <mgba-util/memory.h>
|
#include <mgba-util/memory.h>
|
||||||
#include <mgba-util/vfs.h>
|
#include <mgba-util/vfs.h>
|
||||||
|
|
||||||
|
@ -55,8 +54,8 @@ static void* data;
|
||||||
static size_t dataSize;
|
static size_t dataSize;
|
||||||
static void* savedata;
|
static void* savedata;
|
||||||
static struct mAVStream stream;
|
static struct mAVStream stream;
|
||||||
static int rumbleLevel;
|
static int rumbleUp;
|
||||||
static struct CircleBuffer rumbleHistory;
|
static int rumbleDown;
|
||||||
static struct mRumble rumble;
|
static struct mRumble rumble;
|
||||||
static struct GBALuminanceSource lux;
|
static struct GBALuminanceSource lux;
|
||||||
static int luxLevel;
|
static int luxLevel;
|
||||||
|
@ -254,7 +253,6 @@ void retro_init(void) {
|
||||||
struct retro_rumble_interface rumbleInterface;
|
struct retro_rumble_interface rumbleInterface;
|
||||||
if (environCallback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumbleInterface)) {
|
if (environCallback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumbleInterface)) {
|
||||||
rumbleCallback = rumbleInterface.set_rumble_state;
|
rumbleCallback = rumbleInterface.set_rumble_state;
|
||||||
CircleBufferInit(&rumbleHistory, RUMBLE_PWM);
|
|
||||||
rumble.setRumble = _setRumble;
|
rumble.setRumble = _setRumble;
|
||||||
} else {
|
} else {
|
||||||
rumbleCallback = 0;
|
rumbleCallback = 0;
|
||||||
|
@ -347,6 +345,18 @@ void retro_run(void) {
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
core->desiredVideoDimensions(core, &width, &height);
|
core->desiredVideoDimensions(core, &width, &height);
|
||||||
videoCallback(outputBuffer, width, height, BYTES_PER_PIXEL * 256);
|
videoCallback(outputBuffer, width, height, BYTES_PER_PIXEL * 256);
|
||||||
|
|
||||||
|
if (rumbleCallback) {
|
||||||
|
if (rumbleUp) {
|
||||||
|
rumbleCallback(0, RETRO_RUMBLE_STRONG, rumbleUp * 0xFFFF / (rumbleUp + rumbleDown));
|
||||||
|
rumbleCallback(0, RETRO_RUMBLE_WEAK, rumbleUp * 0xFFFF / (rumbleUp + rumbleDown));
|
||||||
|
} else {
|
||||||
|
rumbleCallback(0, RETRO_RUMBLE_STRONG, 0);
|
||||||
|
rumbleCallback(0, RETRO_RUMBLE_WEAK, 0);
|
||||||
|
}
|
||||||
|
rumbleUp = 0;
|
||||||
|
rumbleDown = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _setupMaps(struct mCore* core) {
|
static void _setupMaps(struct mCore* core) {
|
||||||
|
@ -437,9 +447,8 @@ void retro_reset(void) {
|
||||||
core->reset(core);
|
core->reset(core);
|
||||||
_setupMaps(core);
|
_setupMaps(core);
|
||||||
|
|
||||||
if (rumbleCallback) {
|
rumbleUp = 0;
|
||||||
CircleBufferClear(&rumbleHistory);
|
rumbleDown = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool retro_load_game(const struct retro_game_info* game) {
|
bool retro_load_game(const struct retro_game_info* game) {
|
||||||
|
@ -557,7 +566,6 @@ void retro_unload_game(void) {
|
||||||
data = 0;
|
data = 0;
|
||||||
mappedMemoryFree(savedata, SIZE_CART_FLASH1M);
|
mappedMemoryFree(savedata, SIZE_CART_FLASH1M);
|
||||||
savedata = 0;
|
savedata = 0;
|
||||||
CircleBufferDeinit(&rumbleHistory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t retro_serialize_size(void) {
|
size_t retro_serialize_size(void) {
|
||||||
|
@ -754,15 +762,11 @@ static void _setRumble(struct mRumble* rumble, int enable) {
|
||||||
if (!rumbleCallback) {
|
if (!rumbleCallback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rumbleLevel += enable;
|
if (enable) {
|
||||||
if (CircleBufferSize(&rumbleHistory) == RUMBLE_PWM) {
|
++rumbleUp;
|
||||||
int8_t oldLevel;
|
} else {
|
||||||
CircleBufferRead8(&rumbleHistory, &oldLevel);
|
++rumbleDown;
|
||||||
rumbleLevel -= oldLevel;
|
|
||||||
}
|
}
|
||||||
CircleBufferWrite8(&rumbleHistory, enable);
|
|
||||||
rumbleCallback(0, RETRO_RUMBLE_STRONG, rumbleLevel * 0xFFFF / RUMBLE_PWM);
|
|
||||||
rumbleCallback(0, RETRO_RUMBLE_WEAK, rumbleLevel * 0xFFFF / RUMBLE_PWM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _updateLux(struct GBALuminanceSource* lux) {
|
static void _updateLux(struct GBALuminanceSource* lux) {
|
||||||
|
|
Loading…
Reference in New Issue