chunkSystem.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #define GLM_ENABLE_EXPERIMENTAL
  3. #include <glm/gtx/hash.hpp>
  4. #include "blocks.h"
  5. #include <unordered_map>
  6. #include <glm/vec3.hpp>
  7. #include <glm/vec2.hpp>
  8. #include <optional>
  9. #include "multyPlayer/undoQueue.h"
  10. #include "chunk.h"
  11. struct LightSystem;
  12. struct ChunkSystem
  13. {
  14. std::vector<Chunk*> loadedChunks;
  15. std::vector<int> requestedChunks;
  16. int squareSize = 3;
  17. Chunk *getChunkSafeFromChunkSystemCoordonates(int x, int z);
  18. Chunk *getChunkSafeFromBlockPos(int x, int z);
  19. void setChunkAndNeighboursFlagDirtyFromBlockPos(int x, int z);
  20. void createChunks(int viewDistance);
  21. void update(glm::ivec3 playerBlockPosition, float deltaTime, UndoQueue &undoQueue, LightSystem &lightSystem);
  22. int lastX = 0, lastZ = 0, created = 0;
  23. glm::ivec3 lastPlayerBlockPosition = {};
  24. glm::ivec2 cornerPos = {};
  25. Block *getBlockSafe(int x, int y, int z);
  26. Block *getBlockSafe(glm::dvec3 pos);
  27. Block* getBlockSafeAndChunk(int x, int y, int z, Chunk* &chunk);
  28. Block *rayCast(glm::dvec3 from, glm::vec3 dir, glm::ivec3 &outPos, float maxDist
  29. , std::optional<glm::ivec3> &prevBlockForPlace);
  30. //a client places a block and sends a task to the server for it to be placed
  31. void placeBlockByClient(glm::ivec3 pos, BlockType type, UndoQueue &undoQueue, glm::dvec3 playerPos, LightSystem &lightSystem);
  32. //just place the block
  33. void placeBlockNoClient(glm::ivec3 pos, BlockType type, LightSystem &lightSystem);
  34. //internal use
  35. void changeBlockLightStuff(glm::ivec3 pos, int currentLightLevel, BlockType oldType,
  36. BlockType newType, LightSystem &lightSystem);
  37. std::unordered_map<glm::ivec2, float> recentlyRequestedChunks;
  38. };
  39. int modBlockToChunk(int x);
  40. int divideChunk(int x);
  41. int divideMetaChunk(int chunkPos);