Asset custom ready.
This commit is contained in:
@@ -94,8 +94,14 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
errorChain(ret);
|
errorChain(ret);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASSET_LOAD_STRAT_TEST:
|
case ASSET_LOAD_STRAT_CUSTOM:
|
||||||
assertUnreachable("Asset load strategy not implemented yet.");
|
assertNotNull(def->custom, "Asset load function cannot be NULL.");
|
||||||
|
assetcustom_t customData = {
|
||||||
|
.zipFile = file,
|
||||||
|
.output = output
|
||||||
|
};
|
||||||
|
errorChain(def->custom(&customData));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assertUnreachable("Unknown asset load strategy.");
|
assertUnreachable("Unknown asset load strategy.");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include <zip.h>
|
#include "assettype.h"
|
||||||
|
|
||||||
#if ASSET_TYPE == wad
|
#if ASSET_TYPE == wad
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "type/assetpaletteimage.h"
|
#include "type/assetpaletteimage.h"
|
||||||
#include "type/assetalphaimage.h"
|
#include "type/assetalphaimage.h"
|
||||||
|
#include "type/assetlanguage.h"
|
||||||
|
#include <zip.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ASSET_TYPE_NULL,
|
ASSET_TYPE_NULL,
|
||||||
@@ -19,18 +21,21 @@ typedef enum {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ASSET_LOAD_STRAT_ENTIRE,
|
ASSET_LOAD_STRAT_ENTIRE,
|
||||||
ASSET_LOAD_STRAT_TEST
|
ASSET_LOAD_STRAT_CUSTOM
|
||||||
} assetloadstrat_t;
|
} assetloadstrat_t;
|
||||||
|
|
||||||
|
typedef struct assetcustom_s {
|
||||||
|
zip_file_t *zipFile;
|
||||||
|
void *output;
|
||||||
|
} assetcustom_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char_t *header;
|
const char_t *header;
|
||||||
const size_t dataSize;
|
const size_t dataSize;
|
||||||
const assetloadstrat_t loadStrategy;
|
const assetloadstrat_t loadStrategy;
|
||||||
union {
|
union {
|
||||||
errorret_t (*entire)(void *data, void *output);
|
errorret_t (*entire)(void *data, void *output);
|
||||||
struct {
|
errorret_t (*custom)(assetcustom_t *custom);
|
||||||
void *test;
|
|
||||||
} test;
|
|
||||||
};
|
};
|
||||||
} assettypedef_t;
|
} assettypedef_t;
|
||||||
|
|
||||||
@@ -55,10 +60,7 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
|||||||
|
|
||||||
[ASSET_TYPE_LANGUAGE] = {
|
[ASSET_TYPE_LANGUAGE] = {
|
||||||
.header = "DLF",
|
.header = "DLF",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_TEST,
|
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.dataSize = 0, // Variable size
|
.custom = assetLanguageInit
|
||||||
.test = {
|
|
||||||
.test = NULL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
assetalphaimage.c
|
assetalphaimage.c
|
||||||
assetpaletteimage.c
|
assetpaletteimage.c
|
||||||
|
assetlanguage.c
|
||||||
)
|
)
|
||||||
@@ -5,4 +5,10 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "assetlanguage.h"
|
#include "asset/asset.h"
|
||||||
|
|
||||||
|
errorret_t assetLanguageInit(assetcustom_t *custom) {
|
||||||
|
zip_fclose(custom->zipFile);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "error/error.h"
|
||||||
#include "locale/language/keys.h"
|
#include "locale/language/keys.h"
|
||||||
|
|
||||||
#define ASSET_LANG_CHUNK_CHAR_COUNT 6 * 1024 // 6 KB per chunk
|
#define ASSET_LANG_CHUNK_CHAR_COUNT 6 * 1024 // 6 KB per chunk
|
||||||
@@ -26,4 +27,14 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
assetlanguagestring_t strings[LANG_KEY_COUNT];
|
assetlanguagestring_t strings[LANG_KEY_COUNT];
|
||||||
} assetlanguageheader_t;
|
} assetlanguageheader_t;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
typedef struct assetcustom_s assetcustom_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receiving function from the asset manager to initialize language assets.
|
||||||
|
*
|
||||||
|
* @param custom Pointer to custom asset loading data.
|
||||||
|
* @return Error code.
|
||||||
|
*/
|
||||||
|
errorret_t assetLanguageInit(assetcustom_t *custom);
|
||||||
Reference in New Issue
Block a user