Better player encapsulation. World persistence. Cleaned up CPU and GPU memory leaks.

This commit is contained in:
Jake
2025-05-30 10:56:22 -04:00
parent 585f72a4bd
commit 701c72a2a5
10 changed files with 168 additions and 228 deletions

View File

@@ -14,6 +14,12 @@ 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
@@ -24,13 +30,16 @@ static const int faceOffsets[6][3] = {
{ 0, 0, 1 } // front
};
typedef struct {
Block blocks[CHUNK_SIZE_X][CHUNK_SIZE_Y][CHUNK_SIZE_Z];
} Chunk;
// 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

View File

@@ -5,6 +5,17 @@
#include "raylib.h"
#include "chunkStructures.h"
typedef struct {
Vector3 mapPosition; // Player's world position (camera position)
Vector2 playerOrientation; // Yaw (x) and pitch (y), in radians
Vector3 forward; // Direction vector computed from yaw/pitch
Vector3 right; // Right vector
float moveSpeed; // Movement speed
Camera3D camera;
} Player;
void UpdatePlayer(Player *player);
typedef struct {
bool hit;
Vector3 position;
@@ -15,8 +26,12 @@ typedef struct {
RaycastHit RaycastChunk(const Chunk *chunk, Vector3 origin, Vector3 direction, float maxDistance);
RaycastHit GetPlayerRaycastHit(Player *player, Chunk *chunk, float maxDistance);
void UpdateFreeCamera(Camera3D *cam, float speed, float *yawOut, float *pitchOut);
void DrawFaceHighlight(Vector3 blockPos, Vector3 normal);
void HandleBlockInteraction(Player *player, Chunk *chunk, RaycastHit hit, int blockSelection);
#endif