Fixed assets not loading.

This commit is contained in:
2021-11-07 11:05:55 -08:00
parent 332d1c3080
commit b06099d11e
8 changed files with 35 additions and 66 deletions

View File

@ -59,24 +59,22 @@ char * assetStringLoad(char *assetName) {
assetbuffer_t * assetBufferOpen(char *assetName) {
// Get the directory based on the raw input by creating a new string.
FILE *fptr;
size_t lenAsset = strlen(assetName);// Get the length of asset
size_t lenPrefix = strlen(ASSET_PREFIX);// Get the length of the prefix
// Create str to house both the prefix and asset, and null terminator
char *joined = malloc(lenAsset + lenPrefix + 1);
if(joined == NULL) return NULL;// Mem okay?
FILE *fptr;
char filename[512];
joined[0] = '\0';//Start at null
strcat(joined, ASSET_PREFIX);//Add prefix
strcat(joined, assetName);//Add body
// Prep filename
filename[0] = '\0';//Start at null
strcat(filename, ASSET_PREFIX);//Add prefix
strcat(filename, assetName);//Add body
printf("Opening up %s\n", joined);
printf("Opening up %s\n", filename);
// Open the file pointer now.
fptr = fopen(joined, "rb");
free(joined);// Free the string we just created
if(!fptr) return NULL;// File available?
fptr = fopen(filename, "rb");
if(fptr == NULL) {
printf("Error opening %s: %s\n", filename, strerror(errno));
return NULL;// File available?
}
return (assetbuffer_t *)fptr;
}
@ -89,14 +87,15 @@ int32_t assetBufferRead(assetbuffer_t *buffer, char *data, size_t size) {
}
int32_t assetBufferEnd(assetbuffer_t *buffer) {
return feof((FILE *)buffer);
// return feof((FILE *)buffer);
return fseek((FILE *)buffer, 0, SEEK_END);// Seek to the end
}
int32_t assetBufferStart(assetbuffer_t *buffer) {
return fseek((FILE *)buffer, 0, SEEK_SET);
}
int32_t assetBufferSkip(assetbuffer_t *buffer, size_t n) {
int32_t assetBufferSkip(assetbuffer_t *buffer, long n) {
return fseek((FILE *)buffer, n, SEEK_CUR);
}

View File

@ -81,7 +81,7 @@ int32_t assetBufferStart(assetbuffer_t *buffer);
* @param n Count of bytes to skip.
* @return 0 if successful, otherwise unsuccessful.
*/
int32_t assetBufferSkip(assetbuffer_t *buffer, size_t n);
int32_t assetBufferSkip(assetbuffer_t *buffer, long n);
/**
* Retreive the current byte position within the asset that the head is at.

View File

@ -346,11 +346,26 @@ bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item) {
char buffer[128];
scaledtexture_t *st;
scaledtexturescale_t *sts;
size_t length;
st = item->data.scaleTexture.scaledTexture;
sts = st->scales + item->data.scaleTexture.scale;
// Get filename
sprintf(buffer, "%s/%s_%i.texture", st->path, st->file, sts->scale);
item->data.scaleTexture.data = (pixel_t *)assetRawLoad(buffer);
// Create some space
length = assetRawLoad(buffer, NULL);
if(length == 0) return false;
item->data.scaleTexture.data = malloc(sizeof(pixel_t) * length);
// Load
length = assetRawLoad(buffer, (uint8_t *)item->data.scaleTexture.data);
if(length == 0) {
free(item->data.scaleTexture.data);
return false;
}
return true;
}

View File

@ -1,12 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "gui.h"
void guiLoad() {
}

View File

@ -1,14 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "asset.h"
#include "csv.h"
#include "xml.h"
void guiLoad();