Added player struct. Multiple chunks, and player interaction updates to support them.

This commit is contained in:
Jake
2025-06-03 21:47:35 -04:00
parent 77cba9260a
commit 06b9a621ef
12 changed files with 303 additions and 148 deletions

View File

@@ -1,6 +1,6 @@
// blockTypes.h
#ifndef BLOCK_TYPES_H
#define BLOCKTYPES_H
#define BLOCK_TYPES_H
// Definitions for Block IDs (notes are texture atlas indicies)
#define BLOCK_AIR 0 // No texture.

11
include/chunkIO.h Normal file
View File

@@ -0,0 +1,11 @@
// chunkIO.h
#ifndef CHUNK_IO_H
#define CHUNK_IO_H
#include <stdbool.h>
#include "chunkStructures.h"
bool SaveChunk(const Chunk *chunk);
bool LoadChunk(Chunk *chunk);
#endif

View File

@@ -18,6 +18,9 @@ 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; //
bool hasChanged; // Flag that determines if chunk needs to be saved on unload
int x;
int z;
} Chunk;
// 6 directions for checking neighbors: +/-X, +/-Y, +/-Z
@@ -36,10 +39,6 @@ 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);
void InitChunk(Chunk *chunk, int chunkX, int chunkZ);
#endif

View File

@@ -4,6 +4,7 @@
#include "raylib.h"
#include "chunkStructures.h"
#include "world.h"
typedef struct {
Vector3 mapPosition; // Player's world position (camera position)
@@ -19,14 +20,20 @@ void UpdatePlayer(Player *player);
typedef struct {
bool hit;
Vector3 position;
int hitBlockX, hitBlockY, hitBlockZ;
Vector3 normal;
int blockID;
float t;
int chunkX;
int chunkZ;
} RaycastHit;
RaycastHit RaycastChunk(const Chunk *chunk, Vector3 origin, Vector3 direction, float maxDistance);
RaycastHit GetPlayerRaycastHit(Player *player, Chunk *chunk, float maxDistance);
RaycastHit GetPlayerRaycastHit(Player *player, World *world, float maxDistance);
// Osolete with multichunk worlds.
//RaycastHit GetPlayerRaycastHit(Player *player, Chunk *chunk, float maxDistance);
void UpdateFreeCamera(Camera3D *cam, float speed, float *yawOut, float *pitchOut);

22
include/world.h Normal file
View File

@@ -0,0 +1,22 @@
// world.h
#ifndef WORLD_H
#define WORLD_H
#include "chunkStructures.h"
#define WORLD_SIZE_X 16
#define WORLD_SIZE_Z 16
// World is currently a flat grid of chunks on the X-Z plane
typedef struct {
Chunk *chunks[WORLD_SIZE_X][WORLD_SIZE_Z];
} World;
void InitWorld(World *world);
void FreeWorld(World *world);
void UpdateWorld(World *world);
Chunk *GetChunk(World *world, int chunkX, int chunkZ);
Chunk *GetChunkContainingBlock(World *world, int wx, int wz);
#endif