(EMSCRIPTEN) add analog emulator support
This commit is contained in:
parent
7dfb9d0437
commit
57d1cbbf26
|
@ -60,7 +60,7 @@ WANT_MINIZ = 1
|
||||||
MEMORY = 67108864
|
MEMORY = 67108864
|
||||||
LTO = 0
|
LTO = 0
|
||||||
# XXX: setting this to 1/2 currently crashes Firefox nightly
|
# XXX: setting this to 1/2 currently crashes Firefox nightly
|
||||||
PRECISE_F32 = 0
|
PRECISE_F32 = 2
|
||||||
|
|
||||||
ifneq ($(NATIVE_ZLIB),)
|
ifneq ($(NATIVE_ZLIB),)
|
||||||
WANT_MINIZ = 0
|
WANT_MINIZ = 0
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
typedef struct rwebinput_state
|
typedef struct rwebinput_state
|
||||||
{
|
{
|
||||||
char keys[32];
|
uint8_t keys[32];
|
||||||
int mouse_x;
|
int mouse_x;
|
||||||
int mouse_y;
|
int mouse_y;
|
||||||
char mouse_l;
|
char mouse_l;
|
||||||
|
|
|
@ -58,7 +58,7 @@ var LibraryRWebInput = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
RWebInputInit: function(latency) {
|
RWebInputInit: function() {
|
||||||
if (RI.contexts.length === 0) {
|
if (RI.contexts.length === 0) {
|
||||||
document.addEventListener('keyup', RI.eventHandler, false);
|
document.addEventListener('keyup', RI.eventHandler, false);
|
||||||
document.addEventListener('keydown', RI.eventHandler, false);
|
document.addEventListener('keydown', RI.eventHandler, false);
|
||||||
|
|
|
@ -662,6 +662,22 @@ const struct rarch_key_map rarch_key_map_rwebinput[] = {
|
||||||
{ 88, RETROK_x },
|
{ 88, RETROK_x },
|
||||||
{ 89, RETROK_y },
|
{ 89, RETROK_y },
|
||||||
{ 90, RETROK_z },
|
{ 90, RETROK_z },
|
||||||
|
{ 222, RETROK_QUOTE },
|
||||||
|
{ 188, RETROK_COMMA },
|
||||||
|
{ 173, RETROK_MINUS },
|
||||||
|
{ 191, RETROK_SLASH },
|
||||||
|
{ 59, RETROK_SEMICOLON },
|
||||||
|
{ 61, RETROK_EQUALS },
|
||||||
|
{ 219, RETROK_LEFTBRACKET },
|
||||||
|
{ 220, RETROK_BACKSLASH },
|
||||||
|
{ 221, RETROK_RIGHTBRACKET },
|
||||||
|
{ 188, RETROK_KP_PERIOD },
|
||||||
|
{ 17, RETROK_RCTRL },
|
||||||
|
{ 18, RETROK_RALT },
|
||||||
|
{ 190, RETROK_PERIOD },
|
||||||
|
{ 145, RETROK_SCROLLOCK },
|
||||||
|
{ 20, RETROK_CAPSLOCK },
|
||||||
|
{ 144, RETROK_NUMLOCK },
|
||||||
{ 0, RETROK_UNKNOWN },
|
{ 0, RETROK_UNKNOWN },
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "../boolean.h"
|
#include "../boolean.h"
|
||||||
#include "../general.h"
|
#include "../general.h"
|
||||||
|
#include "keyboard_line.h"
|
||||||
|
|
||||||
#include "../emscripten/RWebInput.h"
|
#include "../emscripten/RWebInput.h"
|
||||||
|
|
||||||
|
@ -92,6 +93,17 @@ static int16_t rwebinput_mouse_state(rwebinput_input_t *rwebinput, unsigned id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, const struct retro_keybind *binds, unsigned index, unsigned id)
|
||||||
|
{
|
||||||
|
unsigned id_minus = 0;
|
||||||
|
unsigned id_plus = 0;
|
||||||
|
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||||
|
|
||||||
|
int16_t pressed_minus = rwebinput_is_pressed(rwebinput, binds, id_minus) ? -0x7fff : 0;
|
||||||
|
int16_t pressed_plus = rwebinput_is_pressed(rwebinput, binds, id_plus) ? 0x7fff : 0;
|
||||||
|
return pressed_plus + pressed_minus;
|
||||||
|
}
|
||||||
|
|
||||||
static int16_t rwebinput_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
|
static int16_t rwebinput_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
|
||||||
{
|
{
|
||||||
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
||||||
|
@ -101,6 +113,9 @@ static int16_t rwebinput_input_state(void *data, const struct retro_keybind **bi
|
||||||
case RETRO_DEVICE_JOYPAD:
|
case RETRO_DEVICE_JOYPAD:
|
||||||
return rwebinput_is_pressed(rwebinput, binds[port], id);
|
return rwebinput_is_pressed(rwebinput, binds[port], id);
|
||||||
|
|
||||||
|
case RETRO_DEVICE_ANALOG:
|
||||||
|
return rwebinput_analog_pressed(rwebinput, binds[port], index, id);
|
||||||
|
|
||||||
case RETRO_DEVICE_KEYBOARD:
|
case RETRO_DEVICE_KEYBOARD:
|
||||||
return rwebinput_key_pressed(rwebinput, id);
|
return rwebinput_key_pressed(rwebinput, id);
|
||||||
|
|
||||||
|
@ -127,6 +142,23 @@ static void rwebinput_input_poll(void *data)
|
||||||
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
||||||
|
|
||||||
rwebinput_state_t *state = RWebInputPoll(rwebinput->context);
|
rwebinput_state_t *state = RWebInputPoll(rwebinput->context);
|
||||||
|
|
||||||
|
// get new keys
|
||||||
|
for (unsigned i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
if (state->keys[i] != rwebinput->state.keys[i])
|
||||||
|
{
|
||||||
|
uint8_t diff = state->keys[i] ^ rwebinput->state.keys[i];
|
||||||
|
for (unsigned k = 0; diff; diff >>= 1, k++)
|
||||||
|
{
|
||||||
|
if (diff & 1)
|
||||||
|
{
|
||||||
|
input_keyboard_event((state->keys[i] & (1 << k)) != 0, input_translate_keysym_to_rk(i * 8 + k), 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&rwebinput->state, state, sizeof(rwebinput->state));
|
memcpy(&rwebinput->state, state, sizeof(rwebinput->state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +173,7 @@ static uint64_t rwebinput_get_capabilities(void *data)
|
||||||
uint64_t caps = 0;
|
uint64_t caps = 0;
|
||||||
|
|
||||||
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
||||||
|
caps |= (1 << RETRO_DEVICE_ANALOG);
|
||||||
caps |= (1 << RETRO_DEVICE_KEYBOARD);
|
caps |= (1 << RETRO_DEVICE_KEYBOARD);
|
||||||
caps |= (1 << RETRO_DEVICE_MOUSE);
|
caps |= (1 << RETRO_DEVICE_MOUSE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue