#pragma once #define GLM_ENABLE_EXPERIMENTAL #include #include "blocks.h" #include #include #include #include #include "multyPlayer/undoQueue.h" #include "chunk.h" #include #include #include #include struct LightSystem; void bakeWorkerThread(int index, ThreadPool &threadPool); struct ChunkSystem { BigGpuBuffer gpuBuffer; struct ChunkSystemSettings { //max number of chunks the client can be waiting for at a time. //note that this number is not a hard limit, if the player moves or teleports it will always be able to request //more chunks, this is a hard limit only when the player s int maxWaitingSubmisions = 15; }chunkSystemSettings; bool shouldUpdateLights = 0; std::vector loadedChunks; int squareSize = 4; std::vector chunksToAddLight; glm::ivec2 lastPlayerPos = {}; Block *getBlockAndData(glm::ivec3 blockPos, std::vector &data, Chunk *& chunk); //[0 -> squareSize) Chunk *getChunksInMatrixSpaceUnsafe(int x, int z); Chunk *getChunkSafeFromMatrixSpace(int x, int z); Chunk *getChunkSafeFromBlockPos(int x, int z); //this is the chunk pos, so not in matrix space Chunk *getChunkSafeFromChunkPos(int x, int z); glm::ivec2 fromBlockPosToMatrixSpace(int x, int z); glm::ivec2 fromMatrixSpaceToChunkSpace(int x, int z); void setChunkAndNeighboursFlagDirtyFromBlockPos(int x, int z); void init(int squareDistance); void changeRenderDistance(int squareDistance, bool notifyServer); void cleanup(bool notifyServer); void update(glm::ivec3 playerBlockPosition, float deltaTime, UndoQueue &undoQueue, LightSystem &lightSystem, InteractionData &interaction, ThreadPool &threadPool, Renderer &renderer, ClientEntityManager &clientEntityManager); bool isChunkInRadius(glm::ivec2 playerPos, glm::ivec2 chunkPos); bool isChunkInRadiusAndBounds(glm::ivec2 playerPos, glm::ivec2 chunkPos); bool shouldRecieveEntity(glm::dvec3 entityPos); int lastX = 0, lastZ = 0, created = 0; glm::ivec3 lastPlayerBlockPosition = {}; glm::ivec2 cornerPos = {}; Block *getBlockSafe(int x, int y, int z); Block *getBlockSafe(glm::dvec3 pos); Block* getBlockSafeAndChunk(int x, int y, int z, Chunk* &chunk); void getBlockSafeWithNeigbhours(int x, int y, int z, Block *¢er, Block *&front, Block *&back, Block *&top, Block *&bottom, Block *&left, Block *&right); void getBlockSafeWithNeigbhoursStopIfCenterFails(int x, int y, int z, Block *¢er, Block *&front, Block *&back, Block *&top, Block *&bottom, Block *&left, Block *&right); Block *rayCast(glm::dvec3 from, glm::vec3 dir, glm::ivec3 &outPos, float maxDist , std::optional &prevBlockForPlace, float &outDist); //a client places a block and sends a task to the server for it to be placed //returns true if succeeded bool placeBlockByClient(glm::ivec3 pos, unsigned char inventorySlot, UndoQueue &undoQueue, glm::dvec3 playerPos, LightSystem &lightSystem, PlayerInventory &inventory, bool decreaseCounter, int faceDirection, int topPartForSlabs, bool isOnWall, ClientEntityManager &clientEntityManager ); //used by the client to place blocks in creative mode using copy paste stuff bool placeBlockByClientForce(glm::ivec3 pos, Block block, UndoQueue &undoQue, LightSystem &lightSystem, ClientEntityManager &clientEntityManager ); //a client breaks a block and sends a task to the server for it to be blocked //returns true if succeeded bool breakBlockByClient(glm::ivec3 pos, UndoQueue &undoQueue, glm::dvec3 playerPos, LightSystem &lightSystem, ClientEntityManager &clientEntityManager ); void placeBlockByServerAndRemoveFromUndoQueue(glm::ivec3 pos, Block block, LightSystem &lightSystem, InteractionData &playerInteraction, UndoQueue &undoQueue, ClientEntityManager &clientEntityManager, std::vector *optionalData = 0); //just place the block, forcely by server void placeBlockNoClient(glm::ivec3 pos, Block block, LightSystem &lightSystem, std::vector *optionalData, InteractionData &playerInteraction, ClientEntityManager &clientEntityManager); //internal use void changeBlockLightStuff(glm::ivec3 pos, int currentSkyLightLevel, int currentNormalLightLevel, BlockType oldType, BlockType newType, LightSystem &lightSystem); //unloads all loaded chunks void dropAllChunks(BigGpuBuffer *gpuBuffer, bool notifyServer); //unloads a chunk atn the specified index in the matrix vector, //ASSUMES THE CHUNK IS LOADED AND HAS GPU DATA void dropChunkAtIndexUnsafe(int index, BigGpuBuffer *gpuBuffer); void dropChunkAtIndexSafe(int index, BigGpuBuffer *gpuBuffer); }; bool isChunkInRadius(glm::ivec2 playerPos, glm::ivec2 chunkPos, int squareSize);