FInished porting last asset loader types
This commit is contained in:
@@ -12,7 +12,11 @@
|
||||
|
||||
assetentrycallbacks_t ASSET_ENTRY_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
||||
[ASSET_LOADER_TYPE_NULL] = { 0 },
|
||||
|
||||
|
||||
[ASSET_LOADER_TYPE_MESH] = {
|
||||
.dispose = &assetMeshDisposeNEW
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_TEXTURE] = {
|
||||
.dispose = &assetTextureDisposeNEW
|
||||
},
|
||||
@@ -20,6 +24,14 @@ assetentrycallbacks_t ASSET_ENTRY_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
||||
[ASSET_LOADER_TYPE_TILESET] = {
|
||||
.dispose = &assetTilesetDisposeNEW
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_LOCALE] = {
|
||||
.dispose = &assetLocaleDisposeNEW
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_JSON] = {
|
||||
.dispose = &assetJsonDisposeNEW
|
||||
},
|
||||
};
|
||||
|
||||
void assetEntryInit(
|
||||
|
||||
@@ -9,28 +9,41 @@
|
||||
#include "asset/loader/display/assetmeshloader.h"
|
||||
#include "asset/loader/display/assettextureloader.h"
|
||||
#include "asset/loader/display/assettilesetloader.h"
|
||||
#include "asset/loader/locale/assetlocaleloader.h"
|
||||
#include "asset/loader/json/assetjsonloader.h"
|
||||
|
||||
typedef enum {
|
||||
ASSET_LOADER_TYPE_NULL,
|
||||
|
||||
// ASSET_LOADER_TYPE_MESH,
|
||||
|
||||
ASSET_LOADER_TYPE_MESH,
|
||||
ASSET_LOADER_TYPE_TEXTURE,
|
||||
ASSET_LOADER_TYPE_TILESET,
|
||||
ASSET_LOADER_TYPE_LOCALE,
|
||||
ASSET_LOADER_TYPE_JSON,
|
||||
|
||||
ASSET_LOADER_TYPE_COUNT
|
||||
} assetloadertype_t;
|
||||
|
||||
typedef union {
|
||||
assetmeshloaderinput_t mesh;
|
||||
assettextureloaderinput_t texture;
|
||||
assettilesetloaderinput_t tileset;
|
||||
assetlocaleloaderinput_t locale;
|
||||
assetjsonloaderinput_t json;
|
||||
} assetloaderinput_t;
|
||||
|
||||
typedef union {
|
||||
assetmeshloaderloading_t mesh;
|
||||
assettextureloaderloading_t texture;
|
||||
assettilesetloaderloading_t tileset;
|
||||
assetlocaleloaderloading_t locale;
|
||||
assetjsonloaderloading_t json;
|
||||
} assetloaderloading_t;
|
||||
|
||||
typedef union {
|
||||
assetmeshoutput_t mesh;
|
||||
assettextureoutput_t texture;
|
||||
assettilesetoutput_t tileset;
|
||||
assetlocaleoutput_t locale;
|
||||
assetjsonoutput_t json;
|
||||
} assetloaderoutput_t;
|
||||
@@ -11,9 +11,9 @@
|
||||
assetloadingcallbacks_t ASSET_LOADING_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
||||
[ASSET_LOADER_TYPE_NULL] = { 0 },
|
||||
|
||||
// [ASSET_LOADER_TYPE_MESH] = {
|
||||
// .loadSync = assetMeshLoaderNEW,
|
||||
// },
|
||||
[ASSET_LOADER_TYPE_MESH] = {
|
||||
.loadSync = assetMeshLoaderNEW,
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_TEXTURE] = {
|
||||
.loadSync = assetTextureLoaderNEW
|
||||
@@ -24,7 +24,11 @@ assetloadingcallbacks_t ASSET_LOADING_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
||||
.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/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, ¶ms));
|
||||
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) {
|
||||
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->outMesh, "Output mesh cannot be null");
|
||||
assertNotNull(output->outVertices, "Output vertices cannot be null");
|
||||
|
||||
@@ -24,8 +24,26 @@ typedef struct {
|
||||
mesh_t *outMesh;
|
||||
meshvertex_t **outVertices;
|
||||
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;
|
||||
|
||||
errorret_t assetMeshLoaderNEW(assetloading_t *loading);
|
||||
errorret_t assetMeshDisposeNEW(assetentry_t *entry);
|
||||
|
||||
// END NEW STUFF
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
vec3 normal;
|
||||
|
||||
@@ -9,6 +9,26 @@
|
||||
#include "util/memory.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) {
|
||||
assertNotNull(file, "Asset file pointer for JSON loader is null.");
|
||||
assertNotNull(outDoc, "Output pointer for JSON loader is null.");
|
||||
|
||||
@@ -15,6 +15,21 @@ typedef struct {
|
||||
void *nothing;
|
||||
} 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.
|
||||
*
|
||||
|
||||
@@ -11,6 +11,24 @@
|
||||
#include "util/string.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(
|
||||
assetlocalefile_t *localeFile,
|
||||
const char_t *path
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
#pragma once
|
||||
#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
|
||||
|
||||
typedef enum {
|
||||
@@ -43,6 +50,13 @@ typedef struct {
|
||||
uint8_t pluralDefaultIndex;
|
||||
} 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.
|
||||
*
|
||||
|
||||
@@ -13,28 +13,21 @@ localemanager_t LOCALE;
|
||||
|
||||
errorret_t localeManagerInit() {
|
||||
memoryZero(&LOCALE, sizeof(localemanager_t));
|
||||
|
||||
errorChain(localeManagerSetLocale(&LOCALE_EN_US));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t localeManagerSetLocale(const localeinfo_t *locale) {
|
||||
if(LOCALE.fileOpen) {
|
||||
errorChain(assetLocaleFileDispose(&LOCALE.file));
|
||||
LOCALE.fileOpen = false;
|
||||
}
|
||||
assertNotNull(locale, "Locale cannot be NULL");
|
||||
|
||||
// Init the asset file
|
||||
errorChain(assetLocaleFileInit(&LOCALE.file, locale->file));
|
||||
LOCALE.fileOpen = true;
|
||||
LOCALE.locale = locale;
|
||||
LOCALE.entry = assetGetEntry(locale->file, ASSET_LOADER_TYPE_LOCALE, NULL);
|
||||
errorChain(assetRequireLoaded(LOCALE.entry));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void localeManagerDispose() {
|
||||
if(LOCALE.fileOpen) {
|
||||
errorCatch(errorPrint(assetLocaleFileDispose(&LOCALE.file)));
|
||||
LOCALE.fileOpen = false;
|
||||
}
|
||||
LOCALE.entry = NULL;
|
||||
LOCALE.locale = NULL;
|
||||
}
|
||||
@@ -9,12 +9,11 @@
|
||||
#include "error/error.h"
|
||||
#include "localemanager.h"
|
||||
#include "locale/localeinfo.h"
|
||||
#include "asset/loader/locale/assetlocaleloader.h"
|
||||
#include "asset/asset.h"
|
||||
|
||||
typedef struct {
|
||||
const localeinfo_t *locale;
|
||||
assetlocalefile_t file;
|
||||
bool_t fileOpen;
|
||||
assetentry_t *entry;
|
||||
} localemanager_t;
|
||||
|
||||
extern localemanager_t LOCALE;
|
||||
@@ -46,7 +45,7 @@ errorret_t localeManagerSetLocale(const localeinfo_t *locale);
|
||||
*/
|
||||
#define localeManagerGetText(id, buffer, bufferSize, plural, ...) \
|
||||
assetLocaleGetStringWithVA( \
|
||||
&LOCALE.file, \
|
||||
&LOCALE.entry->data.locale, \
|
||||
id, \
|
||||
plural, \
|
||||
buffer, \
|
||||
@@ -69,7 +68,7 @@ errorret_t localeManagerSetLocale(const localeinfo_t *locale);
|
||||
id, buffer, bufferSize, plural, args, argCount \
|
||||
) \
|
||||
assetLocaleGetStringWithArgs( \
|
||||
&LOCALE.file, \
|
||||
&LOCALE.entry->data.locale, \
|
||||
id, \
|
||||
plural, \
|
||||
buffer, \
|
||||
|
||||
Reference in New Issue
Block a user