More fixes

This commit is contained in:
2026-03-08 10:20:55 -05:00
parent 5c4537b2fa
commit 8efdf59ebd
19 changed files with 113 additions and 49 deletions

View File

@@ -7,7 +7,7 @@
#pragma once
#include "type/assettexture.h"
#include "type/assetpalette.h"
// #include "type/assetpalette.h"
#include "type/assettileset.h"
#include "type/assetlanguage.h"
#include "type/assetscript.h"
@@ -19,7 +19,7 @@ typedef enum {
ASSET_TYPE_NULL,
ASSET_TYPE_TEXTURE,
ASSET_TYPE_PALETTE,
// ASSET_TYPE_PALETTE,
ASSET_TYPE_TILESET,
ASSET_TYPE_LANGUAGE,
ASSET_TYPE_SCRIPT,
@@ -66,12 +66,12 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
.entire = assetTextureLoad
},
[ASSET_TYPE_PALETTE] = {
.extension = "dpf",
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
.dataSize = sizeof(palette_t),
.entire = assetPaletteLoad
},
// [ASSET_TYPE_PALETTE] = {
// .extension = "dpf",
// .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
// .dataSize = sizeof(palette_t),
// .entire = assetPaletteLoad
// },
[ASSET_TYPE_TILESET] = {
.extension = "dtf",

View File

@@ -7,7 +7,6 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
assettexture.c
assetpalette.c
assettileset.c
assetlanguage.c
assetscript.c

View File

@@ -138,14 +138,14 @@ errorret_t assetMapChunkHandler(assetcustom_t custom) {
mesh_t *mesh = &chunk->meshes[i];
meshInit(
mesh,
MESH_PRIMITIVE_TRIANGLES,
MESH_PRIMITIVE_TYPE_TRIANGLES,
modelHeader.vertexCount,
&chunk->vertices[vertexIndex]
);
vertexIndex += modelHeader.vertexCount;
} else {
chunk->meshes[i].vertexCount = 0;
// chunk->meshes[i].vertexCount = 0;
}
}

View File

@@ -1,47 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "assetpalette.h"
#include "asset/assettype.h"
#include "assert/assert.h"
errorret_t assetPaletteLoad(assetentire_t entire) {
assertNotNull(entire.data, "Data pointer cannot be NULL.");
assertNotNull(entire.output, "Output pointer cannot be NULL.");
assetpalette_t *assetData = (assetpalette_t *)entire.data;
palette_t *palette = (palette_t *)entire.output;
// Read header and version (first 4 bytes)
if(
assetData->header[0] != 'D' ||
assetData->header[1] != 'P' ||
assetData->header[2] != 'F'
) {
errorThrow("Invalid palette header");
}
// Version (can only be 1 atm)
if(assetData->version != 0x01) {
errorThrow("Unsupported palette version");
}
// Check color count.
if(
assetData->colorCount == 0 ||
assetData->colorCount > PALETTE_COLOR_COUNT_MAX
) {
errorThrow("Invalid palette color count");
}
paletteInit(
palette,
assetData->colorCount,
assetData->colors
);
errorOk();
}

View File

@@ -1,30 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
#include "display/texture/palette.h"
typedef struct assetentire_s assetentire_t;
#pragma pack(push, 1)
typedef struct {
char_t header[3];
uint8_t version;
uint8_t colorCount;
color_t colors[PALETTE_COLOR_COUNT_MAX];
} assetpalette_t;
#pragma pack(pop)
/**
* Loads a palette from the given data pointer into the output palette.
*
* @param entire Data received from the asset loader system.
* @return An error code.
*/
errorret_t assetPaletteLoad(assetentire_t entire);

View File

@@ -12,6 +12,7 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
# Subdirectories
add_subdirectory(camera)
add_subdirectory(framebuffer)
add_subdirectory(mesh)
add_subdirectory(texture)

View File

