mirror of
https://github.com/whoahq/whoa.git
synced 2026-03-18 05:31:07 +03:00
Adds the platform layer for building whoa as a WebAssembly application: Working: - CMake configuration for WHOA_SYSTEM_WEB with pthreads and ASYNCIFY - Web entry point and HTML shell template - Event loop adapted for emscripten_set_main_loop callback model - WebSocket-based networking (WowConnection over JS WebSocket API) - Sound system stubs (audio not yet implemented) - FetchFS for async file loading from web server - Freetype fixes for WASM compatibility (type mismatches) - Input handling for web canvas Missing (in separate commits): - WebGPU graphics backend (CGxDeviceWebGPU) - WGSL shaders - API selection in Device.cpp
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#ifndef NET_CONNECTION_WEB_WS_STATE_HPP
|
|
#define NET_CONNECTION_WEB_WS_STATE_HPP
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
#include <emscripten/websocket.h>
|
|
|
|
struct WsRecvBuffer {
|
|
uint8_t* data = nullptr;
|
|
int32_t size = 0;
|
|
int32_t capacity = 0;
|
|
|
|
void append(const uint8_t* src, int32_t len) {
|
|
if (size + len > capacity) {
|
|
int32_t newCap = std::max(capacity ? capacity * 2 : 4096, size + len);
|
|
data = static_cast<uint8_t*>(realloc(data, newCap));
|
|
capacity = newCap;
|
|
}
|
|
memcpy(data + size, src, len);
|
|
size += len;
|
|
}
|
|
|
|
int32_t read(uint8_t* dst, int32_t maxLen) {
|
|
int32_t toRead = std::min(maxLen, size);
|
|
if (toRead > 0) {
|
|
memcpy(dst, data, toRead);
|
|
size -= toRead;
|
|
if (size > 0) {
|
|
memmove(data, data + toRead, size);
|
|
}
|
|
}
|
|
return toRead;
|
|
}
|
|
|
|
void clear() {
|
|
free(data);
|
|
data = nullptr;
|
|
size = 0;
|
|
capacity = 0;
|
|
}
|
|
};
|
|
|
|
struct WsState {
|
|
EMSCRIPTEN_WEBSOCKET_T ws = 0;
|
|
WsRecvBuffer recvBuf;
|
|
bool connectPending = false;
|
|
bool closePending = false;
|
|
bool errorPending = false;
|
|
char connectHost[256] = {0};
|
|
};
|
|
|
|
#endif
|