Couple world pos fixes/improvements.

This commit is contained in:
2025-11-09 21:19:28 -06:00
parent aee06f51f0
commit 13365dd390
5 changed files with 35 additions and 15 deletions

View File

@@ -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];

View File

@@ -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];

View File

@@ -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)
} tile_t;

14
src/rpg/world/worldpos.c Normal file
View File

@@ -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);
}

View File

@@ -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;
} 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);