mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
emscripten: Fixed compiling on C89 compilers.
This commit is contained in:
parent
b84fe2c06b
commit
759319729c
@ -328,6 +328,9 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
|
|||||||
static int
|
static int
|
||||||
EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
|
EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||||
{
|
{
|
||||||
|
int available;
|
||||||
|
int capture_available;
|
||||||
|
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
|
impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
|
||||||
impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
|
impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
|
||||||
@ -339,7 +342,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|||||||
impl->ProvidesOwnCallbackThread = 1;
|
impl->ProvidesOwnCallbackThread = 1;
|
||||||
|
|
||||||
/* check availability */
|
/* check availability */
|
||||||
const int available = EM_ASM_INT_V({
|
available = EM_ASM_INT_V({
|
||||||
if (typeof(AudioContext) !== 'undefined') {
|
if (typeof(AudioContext) !== 'undefined') {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (typeof(webkitAudioContext) !== 'undefined') {
|
} else if (typeof(webkitAudioContext) !== 'undefined') {
|
||||||
@ -352,7 +355,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|||||||
SDL_SetError("No audio context available");
|
SDL_SetError("No audio context available");
|
||||||
}
|
}
|
||||||
|
|
||||||
const int capture_available = available && EM_ASM_INT_V({
|
capture_available = available && EM_ASM_INT_V({
|
||||||
if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
|
if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
|
} else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
|
||||||
|
@ -490,6 +490,8 @@ static EM_BOOL
|
|||||||
Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
|
Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
|
||||||
{
|
{
|
||||||
Uint32 scancode;
|
Uint32 scancode;
|
||||||
|
SDL_bool prevent_default;
|
||||||
|
SDL_bool is_nav_key;
|
||||||
|
|
||||||
/* .keyCode is deprecated, but still the most reliable way to get keys */
|
/* .keyCode is deprecated, but still the most reliable way to get keys */
|
||||||
if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
|
if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
|
||||||
@ -517,12 +519,12 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
|
prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
|
||||||
|
|
||||||
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
|
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
|
||||||
* we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
|
* we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
|
||||||
*/
|
*/
|
||||||
SDL_bool is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
|
is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
|
||||||
keyEvent->keyCode == 9 /* tab */ ||
|
keyEvent->keyCode == 9 /* tab */ ||
|
||||||
keyEvent->keyCode == 37 /* left */ ||
|
keyEvent->keyCode == 37 /* left */ ||
|
||||||
keyEvent->keyCode == 38 /* up */ ||
|
keyEvent->keyCode == 38 /* up */ ||
|
||||||
@ -629,6 +631,8 @@ Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChang
|
|||||||
void
|
void
|
||||||
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
|
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
|
||||||
{
|
{
|
||||||
|
const char *keyElement;
|
||||||
|
|
||||||
/* There is only one window and that window is the canvas */
|
/* There is only one window and that window is the canvas */
|
||||||
emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
|
emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
|
||||||
|
|
||||||
@ -651,7 +655,7 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
|
|||||||
emscripten_set_pointerlockchange_callback(NULL, data, 0, Emscripten_HandlePointerLockChange);
|
emscripten_set_pointerlockchange_callback(NULL, data, 0, Emscripten_HandlePointerLockChange);
|
||||||
|
|
||||||
/* Keyboard events are awkward */
|
/* Keyboard events are awkward */
|
||||||
const char *keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
|
keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
|
||||||
if (!keyElement) keyElement = "#window";
|
if (!keyElement) keyElement = "#window";
|
||||||
|
|
||||||
emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
|
emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
|
||||||
@ -668,6 +672,8 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
|
|||||||
void
|
void
|
||||||
Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
|
Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
|
||||||
{
|
{
|
||||||
|
const char *target;
|
||||||
|
|
||||||
/* only works due to having one window */
|
/* only works due to having one window */
|
||||||
emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
|
emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
|
||||||
|
|
||||||
@ -689,7 +695,7 @@ Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
|
|||||||
|
|
||||||
emscripten_set_pointerlockchange_callback(NULL, NULL, 0, NULL);
|
emscripten_set_pointerlockchange_callback(NULL, NULL, 0, NULL);
|
||||||
|
|
||||||
const char *target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
|
target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
target = "#window";
|
target = "#window";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user