diff --git a/src/rpg/world/chunk.h b/src/rpg/world/chunk.h index ea0de92..54b4d34 100644 --- a/src/rpg/world/chunk.h +++ b/src/rpg/world/chunk.h @@ -9,11 +9,6 @@ #include "rpg/world/tile.h" #include "worldpos.h" -#define CHUNK_WIDTH 4 -#define CHUNK_HEIGHT 4 -#define CHUNK_DEPTH 32 -#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH) - typedef struct chunk_s { chunkpos_t position; tile_t tiles[CHUNK_TILE_COUNT]; diff --git a/src/rpg/world/map.h b/src/rpg/world/map.h index dc0b3a6..82fd8f1 100644 --- a/src/rpg/world/map.h +++ b/src/rpg/world/map.h @@ -8,11 +8,6 @@ #pragma once #include "rpg/world/chunk.h" -#define MAP_CHUNK_WIDTH 3 -#define MAP_CHUNK_HEIGHT 3 -#define MAP_CHUNK_DEPTH 1 -#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH) - typedef struct map_s { chunk_t chunks[MAP_CHUNK_COUNT]; chunk_t *chunkOrder[MAP_CHUNK_COUNT]; diff --git a/src/rpg/world/tile.h b/src/rpg/world/tile.h index c4bee1f..d601fa1 100644 --- a/src/rpg/world/tile.h +++ b/src/rpg/world/tile.h @@ -8,8 +8,6 @@ #pragma once #include "dusk.h" -#pragma pack(push, 1) typedef struct tile_s { uint8_t id; -} tile_t; -#pragma pack(pop) \ No newline at end of file +} tile_t; \ No newline at end of file diff --git a/src/rpg/world/worldpos.c b/src/rpg/world/worldpos.c new file mode 100644 index 0000000..86db743 --- /dev/null +++ b/src/rpg/world/worldpos.c @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "worldpos.h" + +void chunkPosToWorldPos(const chunkpos_t* chunkPos, worldpos_t* out) { + out->x = (worldunit_t)(chunkPos->x * CHUNK_WIDTH); + out->y = (worldunit_t)(chunkPos->y * CHUNK_HEIGHT); + out->z = (worldunit_t)(chunkPos->z * CHUNK_DEPTH); +} \ No newline at end of file diff --git a/src/rpg/world/worldpos.h b/src/rpg/world/worldpos.h index 5022a0d..bc2bb8f 100644 --- a/src/rpg/world/worldpos.h +++ b/src/rpg/world/worldpos.h @@ -8,9 +8,19 @@ #pragma once #include "dusk.h" +#define CHUNK_WIDTH 4 +#define CHUNK_HEIGHT 4 +#define CHUNK_DEPTH 32 +#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH) + +#define MAP_CHUNK_WIDTH 3 +#define MAP_CHUNK_HEIGHT 3 +#define MAP_CHUNK_DEPTH 1 +#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH) + typedef int32_t worldunit_t; typedef int16_t chunkunit_t; -typedef int32_t chunkindex_t; +typedef int8_t chunkindex_t; typedef int32_t worldunits_t; typedef int32_t chunkunits_t; @@ -21,4 +31,12 @@ typedef struct worldpos_s { typedef struct chunkpos_t { chunkunit_t x, y, z; -} chunkpos_t; \ No newline at end of file +} chunkpos_t; + +/** + * Converts a world position to a chunk position. + * + * @param worldPos The world position. + * @param out The output chunk position. + */ +void chunkPosToWorldPos(const chunkpos_t* chunkPos, worldpos_t* out); \ No newline at end of file