early-access version 1617

This commit is contained in:
pineappleEA
2021-04-20 21:40:33 +02:00
parent 242b6f6b49
commit f46563104f
510 changed files with 141726 additions and 62846 deletions

View File

@@ -55,7 +55,7 @@ static const SDL_Scancode emscripten_scancode_table[] = {
/* 9 */ SDL_SCANCODE_TAB,
/* 10 */ SDL_SCANCODE_UNKNOWN,
/* 11 */ SDL_SCANCODE_UNKNOWN,
/* 12 */ SDL_SCANCODE_UNKNOWN,
/* 12 */ SDL_SCANCODE_KP_5,
/* 13 */ SDL_SCANCODE_RETURN,
/* 14 */ SDL_SCANCODE_UNKNOWN,
/* 15 */ SDL_SCANCODE_UNKNOWN,
@@ -103,10 +103,10 @@ static const SDL_Scancode emscripten_scancode_table[] = {
/* 57 */ SDL_SCANCODE_9,
/* 58 */ SDL_SCANCODE_UNKNOWN,
/* 59 */ SDL_SCANCODE_SEMICOLON,
/* 60 */ SDL_SCANCODE_UNKNOWN,
/* 60 */ SDL_SCANCODE_NONUSBACKSLASH,
/* 61 */ SDL_SCANCODE_EQUALS,
/* 62 */ SDL_SCANCODE_UNKNOWN,
/* 63 */ SDL_SCANCODE_UNKNOWN,
/* 63 */ SDL_SCANCODE_MINUS,
/* 64 */ SDL_SCANCODE_UNKNOWN,
/* 65 */ SDL_SCANCODE_A,
/* 66 */ SDL_SCANCODE_B,
@@ -203,7 +203,7 @@ static const SDL_Scancode emscripten_scancode_table[] = {
/* 157 */ SDL_SCANCODE_UNKNOWN,
/* 158 */ SDL_SCANCODE_UNKNOWN,
/* 159 */ SDL_SCANCODE_UNKNOWN,
/* 160 */ SDL_SCANCODE_UNKNOWN,
/* 160 */ SDL_SCANCODE_GRAVE,
/* 161 */ SDL_SCANCODE_UNKNOWN,
/* 162 */ SDL_SCANCODE_UNKNOWN,
/* 163 */ SDL_SCANCODE_KP_HASH, /*KaiOS phone keypad*/
@@ -214,7 +214,7 @@ static const SDL_Scancode emscripten_scancode_table[] = {
/* 168 */ SDL_SCANCODE_UNKNOWN,
/* 169 */ SDL_SCANCODE_UNKNOWN,
/* 170 */ SDL_SCANCODE_KP_MULTIPLY, /*KaiOS phone keypad*/
/* 171 */ SDL_SCANCODE_UNKNOWN,
/* 171 */ SDL_SCANCODE_RIGHTBRACKET,
/* 172 */ SDL_SCANCODE_UNKNOWN,
/* 173 */ SDL_SCANCODE_MINUS, /*FX*/
/* 174 */ SDL_SCANCODE_VOLUMEDOWN, /*IE, Chrome*/
@@ -363,7 +363,7 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve
if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN) {
if (SDL_GetMouse()->relative_mode && !window_data->has_pointer_lock) {
emscripten_request_pointerlock(NULL, 0); /* try to regrab lost pointer lock. */
emscripten_request_pointerlock(window_data->canvas_id, 0); /* try to regrab lost pointer lock. */
}
sdl_button_state = SDL_PRESSED;
sdl_event_type = SDL_MOUSEBUTTONDOWN;
@@ -485,6 +485,16 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
scancode = emscripten_scancode_table[keyEvent->keyCode];
if (keyEvent->keyCode == 0) {
/* KaiOS Left Soft Key and Right Soft Key, they act as OK/Next/Menu and Cancel/Back/Clear */
if (SDL_strncmp(keyEvent->key, "SoftLeft", 9) == 0) {
scancode = SDL_SCANCODE_AC_FORWARD;
}
if (SDL_strncmp(keyEvent->key, "SoftRight", 10) == 0) {
scancode = SDL_SCANCODE_AC_BACK;
}
}
if (scancode != SDL_SCANCODE_UNKNOWN) {
if (keyEvent->location == DOM_KEY_LOCATION_RIGHT) {
@@ -503,6 +513,55 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
break;
}
}
else if (keyEvent->location == DOM_KEY_LOCATION_NUMPAD) {
switch (scancode) {
case SDL_SCANCODE_0:
case SDL_SCANCODE_INSERT:
scancode = SDL_SCANCODE_KP_0;
break;
case SDL_SCANCODE_1:
case SDL_SCANCODE_END:
scancode = SDL_SCANCODE_KP_1;
break;
case SDL_SCANCODE_2:
case SDL_SCANCODE_DOWN:
scancode = SDL_SCANCODE_KP_2;
break;
case SDL_SCANCODE_3:
case SDL_SCANCODE_PAGEDOWN:
scancode = SDL_SCANCODE_KP_3;
break;
case SDL_SCANCODE_4:
case SDL_SCANCODE_LEFT:
scancode = SDL_SCANCODE_KP_4;
break;
case SDL_SCANCODE_5:
scancode = SDL_SCANCODE_KP_5;
break;
case SDL_SCANCODE_6:
case SDL_SCANCODE_RIGHT:
scancode = SDL_SCANCODE_KP_6;
break;
case SDL_SCANCODE_7:
case SDL_SCANCODE_HOME:
scancode = SDL_SCANCODE_KP_7;
break;
case SDL_SCANCODE_8:
case SDL_SCANCODE_UP:
scancode = SDL_SCANCODE_KP_8;
break;
case SDL_SCANCODE_9:
case SDL_SCANCODE_PAGEUP:
scancode = SDL_SCANCODE_KP_9;
break;
case SDL_SCANCODE_RETURN:
scancode = SDL_SCANCODE_KP_ENTER;
break;
case SDL_SCANCODE_DELETE:
scancode = SDL_SCANCODE_KP_PERIOD;
break;
}
}
SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode);
}
}
@@ -548,7 +607,7 @@ Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChang
window_data->requested_fullscreen_mode = 0;
if(!window_data->requested_fullscreen_mode)
window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't reqest fullscreen*/
window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't request fullscreen*/
}
else
{
@@ -635,6 +694,16 @@ Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChang
return 0;
}
static const char*
Emscripten_HandleBeforeUnload(int eventType, const void *reserved, void *userData)
{
/* This event will need to be handled synchronously, e.g. using
SDL_AddEventWatch, as the page is being closed *now*. */
/* No need to send a SDL_QUIT, the app won't get control again. */
SDL_SendAppEvent(SDL_APP_TERMINATING);
return ""; /* don't trigger confirmation dialog */
}
void
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
{
@@ -674,6 +743,8 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, data, 0, Emscripten_HandleResize);
emscripten_set_visibilitychange_callback(data, 0, Emscripten_HandleVisibilityChange);
emscripten_set_beforeunload_callback(data, Emscripten_HandleBeforeUnload);
}
void
@@ -716,6 +787,8 @@ Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 0, NULL);
emscripten_set_visibilitychange_callback(NULL, 0, NULL);
emscripten_set_beforeunload_callback(NULL, NULL);
}
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */

