Fixed assets not loading.
This commit is contained in:
@ -59,24 +59,22 @@ char * assetStringLoad(char *assetName) {
|
|||||||
|
|
||||||
assetbuffer_t * assetBufferOpen(char *assetName) {
|
assetbuffer_t * assetBufferOpen(char *assetName) {
|
||||||
// Get the directory based on the raw input by creating a new string.
|
// Get the directory based on the raw input by creating a new string.
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
size_t lenAsset = strlen(assetName);// Get the length of asset
|
char filename[512];
|
||||||
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?
|
|
||||||
|
|
||||||
joined[0] = '\0';//Start at null
|
// Prep filename
|
||||||
strcat(joined, ASSET_PREFIX);//Add prefix
|
filename[0] = '\0';//Start at null
|
||||||
strcat(joined, assetName);//Add body
|
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.
|
// Open the file pointer now.
|
||||||
fptr = fopen(joined, "rb");
|
fptr = fopen(filename, "rb");
|
||||||
free(joined);// Free the string we just created
|
if(fptr == NULL) {
|
||||||
if(!fptr) return NULL;// File available?
|
printf("Error opening %s: %s\n", filename, strerror(errno));
|
||||||
|
return NULL;// File available?
|
||||||
|
}
|
||||||
return (assetbuffer_t *)fptr;
|
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) {
|
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) {
|
int32_t assetBufferStart(assetbuffer_t *buffer) {
|
||||||
return fseek((FILE *)buffer, 0, SEEK_SET);
|
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);
|
return fseek((FILE *)buffer, n, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ int32_t assetBufferStart(assetbuffer_t *buffer);
|
|||||||
* @param n Count of bytes to skip.
|
* @param n Count of bytes to skip.
|
||||||
* @return 0 if successful, otherwise unsuccessful.
|
* @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.
|
* Retreive the current byte position within the asset that the head is at.
|
||||||
|
@ -346,11 +346,26 @@ bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item) {
|
|||||||
char buffer[128];
|
char buffer[128];
|
||||||
scaledtexture_t *st;
|
scaledtexture_t *st;
|
||||||
scaledtexturescale_t *sts;
|
scaledtexturescale_t *sts;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
st = item->data.scaleTexture.scaledTexture;
|
st = item->data.scaleTexture.scaledTexture;
|
||||||
sts = st->scales + item->data.scaleTexture.scale;
|
sts = st->scales + item->data.scaleTexture.scale;
|
||||||
|
|
||||||
|
// Get filename
|
||||||
sprintf(buffer, "%s/%s_%i.texture", st->path, st->file, sts->scale);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
|
||||||
|
|
||||||
}
|
|
@ -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();
|
|
@ -24,8 +24,8 @@ void _renderTest(
|
|||||||
bool dawnGameInit(dawngame_t *game) {
|
bool dawnGameInit(dawngame_t *game) {
|
||||||
renderListInit(&game->renderList, 512, 512);
|
renderListInit(&game->renderList, 512, 512);
|
||||||
|
|
||||||
assetShaderLoad(&shader, "shaders/textured.vert", "shaders/textured.frag");
|
// assetShaderLoad(&shader, "shaders/textured.vert", "shaders/textured.frag");
|
||||||
assetTextureLoad(&texture, "test_texture.png");
|
// assetTextureLoad(&texture, "test_texture.png");
|
||||||
cubeInit(&cube, 1, 1, 1);
|
cubeInit(&cube, 1, 1, 1);
|
||||||
|
|
||||||
items[itemCount++].onRender = &_renderTest;
|
items[itemCount++].onRender = &_renderTest;
|
||||||
|
@ -31,10 +31,10 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
|||||||
void sandboxGameUpdate(sandboxgame_t *game) {
|
void sandboxGameUpdate(sandboxgame_t *game) {
|
||||||
camera_t camera;
|
camera_t camera;
|
||||||
float n = assetManagerProgressGet(&game->manager);
|
float n = assetManagerProgressGet(&game->manager);
|
||||||
printf("Loading %.2f\n", n);
|
|
||||||
|
|
||||||
if(n < 1.0f) {
|
if(n < 1.0f) {
|
||||||
assetManagerUpdate(&game->manager);
|
assetManagerUpdate(&game->manager);
|
||||||
|
printf("Loading %.2f\n", n);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,24 +7,5 @@
|
|||||||
|
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
|
||||||
scripterreturn_t _scriptApiShaderLoad(scriptercontext_t *ctx) {
|
|
||||||
assetShaderLoad(
|
|
||||||
duk_to_pointer(ctx, 0),
|
|
||||||
duk_to_string(ctx, 1),
|
|
||||||
duk_to_string(ctx, 2)
|
|
||||||
);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
scripterreturn_t _scriptApiTextureLoad(scriptercontext_t *ctx) {
|
|
||||||
assetTextureLoad(
|
|
||||||
duk_to_pointer(ctx, 0),
|
|
||||||
duk_to_string(ctx, 1)
|
|
||||||
);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scriptsApiAsset(scripter_t *s) {
|
void scriptsApiAsset(scripter_t *s) {
|
||||||
scripterDefineMethod(s, "assetShaderLoad", 3, &_scriptApiShaderLoad);
|
|
||||||
scripterDefineMethod(s, "assetTextureLoad", 2, &_scriptApiTextureLoad);
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user