Prepping for async

This commit is contained in:
2026-06-01 10:57:40 -05:00
parent 6acfca6d48
commit a79ee429b4
22 changed files with 745 additions and 164 deletions
+35 -15
View File
@@ -20,16 +20,24 @@ errorret_t assetMeshLoaderSync(assetloading_t *loading) {
assetfile_t *file = &loading->loading.mesh.file;
assetmeshinputaxis_t axis = loading->entry->input->mesh;
errorChain(assetFileInit(file, loading->entry->name, NULL, NULL));
errorChain(assetFileOpen(file));
assetLoaderErrorChain(loading, assetFileInit(
file, loading->entry->name, NULL, NULL
));
assetLoaderErrorChain(loading, assetFileOpen(file));
// Skip the 80-byte STL header
errorChain(assetFileRead(file, NULL, 80));
if(file->lastRead != 80) errorThrow("Failed to skip STL header");
assetLoaderErrorChain(loading, assetFileRead(file, NULL, 80));
if(file->lastRead != 80) {
assetLoaderErrorThrow(loading, "Failed to skip STL header.");
}
uint32_t triangleCount;
errorChain(assetFileRead(file, &triangleCount, sizeof(uint32_t)));
if(file->lastRead != sizeof(uint32_t)) errorThrow("Failed to read tri count");
assetLoaderErrorChain(
loading, assetFileRead(file, &triangleCount, sizeof(uint32_t))
);
if(file->lastRead != sizeof(uint32_t)) {
assetLoaderErrorThrow(loading, "Failed to read tri count");
}
triangleCount = endianLittleToHost32(triangleCount);
out->vertices = memoryAllocate(sizeof(meshvertex_t) * triangleCount * 3);
@@ -42,19 +50,25 @@ errorret_t assetMeshLoaderSync(assetloading_t *loading) {
if(ret.code != ERROR_OK) {
memoryFree(verts);
out->vertices = NULL;
errorChain(ret);
assetLoaderErrorChain(loading, ret);
}
if(file->lastRead != sizeof(triData)) {
memoryFree(verts);
out->vertices = NULL;
errorThrow("Failed to read triangle data");
assetLoaderErrorThrow(loading, "Failed to read triangle data");
}
for(uint8_t j = 0; j < 3; j++) {
#if MESH_ENABLE_COLOR
verts[i * 3 + j].color.r = (uint8_t)(endianLittleToHostFloat(triData.normal[0]) * 255.0f);
verts[i * 3 + j].color.g = (uint8_t)(endianLittleToHostFloat(triData.normal[1]) * 255.0f);
verts[i * 3 + j].color.b = (uint8_t)(endianLittleToHostFloat(triData.normal[2]) * 255.0f);
verts[i * 3 + j].color.r = (
(uint8_t)(endianLittleToHostFloat(triData.normal[0]) * 255.0f)
);
verts[i * 3 + j].color.g = (
(uint8_t)(endianLittleToHostFloat(triData.normal[1]) * 255.0f)
);
verts[i * 3 + j].color.b = (
(uint8_t)(endianLittleToHostFloat(triData.normal[2]) * 255.0f)
);
verts[i * 3 + j].color.a = 0xFF;
#endif
@@ -62,7 +76,9 @@ errorret_t assetMeshLoaderSync(assetloading_t *loading) {
verts[i * 3 + j].uv[1] = 0.0f;
for(uint8_t k = 0; k < 3; k++) {
verts[i * 3 + j].pos[k] = endianLittleToHostFloat(triData.positions[j][k]);
verts[i * 3 + j].pos[k] = endianLittleToHostFloat(
triData.positions[j][k]
);
}
switch(axis) {
@@ -104,17 +120,21 @@ errorret_t assetMeshLoaderSync(assetloading_t *loading) {
if(ret.code != ERROR_OK) {
memoryFree(verts);
out->vertices = NULL;
errorChain(ret);
assetLoaderErrorChain(loading, ret);
}
assetFileDispose(file);
ret = meshInit(&out->mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, triangleCount * 3, verts);
ret = meshInit(
&out->mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, triangleCount * 3, verts
);
if(ret.code != ERROR_OK) {
loading->entry->state = ASSET_ENTRY_STATE_ERROR;
memoryFree(verts);
out->vertices = NULL;
errorChain(ret);
assetLoaderErrorChain(loading, ret);
}
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
errorOk();
}