46 lines
1.0 KiB
C
46 lines
1.0 KiB
C
// chunkStructures.h
|
|
|
|
#ifndef CHUNK_STRUCTURES_H
|
|
#define CHUNK_STRUCTURES_H
|
|
|
|
#include "raylib.h"
|
|
|
|
#define CHUNK_SIZE_X 16
|
|
#define CHUNK_SIZE_Y 256
|
|
#define CHUNK_SIZE_Z 16
|
|
|
|
|
|
typedef struct {
|
|
int type; // 0 = air, 1 = dirt, etc.
|
|
} Block;
|
|
|
|
typedef struct {
|
|
Block blocks[CHUNK_SIZE_X][CHUNK_SIZE_Y][CHUNK_SIZE_Z];
|
|
Mesh mesh; // Owned by the chunk, valid only at runtime
|
|
bool hasMesh; //
|
|
} Chunk;
|
|
|
|
// 6 directions for checking neighbors: +/-X, +/-Y, +/-Z
|
|
static const int faceOffsets[6][3] = {
|
|
{ -1, 0, 0 }, // left
|
|
{ 1, 0, 0 }, // right
|
|
{ 0, -1, 0 }, // bottom
|
|
{ 0, 1, 0 }, // top
|
|
{ 0, 0, -1 }, // back
|
|
{ 0, 0, 1 } // front
|
|
};
|
|
|
|
// Function to check if a face of a block is exposed.
|
|
int IsBlockFaceExposed(Chunk *chunk, int x, int y, int z, int dir);
|
|
|
|
// Function that places a tree dumbly.
|
|
void PlaceTreeAt(Chunk *chunk, int x, int y, int z) ;
|
|
|
|
// Save chunk to disk.
|
|
bool SaveChunk(const Chunk *chunk, const char *filename);
|
|
|
|
// Load chunk from disk.
|
|
bool LoadChunk(Chunk *chunk, const char *filename);
|
|
|
|
#endif
|