Time is better.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
Reference in New Issue
Block a user