Example scene working
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "asset/loader/assetloader.h"
|
||||
#include "asset/loader/assetentry.h"
|
||||
#include "asset/loader/json/assetjsonloader.h"
|
||||
#include "thread/thread.h"
|
||||
#include "util/memory.h"
|
||||
#include <zip.h>
|
||||
|
||||
@@ -20,6 +21,32 @@
|
||||
static const char_t *JSON_VALID = "{\"hello\":\"world\",\"count\":42}";
|
||||
static const char_t *JSON_INVALID = "{ this is definitely not valid json !!!";
|
||||
|
||||
// ============================================================
|
||||
// Async thread helper
|
||||
// ============================================================
|
||||
|
||||
typedef struct {
|
||||
assetloading_t *loading;
|
||||
bool_t ok;
|
||||
} json_async_run_t;
|
||||
|
||||
static void json_async_thread_cb(thread_t *thread) {
|
||||
json_async_run_t *run = (json_async_run_t *)thread->data;
|
||||
errorret_t ret = assetJsonLoaderAsync(run->loading);
|
||||
run->ok = errorIsOk(ret);
|
||||
if(errorIsNotOk(ret)) errorCatch(ret);
|
||||
}
|
||||
|
||||
static bool_t run_json_async(assetloading_t *loading) {
|
||||
json_async_run_t run = { .loading = loading, .ok = false };
|
||||
thread_t thread;
|
||||
threadInit(&thread, json_async_thread_cb);
|
||||
thread.data = &run;
|
||||
threadStart(&thread);
|
||||
threadStop(&thread);
|
||||
return run.ok;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// In-memory ZIP
|
||||
// ============================================================
|
||||
@@ -110,8 +137,10 @@ static errorret_t loader_ctx_run(loader_ctx_t *ctx) {
|
||||
errorret_t ret = assetJsonLoaderSync(&ctx->loading);
|
||||
if(errorIsNotOk(ret)) return ret;
|
||||
|
||||
ret = assetJsonLoaderAsync(&ctx->loading);
|
||||
if(errorIsNotOk(ret)) return ret;
|
||||
if(!run_json_async(&ctx->loading)) {
|
||||
ctx->entry.state = ASSET_ENTRY_STATE_ERROR;
|
||||
errorThrow("Async JSON load failed");
|
||||
}
|
||||
|
||||
return assetJsonLoaderSync(&ctx->loading);
|
||||
}
|
||||
@@ -162,8 +191,7 @@ static void test_json_parse_error(void **state) {
|
||||
errorret_t ret = assetJsonLoaderSync(&ctx.loading);
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
ret = assetJsonLoaderAsync(&ctx.loading);
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_true(run_json_async(&ctx.loading));
|
||||
|
||||
ret = assetJsonLoaderSync(&ctx.loading);
|
||||
assert_true(errorIsNotOk(ret));
|
||||
@@ -184,9 +212,7 @@ static void test_json_missing_file(void **state) {
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
// Async phase stat-fails because the file isn't in the ZIP.
|
||||
ret = assetJsonLoaderAsync(&ctx.loading);
|
||||
assert_true(errorIsNotOk(ret));
|
||||
errorCatch(ret);
|
||||
assert_false(run_json_async(&ctx.loading));
|
||||
|
||||
assert_int_equal(ctx.entry.state, ASSET_ENTRY_STATE_ERROR);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user