Time is better.
This commit is contained in:
@@ -44,7 +44,7 @@ void cutsceneItemUpdate(const cutsceneitem_t *item, cutsceneitemdata_t *data) {
|
||||
break;
|
||||
|
||||
case CUTSCENE_ITEM_TYPE_WAIT:
|
||||
data->wait -= TIME.fixedDelta;
|
||||
data->wait -= TIME.delta;
|
||||
if(data->wait <= 0) cutsceneSystemNext();
|
||||
break;
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ errorret_t rpgInit(void) {
|
||||
}
|
||||
|
||||
void rpgUpdate(void) {
|
||||
if(!TIME.fixedUpdate) return;
|
||||
#if TIME_FIXED == 0
|
||||
if(TIME.dynamicUpdate) return;
|
||||
#endif
|
||||
|
||||
// TODO: Do not update if the scene is not the map scene?
|
||||
mapUpdate();
|
||||
|
||||
@@ -19,7 +19,11 @@ void rpgCameraInit(void) {
|
||||
void rpgCameraUpdate(void) {
|
||||
switch(RPG_CAMERA.mode) {
|
||||
case RPG_CAMERA_MODE_FREE:
|
||||
// Free camera mode; nothing to do.
|
||||
mapPositionSet(
|
||||
(int16_t)(RPG_CAMERA.free.x / CHUNK_WIDTH) - (MAP_CHUNK_WIDTH / 2),
|
||||
(int16_t)(RPG_CAMERA.free.y / CHUNK_HEIGHT) - (MAP_CHUNK_HEIGHT / 2),
|
||||
(int16_t)(RPG_CAMERA.free.z / CHUNK_DEPTH) - (MAP_CHUNK_DEPTH / 2)
|
||||
);
|
||||
break;
|
||||
|
||||
case RPG_CAMERA_MODE_FOLLOW_ENTITY: {
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
chunk.c
|
||||
map.c
|
||||
)
|
||||
20
src/rpg/world/chunk.c
Normal file
20
src/rpg/world/chunk.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "chunk.h"
|
||||
|
||||
uint32_t chunkGetTileIndex(
|
||||
const uint8_t relativeTileX,
|
||||
const uint8_t relativeTileY,
|
||||
const uint8_t relativeTileZ
|
||||
) {
|
||||
return (
|
||||
(relativeTileZ * CHUNK_WIDTH * CHUNK_HEIGHT) +
|
||||
(relativeTileY * CHUNK_WIDTH) +
|
||||
relativeTileX
|
||||
);
|
||||
}
|
||||
@@ -16,4 +16,18 @@
|
||||
typedef struct chunk_s {
|
||||
int16_t x, y, z;
|
||||
tile_t tiles[CHUNK_TILE_COUNT];
|
||||
} chunk_t;
|
||||
} chunk_t;
|
||||
|
||||
/**
|
||||
* Gets the tile index for a tile position within a chunk.
|
||||
*
|
||||
* @param relativeTileX The X coordinate of the tile within the chunk.
|
||||
* @param relativeTileY The Y coordinate of the tile within the chunk.
|
||||
* @param relativeTileZ The Z coordinate of the tile within the chunk.
|
||||
* @return The tile index within the chunk.
|
||||
*/
|
||||
uint32_t chunkGetTileIndex(
|
||||
const uint8_t relativeTileX,
|
||||
const uint8_t relativeTileY,
|
||||
const uint8_t relativeTileZ
|
||||
);
|
||||
@@ -7,24 +7,14 @@
|
||||
|
||||
#include "map.h"
|
||||
#include "util/memory.h"
|
||||
#include <stdio.h> // For printf
|
||||
|
||||
map_t MAP;
|
||||
|
||||
// Dummy functions for chunk loading/unloading
|
||||
void mapChunkUnload(chunk_t* chunk) {
|
||||
// Placeholder for unloading logic
|
||||
printf("Unloading chunk at (%d, %d, %d)\n", chunk->x, chunk->y, chunk->z);
|
||||
}
|
||||
|
||||
void mapChunkLoad(chunk_t* chunk) {
|
||||
// Placeholder for loading logic
|
||||
printf("Loading chunk at (%d, %d, %d)\n", chunk->x, chunk->y, chunk->z);
|
||||
}
|
||||
|
||||
void mapInit() {
|
||||
memoryZero(&MAP, sizeof(map_t));
|
||||
|
||||
// Init the default chunks. In future I'll probably make this based on where
|
||||
// the player spawns in to save an initial mapSet.
|
||||
uint32_t index = 0;
|
||||
for(uint32_t z = 0; z < MAP_CHUNK_DEPTH; z++) {
|
||||
for(uint32_t y = 0; y < MAP_CHUNK_HEIGHT; y++) {
|
||||
@@ -122,4 +112,50 @@ void mapPositionSet(const int16_t x, const int16_t y, const int16_t z) {
|
||||
|
||||
void mapUpdate() {
|
||||
|
||||
}
|
||||
void mapChunkUnload(chunk_t* chunk) {
|
||||
}
|
||||
|
||||
void mapChunkLoad(chunk_t* chunk) {
|
||||
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
|
||||
|
||||
uint8_t x, y, z;
|
||||
x = 1;
|
||||
y = 2;
|
||||
z = 0;
|
||||
|
||||
chunk->tiles[
|
||||
(z * CHUNK_WIDTH * CHUNK_HEIGHT) +
|
||||
(y * CHUNK_WIDTH) +
|
||||
x
|
||||
] = (tile_t){ .id = 1 };
|
||||
}
|
||||
|
||||
uint8_t mapGetChunkIndexAt(
|
||||
const int16_t chunkX,
|
||||
const int16_t chunkY,
|
||||
const int16_t chunkZ
|
||||
) {
|
||||
int16_t relX = chunkX - MAP.x;
|
||||
int16_t relY = chunkY - MAP.y;
|
||||
int16_t relZ = chunkZ - MAP.z;
|
||||
|
||||
if(
|
||||
relX < 0 || relX >= MAP_CHUNK_WIDTH ||
|
||||
relY < 0 || relY >= MAP_CHUNK_HEIGHT ||
|
||||
relZ < 0 || relZ >= MAP_CHUNK_DEPTH
|
||||
) {
|
||||
return UINT8_MAX;
|
||||
}
|
||||
|
||||
return (
|
||||
(relZ * MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT) +
|
||||
(relY * MAP_CHUNK_WIDTH) +
|
||||
relX
|
||||
);
|
||||
}
|
||||
|
||||
chunk_t* mapGetChunkByIndex(const uint8_t index) {
|
||||
if(index >= MAP_CHUNK_COUNT) return NULL;
|
||||
return &MAP.chunks[index];
|
||||
}
|
||||
@@ -33,15 +33,45 @@ void mapUpdate();
|
||||
|
||||
/**
|
||||
* Sets the map position and updates chunks accordingly.
|
||||
*
|
||||
* @param x The new X position.
|
||||
* @param y The new Y position.
|
||||
* @param z The new Z position.
|
||||
*/
|
||||
void mapPositionSet(const int16_t x, const int16_t y, const int16_t z);
|
||||
|
||||
/**
|
||||
* Dummy: Unloads a chunk.
|
||||
* Unloads a chunk.
|
||||
*
|
||||
* @param chunk The chunk to unload.
|
||||
*/
|
||||
void mapChunkUnload(chunk_t* chunk);
|
||||
|
||||
/**
|
||||
* Dummy: Loads a chunk.
|
||||
* Loads a chunk.
|
||||
*
|
||||
* @param chunk The chunk to load.
|
||||
*/
|
||||
void mapChunkLoad(chunk_t* chunk);
|
||||
void mapChunkLoad(chunk_t* chunk);
|
||||
|
||||
/**
|
||||
* Gets the index of a chunk at the specified CHUNK coordinates.
|
||||
*
|
||||
* @param chunkX The X coordinate of the chunk (in CHUNK units).
|
||||
* @param chunkY The Y coordinate of the chunk (in CHUNK units).
|
||||
* @param chunkZ The Z coordinate of the chunk (in CHUNK units).
|
||||
* @return The index of the chunk, or UINT8_MAX if out of bounds.
|
||||
*/
|
||||
uint8_t mapGetChunkIndexAt(
|
||||
const int16_t chunkX,
|
||||
const int16_t chunkY,
|
||||
const int16_t chunkZ
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets a chunk by its index.
|
||||
*
|
||||
* @param chunkIndex The index of the chunk.
|
||||
* @return A pointer to the chunk.
|
||||
*/
|
||||
chunk_t * mapGetChunk(const uint8_t chunkIndex);
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "dusk.h"
|
||||
|
||||
typedef uint8_t worldunit_t;
|
||||
typedef int16_t chunkunit_t;
|
||||
typedef int8_t worldunits_t;
|
||||
|
||||
typedef struct worldpos_s {
|
||||
|
||||
Reference in New Issue
Block a user