first commit

This commit is contained in:
Jake
2025-05-26 20:59:26 -04:00
commit f4cfde8cf9
16 changed files with 816 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
// atlasDefinitions.h
// This header file contians define statements linking the names of each texture in the atlas to its index.
// I feel like there's probably a better way to link these things together, but this will work for now.'
#ifndef ATLAS_DEFINITIONS_H
#define ATLAS_DEFINITIONS_H
#define TILE_STONE 0
#define TILE_DIRT 1
#define TILE_GRASS_TOP 2
#define TILE_GRASS_SIDE 3
#define TILE_SAND 4
#define TILE_GRAVEL 5
#define TILE_LOG_TOP 6
#define TILE_LOG_SIDE 7
#define TILE_LEAF 8
#endif

23
include/blockTypes.h Normal file
View File

@@ -0,0 +1,23 @@
// blockTypes.h
#ifndef BLOCK_TYPES_H
#define BLOCKTYPES_H
// Definitions for Block IDs (notes are texture atlas indicies)
#define BLOCK_AIR 0 // No texture.
#define BLOCK_STONE 1 // 0
#define BLOCK_DIRT 2 // 1
#define BLOCK_GRASS 3 // top, 2, sides 3, bottom 1
#define BLOCK_SAND 4 // 4
#define BLOCK_GRAVEL 5 // 5
#define BLOCK_LOG 6 // top 6, sides 7, bottom 6
#define BLOCK_LEAF 7 // 8
typedef struct {
int id;
const char *name;
int faceTiles[6]; // Index by face: 0=-X, 1=+X, 2=-Y, 3=+Y, 4=-Z, 5=+Z
} BlockType;
const BlockType *GetBlockType(int blockID);
#endif

16
include/chunkGenerator.h Normal file
View File

@@ -0,0 +1,16 @@
// Chunk generation functions for voxelThing.
#ifndef CHUNK_GENERATOR_H
#define CHUNK_GENERATOR_H
#include "chunkStructures.h"
// Function for initializing a chunk as a typical sort of flatworld chunk.
void GenerateFlatChunk(Chunk *chunk) ;
// Function to initialize the chunk with dirt.
void GenerateChunk(Chunk *chunk);
// Function for initializing a chunk sparsely. (still dirt)
void GenerateSparseChunk(Chunk *chunk);
#endif

11
include/chunkRenderer.h Normal file
View File

@@ -0,0 +1,11 @@
// chunkRenderer.h
#ifndef CHUNK_RENDERER_H
#define CHUNK_RENDERER_H
#include "raylib.h"
#include "chunkStructures.h"
Mesh GenerateChunkMesh(Chunk *chunk);
Vector2 GetTileUV(int tileIndex, int corner);
#endif

36
include/chunkStructures.h Normal file
View File

@@ -0,0 +1,36 @@
// chunkStructures.h
#ifndef CHUNK_STRUCTURES_H
#define CHUNK_STRUCTURES_H
#include "raylib.h"
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 16
#define CHUNK_SIZE_Z 16
typedef struct {
int type; // 0 = air, 1 = dirt, etc.
} Block;
// 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
};
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);
void PlaceTreeAt(Chunk *chunk, int x, int y, int z) ;
#endif

View File

@@ -0,0 +1,22 @@
// playerController.h
#ifndef PLAYER_CONTROLLER_H
#define PLAYER_CONTROLLER_H
#include "raylib.h"
#include "chunkStructures.h"
typedef struct {
bool hit;
Vector3 position;
Vector3 normal;
int blockID;
float t;
} RaycastHit;
RaycastHit RaycastChunk(const Chunk *chunk, Vector3 origin, Vector3 direction, float maxDistance);
void UpdateFreeCamera(Camera3D *cam, float speed, float *yawOut, float *pitchOut);
void DrawFaceHighlight(Vector3 blockPos, Vector3 normal);
#endif