Example scene working

This commit is contained in:
2026-06-06 18:46:08 -05:00
parent 003b647d83
commit 9edb2aa0c1
13 changed files with 342 additions and 81 deletions
+34 -9
View File
@@ -10,6 +10,7 @@
#include "asset/loader/assetloader.h"
#include "asset/loader/assetentry.h"
#include "asset/loader/display/assettilesetloader.h"
#include "thread/thread.h"
#include "util/memory.h"
#include <zip.h>
@@ -91,6 +92,32 @@ static const uint8_t DTF_INVALID_UV[] = {
0x00, 0x00, 0x00, 0x40
};
// ============================================================
// Async thread helper
// ============================================================
typedef struct {
assetloading_t *loading;
bool_t ok;
} tileset_async_run_t;
static void tileset_async_thread_cb(thread_t *thread) {
tileset_async_run_t *run = (tileset_async_run_t *)thread->data;
errorret_t ret = assetTilesetLoaderAsync(run->loading);
run->ok = errorIsOk(ret);
if(errorIsNotOk(ret)) errorCatch(ret);
}
static bool_t run_tileset_async(assetloading_t *loading) {
tileset_async_run_t run = { .loading = loading, .ok = false };
thread_t thread;
threadInit(&thread, tileset_async_thread_cb);
thread.data = &run;
threadStart(&thread);
threadStop(&thread);
return run.ok;
}
// ============================================================
// In-memory ZIP
// ============================================================
@@ -183,8 +210,10 @@ static errorret_t loader_ctx_run(loader_ctx_t *ctx) {
errorret_t ret = assetTilesetLoaderSync(&ctx->loading);
if(errorIsNotOk(ret)) return ret;
ret = assetTilesetLoaderAsync(&ctx->loading);
if(errorIsNotOk(ret)) return ret;
if(!run_tileset_async(&ctx->loading)) {
ctx->entry.state = ASSET_ENTRY_STATE_ERROR;
errorThrow("Async tileset load failed");
}
return assetTilesetLoaderSync(&ctx->loading);
}
@@ -238,8 +267,7 @@ static void test_tileset_bad_magic(void **state) {
errorret_t ret = assetTilesetLoaderSync(&ctx.loading);
assert_true(errorIsOk(ret));
ret = assetTilesetLoaderAsync(&ctx.loading);
assert_true(errorIsOk(ret));
assert_true(run_tileset_async(&ctx.loading));
ret = assetTilesetLoaderSync(&ctx.loading);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
@@ -255,8 +283,7 @@ static void test_tileset_bad_version(void **state) {
errorret_t ret = assetTilesetLoaderSync(&ctx.loading);
assert_true(errorIsOk(ret));
ret = assetTilesetLoaderAsync(&ctx.loading);
assert_true(errorIsOk(ret));
assert_true(run_tileset_async(&ctx.loading));
ret = assetTilesetLoaderSync(&ctx.loading);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
@@ -328,9 +355,7 @@ static void test_tileset_missing_file(void **state) {
errorret_t ret = assetTilesetLoaderSync(&ctx.loading);
assert_true(errorIsOk(ret));
ret = assetTilesetLoaderAsync(&ctx.loading);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
assert_false(run_tileset_async(&ctx.loading));
assert_int_equal(ctx.entry.state, ASSET_ENTRY_STATE_ERROR);
loader_ctx_dispose(&ctx);