FInished porting last asset loader types

This commit is contained in:
2026-05-30 07:59:06 -05:00
parent 0bcde064af
commit 3271e8c7d6
11 changed files with 164 additions and 28 deletions
+12
View File
@@ -13,6 +13,10 @@
assetentrycallbacks_t ASSET_ENTRY_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = { assetentrycallbacks_t ASSET_ENTRY_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
[ASSET_LOADER_TYPE_NULL] = { 0 }, [ASSET_LOADER_TYPE_NULL] = { 0 },
[ASSET_LOADER_TYPE_MESH] = {
.dispose = &assetMeshDisposeNEW
},
[ASSET_LOADER_TYPE_TEXTURE] = { [ASSET_LOADER_TYPE_TEXTURE] = {
.dispose = &assetTextureDisposeNEW .dispose = &assetTextureDisposeNEW
}, },
@@ -20,6 +24,14 @@ assetentrycallbacks_t ASSET_ENTRY_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
[ASSET_LOADER_TYPE_TILESET] = { [ASSET_LOADER_TYPE_TILESET] = {
.dispose = &assetTilesetDisposeNEW .dispose = &assetTilesetDisposeNEW
}, },
[ASSET_LOADER_TYPE_LOCALE] = {
.dispose = &assetLocaleDisposeNEW
},
[ASSET_LOADER_TYPE_JSON] = {
.dispose = &assetJsonDisposeNEW
},
}; };
void assetEntryInit( void assetEntryInit(
+14 -1
View File
@@ -9,28 +9,41 @@
#include "asset/loader/display/assetmeshloader.h" #include "asset/loader/display/assetmeshloader.h"
#include "asset/loader/display/assettextureloader.h" #include "asset/loader/display/assettextureloader.h"
#include "asset/loader/display/assettilesetloader.h" #include "asset/loader/display/assettilesetloader.h"
#include "asset/loader/locale/assetlocaleloader.h"
#include "asset/loader/json/assetjsonloader.h"
typedef enum { typedef enum {
ASSET_LOADER_TYPE_NULL, ASSET_LOADER_TYPE_NULL,
// ASSET_LOADER_TYPE_MESH, ASSET_LOADER_TYPE_MESH,
ASSET_LOADER_TYPE_TEXTURE, ASSET_LOADER_TYPE_TEXTURE,
ASSET_LOADER_TYPE_TILESET, ASSET_LOADER_TYPE_TILESET,
ASSET_LOADER_TYPE_LOCALE,
ASSET_LOADER_TYPE_JSON,
ASSET_LOADER_TYPE_COUNT ASSET_LOADER_TYPE_COUNT
} assetloadertype_t; } assetloadertype_t;
typedef union { typedef union {
assetmeshloaderinput_t mesh;
assettextureloaderinput_t texture; assettextureloaderinput_t texture;
assettilesetloaderinput_t tileset; assettilesetloaderinput_t tileset;
assetlocaleloaderinput_t locale;
assetjsonloaderinput_t json;
} assetloaderinput_t; } assetloaderinput_t;
typedef union { typedef union {
assetmeshloaderloading_t mesh;
assettextureloaderloading_t texture; assettextureloaderloading_t texture;
assettilesetloaderloading_t tileset; assettilesetloaderloading_t tileset;
assetlocaleloaderloading_t locale;
assetjsonloaderloading_t json;
} assetloaderloading_t; } assetloaderloading_t;
typedef union { typedef union {
assetmeshoutput_t mesh;
assettextureoutput_t texture; assettextureoutput_t texture;
assettilesetoutput_t tileset; assettilesetoutput_t tileset;
assetlocaleoutput_t locale;
assetjsonoutput_t json;
} assetloaderoutput_t; } assetloaderoutput_t;
+9 -5
View File
@@ -11,9 +11,9 @@
assetloadingcallbacks_t ASSET_LOADING_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = { assetloadingcallbacks_t ASSET_LOADING_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
[ASSET_LOADER_TYPE_NULL] = { 0 }, [ASSET_LOADER_TYPE_NULL] = { 0 },
// [ASSET_LOADER_TYPE_MESH] = { [ASSET_LOADER_TYPE_MESH] = {
// .loadSync = assetMeshLoaderNEW, .loadSync = assetMeshLoaderNEW,
// }, },
[ASSET_LOADER_TYPE_TEXTURE] = { [ASSET_LOADER_TYPE_TEXTURE] = {
.loadSync = assetTextureLoaderNEW .loadSync = assetTextureLoaderNEW
@@ -24,7 +24,11 @@ assetloadingcallbacks_t ASSET_LOADING_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
.loadSync = assetTilesetLoaderNEW .loadSync = assetTilesetLoaderNEW
}, },
// [ASSET_LOADER_TYPE_SHADER] = { [ASSET_LOADER_TYPE_LOCALE] = {
.loadSync = assetLocaleLoaderNEW
},
// } [ASSET_LOADER_TYPE_JSON] = {
.loadSync = assetJsonLoaderNEW
},
}; };
@@ -11,10 +11,40 @@
#include "util/endian.h" #include "util/endian.h"
#include "util/memory.h" #include "util/memory.h"
#include "asset/loader/assetloading.h"
#include "asset/loader/assetentry.h"
errorret_t assetMeshLoaderNEW(assetloading_t *loading) {
assertNotNull(loading, "Loading cannot be NULL");
assertTrue(loading->type == ASSET_LOADER_TYPE_MESH, "Invalid type.");
assetmeshoutput_t *out = &loading->entry->data.mesh;
assetfile_t *file = &loading->loading.mesh.file;
assetmeshloaderparams_t params = {
.outMesh = &out->mesh,
.outVertices = &out->vertices,
.inputAxis = loading->entry->input->mesh
};
errorChain(assetFileInit(file, loading->entry->name, NULL, &params));
errorChain(assetMeshLoader(file));
assetFileDispose(file);
errorOk();
}
errorret_t assetMeshDisposeNEW(assetentry_t *entry) {
assertNotNull(entry, "Asset entry cannot be NULL");
assertTrue(entry->type == ASSET_LOADER_TYPE_MESH, "Invalid type.");
errorChain(meshDispose(&entry->data.mesh.mesh));
memoryFree(entry->data.mesh.vertices);
errorOk();
}
errorret_t assetMeshLoader(assetfile_t *file) { errorret_t assetMeshLoader(assetfile_t *file) {
assertNotNull(file, "Asset file cannot be null"); assertNotNull(file, "Asset file cannot be null");
assetmeshoutput_t *output = (assetmeshoutput_t *)file->output; assetmeshloaderparams_t *output = (assetmeshloaderparams_t *)file->output;
assertNotNull(output, "Output cannot be null"); assertNotNull(output, "Output cannot be null");
assertNotNull(output->outMesh, "Output mesh cannot be null"); assertNotNull(output->outMesh, "Output mesh cannot be null");
assertNotNull(output->outVertices, "Output vertices cannot be null"); assertNotNull(output->outVertices, "Output vertices cannot be null");
@@ -24,8 +24,26 @@ typedef struct {
mesh_t *outMesh; mesh_t *outMesh;
meshvertex_t **outVertices; meshvertex_t **outVertices;
assetmeshinputaxis_t inputAxis; assetmeshinputaxis_t inputAxis;
} assetmeshloaderparams_t;
// NEW STUFF
typedef struct assetloading_s assetloading_t;
typedef struct assetentry_s assetentry_t;
typedef assetmeshinputaxis_t assetmeshloaderinput_t;
typedef struct {
assetfile_t file;
} assetmeshloaderloading_t;
typedef struct {
mesh_t mesh;
meshvertex_t *vertices;
} assetmeshoutput_t; } assetmeshoutput_t;
errorret_t assetMeshLoaderNEW(assetloading_t *loading);
errorret_t assetMeshDisposeNEW(assetentry_t *entry);
// END NEW STUFF
#pragma pack(push, 1) #pragma pack(push, 1)
typedef struct { typedef struct {
vec3 normal; vec3 normal;
@@ -9,6 +9,26 @@
#include "util/memory.h" #include "util/memory.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "asset/loader/assetloading.h"
#include "asset/loader/assetentry.h"
errorret_t assetJsonLoaderNEW(assetloading_t *loading) {
assertNotNull(loading, "Loading cannot be NULL");
assertTrue(loading->type == ASSET_LOADER_TYPE_JSON, "Invalid type.");
assetfile_t *file = &loading->loading.json.file;
errorChain(assetFileInit(file, loading->entry->name, NULL, &loading->entry->data.json));
return assetJsonLoader(file);
}
errorret_t assetJsonDisposeNEW(assetentry_t *entry) {
assertNotNull(entry, "Asset entry cannot be NULL");
assertTrue(entry->type == ASSET_LOADER_TYPE_JSON, "Invalid type.");
yyjson_doc_free(entry->data.json);
entry->data.json = NULL;
errorOk();
}
errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc) { errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc) {
assertNotNull(file, "Asset file pointer for JSON loader is null."); assertNotNull(file, "Asset file pointer for JSON loader is null.");
assertNotNull(outDoc, "Output pointer for JSON loader is null."); assertNotNull(outDoc, "Output pointer for JSON loader is null.");
@@ -15,6 +15,21 @@ typedef struct {
void *nothing; void *nothing;
} assetjsonloaderparams_t; } assetjsonloaderparams_t;
// NEW STUFF
typedef struct assetloading_s assetloading_t;
typedef struct assetentry_s assetentry_t;
typedef struct { void *nothing; } assetjsonloaderinput_t;
typedef struct {
assetfile_t file;
} assetjsonloaderloading_t;
typedef yyjson_doc * assetjsonoutput_t;
errorret_t assetJsonLoaderNEW(assetloading_t *loading);
errorret_t assetJsonDisposeNEW(assetentry_t *entry);
// END NEW STUFF
/** /**
* Loads a JSON document from the specified asset file. * Loads a JSON document from the specified asset file.
* *
@@ -11,6 +11,24 @@
#include "util/string.h" #include "util/string.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "asset/loader/assetloading.h"
#include "asset/loader/assetentry.h"
errorret_t assetLocaleLoaderNEW(assetloading_t *loading) {
assertNotNull(loading, "Loading cannot be NULL");
assertTrue(loading->type == ASSET_LOADER_TYPE_LOCALE, "Invalid type.");
return assetLocaleFileInit(
&loading->entry->data.locale,
loading->entry->name
);
}
errorret_t assetLocaleDisposeNEW(assetentry_t *entry) {
assertNotNull(entry, "Asset entry cannot be NULL");
assertTrue(entry->type == ASSET_LOADER_TYPE_LOCALE, "Invalid type.");
return assetLocaleFileDispose(&entry->data.locale);
}
errorret_t assetLocaleFileInit( errorret_t assetLocaleFileInit(
assetlocalefile_t *localeFile, assetlocalefile_t *localeFile,
const char_t *path const char_t *path
@@ -8,6 +8,13 @@
#pragma once #pragma once
#include "asset/assetfile.h" #include "asset/assetfile.h"
// NEW STUFF
typedef struct assetloading_s assetloading_t;
typedef struct assetentry_s assetentry_t;
typedef struct { void *nothing; } assetlocaleloaderinput_t;
typedef struct { void *nothing; } assetlocaleloaderloading_t;
#define ASSET_LOCALE_FILE_PLURAL_FORM_COUNT 6 #define ASSET_LOCALE_FILE_PLURAL_FORM_COUNT 6
typedef enum { typedef enum {
@@ -43,6 +50,13 @@ typedef struct {
uint8_t pluralDefaultIndex; uint8_t pluralDefaultIndex;
} assetlocalefile_t; } assetlocalefile_t;
typedef assetlocalefile_t assetlocaleoutput_t;
errorret_t assetLocaleLoaderNEW(assetloading_t *loading);
errorret_t assetLocaleDisposeNEW(assetentry_t *entry);
// END NEW STUFF
/** /**
* Initialize a locale asset file. * Initialize a locale asset file.
* *
+6 -13
View File
@@ -13,28 +13,21 @@ localemanager_t LOCALE;
errorret_t localeManagerInit() { errorret_t localeManagerInit() {
memoryZero(&LOCALE, sizeof(localemanager_t)); memoryZero(&LOCALE, sizeof(localemanager_t));
errorChain(localeManagerSetLocale(&LOCALE_EN_US)); errorChain(localeManagerSetLocale(&LOCALE_EN_US));
errorOk(); errorOk();
} }
errorret_t localeManagerSetLocale(const localeinfo_t *locale) { errorret_t localeManagerSetLocale(const localeinfo_t *locale) {
if(LOCALE.fileOpen) { assertNotNull(locale, "Locale cannot be NULL");
errorChain(assetLocaleFileDispose(&LOCALE.file));
LOCALE.fileOpen = false;
}
// Init the asset file LOCALE.locale = locale;
errorChain(assetLocaleFileInit(&LOCALE.file, locale->file)); LOCALE.entry = assetGetEntry(locale->file, ASSET_LOADER_TYPE_LOCALE, NULL);
LOCALE.fileOpen = true; errorChain(assetRequireLoaded(LOCALE.entry));
errorOk(); errorOk();
} }
void localeManagerDispose() { void localeManagerDispose() {
if(LOCALE.fileOpen) { LOCALE.entry = NULL;
errorCatch(errorPrint(assetLocaleFileDispose(&LOCALE.file))); LOCALE.locale = NULL;
LOCALE.fileOpen = false;
}
} }
+4 -5
View File
@@ -9,12 +9,11 @@
#include "error/error.h" #include "error/error.h"
#include "localemanager.h" #include "localemanager.h"
#include "locale/localeinfo.h" #include "locale/localeinfo.h"
#include "asset/loader/locale/assetlocaleloader.h" #include "asset/asset.h"
typedef struct { typedef struct {
const localeinfo_t *locale; const localeinfo_t *locale;
assetlocalefile_t file; assetentry_t *entry;
bool_t fileOpen;
} localemanager_t; } localemanager_t;
extern localemanager_t LOCALE; extern localemanager_t LOCALE;
@@ -46,7 +45,7 @@ errorret_t localeManagerSetLocale(const localeinfo_t *locale);
*/ */
#define localeManagerGetText(id, buffer, bufferSize, plural, ...) \ #define localeManagerGetText(id, buffer, bufferSize, plural, ...) \
assetLocaleGetStringWithVA( \ assetLocaleGetStringWithVA( \
&LOCALE.file, \ &LOCALE.entry->data.locale, \
id, \ id, \
plural, \ plural, \
buffer, \ buffer, \
@@ -69,7 +68,7 @@ errorret_t localeManagerSetLocale(const localeinfo_t *locale);
id, buffer, bufferSize, plural, args, argCount \ id, buffer, bufferSize, plural, args, argCount \
) \ ) \
assetLocaleGetStringWithArgs( \ assetLocaleGetStringWithArgs( \
&LOCALE.file, \ &LOCALE.entry->data.locale, \
id, \ id, \
plural, \ plural, \
buffer, \ buffer, \