diff --git a/misc/portability.md b/misc/portability.md index 27935a1ed..f4814a339 100644 --- a/misc/portability.md +++ b/misc/portability.md @@ -60,8 +60,8 @@ posix note: Register access is highly dependent on OS and architecture. Play multiple audio streams with varying sample rates Define: -- ```CC_BUILD_WIN``` - Use WinMM for audio -- ```CC_BUILD_POSIX``` - Use OpenAL for audio +- ```CC_BUILD_WINMM``` - Use WinMM for audio (Windows) +- ```CC_BUILD_OpenAL``` - Use OpenAL for audio ### 3D Graphics Texturing, depth buffer, alpha, etc (See Graphics.h for full list) @@ -76,5 +76,5 @@ Define: HTTP, HTTPS, and cookies (ETag and Last-Modified recommended) Define: -- ```CC_BUILD_WIN``` - use WinINet as http backend -- ```CC_BUILD_POSIX``` - use libcurl as http backend \ No newline at end of file +- ```CC_BUILD_WININET``` - use WinINet for http (Windows) +- ```CC_BUILD_CURL``` - use libcurl for http \ No newline at end of file diff --git a/src/Audio.c b/src/Audio.c index a4f1235e8..2d034ed9d 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -12,7 +12,7 @@ #include "Chat.h" #include "Stream.h" -#if defined CC_BUILD_WIN +#if defined CC_BUILD_WINMM #define WIN32_LEAN_AND_MEAN #define NOSERVICE #define NOMCX @@ -24,7 +24,7 @@ #include #include -#elif defined CC_BUILD_POSIX +#elif defined CC_BUILD_OPENAL #include #if defined CC_BUILD_OSX #include @@ -70,7 +70,7 @@ static void Volume_Mix8(uint8_t* samples, int count, int volume) { *------------------------------------------------Native implementation----------------------------------------------------* *#########################################################################################################################*/ static ReturnCode Audio_AllCompleted(AudioHandle handle, bool* finished); -#if defined CC_BUILD_WIN +#if defined CC_BUILD_WINMM struct AudioContext { HWAVEOUT Handle; WAVEHDR Headers[AUDIO_MAX_BUFFERS]; @@ -175,7 +175,7 @@ ReturnCode Audio_IsCompleted(AudioHandle handle, int idx, bool* completed) { } ReturnCode Audio_IsFinished(AudioHandle handle, bool* finished) { return Audio_AllCompleted(handle, finished); } -#elif defined CC_BUILD_POSIX +#elif defined CC_BUILD_OPENAL struct AudioContext { ALuint Source; ALuint Buffers[AUDIO_MAX_BUFFERS]; @@ -382,7 +382,22 @@ ReturnCode Audio_IsFinished(AudioHandle handle, bool* finished) { alGetSourcei(ctx->Source, AL_SOURCE_STATE, &state); *finished = state != AL_PLAYING; return 0; } +#else +struct AudioContext { int Count; struct AudioFormat Format; }; +static struct AudioContext Audio_Contexts[1]; + +void Audio_Open(AudioHandle* handle, int buffers) { } +ReturnCode Audio_Close(AudioHandle handle) { return 1; } +ReturnCode Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) { return 1; } +ReturnCode Audio_BufferData(AudioHandle handle, int idx, void* data, uint32_t dataSize) { return 1; } +ReturnCode Audio_Play(AudioHandle handle) { return 1; } +ReturnCode Audio_Stop(AudioHandle handle) { return 1; } +ReturnCode Audio_IsCompleted(AudioHandle handle, int idx, bool* completed) { return 1; } +ReturnCode Audio_IsFinished(AudioHandle handle, bool* finished) { return 1; } +void Audio_SysInit(void) { } +void Audio_SysFree(void) { } #endif + static ReturnCode Audio_AllCompleted(AudioHandle handle, bool* finished) { struct AudioContext* ctx = &Audio_Contexts[handle]; ReturnCode res; diff --git a/src/Core.h b/src/Core.h index 649f004af..f5e0c23a8 100644 --- a/src/Core.h +++ b/src/Core.h @@ -135,7 +135,7 @@ typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec; #define CC_BUILD_GLMODERN #define CC_BUILD_WEBCANVAS #define CC_BUILD_WEBGL -//#error "Web backend is still a WIP. Please do not publicly mention it, thanks." +#error "Web backend is still a WIP. Please do not publicly mention it, thanks." #endif #endif diff --git a/src/Http.c b/src/Http.c index e7d8ffde0..5f7499405 100644 --- a/src/Http.c +++ b/src/Http.c @@ -5,7 +5,7 @@ #include "Stream.h" #include "GameStructs.h" -#if defined CC_BUILD_WIN +#if defined CC_BUILD_WININET #define WIN32_LEAN_AND_MEAN #define NOSERVICE #define NOMCX @@ -20,10 +20,8 @@ #define HTTP_QUERY_ETAG 54 /* Missing from some old MingW32 headers */ #elif defined CC_BUILD_WEB /* Use javascript web api for Emscripten */ -#undef CC_BUILD_POSIX #include -#elif defined CC_BUILD_POSIX -/* POSIX is mainly shared between Linux and OSX */ +#elif defined CC_BUILD_CURL #include #include #endif @@ -229,7 +227,7 @@ static void Http_FinishRequest(struct HttpRequest* req) { /*########################################################################################################################* *------------------------------------------------Emscripten implementation------------------------------------------------* *#########################################################################################################################*/ -#ifdef CC_BUILD_WEB +#if defined CC_BUILD_WEB static void Http_SysInit(void) { } static void Http_SysFree(void) { } static void Http_DownloadAsync(struct HttpRequest* req); @@ -298,7 +296,7 @@ static void Http_DownloadAsync(struct HttpRequest* req) { /*########################################################################################################################* *--------------------------------------------------Native implementation--------------------------------------------------* *#########################################################################################################################*/ -#ifdef CC_BUILD_WIN +#if defined CC_BUILD_WININET static HINTERNET hInternet; /* TODO: Test last modified and etag even work */ #define FLAG_STATUS HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER @@ -534,8 +532,7 @@ static void Http_SysFree(void) { } InternetCloseHandle(hInternet); } -#endif -#ifdef CC_BUILD_POSIX +#elif defined CC_BUILD_CURL static CURL* curl; static void Http_SysInit(void) { diff --git a/src/Window.c b/src/Window.c index 14aac3818..8c4f5336d 100644 --- a/src/Window.c +++ b/src/Window.c @@ -2549,13 +2549,26 @@ static void Window_RefreshBounds(void) { Window_Bounds = r; } +static void Window_CorrectFocus(void) { + /* Sometimes emscripten_request_pointerlock doesn't always acquire focus */ + /* Browser also only allows pointer locks requests in response to user input */ + EmscriptenPointerlockChangeEvent status; + status.isActive = false; + return; + + emscripten_get_pointerlock_status(&status); + if (win_rawMouse && !status.isActive) Window_EnableRawMouse(); +} + static EM_BOOL Window_MouseWheel(int type, const EmscriptenWheelEvent* ev, void* data) { Mouse_SetWheel(Mouse_Wheel - ev->deltaY); + Window_CorrectFocus(); return true; } static EM_BOOL Window_MouseButton(int type, const EmscriptenMouseEvent* ev, void* data) { MouseButton btn; + Window_CorrectFocus(); switch (ev->button) { case 0: btn = MOUSE_LEFT; break; @@ -2664,7 +2677,9 @@ static Key Window_MapKey(int k) { static EM_BOOL Window_Key(int type, const EmscriptenKeyboardEvent* ev , void* data) { Key key = Window_MapKey(ev->keyCode); - int kc = ev->keyCode; + int kc = ev->keyCode; + + Window_CorrectFocus(); if (!key) return false; if (ev->location == DOM_KEY_LOCATION_RIGHT) { @@ -2686,12 +2701,14 @@ static EM_BOOL Window_Key(int type, const EmscriptenKeyboardEvent* ev , void* da /* Must not intercept keydown for regular keys, otherwise KeyPress doesn't get raised */ /* However, do want to prevent browser's behaviour on F11,F5, home etc */ /* e.g. not preventing F11 means browser makes page fullscreen instead of just canvas */ - return (key >= KEY_F1 && key <= KEY_F35) || (key >= KEY_UP && key <= KEY_RIGHT) || - (key >= KEY_INSERT && key <= KEY_MENU) || (key >= KEY_ENTER && key <= KEY_NUMLOCK); + return (key >= KEY_F1 && key <= KEY_F35) || (key >= KEY_UP && key <= KEY_RIGHT) || + (key >= KEY_INSERT && key <= KEY_MENU) || (key >= KEY_ENTER && key <= KEY_NUMLOCK && key != KEY_SPACE); } static EM_BOOL Window_KeyPress(int type, const EmscriptenKeyboardEvent* ev, void* data) { char keyChar; + Window_CorrectFocus(); + if (Convert_TryUnicodeToCP437(ev->charCode, &keyChar)) { Event_RaiseInt(&KeyEvents.Press, keyChar); }