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.

chunk.h 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "voxelutils.h"
  3. #include "util/mobileatomic.h"
  4. #include <glm/glm.hpp>
  5. namespace vtk {
  6. class World;
  7. class HeightMap;
  8. class Chunk {
  9. friend class World;
  10. public:
  11. Chunk(World& world);
  12. bool isLoaded();
  13. // BREAK AND PLACE FUNCS
  14. // These handle all the mesh rebuilds and heightmap updates for you
  15. // Positions are chunk relative (0-15 on all axes)
  16. //break a voxel, returns the type of the voxel that was just broken
  17. unsigned breakVoxel(const glm::ivec3& pos);
  18. //place voxel, will not override previous voxels, returns true if successful
  19. bool placeVoxel(const glm::ivec3& pos, const unsigned& type);
  20. bool isVoxelSolid(const int& x, const int& y, const int& z); //Is the voxel not a transparent type?
  21. void setVoxelType(const glm::ivec3& pos, const unsigned& type);
  22. void setVoxelType(const int& x, const int& y, const int& z, const unsigned& type, const bool& update = false);
  23. unsigned getVoxelType(const glm::ivec3& pos);
  24. unsigned getVoxelType(const unsigned& x, const unsigned& y, const unsigned& z);
  25. glm::ivec3 getWorldCoords(const int& x, const int& y, const int& z);
  26. unsigned getLightLevel(const glm::ivec3& pos);
  27. unsigned short getLightPacked(const glm::ivec3& pos);
  28. HeightMap* getHeightMap();
  29. void setPos(const glm::ivec3& pos);
  30. glm::ivec3 getPos();
  31. World& getWorld();
  32. protected:
  33. void setQueuedForMeshRebuild(const bool& rebuild = true);
  34. bool isQueuedForMeshRebuild();
  35. std::array<util::MobileAtomic<unsigned>, 4096> mData;
  36. std::array<util::MobileAtomic<unsigned short>, 4096> mLighting;
  37. World& mLinkedWorld;
  38. glm::ivec3 mPos;
  39. std::atomic<bool> mLoaded;
  40. std::atomic<bool> mQueuedForMeshRebuild;
  41. };
  42. }