Move MSDOS and webclient backend files out

This commit is contained in:
UnknownShadow200 2025-07-09 18:56:08 +10:00
parent 01c2e1c3fd
commit 85f1b4c5c5
10 changed files with 85 additions and 91 deletions

View File

@ -21,9 +21,10 @@ jobs:
- uses: actions/checkout@v4
- name: Compiles webclient
id: compile
env:
SRCS: "src/*.c src/webclient/*.c"
run: |
cd src
emcc *.c -o ClassiCube.js -s WASM=0 -s NO_EXIT_RUNTIME=1 -s LEGACY_VM_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 -s ABORTING_MALLOC=0 -s ENVIRONMENT=web -s TOTAL_STACK=256Kb --js-library interop_web.js -Os -g2 -s SINGLE_FILE
emcc ${{ env.SRCS }} -o ClassiCube.js -s WASM=0 -s NO_EXIT_RUNTIME=1 -s LEGACY_VM_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 -s ABORTING_MALLOC=0 -s ENVIRONMENT=web -s TOTAL_STACK=256Kb --js-library src/webclient/interop_web.js -Os -g2 -s SINGLE_FILE
sed -i 's#eventHandler.useCapture);#{ useCapture: eventHandler.useCapture, passive: false });#g' ClassiCube.js
- uses: ./.github/actions/notify_failure
@ -35,7 +36,7 @@ jobs:
- uses: ./.github/actions/upload_build
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'src/ClassiCube.js'
SOURCE_FILE: 'ClassiCube.js'
DEST_NAME: 'ClassiCube.js'

View File

@ -59,9 +59,12 @@ ifeq ($(PLAT),web)
CC = emcc
OEXT = .html
CFLAGS = -g
LDFLAGS = -g -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=256Kb --js-library $(SOURCE_DIR)/interop_web.js
LDFLAGS = -g -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=256Kb --js-library $(SOURCE_DIR)/webclient/interop_web.js
BUILD_DIR = build/web
BEARSSL = 0
BUILD_DIRS += $(BUILD_DIR)/src/webclient
C_SOURCES += $(wildcard src/webclient/*.c)
endif
ifeq ($(PLAT),mingw)
@ -176,6 +179,9 @@ ifeq ($(PLAT),dos)
OEXT = .exe
BUILD_DIR = build/dos
BEARSSL = 0
BUILD_DIRS += $(BUILD_DIR)/src/msdos
C_SOURCES += $(wildcard src/msdos/*.c)
endif
@ -194,9 +200,7 @@ endif
ifeq ($(BEARSSL),1)
BUILD_DIRS += $(BUILD_DIR)/third_party/bearssl
BEARSSL_SOURCES = $(wildcard third_party/bearssl/*.c)
BEARSSL_OBJECTS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(BEARSSL_SOURCES))
OBJECTS += $(BEARSSL_OBJECTS)
C_SOURCES += $(wildcard third_party/bearssl/*.c)
endif
ifdef RELEASE

View File

@ -206,8 +206,8 @@ NOTE: If you are distributing a modified version, **please change the bundle ID
1. Install emscripten if necessary.
2. Run either:
* `make web` or
* `emcc src/*.c -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library interop_web.js`
* `make web` - produces simple non-optimised output, easier to debug
* `make web RELEASE=1` - produces optimised output, harder to debug
The generated javascript file has some issues. [See here for how to fix](doc/compile-fixes.md#webclient-patches)

View File

@ -1,15 +1,13 @@
#include "Core.h"
#if defined CC_BUILD_MSDOS
#include "../_PlatformBase.h"
#include "../Stream.h"
#include "../ExtMath.h"
#include "../SystemFonts.h"
#include "../Funcs.h"
#include "../Window.h"
#include "../Utils.h"
#include "../Errors.h"
#include "../PackedCol.h"
#include "_PlatformBase.h"
#include "Stream.h"
#include "ExtMath.h"
#include "SystemFonts.h"
#include "Funcs.h"
#include "Window.h"
#include "Utils.h"
#include "Errors.h"
#include "PackedCol.h"
#include <errno.h>
#include <time.h>
#include <stdlib.h>
@ -39,7 +37,7 @@ cc_bool Platform_ReadonlyFilesystem;
/*########################################################################################################################*
*-----------------------------------------------------Main entrypoint-----------------------------------------------------*
*#########################################################################################################################*/
#include "main_impl.h"
#include "../main_impl.h"
int main(int argc, char** argv) {
cc_result res;
@ -450,4 +448,4 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* arg
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
return 0;
}
#endif

View File

@ -1,12 +1,10 @@
#include "Core.h"
#if defined CC_BUILD_MSDOS
#include "../_WindowBase.h"
#include "../String.h"
#include "../Funcs.h"
#include "../Bitmap.h"
#include "../Options.h"
#include "../Errors.h"
#include "_WindowBase.h"
#include "String.h"
#include "Funcs.h"
#include "Bitmap.h"
#include "Options.h"
#include "Errors.h"
#include <dpmi.h>
#include <sys/nearptr.h>
#include <pc.h>
@ -347,4 +345,4 @@ void Window_UpdateRawMouse(void) {
void Window_DisableRawMouse(void) {
DefaultDisableRawMouse();
}
#endif

View File

@ -1,12 +1,9 @@
#include "Core.h"
#if defined CC_BUILD_WEBAUDIO
struct AudioContext { int contextID, count; void* data; };
#define AUDIO_OVERRIDE_SOUNDS
#define AUDIO_OVERRIDE_ALLOC
#include "_AudioBase.h"
#include "Funcs.h"
#include "../_AudioBase.h"
#include "../Funcs.h"
extern int interop_InitAudio(void);
extern int interop_AudioCreate(void);
@ -140,5 +137,4 @@ void AudioBackend_LoadSounds(void) {
}
}
}
#endif

