About to implement load strategy
This commit is contained in:
@@ -62,9 +62,10 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
// Find the asset type based on the header
|
// Find the asset type based on the header
|
||||||
const assettypedef_t *def = NULL;
|
const assettypedef_t *def = NULL;
|
||||||
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
|
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
|
||||||
if(ASSET_TYPE_DEFINITIONS[i].header == NULL) continue;
|
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
|
||||||
if(strcmp(header.header, ASSET_TYPE_DEFINITIONS[i].header) != 0) continue;
|
if(cmp->header == NULL) continue;
|
||||||
def = &ASSET_TYPE_DEFINITIONS[i];
|
if(strcmp(header.header, cmp->header) != 0) continue;
|
||||||
|
def = cmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(def == NULL) {
|
if(def == NULL) {
|
||||||
@@ -73,7 +74,9 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We found the asset type, now load the asset data
|
// We found the asset type, now load the asset data
|
||||||
assertNotNull(def->load, "Asset load function cannot be NULL.");
|
switch(def->loadStrategy) {
|
||||||
|
case ASSET_LOAD_STRAT_ENTIRE:
|
||||||
|
assertNotNull(def->entire, "Asset load function cannot be NULL.");
|
||||||
void *data = memoryAllocate(def->dataSize);
|
void *data = memoryAllocate(def->dataSize);
|
||||||
bytesRead = zip_fread(file, data, def->dataSize);
|
bytesRead = zip_fread(file, data, def->dataSize);
|
||||||
if(bytesRead == 0 || bytesRead > def->dataSize) {
|
if(bytesRead == 0 || bytesRead > def->dataSize) {
|
||||||
@@ -86,9 +89,18 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
|
|
||||||
// Pass to the asset type loader
|
// Pass to the asset type loader
|
||||||
errorret_t ret = def->load(data, output);
|
errorret_t ret = def->entire(data, output);
|
||||||
memoryFree(data);
|
memoryFree(data);
|
||||||
errorChain(ret);
|
errorChain(ret);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ASSET_LOAD_STRAT_TEST:
|
||||||
|
assertUnreachable("Asset load strategy not implemented yet.");
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Unknown asset load strategy.");
|
||||||
|
}
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,25 @@ typedef enum {
|
|||||||
ASSET_TYPE_NULL,
|
ASSET_TYPE_NULL,
|
||||||
ASSET_TYPE_PALETTE_IMAGE,
|
ASSET_TYPE_PALETTE_IMAGE,
|
||||||
ASSET_TYPE_ALPHA_IMAGE,
|
ASSET_TYPE_ALPHA_IMAGE,
|
||||||
|
ASSET_TYPE_LANGUAGE,
|
||||||
ASSET_TYPE_COUNT,
|
ASSET_TYPE_COUNT,
|
||||||
} assettype_t;
|
} assettype_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ASSET_LOAD_STRAT_ENTIRE,
|
ASSET_LOAD_STRAT_ENTIRE,
|
||||||
|
ASSET_LOAD_STRAT_TEST
|
||||||
} assetloadstrat_t;
|
} assetloadstrat_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;
|
||||||
errorret_t (*load)(void *data, void *output);
|
union {
|
||||||
|
errorret_t (*entire)(void *data, void *output);
|
||||||
|
struct {
|
||||||
|
void *test;
|
||||||
|
} test;
|
||||||
|
};
|
||||||
} assettypedef_t;
|
} assettypedef_t;
|
||||||
|
|
||||||
static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
||||||
@@ -36,13 +43,22 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
|||||||
.header = "DPI",
|
.header = "DPI",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assetpaletteimage_t),
|
.dataSize = sizeof(assetpaletteimage_t),
|
||||||
.load = assetPaletteImageLoad
|
.entire = assetPaletteImageLoad
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_ALPHA_IMAGE] = {
|
[ASSET_TYPE_ALPHA_IMAGE] = {
|
||||||
.header = "DAI",
|
.header = "DAI",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assetalphaimage_t),
|
.dataSize = sizeof(assetalphaimage_t),
|
||||||
.load = assetAlphaImageLoad
|
.entire = assetAlphaImageLoad
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[ASSET_TYPE_LANGUAGE] = {
|
||||||
|
.header = "DLF",
|
||||||
|
.loadStrategy = ASSET_LOAD_STRAT_TEST,
|
||||||
|
.dataSize = 0, // Variable size
|
||||||
|
.test = {
|
||||||
|
.test = NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
8
src/asset/type/assetlanguage.c
Normal file
8
src/asset/type/assetlanguage.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "assetlanguage.h"
|
||||||
@@ -8,6 +8,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "locale/language/keys.h"
|
#include "locale/language/keys.h"
|
||||||
|
|
||||||
|
#define ASSET_LANG_CHUNK_CHAR_COUNT 6 * 1024 // 6 KB per chunk
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef char assetlanguagechunk_t[ASSET_LANG_CHUNK_CHAR_COUNT];
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t chunk;
|
uint32_t chunk;
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ errorret_t engineInit(void) {
|
|||||||
// Init systems. Order is important.
|
// Init systems. Order is important.
|
||||||
timeInit();
|
timeInit();
|
||||||
inputInit();
|
inputInit();
|
||||||
localeManagerInit();
|
|
||||||
errorChain(assetInit());
|
errorChain(assetInit());
|
||||||
|
errorChain(localeManagerInit());
|
||||||
errorChain(displayInit());
|
errorChain(displayInit());
|
||||||
errorChain(uiInit());
|
errorChain(uiInit());
|
||||||
errorChain(rpgInit());
|
errorChain(rpgInit());
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "dusk.h"
|
|
||||||
|
|
||||||
#define LANG_CHUNK_CHAR_COUNT 6 * 1024 // 6 KB per chunk
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef char languagechunkdata_t[LANG_CHUNK_CHAR_COUNT];
|
|
||||||
#pragma pack(pop)
|
|
||||||
@@ -7,9 +7,13 @@
|
|||||||
|
|
||||||
#include "localemanager.h"
|
#include "localemanager.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
#include "asset/asset.h"
|
||||||
|
|
||||||
localemanager_t LOCALE;
|
localemanager_t LOCALE;
|
||||||
|
|
||||||
void localeManagerInit() {
|
errorret_t localeManagerInit() {
|
||||||
memoryZero(&LOCALE, sizeof(localemanager_t));
|
memoryZero(&LOCALE, sizeof(localemanager_t));
|
||||||
|
|
||||||
|
errorChain(assetLoad("language/us.dlf", &LOCALE));
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "error/error.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *nothing;
|
void *nothing;
|
||||||
@@ -16,5 +16,7 @@ extern localemanager_t LOCALE;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the locale system.
|
* Initialize the locale system.
|
||||||
|
*
|
||||||
|
* @return An error code if a failure occurs.
|
||||||
*/
|
*/
|
||||||
void localeManagerInit();
|
errorret_t localeManagerInit();
|
||||||
@@ -21,6 +21,8 @@ for asset in inputAssets:
|
|||||||
asset = processAsset(asset)
|
asset = processAsset(asset)
|
||||||
files.extend(asset['files'])
|
files.extend(asset['files'])
|
||||||
|
|
||||||
|
files.extend(processLanguageList()['files'])
|
||||||
|
|
||||||
# Take assets and add to a zip archive.
|
# Take assets and add to a zip archive.
|
||||||
outputFileName = args.output_file
|
outputFileName = args.output_file
|
||||||
print(f"Creating output file: {outputFileName}")
|
print(f"Creating output file: {outputFileName}")
|
||||||
@@ -32,7 +34,6 @@ with zipfile.ZipFile(outputFileName, 'w') as zipf:
|
|||||||
# Generate additional headers.
|
# Generate additional headers.
|
||||||
processPaletteList()
|
processPaletteList()
|
||||||
processTilesetList()
|
processTilesetList()
|
||||||
processLanguageList()
|
|
||||||
|
|
||||||
# Finalize build
|
# Finalize build
|
||||||
if args.build_type == 'header':
|
if args.build_type == 'header':
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ def processLanguageList():
|
|||||||
|
|
||||||
# We have now chunked all the keys for this language!
|
# We have now chunked all the keys for this language!
|
||||||
langBuffer = b""
|
langBuffer = b""
|
||||||
|
files = []
|
||||||
|
|
||||||
# Write header info
|
# Write header info
|
||||||
langBuffer += b'DLF' # Dusk Language File
|
langBuffer += b'DLF' # Dusk Language File
|
||||||
@@ -128,6 +129,7 @@ def processLanguageList():
|
|||||||
|
|
||||||
# Write out the language data file
|
# Write out the language data file
|
||||||
outputFile = os.path.join(args.output_assets, "language", f"{lang}.dlf")
|
outputFile = os.path.join(args.output_assets, "language", f"{lang}.dlf")
|
||||||
|
files.append(outputFile)
|
||||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
with open(outputFile, "wb") as f:
|
with open(outputFile, "wb") as f:
|
||||||
f.write(langBuffer)
|
f.write(langBuffer)
|
||||||
@@ -139,6 +141,10 @@ def processLanguageList():
|
|||||||
with open(outputFile, "w") as f:
|
with open(outputFile, "w") as f:
|
||||||
f.write(headerKeys)
|
f.write(headerKeys)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'files': files
|
||||||
|
}
|
||||||
|
|
||||||
def getLanguageVariableName(languageKey):
|
def getLanguageVariableName(languageKey):
|
||||||
# Take the language key, prepend LANG_, uppercase, replace any non symbols
|
# Take the language key, prepend LANG_, uppercase, replace any non symbols
|
||||||
# with _
|
# with _
|
||||||
|
|||||||
Reference in New Issue
Block a user