changes to build system, emscipten progress (can render solid color, yippie!)

This commit is contained in:
veclavtalica
2025-02-21 19:06:19 +03:00
parent dd4fc45be3
commit f25e27b102
11 changed files with 29 additions and 12 deletions

View File

@ -24,9 +24,9 @@
static void pack_contents_modified(char const *path, enum FilewatchAction action);
#ifndef EMSCRIPTEN
static SDL_sem *opengl_load_semaphore;
#endif
/* note: it drives most of IO implicitly, such as audio callbacks */
static void poll_events(void) {
@ -425,6 +425,7 @@ static bool initialize(void) {
toml_datum_t datum_debug = toml_bool_in(game, "debug");
ctx.game.debug = datum_debug.ok ? datum_debug.u.b : true;
#ifndef EMSCRIPTEN
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
@ -441,6 +442,11 @@ static bool initialize(void) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
toml_datum_t datum_title = toml_string_in(about, "title");
if (!datum_title.ok)
datum_title.u.s = SDL_strdup("townengine project");
@ -624,9 +630,11 @@ static bool initialize(void) {
profile_end("game object load");
/* delayed as further as possible so that more work is done before we have to wait */
#ifndef EMSCRIPTEN
SDL_SemWait(opengl_load_semaphore);
SDL_DestroySemaphore(opengl_load_semaphore);
profile_end("opengl loading");
#endif
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
@ -763,6 +771,7 @@ int enter_loop(int argc, char **argv) {
}
profile_end("SDL initialization");
#ifndef EMSCRIPTEN
profile_start("opengl loading");
opengl_load_semaphore = SDL_CreateSemaphore(0);
SDL_Thread *opengl_load_thread = SDL_CreateThread(opengl_load_thread_fn, "opengl loader", opengl_load_semaphore);
@ -773,6 +782,7 @@ int enter_loop(int argc, char **argv) {
SDL_DetachThread(opengl_load_thread);
opengl_load_thread = NULL;
#endif
ctx.argc = argc;
ctx.argv = argv;

View File

@ -50,6 +50,7 @@ bool workers_init(size_t worker_count) {
if (worker_count > MAX_WORKERS)
worker_count = MAX_WORKERS;
#ifndef EMSCRIPTEN
/* spawn a bunch of detached threads without references to them */
for (size_t i = 0; i < worker_count; ++i) {
SDL_Thread *thread = SDL_CreateThread(worker_thread, "worker", NULL);
@ -61,11 +62,13 @@ bool workers_init(size_t worker_count) {
workers_job_semaphore = SDL_CreateSemaphore(0);
workers_exit_semaphore = SDL_CreateSemaphore(0);
workers_mutex = SDL_CreateMutex();
#endif
return true;
}
void workers_deinit(void) {
#ifndef EMSCRIPTEN
SDL_LockMutex(workers_mutex);
workers_should_exit = true;
SDL_UnlockMutex(workers_mutex);
@ -77,5 +80,6 @@ void workers_deinit(void) {
SDL_DestroyMutex(workers_mutex);
SDL_DestroySemaphore(workers_job_semaphore);
SDL_DestroySemaphore(workers_exit_semaphore);
#endif
workers_pool_size = 0;
}