Remove internal server cuz we have it in the networking branch.

Minor refactoring (changed all Chunk* world or Chunk world[] to World world)
This commit is contained in:
milkwx3
2026-06-24 16:00:56 +03:00
parent cf53a42620
commit 3ad54bd59d
13 changed files with 137 additions and 522 deletions
+35 -39
View File
@@ -77,7 +77,7 @@
#define DEFAULT_FONT_SIZE 16
#define TPS 30.0
#define TPS_DIV 1.0 / TPS
#define RENDER_DISTANCE 16
#define RENDER_DISTANCE 128
#define RENDER_DISTANCE_SQUARED RENDER_DISTANCE*RENDER_DISTANCE
#define MAX_HP 100
#define PATH_APPEND "resources/"
@@ -152,7 +152,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];
};
#if !defined(SERVER)
typedef struct ChunkRenderData ChunkRenderData;
@@ -288,28 +288,33 @@ struct Particle {
int lifetime;
int data[8];
};
typedef struct World World;
struct World {
Chunk chunks[MAX_WORLD_AREA];
};
extern const BlockDef BLOCKS[];
int GetBlock(World&world,int x,int y,int z);
bool CanTick(int blockType);
bool GetCloud(int x,int z);
bool IsTranslucent(int blockType);
void SetBlockChunk(Chunk *c,int x,int y,int z,int t);
void RebuildHeightmap(Chunk *c);
void RebuildHeightmap(Chunk&c);
int GetBiome(int sx,int sy);
void SetBlockChunkFast(Chunk *c,int i,int t);
void SetBlock(Chunk world[],int x,int y,int z,int t);
void SetBlock(World&world,int x,int y,int z,int t);
void InitWorldgen(int worldType);
Vector3 WorldPosition(int cx,int cz,int localX,int y,int localZ);
Chunk GenerateChunk(int _x,int _y);
void GenerateWorldAdditional(Chunk world[]);
void TickBlock(Chunk world[],int wx,int wy,int wz);
void TickChunk(Chunk *chunk,Chunk *world,int wx,int wz);
void RebuildOpaqueMask(Chunk *chunk);
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);
#if !defined(SERVER)
ChunkRenderData GenerateCRDOpaque(const Chunk&chunk,Chunk world[]);
ChunkRenderData GenerateCRDTranslucent(Chunk chunk,Chunk world[]);
ChunkRenderData GenerateCRDOpaque(Chunk&chunk,World&world);
ChunkRenderData GenerateCRDTranslucent(Chunk chunk,World&world);
#endif
void SaveWorld(Chunk world[],const char *path);
bool LoadWorld(Chunk world[],const char *path);
void SaveWorld(World&world,const char *path);
bool LoadWorld(World&world,const char *path);
extern long nsTotal;
void Debug_StartMeasure();
#if defined(WIN32)
@@ -356,11 +361,11 @@ extern Vector3 player_velocity;
extern Vector3 player_velocity;
#if !defined(SERVER)
void TakeDamage(float amount);
void SetBlockNetwork(Chunk world[],int bx,int by,int bz,int t);
void SetBlockNetwork(World&world,int bx,int by,int bz,int t);
#endif
Entity NewEntity();
void AddEntity(Entity ent);
void UpdateEntities(Chunk world[],float dt);
void UpdateEntities(World&world,float dt);
extern float globalCounter;
#if !defined(SERVER)
void DrawEntities(float dt);
@@ -448,42 +453,43 @@ inline void GetXYZFromIndex(int index,int *x,int *y,int *z){
};
inline int GetIndexChunk(int x,int y,int z){
if(x < 0 || y < 0 || z < 0 || x >= CHUNK_SIZE || y >= WORLD_HEIGHT || z >= CHUNK_SIZE) return 0;
return x + CHUNK_SIZE * (z + CHUNK_SIZE* y);
return x + CHUNK_SIZE * (z + CHUNK_SIZE * y);
};
inline int GetIndexChunk2D(int x,int z){
if(x < 0 || z < 0 || x >= CHUNK_SIZE || z >= CHUNK_SIZE) return 0;
return x + CHUNK_SIZE * 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 int GetIndexWorld(int x,int z){
if(CheckOOBWorld(x << 4, 0, z << 4)) return 0;
return x + MAX_WORLD_SIZE * z;
};
inline void GetXZFromIndex(int index,int *x,int *z){
*z = index / MAX_WORLD_SIZE;
*x = index % MAX_WORLD_SIZE;
};
inline bool TestMask(uint16_t *maskArray,int position){
inline bool TestMask(const uint16_t *maskArray,int position){
if (position < 0 || position >= CHUNK_DATA_SIZE) return false;
int index = position >> 4;
int bit = position & 15;
int maskArrayLen = CHUNK_DATA_SIZE << 4;
return (maskArray[index] & (1u << bit)) != 0;
};
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 CheckOOBChunk(int x,int y,int z){
return (x < 0 || y < 0 || z < 0 || x >= CHUNK_SIZE || y >= WORLD_HEIGHT || z >= CHUNK_SIZE);
};
inline bool TestOpaqueMaskWorld(Chunk world[],int x,int y,int z){
inline bool TestOpaqueMaskWorld(const World&world,int x,int y,int z){
if(CheckOOBWorld(x, y, z)) return true;
Chunk* c = &world[GetIndexWorld(x >> 4, z >> 4)];
int localIndex = GetIndexChunk((uint8_t)x & 15, y, (uint8_t)z & 15);
return TestMask(c->opaqueMask, localIndex);
const Chunk c = world.chunks[GetIndexWorld(x >> 4, z >> 4)];
const int localIndex = GetIndexChunk((uint8_t)x & 15, y, (uint8_t)z & 15);
return TestMask(c.opaqueMask, localIndex);
};
inline bool TestAirMaskWorld(Chunk world[],int x,int y,int z){
inline bool TestAirMaskWorld(const World&world,int x,int y,int z){
if(CheckOOBWorld(x, y, z)) return true;
Chunk* c = &world[GetIndexWorld(x >> 4, z >> 4)];
int localIndex = GetIndexChunk((uint8_t)x & 15, y, (uint8_t)z & 15);
return TestMask(c->airMask, localIndex);
const Chunk c = world.chunks[GetIndexWorld(x >> 4, z >> 4)];
const int localIndex = GetIndexChunk((uint8_t)x & 15, y, (uint8_t)z & 15);
return TestMask(c.airMask, localIndex);
};
inline int fetch_block(Chunk chunk,int x,int y,int z){
if(x<0||x>=CHUNK_SIZE||y<0||y>=WORLD_HEIGHT||z<0||z>=CHUNK_SIZE) return 0;
@@ -493,14 +499,6 @@ inline int fetch_block_ptr(Chunk *chunk,int x,int y,int z){
if(x<0||x>=CHUNK_SIZE||y<0||y>=WORLD_HEIGHT||z<0||z>=CHUNK_SIZE) return 0;
return chunk->blocks[GetIndexChunk(x, y, z)];
};
inline int GetBlock(Chunk world[],int x,int y,int z){
if(CheckOOBWorld(x, y, z)) return 0;
int locX = x % CHUNK_SIZE;
int locZ = z % CHUNK_SIZE;
int cx = x / CHUNK_SIZE;
int cz = z / CHUNK_SIZE;
return fetch_block(world[GetIndexWorld(cx, cz)], locX, y, locZ);
};
inline void *grow(void *ptr,size_t oldBytes,size_t newBytes){
if (!ptr) return malloc(newBytes);
return realloc(ptr, newBytes);
@@ -603,7 +601,7 @@ void UpdateHotbar();
void LocaleUpdate();
void LoadRecipes();
#endif
void ParticlesUpdate(float dt,Chunk world[]);
void ParticlesUpdate(float dt,World&world);
void ParticlesDraw();
void AddParticle(Particle part);
Particle NewParticle(Vector3 position);
@@ -616,8 +614,6 @@ void SavePlayerData();
bool LoadPlayerData();
void MS_PlaySound(Sound src,float pitch,float volume,Vector3 position);
void MS_Update(float dt,Camera camera);
void ServerNetworkUpdate();
void StopInternalServer();
#define INTERFACE 0
#define EXPORT_INTERFACE 0
#define LOCAL_INTERFACE 0