audio/http backend is no longer tied to platform backend

This commit is contained in:
UnknownShadow200 2019-03-30 13:09:58 +11:00
parent 2bb78ec692
commit b437e8289b
5 changed files with 49 additions and 20 deletions

View File

@ -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
- ```CC_BUILD_WININET``` - use WinINet for http (Windows)
- ```CC_BUILD_CURL``` - use libcurl for http

View File

@ -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 <windows.h>
#include <mmsystem.h>
#elif defined CC_BUILD_POSIX
#elif defined CC_BUILD_OPENAL
#include <pthread.h>
#if defined CC_BUILD_OSX
#include <OpenAL/al.h>
@ -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;

View File

@ -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

View File

@ -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 <emscripten/fetch.h>
#elif defined CC_BUILD_POSIX
/* POSIX is mainly shared between Linux and OSX */
#elif defined CC_BUILD_CURL
#include <curl/curl.h>
#include <time.h>
#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) {

View File

@ -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;
@ -2665,6 +2678,8 @@ 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;
Window_CorrectFocus();
if (!key) return false;
if (ev->location == DOM_KEY_LOCATION_RIGHT) {
@ -2687,11 +2702,13 @@ static EM_BOOL Window_Key(int type, const EmscriptenKeyboardEvent* ev , void* da
/* 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);
(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);
}