From 3ce1566a2efd8f6110f06de54676661c36772476 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 1 Sep 2025 11:10:28 -0500 Subject: [PATCH] Merge --- src/CMakeLists.txt | 1 + src/asset/asset.h | 2 +- src/display/CMakeLists.txt | 1 + src/display/palette.c | 19 +++++++++++++++++++ src/display/palette.h | 26 ++++++++++++++++++++++++++ src/engine/engine.c | 12 +++++------- src/rpg/CMakeLists.txt | 1 + src/rpg/rpg.c | 13 +++++++++++++ src/rpg/rpg.h | 13 +++++++++++++ src/rpg/world/chunk.c | 6 +++--- src/rpg/world/chunk.h | 6 +++--- src/rpg/world/chunkdata.h | 2 +- src/rpg/world/overworld.c | 4 ++-- src/rpg/world/world.h | 16 ++++++++++++++++ 14 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 src/display/palette.c create mode 100644 src/display/palette.h create mode 100644 src/rpg/rpg.c create mode 100644 src/rpg/rpg.h create mode 100644 src/rpg/world/world.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb5425b..e84eb72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory(engine) add_subdirectory(error) add_subdirectory(input) # add_subdirectory(locale) +add_subdirectory(rpg) add_subdirectory(scene) add_subdirectory(thread) add_subdirectory(time) diff --git a/src/asset/asset.h b/src/asset/asset.h index 89df0b0..6c37182 100644 --- a/src/asset/asset.h +++ b/src/asset/asset.h @@ -99,7 +99,7 @@ extern asset_t ASSET; errorret_t assetInit(void); /** - * Gets an asset by filename, does not load it. + * Loads an asset by filename, blocking. * * @param filename The filename of the asset to get. * @param callback The callback to call when the asset is loaded. diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index 84b6db8..ae46353 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -8,6 +8,7 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE display.c camera.c + palette.c ) # Subdirectories diff --git a/src/display/palette.c b/src/display/palette.c new file mode 100644 index 0000000..3fc29d0 --- /dev/null +++ b/src/display/palette.c @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "palette.h" +#include "assert/assert.h" + +palette_t PALETTE[PALETTE_COUNT_MAX]; +uint8_t PALETTE_COUNT = 0; + +void paletteAssetLoadCallback(void *data) { + assertNotNull(data, "Data cannot be NULL."); + + uint8_t index = *((uint8_t*)data); + assertTrue(index < PALETTE_COUNT_MAX, "Palette index out of bounds."); +} \ No newline at end of file diff --git a/src/display/palette.h b/src/display/palette.h new file mode 100644 index 0000000..bfa17ec --- /dev/null +++ b/src/display/palette.h @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef struct { + +} palette_t; + +#define PALETTE_COUNT_MAX 8 + +extern palette_t PALETTE[PALETTE_COUNT_MAX]; +extern uint8_t PALETTE_COUNT; + +/** + * Palette asset load callback. + * + * @param data The data passed to the callback, should be a uint8_t* index + * into the PALETTE array. + */ +void paletteAssetLoadCallback(void *data); \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 502fae8..1b60bbe 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -11,17 +11,13 @@ #include "console/console.h" #include "display/display.h" #include "asset/asset.h" +#include "rpg/rpg.h" +#include "display/palette.h" #include "scene/test/scenetest.h" engine_t ENGINE; -void assetLoadCallback(void *data) { - consolePrint("Asset load callback called!"); - // test = ASSET.loaded.palette; - // consolePrint("Loaded palette with %d colors", ASSET.data.palette.colorCount); -} - errorret_t engineInit(void) { memoryZero(&ENGINE, sizeof(engine_t)); ENGINE.running = true; @@ -31,8 +27,10 @@ errorret_t engineInit(void) { consoleInit(); errorChain(assetInit()); errorChain(displayInit()); + rpgInit(); - assetLoad("entities.dpi", assetLoadCallback, NULL); + uint8_t slot = 0; + assetLoad("entities.dpi", paletteAssetLoadCallback, &slot); if(ASSET.state == ASSET_STATE_ERROR) errorChain(ASSET.error); sceneTestAdd(); diff --git a/src/rpg/CMakeLists.txt b/src/rpg/CMakeLists.txt index 325ce9f..7722d91 100644 --- a/src/rpg/CMakeLists.txt +++ b/src/rpg/CMakeLists.txt @@ -6,6 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE + rpg.c ) # Subdirs diff --git a/src/rpg/rpg.c b/src/rpg/rpg.c new file mode 100644 index 0000000..31dd453 --- /dev/null +++ b/src/rpg/rpg.c @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "rpg.h" +#include "rpg/entity/player.h" + +void rpgInit() { + +} \ No newline at end of file diff --git a/src/rpg/rpg.h b/src/rpg/rpg.h new file mode 100644 index 0000000..541ca58 --- /dev/null +++ b/src/rpg/rpg.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once + +/** + * Initializes the RPG subsystem. + */ +void rpgInit(); \ No newline at end of file diff --git a/src/rpg/world/chunk.c b/src/rpg/world/chunk.c index 9bd2fbd..40cee7d 100644 --- a/src/rpg/world/chunk.c +++ b/src/rpg/world/chunk.c @@ -8,7 +8,7 @@ #include "chunk.h" #include "util/memory.h" #include "assert/assert.h" -#include "world/world.h" +#include "rpg/world/world.h" void renderChunkUpdated(chunk_t *chunk); @@ -260,12 +260,12 @@ void chunkLoad(chunk_t *chunk, const uint16_t x, const uint16_t y) { }; // Load this entity. - entityLoad(entity, data); + // entityLoad(entity, data); data++; } // Allow the rendering platform to know this chunk is loaded. - renderChunkUpdated(chunk); + // renderChunkUpdated(chunk); } void chunkUnload(chunk_t *chunk) { diff --git a/src/rpg/world/chunk.h b/src/rpg/world/chunk.h index c2bcf36..3b598aa 100644 --- a/src/rpg/world/chunk.h +++ b/src/rpg/world/chunk.h @@ -7,15 +7,15 @@ #pragma once #include "tile.h" -#include "display/render.h" +#include "display/display.h" #define CHUNK_WIDTH 8 #define CHUNK_HEIGHT 8 #define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT) #define CHUNK_ENTITY_COUNT_MAX 8 -#define CHUNK_MAP_WIDTH (((RENDER_WIDTH / TILE_WIDTH_HEIGHT)/CHUNK_WIDTH)+2) -#define CHUNK_MAP_HEIGHT (((RENDER_HEIGHT / TILE_WIDTH_HEIGHT)/CHUNK_HEIGHT)+2) +#define CHUNK_MAP_WIDTH (((DISPLAY_WIDTH / TILE_WIDTH_HEIGHT)/CHUNK_WIDTH)+2) +#define CHUNK_MAP_HEIGHT (((DISPLAY_HEIGHT / TILE_WIDTH_HEIGHT)/CHUNK_HEIGHT)+2) #define CHUNK_MAP_COUNT (CHUNK_MAP_WIDTH * CHUNK_MAP_HEIGHT) typedef struct { diff --git a/src/rpg/world/chunkdata.h b/src/rpg/world/chunkdata.h index ecd2c31..686558b 100644 --- a/src/rpg/world/chunkdata.h +++ b/src/rpg/world/chunkdata.h @@ -7,7 +7,7 @@ #pragma once #include "chunk.h" -#include "entity/entity.h" +#include "rpg/entity/entity.h" typedef struct { uint8_t layerBase[CHUNK_TILE_COUNT]; diff --git a/src/rpg/world/overworld.c b/src/rpg/world/overworld.c index de51e28..6d6ae8e 100644 --- a/src/rpg/world/overworld.c +++ b/src/rpg/world/overworld.c @@ -7,9 +7,9 @@ #include "overworld.h" #include "chunk.h" -#include "display/render.h" +#include "display/display.h" #include "assert/assert.h" -#include "entity/entity.h" +#include "rpg/entity/entity.h" uint32_t OVERWORLD_CAMERA_X; uint32_t OVERWORLD_CAMERA_Y; diff --git a/src/rpg/world/world.h b/src/rpg/world/world.h new file mode 100644 index 0000000..64b837e --- /dev/null +++ b/src/rpg/world/world.h @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "rpg/world/chunkdata.h" + +#define WORLD_WIDTH 1 +#define WORLD_HEIGHT 1 + +static const chunkdata_t *WORLD_CHUNKS[WORLD_HEIGHT * WORLD_WIDTH] = { + NULL +}; \ No newline at end of file