View File

@ -1,10 +1,10 @@
#include "Core.h"
#ifdef CC_BUILD_WEB
#include "_HttpBase.h"
#include "../_HttpBase.h"
#include "../Errors.h"
#include <emscripten/emscripten.h>
#include "Errors.h"
extern int interop_DownloadAsync(const char* url, int method, int reqID);
extern int interop_IsHttpsOnly(void);
static struct RequestList workingReqs, queuedReqs;
static cc_uint64 startTime;
@ -21,7 +21,7 @@ cc_bool Http_GetResult(int reqID, struct HttpRequest* item) {
}
cc_bool Http_GetCurrent(int* reqID, int* progress) {
/* TODO: Stubbed as this isn't required at the moment */
// TODO: Stubbed as this isn't required at the moment
*progress = 0;
return 0;
}
@ -59,7 +59,7 @@ static void Http_StartNextDownload(void) {
struct HttpRequest* req;
cc_result res;
/* Avoid making too many requests at once */
// Avoid making too many requests at once
if (workingReqs.count >= HTTP_MAX_CONCURRENCY) return;
if (!queuedReqs.count) return;
String_InitArray(url, urlBuffer);
@ -72,11 +72,11 @@ static void Http_StartNextDownload(void) {
res = interop_DownloadAsync(urlStr, req->requestType, req->id);
if (res) {
/* interop error code -> ClassiCube error code */
// interop error code -> ClassiCube error code
if (res == 1) res = ERR_INVALID_DATA_URL;
req->result = res;
/* Invalid URL so move onto next request */
// Invalid URL so move onto next request
Http_FinishRequest(req);
RequestList_RemoveAt(&queuedReqs, 0);
Http_StartNextDownload();
@ -98,7 +98,7 @@ EMSCRIPTEN_KEEPALIVE void Http_OnFinishedAsync(int reqID, void* data, int len, i
int idx = RequestList_Find(&workingReqs, reqID);
if (idx == -1) {
/* Shouldn't ever happen, but log a warning anyways */
// Shouldn't ever happen, but log a warning anyways
Mem_Free(data);
Platform_Log1("Ignoring invalid request (%i)", &reqID);
} else {
@ -108,7 +108,7 @@ EMSCRIPTEN_KEEPALIVE void Http_OnFinishedAsync(int reqID, void* data, int len, i
req->statusCode = status;
req->contentLength = len;
/* Usually this happens when denied by CORS */
// Usually this happens when denied by CORS
if (!status && !data) req->result = ERR_DOWNLOAD_INVALID;
if (req->data) Platform_Log1("HTTP returned data: %i bytes", &req->size);
@ -118,9 +118,9 @@ EMSCRIPTEN_KEEPALIVE void Http_OnFinishedAsync(int reqID, void* data, int len, i
Http_StartNextDownload();
}
/* Adds a req to the list of pending requests, waking up worker thread if needed */
// Adds a req to the list of pending requests, waking up worker thread if needed
static void HttpBackend_Add(struct HttpRequest* req, cc_uint8 flags) {
/* Add time based query string parameter to bypass browser cache */
// Add time based query string parameter to bypass browser cache
if (flags & HTTP_FLAG_NOCACHE) {
cc_string url = String_FromRawArray(req->url);
int lo = (int)(startTime), hi = (int)(startTime >> 32);
@ -137,7 +137,7 @@ static void HttpBackend_Add(struct HttpRequest* req, cc_uint8 flags) {
*#########################################################################################################################*/
static void Http_Init(void) {
Http_InitCommon();
/* If this webpage is https://, browsers deny any http:// downloading */
// If this webpage is https://, browsers deny any http:// downloading
httpsOnly = interop_IsHttpsOnly();
startTime = DateTime_CurrentUTC();
@ -145,4 +145,4 @@ static void Http_Init(void) {
RequestList_Init(&workingReqs);
RequestList_Init(&processedReqs);
}
#endif

View File

@ -1,14 +1,11 @@
#include "Core.h"
#if defined CC_BUILD_WEB
#include "_PlatformBase.h"
#include "Stream.h"
#include "ExtMath.h"
#include "SystemFonts.h"
#include "Funcs.h"
#include "Window.h"
#include "Utils.h"
#include "Errors.h"
#include "../_PlatformBase.h"
#include "../Stream.h"
#include "../ExtMath.h"
#include "../SystemFonts.h"
#include "../Funcs.h"
#include "../Window.h"
#include "../Utils.h"
#include "../Errors.h"
#include <stdlib.h>
#include <string.h>
@ -22,16 +19,16 @@
#define O_EXCL 0x080
#define O_TRUNC 0x200
/* Unfortunately, errno constants are different in some older emscripten versions */
/* (linux errno numbers compared to WASI errno numbers) */
/* So just use the same errono numbers as interop_web.js */
// Unfortunately, errno constants are different in some older emscripten versions
// (linux errno numbers compared to WASI errno numbers)
// So just use the same errono numbers as interop_web.js
#define _ENOENT 2
#define _EAGAIN 6 /* same as EWOULDBLOCK */
#define _EAGAIN 6 // same as EWOULDBLOCK
#define _EEXIST 17
#define _EHOSTUNREACH 23
#define _EINPROGRESS 26
const cc_result ReturnCode_FileShareViolation = 1000000000; /* Not used in web filesystem backend */
const cc_result ReturnCode_FileShareViolation = 1000000000; // Not used in web filesystem backend
const cc_result ReturnCode_FileNotFound = _ENOENT;
const cc_result ReturnCode_SocketInProgess = _EINPROGRESS;
const cc_result ReturnCode_SocketWouldBlock = _EAGAIN;
@ -424,18 +421,18 @@ cc_result Platform_GetEntropy(void* data, int len) {
*#########################################################################################################################*/
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
int i, count;
argc--; argv++; /* skip executable path argument */
argc--; argv++; // skip executable path argument //
count = min(argc, GAME_MAX_CMDARGS);
for (i = 0; i < count; i++) { args[i] = String_FromReadonly(argv[i]); }
return count;
}
#include "main_impl.h"
#include "../main_impl.h"
static int _argc;
static char** _argv;
/* webclient does some asynchronous initialisation first, then kickstarts the game after that */
// webclient does some asynchronous initialisation first, then kickstarts the game after that
static void web_main(void) {
SetupProgram(_argc, _argv);
@ -462,11 +459,11 @@ extern void interop_AsyncDownloadTexturePack(const char* path);
EMSCRIPTEN_KEEPALIVE int main(int argc, char** argv) {
_argc = argc; _argv = argv;
/* Game loads resources asynchronously, then actually starts itself */
/* main */
/* > texture pack download (async) */
/* > load indexedDB (async) */
/* > web_main (game actually starts) */
// Game loads resources asynchronously, then actually starts itself:
// main
// > texture pack download (async)
// > load indexedDB (async)
// > web_main (game actually starts)
interop_FS_Init();
interop_DirectorySetWorking("/classicube");
interop_AsyncDownloadTexturePack("texpacks/default.zip");
@ -475,12 +472,12 @@ EMSCRIPTEN_KEEPALIVE int main(int argc, char** argv) {
extern void interop_LoadIndexedDB(void);
extern void interop_AsyncLoadIndexedDB(void);
/* Asynchronous callback after texture pack is downloaded */
// Asynchronous callback after texture pack is downloaded
EMSCRIPTEN_KEEPALIVE void main_phase1(void) {
interop_LoadIndexedDB(); /* legacy compatibility */
interop_LoadIndexedDB(); // legacy compatibility
interop_AsyncLoadIndexedDB();
}
/* Asynchronous callback after IndexedDB is loaded */
// Asynchronous callback after IndexedDB is loaded
EMSCRIPTEN_KEEPALIVE void main_phase2(void) { web_main(); }
#endif

View File

@ -1,13 +1,13 @@
#include "Core.h"
#if defined CC_BUILD_WEB && !defined CC_BUILD_SDL
#include "_WindowBase.h"
#include "Game.h"
#include "String.h"
#include "Funcs.h"
#include "ExtMath.h"
#include "Bitmap.h"
#include "Errors.h"
#include "Gui.h"
#include "../Core.h"
#include "../_WindowBase.h"
#include "../Game.h"
#include "../String.h"
#include "../Funcs.h"
#include "../ExtMath.h"
#include "../Bitmap.h"
#include "../Errors.h"
#include "../Gui.h"
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/key_codes.h>
@ -754,7 +754,7 @@ void Window_DisableRawMouse(void) {
*------------------------------------------------Emscripten WebGL context-------------------------------------------------*
*#########################################################################################################################*/
#if CC_GFX_BACKEND_IS_GL()
#include "Graphics.h"
#include "../Graphics.h"
static EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx_handle;
static EM_BOOL GLContext_OnLost(int eventType, const void *reserved, void *userData) {
@ -819,4 +819,4 @@ void GLContext_GetApiInfo(cc_string* info) {
String_AppendUtf8(info, buffer, len);
}
#endif
#endif