@@ -30,10 +30,10 @@ errorret_t displayInit(void) {
#endif
errorChain(quadInit());
errorChain(frameBufferInitBackbuffer());
errorChain(frameBufferInitBackBuffer());
spriteBatchInit();
errorChain(textInit());
errorChain(assetLoad("main_palette.dpf", &PALETTES[0]));
// errorChain(assetLoad("main_palette.dpf", &PALETTES[0]));
screenInit();
errorOk();

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
framebuffer.c
)

View File

@@ -13,9 +13,9 @@
framebuffer_t FRAMEBUFFER_BACKBUFFER = {0};
const framebuffer_t *FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
errorret_t frameBufferInitBackbuffer() {
errorret_t frameBufferInitBackBuffer() {
memoryZero(&FRAMEBUFFER_BACKBUFFER, sizeof(framebuffer_t));
errorChain(frameBufferPlatformInitBackbuffer());
errorChain(frameBufferPlatformInitBackBuffer());
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
errorOk();
}
@@ -24,7 +24,7 @@ errorret_t frameBufferBind(framebuffer_t *framebuffer) {
if(framebuffer == NULL) {
frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
return;
errorOk();
}
errorChain(frameBufferPlatformBind(framebuffer));
@@ -32,21 +32,12 @@ errorret_t frameBufferBind(framebuffer_t *framebuffer) {
errorOk();
}
void frameBufferDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
uint32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
return frameBufferPlatformGetWidth(framebuffer);
}
#if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
assertUnreachable("Cannot dispose of backbuffer");
}
#if DISPLAY_SIZE_DYNAMIC == 0
assertUnreachable("Dynamic size framebuffers not supported");
#else
textureDispose(&framebuffer->texture);
glDeleteFramebuffersEXT(1, &framebuffer->id);
#endif
#endif
uint32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
return frameBufferPlatformGetHeight(framebuffer);
}
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
@@ -62,4 +53,10 @@ void frameBufferDispose(framebuffer_t *framebuffer) {
errorChain(frameBufferPlatformInit(fb, width, height));
errorOk();
}
errorret_t frameBufferDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
errorChain(frameBufferPlatformDispose(framebuffer));
errorOk();
}
#endif

View File

@@ -56,7 +56,7 @@ uint32_t frameBufferGetHeight(const framebuffer_t *framebuffer);
* @param framebuffer The framebuffer to bind, or NULL to bind the backbuffer.
* @return Error for binding the framebuffer.
*/
errorret_t frameBufferBind(const framebuffer_t *framebuffer);
errorret_t frameBufferBind(framebuffer_t *framebuffer);
/**
* Clears the currently bound framebuffer.
@@ -66,19 +66,15 @@ errorret_t frameBufferBind(const framebuffer_t *framebuffer);
*/
void frameBufferClear(uint8_t flags, color_t color);
/**
* Disposes of the framebuffer. Will also be used for request disposing of the
* backbuffer.
*
* @param framebuffer The framebuffer to dispose of.
*/
void frameBufferDispose(framebuffer_t *framebuffer);
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
#ifndef frameBufferPlatformInit
#error "frameBufferPlatformInit not defined for this platform"
#endif
#ifndef frameBufferPlatformDispose
#error "frameBufferPlatformDispose not defined for this platform"
#endif
/**
* Initializes a framebuffer.
*
@@ -92,4 +88,12 @@ void frameBufferDispose(framebuffer_t *framebuffer);
const uint32_t width,
const uint32_t height
);
/**
* Disposes of the framebuffer. Will also be used for request disposing of the
* backbuffer.
*
* @param framebuffer The framebuffer to dispose of.
*/
errorret_t frameBufferDispose(framebuffer_t *framebuffer);
#endif

View File

@@ -8,7 +8,7 @@
#include "text.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "display/spritebatch.h"
#include "display/spritebatch/spritebatch.h"
#include "asset/asset.h"
texture_t DEFAULT_FONT_TEXTURE;

View File

