|
|
|
@ -16,8 +16,13 @@ assetmanageritem_t * assetManagerLoadScaledTexture(
|
|
|
|
|
uint8_t scale;
|
|
|
|
|
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(manager);
|
|
|
|
|
ASSERT_NOT_NULL(path);
|
|
|
|
|
ASSERT_NOT_NULL(file);
|
|
|
|
|
|
|
|
|
|
// Get the scale
|
|
|
|
|
scale = saveManagerGetU8(manager->save, SAVE_KEY_TEXTURE_SCALE);
|
|
|
|
|
ASSERT_LESS_THAN(scale, MANAGED_TEXTURE_SCALE_MAX);
|
|
|
|
|
|
|
|
|
|
// Generate a key
|
|
|
|
|
sprintf(buffer, "%s/%s", path, file);
|
|
|
|
@ -51,10 +56,15 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
|
|
|
|
texturescalescale_t *sts;
|
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(item);
|
|
|
|
|
ASSERT_EQUAL(item->type, ASSET_MANAGER_TYPE_SCALED_TEXTURE);
|
|
|
|
|
|
|
|
|
|
// TODO: This can be improved if we allow both asset dependencies and
|
|
|
|
|
// dependency sibling adding
|
|
|
|
|
|
|
|
|
|
st = &item->data.scaledTexture.textureScale;
|
|
|
|
|
ASSERT_NOT_NULL(st->path);
|
|
|
|
|
ASSERT_NOT_NULL(st->file);
|
|
|
|
|
ASSERT_EQUAL(st->scaleCount, 0);
|
|
|
|
|
|
|
|
|
|
// Begin loading texture XML
|
|
|
|
|
sprintf(buffer, "%s/%s.xml", st->path, st->file);
|
|
|
|
@ -64,22 +74,45 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
|
|
|
|
xmlLoad(&xml, xmlData);
|
|
|
|
|
free(xmlData);
|
|
|
|
|
|
|
|
|
|
ASSERT_STRING_EQUALS(xml.node, "texture");
|
|
|
|
|
ASSERT_EQUAL(xml.childrenCount, MANAGED_TEXTURE_SCALE_MAX);
|
|
|
|
|
|
|
|
|
|
// Parse root texture info
|
|
|
|
|
i = xmlGetAttributeByName(&xml, "channels");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->channels = (uint8_t)atoi(xml.attributeDatas[i]);
|
|
|
|
|
ASSERT_EQUAL(st->channels, TEXTURE_CHANNELS);
|
|
|
|
|
|
|
|
|
|
i = xmlGetAttributeByName(&xml, "width");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->baseWidth = (int16_t)atoi(xml.attributeDatas[i]);
|
|
|
|
|
ASSERT_GREATER_THAN(st->baseWidth, 0);
|
|
|
|
|
|
|
|
|
|
i = xmlGetAttributeByName(&xml, "height");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->baseHeight = (int16_t)atoi(xml.attributeDatas[i]);
|
|
|
|
|
ASSERT_GREATER_THAN(st->baseHeight, 0);
|
|
|
|
|
|
|
|
|
|
for(j = 0; j < xml.childrenCount; j++) {
|
|
|
|
|
child = xml.children + j;
|
|
|
|
|
|
|
|
|
|
ASSERT_STRING_EQUALS(child->node, "texture-scale");
|
|
|
|
|
ASSERT_EQUAL(child->childrenCount, 0);
|
|
|
|
|
|
|
|
|
|
i = xmlGetAttributeByName(child, "scale");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->scales[st->scaleCount].scale = (uint8_t)atoi(child->attributeDatas[i]);
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(st->scales[st->scaleCount].scale, 1);
|
|
|
|
|
|
|
|
|
|
i = xmlGetAttributeByName(child, "width");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->scales[st->scaleCount].width = (int16_t)atoi(child->attributeDatas[i]);
|
|
|
|
|
ASSERT_GREATER_THAN(st->scales[st->scaleCount].width, 0);
|
|
|
|
|
|
|
|
|
|
i = xmlGetAttributeByName(child, "height");
|
|
|
|
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
|
|
|
|
st->scales[st->scaleCount].height = (int16_t)atoi(child->attributeDatas[i]);
|
|
|
|
|
ASSERT_GREATER_THAN(st->scales[st->scaleCount].height, 0);
|
|
|
|
|
st->scaleCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -87,6 +120,7 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
|
|
|
|
xmlDispose(&xml);
|
|
|
|
|
|
|
|
|
|
// Get the scale
|
|
|
|
|
ASSERT_LESS_THAN(item->data.scaledTexture.scale, st->scaleCount);
|
|
|
|
|
sts = st->scales + item->data.scaledTexture.scale;
|
|
|
|
|
|
|
|
|
|
// Get filename
|
|
|
|
@ -94,12 +128,14 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
|
|
|
|
|
|
|
|
|
// Create some space
|
|
|
|
|
length = assetRawLoad(buffer, NULL);
|
|
|
|
|
if(length == 0) return false;
|
|
|
|
|
if(length <= 0) return false;
|
|
|
|
|
|
|
|
|
|
item->data.scaledTexture.data = malloc(sizeof(pixel_t) * length);
|
|
|
|
|
if(item->data.scaledTexture.data == NULL) return false;
|
|
|
|
|
|
|
|
|
|
// Load
|
|
|
|
|
length = assetRawLoad(buffer, (uint8_t *)item->data.scaledTexture.data);
|
|
|
|
|
if(length == 0) {
|
|
|
|
|
if(length <= 0) {
|
|
|
|
|
free(item->data.scaledTexture.data);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -110,16 +146,26 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
|
|
|
|
bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item) {
|
|
|
|
|
texturescale_t *st;
|
|
|
|
|
texturescalescale_t *sts;
|
|
|
|
|
st = &item->data.scaledTexture.textureScale;
|
|
|
|
|
sts = st->scales + item->data.scaledTexture.scale;
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(item);
|
|
|
|
|
ASSERT_EQUAL(item->type, ASSET_MANAGER_TYPE_SCALED_TEXTURE);
|
|
|
|
|
ASSERT_NOT_NULL(item->data.scaledTexture.data);
|
|
|
|
|
|
|
|
|
|
st = &item->data.scaledTexture.textureScale;
|
|
|
|
|
ASSERT_EQUAL(st->scaleCount, MANAGED_TEXTURE_SCALE_MAX);
|
|
|
|
|
ASSERT_LESS_THAN(item->data.scaledTexture.scale, st->scaleCount);
|
|
|
|
|
|
|
|
|
|
sts = st->scales + item->data.scaledTexture.scale;
|
|
|
|
|
printf("Loading texture synchronously. %i x %i\n", sts->width, sts->height);
|
|
|
|
|
|
|
|
|
|
// Create the actual texture.
|
|
|
|
|
textureInit(
|
|
|
|
|
&item->data.scaledTexture.texture,
|
|
|
|
|
sts->width, sts->height,
|
|
|
|
|
item->data.scaledTexture.data
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
free(item->data.scaledTexture.data);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -131,6 +177,11 @@ bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item) {
|
|
|
|
|
bool _assetManagerLoaderScaledTextureResize(
|
|
|
|
|
assetmanager_t *manager, assetmanageritem_t *item, uint8_t scale
|
|
|
|
|
) {
|
|
|
|
|
ASSERT_NOT_NULL(manager);
|
|
|
|
|
ASSERT_NOT_NULL(item);
|
|
|
|
|
ASSERT_LESS_THAN(scale, MANAGED_TEXTURE_SCALE_MAX);
|
|
|
|
|
ASSERT_EQUAL(item->type, ASSET_MANAGER_TYPE_SCALED_TEXTURE);
|
|
|
|
|
|
|
|
|
|
// Check if we need to update
|
|
|
|
|
if(item->data.scaledTexture.scale == scale) return true;
|
|
|
|
|
|
|
|
|
@ -151,6 +202,7 @@ bool _assetManagerLoaderScaledTextureResize(
|
|
|
|
|
|
|
|
|
|
// Update scale.
|
|
|
|
|
item->data.scaledTexture.scale = scale;
|
|
|
|
|
item->data.scaledTexture.textureScale.scaleCount = 0;
|
|
|
|
|
|
|
|
|
|
// Immediately requeue a texture re-load
|
|
|
|
|
if(!_assetManagerLoaderScaledTextureAsync(item)) return false;
|
|
|
|
@ -166,8 +218,11 @@ bool _assetManagerLoaderScaledTextureResize(
|
|
|
|
|
void assetManagerScaledTextureRescaleAll(assetmanager_t *manager) {
|
|
|
|
|
uint8_t i, scale;
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(manager);
|
|
|
|
|
|
|
|
|
|
// Get the new scale
|
|
|
|
|
scale = saveManagerGetU8(manager->save, SAVE_KEY_TEXTURE_SCALE);
|
|
|
|
|
ASSERT_LESS_THAN(scale, MANAGED_TEXTURE_SCALE_MAX);
|
|
|
|
|
|
|
|
|
|
// Rescale each texture. This is, unfortunately, blocking for now.
|
|
|
|
|
for(i = 0; i < manager->itemCount; i++) {
|
|
|
|
|