Couple world pos fixes/improvements.
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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)
|
||||
14
src/rpg/world/worldpos.c
Normal file
14
src/rpg/world/worldpos.c
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -22,3 +32,11 @@ typedef struct worldpos_s {
|
||||
typedef struct chunkpos_t {
|
||||
chunkunit_t x, y, z;
|
||||
} 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);
|
||||
Reference in New Issue
Block a user