You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

world.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "voxelutils.h"
  3. #include "voxelinfo.h"
  4. #include "voxelmath.h"
  5. #include "terraingen.h"
  6. #include "heightmap.h"
  7. #include "graphics/chunkmesh.h"
  8. #include "cuckoohash_map.hh"
  9. #include "concurrentqueue.h"
  10. #include <unordered_map>
  11. #include <vector>
  12. #include <deque>
  13. #include <glm/glm.hpp>
  14. namespace vtk {
  15. class Chunk;
  16. class World {
  17. friend class Chunk;
  18. public:
  19. World();
  20. unsigned breakVoxel(const glm::ivec3& pos);
  21. bool placeVoxel(const glm::ivec3& pos, const unsigned& id);
  22. bool isVoxelSolid(const int& x, const int& y, const int& z);
  23. bool setVoxelType(const int& x, const int& y, const int& z, const unsigned& type, const bool& updateChunk = false);
  24. unsigned getVoxelType(const glm::ivec3& pos);
  25. Chunk* makeChunk(const int& x, const int& y, const int& z, bool insertAfter = true);
  26. bool generateChunk(const int& x, const int& y, const int& z);
  27. bool insertChunk(Chunk* chunk);
  28. Chunk* getChunk(const glm::ivec3& pos);
  29. HeightMap* getHeightMap(const glm::ivec2& pos);
  30. //get max height of world at pos(x,z)
  31. int getHeight(const glm::ivec2& pos);
  32. void queueChunkUpdate(const int& x, const int& y, const int& z, const bool& highpriority = false);
  33. void queueChunkUpdate(const glm::ivec3& pos, const bool& highpriority = false);
  34. void queueChunkLoad(const glm::ivec3& pos);
  35. void draw();
  36. void update();
  37. void queueChunkLoadsAroundPoint(const glm::vec3& point, const int& chunkRadius);
  38. //std::unordered_map<glm::ivec3, Chunk*, ivec3Hash> mChunks;
  39. cuckoohash_map<glm::ivec3, Chunk*, ivec3Hash> mChunks; //chunks
  40. cuckoohash_map<glm::ivec3, ChunkMesh*, ivec3Hash> mChunkMeshes; //meshes
  41. cuckoohash_map<glm::ivec2, HeightMap*, ivec2Hash> mHeightMaps; //heightmaps
  42. std::deque<glm::ivec3> mChunkLoadQueue;
  43. // mesh update queues
  44. moodycamel::ConcurrentQueue<glm::ivec3> mMeshUpdateQueue; // regular one
  45. moodycamel::ConcurrentQueue<glm::ivec3> mMeshUpdateQueueSoon; // high priority one
  46. //heightmap update queue
  47. moodycamel::ConcurrentQueue<glm::ivec2> mHeightMapUpdateQueue;
  48. unsigned chunkSize;
  49. float voxelSize;
  50. int modelMatUni;
  51. TerrainGen terrain;
  52. VoxelInfo voxelInfo;
  53. VoxelMath voxelMath;
  54. bool rebuildThreadActive;
  55. bool mLoadThreadActive;
  56. };
  57. }