/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dusk.h" #include "duskdefs.h" #define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH) #define MAP_CHUNK_WIDTH 3 #define MAP_CHUNK_HEIGHT 3 #define MAP_CHUNK_DEPTH 3 #define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH) typedef int16_t worldunit_t; typedef int16_t chunkunit_t; typedef int16_t chunkindex_t; typedef uint32_t chunktileindex_t; typedef int32_t worldunits_t; typedef int32_t chunkunits_t; typedef struct worldpos_s { worldunit_t x, y, z; } worldpos_t; typedef struct chunkpos_t { chunkunit_t x, y, z; } chunkpos_t; /** * Compares two world positions for equality. * * @param a The first world position. * @param b The second world position. * @return true if equal, false otherwise. */ bool_t worldPosIsEqual(const worldpos_t a, const worldpos_t b); /** * 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); /** * Converts a chunk position to a world position. * * @param worldPos The world position. * @param out The output chunk position. */ void worldPosToChunkPos(const worldpos_t* worldPos, chunkpos_t* out); /** * Converts a position in world-space to an index inside a chunk that the tile * resides in. * * @param worldPos The world position. * @return The tile index within the chunk. */ chunktileindex_t worldPosToChunkTileIndex(const worldpos_t* worldPos); /** * Converts a chunk position to a world position. * * @param worldPos The world position. * @param out The output chunk position. */ chunkindex_t chunkPosToIndex(const chunkpos_t* pos);