@@ -9,6 +9,7 @@
#include "util/memory.h"
#include "assert/assert.h"
#include "asset/asset.h"
#include "display/texture/texture.h"
// #include "entity/entity.h"
#include "util/string.h"
#include "time/time.h"
@@ -195,8 +196,8 @@ void mapChunkUnload(mapchunk_t* chunk) {
// }
for(uint8_t i = 0; i < chunk->meshCount; i++) {
if(chunk->meshes[i].vertexCount == 0) continue;
meshDispose(&chunk->meshes[i]);
// if(chunk->meshes[i].vertexCount == 0) continue;
// meshDispose(&chunk->meshes[i]);
}
}

View File

@@ -8,9 +8,8 @@
#include "util/memory.h"
#include "debug/debug.h"
#include "time/time.h"
#include "display/camera/camera.h"
#include "display/screen.h"
#include "display/screen/screen.h"
scene_t SCENE;

View File

@@ -7,7 +7,7 @@
#include "modulescreen.h"
#include "assert/assert.h"
#include "display/screen.h"
#include "display/screen/screen.h"
void moduleScreen(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");

View File

@@ -6,7 +6,7 @@
*/
#include "modulespritebatch.h"
#include "display/spritebatch.h"
#include "display/spritebatch/spritebatch.h"
#include "assert/assert.h"
void moduleSpriteBatch(scriptcontext_t *context) {

View File

@@ -8,7 +8,7 @@
#include "moduletext.h"
#include "assert/assert.h"
#include "display/text.h"
#include "display/spritebatch.h"
#include "display/spritebatch/spritebatch.h"
void moduleText(scriptcontext_t *context) {
assertNotNull(context, "Script context is null");

View File

@@ -130,4 +130,17 @@ void frameBufferClear(const uint8_t flags, const color_t color) {
errorChain(errorGLCheck());
errorOk();
}
errorret_t frameBufferGLDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
assertUnreachable("Cannot dispose of backbuffer");
}
errorChain(textureDispose(&framebuffer->texture));
glDeleteFramebuffersEXT(1, &framebuffer->id);
errorChain(errorGLCheck());
errorOk();
}
#endif

View File

@@ -19,6 +19,32 @@ typedef struct {
*/
errorret_t frameBufferGLInitBackBuffer(void);
/**
* Gets the height of the framebuffer. (OpenGL implementation).
*
* @param framebuffer The framebuffer to get the height of.
* @return The height of the framebuffer, or 0 if the framebuffer is NULL.
*/
uint32_t frameBufferGLGetWidth(const framebuffergl_t *framebuffer);
/**
* Initializes an OpenGL style framebuffer.
*
* @param fb The framebuffer to initialize.
* @param width The width of the framebuffer.
* @param height The height of the framebuffer.
* @return Either error or not.
*/
uint32_t frameBufferGLGetHeight(const framebuffergl_t *framebuffer);
/**
* Gets the width of the framebuffer. (OpenGL implementation).
*
* @param framebuffer The framebuffer to get the width of.
* @return The width of the framebuffer, or 0 if the framebuffer is NULL.
*/
errorret_t frameBufferGLBind(framebuffergl_t *framebuffer);
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
/**
* Initializes an OpenGL style framebuffer.
@@ -33,4 +59,12 @@ errorret_t frameBufferGLInitBackBuffer(void);
const uint32_t width,
const uint32_t height
);
/**
* Disposes of the framebuffer. Will also be used for request disposing of the
* backbuffer.
*
* @param framebuffer The framebuffer to dispose of.
*/
errorret_t frameBufferGLDispose(framebuffergl_t *framebuffer);
#endif

View File

@@ -10,5 +10,11 @@
typedef framebuffergl_t framebufferplatform_t;
#define frameBufferPlatformInitBackBuffer frameBufferGLInitBackBuffer
#define frameBufferPlatformInit frameBufferGLInit
#define frameBufferPlatformBind frameBufferGLBind
#define frameBufferPlatformGetWidth frameBufferGLGetWidth
#define frameBufferPlatformGetHeight frameBufferGLGetHeight
#define frameBufferPlatformBind frameBufferGLBind
#if DUSK_DISPLAY_SIZE_DYNAMIC
#define frameBufferPlatformInit frameBufferGLInit
#define frameBufferPlatformDispose frameBufferGLDispose
#endif