View File

@@ -24,6 +24,7 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenframebuffer.h"
#include "SDL_hints.h"
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
@@ -162,6 +163,12 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}*/
if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
/* give back control to browser for screen refresh */
emscripten_sleep(0);
}
return 0;
}

View File

@@ -18,8 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
@@ -28,9 +26,9 @@
#include <emscripten/html5.h>
#include "SDL_emscriptenmouse.h"
#include "SDL_emscriptenvideo.h"
#include "../../events/SDL_mouse_c.h"
#include "SDL_assert.h"
static SDL_Cursor*
Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom)
@@ -236,9 +234,19 @@ Emscripten_WarpMouse(SDL_Window* window, int x, int y)
static int
Emscripten_SetRelativeMouseMode(SDL_bool enabled)
{
SDL_Window *window;
SDL_WindowData *window_data;
/* TODO: pointer lock isn't actually enabled yet */
if(enabled) {
if(emscripten_request_pointerlock(NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
window = SDL_GetMouseFocus();
if (window == NULL) {
return -1;
}
window_data = (SDL_WindowData *) window->driverdata;
if(emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
}
} else {

View File

@@ -27,6 +27,7 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenopengles.h"
#include "SDL_hints.h"
#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
@@ -82,9 +83,19 @@ Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
}
SDL_EGL_CreateContext_impl(Emscripten)
SDL_EGL_SwapWindow_impl(Emscripten)
SDL_EGL_MakeCurrent_impl(Emscripten)
int
Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window)
{
EGLBoolean ret = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
/* give back control to browser for screen refresh */
emscripten_sleep(0);
}
return ret;
}
void
Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{

View File

@@ -42,6 +42,7 @@
static int Emscripten_VideoInit(_THIS);
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
static void Emscripten_VideoQuit(_THIS);
static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
static int Emscripten_CreateWindow(_THIS, SDL_Window * window);
static void Emscripten_SetWindowSize(_THIS, SDL_Window * window);
@@ -53,12 +54,6 @@ static void Emscripten_SetWindowTitle(_THIS, SDL_Window * window);
/* Emscripten driver bootstrap functions */
static int
Emscripten_Available(void)
{
return (1);
}
static void
Emscripten_DeleteDevice(SDL_VideoDevice * device)
{
@@ -86,6 +81,7 @@ Emscripten_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = Emscripten_VideoInit;
device->VideoQuit = Emscripten_VideoQuit;
device->GetDisplayUsableBounds = Emscripten_GetDisplayUsableBounds;
device->SetDisplayMode = Emscripten_SetDisplayMode;
@@ -130,7 +126,7 @@ Emscripten_CreateDevice(int devindex)
VideoBootStrap Emscripten_bootstrap = {
EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
Emscripten_Available, Emscripten_CreateDevice
Emscripten_CreateDevice
};
@@ -177,6 +173,22 @@ Emscripten_VideoQuit(_THIS)
Emscripten_FiniMouse();
}
static int
Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{
if (rect) {
rect->x = 0;
rect->y = 0;
rect->w = EM_ASM_INT_V({
return window.innerWidth;
});
rect->h = EM_ASM_INT_V({
return window.innerHeight;
});
}
return 0;
}
static void
Emscripten_PumpEvents(_THIS)
{
@@ -348,8 +360,8 @@ Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * di
static void
Emscripten_SetWindowTitle(_THIS, SDL_Window * window) {
EM_ASM_INT({
if (typeof Module['setWindowTitle'] !== 'undefined') {
Module['setWindowTitle'](UTF8ToString($0));
if (typeof setWindowTitle !== 'undefined') {
setWindowTitle(UTF8ToString($0));
}
return 0;
}, window->title);