Added a basic skylight engine. Currently it's really laggy.

Also tried fixing the autobuild action since it fetches the repo without submodules.
This commit is contained in:
milkwx3
2026-06-24 18:58:15 +03:00
parent 3ad54bd59d
commit d02d751275
8 changed files with 190 additions and 36 deletions
+26 -6
View File
@@ -9,6 +9,7 @@
#undef PlaySound
#undef Sound
#endif
#include <functional>
#include "glfw_keycodes_to_string.h"
#include "../PerlinNoise.hpp"
#include "raylib.h"
@@ -77,7 +78,7 @@
#define DEFAULT_FONT_SIZE 16
#define TPS 30.0
#define TPS_DIV 1.0 / TPS
#define RENDER_DISTANCE 128
#define RENDER_DISTANCE 2
#define RENDER_DISTANCE_SQUARED RENDER_DISTANCE*RENDER_DISTANCE
#define MAX_HP 100
#define PATH_APPEND "resources/"
@@ -152,7 +153,7 @@ struct Chunk {
uint16_t opaqueMask[CHUNK_DATA_SIZE/16];
uint16_t airMask[CHUNK_DATA_SIZE/16];
uint8_t highestBlock[CHUNK_SIZE*CHUNK_SIZE];
uint8_t lights[CHUNK_DATA_SIZE];
uint16_t light[CHUNK_DATA_SIZE];
};
#if !defined(SERVER)
typedef struct ChunkRenderData ChunkRenderData;
@@ -195,9 +196,19 @@ struct Quad2D {
#endif
typedef struct Vector3I Vector3I;
struct Vector3I {
int x;
int y;
int z;
int x, y, z;
bool operator==(const Vector3I& other) const {
return (x == other.x && y == other.y && z == other.z);
};
};
typedef struct Vector3IHash Vector3IHash;
struct Vector3IHash {
size_t operator()(const Vector3I& p) const noexcept {
size_t h1 = std::hash<int>{}(p.x);
size_t h2 = std::hash<int>{}(p.y);
size_t h3 = std::hash<int>{}(p.z);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};
typedef struct Entity Entity;
struct Entity {
@@ -294,6 +305,9 @@ struct World {
};
extern const BlockDef BLOCKS[];
int GetBlock(World&world,int x,int y,int z);
int GetHighestBlock(World&world,int x,int z);
int GetSkyLight(World&world,int x,int y,int z);
Color GetLight(World&world,int x,int y,int z);
bool CanTick(int blockType);
bool GetCloud(int x,int z);
bool IsTranslucent(int blockType);
@@ -302,6 +316,8 @@ void RebuildHeightmap(Chunk&c);
int GetBiome(int sx,int sy);
void SetBlockChunkFast(Chunk *c,int i,int t);
void SetBlock(World&world,int x,int y,int z,int t);
void SetLightChunk(Chunk *c,int x,int y,int z,uint8_t sky,uint8_t r,uint8_t g,uint8_t b);
void SetLight(World&world,int x,int y,int z,uint8_t sky,uint8_t r,uint8_t g,uint8_t b);
void InitWorldgen(int worldType);
Vector3 WorldPosition(int cx,int cz,int localX,int y,int localZ);
Chunk GenerateChunk(int _x,int _y);
@@ -309,6 +325,7 @@ void GenerateWorldAdditional(World&world);
void TickBlock(World&world,int wx,int wy,int wz);
void TickChunk(Chunk *chunk,World&world,int wx,int wz);
void RebuildOpaqueMask(Chunk&chunk);
void RebuildLighting(World&world,int startX,int startZ);
#if !defined(SERVER)
ChunkRenderData GenerateCRDOpaque(Chunk&chunk,World&world);
ChunkRenderData GenerateCRDTranslucent(Chunk chunk,World&world);
@@ -406,7 +423,7 @@ char *DrawChat();
void DrawLogoCenter();
#endif
#if !defined(LEGACY_GL) && !defined(SERVER)
MeshData GenerateChunkMesh(ChunkRenderData chunkRenderData,Chunk chunk,int chunkWorldX,int chunkWorldY,uint8_t sideMask);
MeshData GenerateChunkMesh(World&world,ChunkRenderData chunkRenderData,Chunk chunk,int chunkWorldX,int chunkWorldY,uint8_t sideMask);
MeshData MergeMeshData(const MeshData&a,const MeshData&b);
MeshData CreateCubeMeshData(const BlockDef&def,float cx,float cy,float cz);
Mesh GenChunkMesh(MeshData meshData);
@@ -462,6 +479,9 @@ inline int GetIndexChunk2D(int x,int z){
inline bool CheckOOBWorld(int x,int y,int z){
return (x < 0 || y < 0 || z < 0 || x >= WORLD_SIZE_BLOCKS || y >= WORLD_HEIGHT || z >= WORLD_SIZE_BLOCKS);
};
inline bool CheckOOBWorldChunk(int x,int z){
return (x < 0 || z < 0 || x >= MAX_WORLD_SIZE || z >= MAX_WORLD_SIZE);
};
inline int GetIndexWorld(int x,int z){
if(CheckOOBWorld(x << 4, 0, z << 4)) return 0;
return x + MAX_WORLD_SIZE * z;