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.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. typedef std::pair<short, unsigned short> LightIndexPair;
  9. class Chunk {
  10. friend class World;
  11. public:
  12. Chunk(World& world);
  13. bool isLoaded();
  14. // BREAK AND PLACE FUNCS
  15. // These handle all the mesh rebuilds and heightmap updates for you
  16. // Positions are chunk relative (0-15 on all axes)
  17. //break a voxel, returns the type of the voxel that was just broken
  18. unsigned breakVoxel(const glm::ivec3& pos);
  19. //place voxel, will not override previous voxels, returns true if successful
  20. bool placeVoxel(const glm::ivec3& pos, const unsigned& type);
  21. bool isVoxelSolid(const int& x, const int& y, const int& z); //Is the voxel not a transparent type?
  22. bool isVoxelSolid(const glm::ivec3& pos);
  23. void setVoxelType(const glm::ivec3& pos, const unsigned& type);
  24. void setVoxelType(const int& x, const int& y, const int& z, const unsigned& type, const bool& update = false);
  25. unsigned getVoxelType(const glm::ivec3& pos);
  26. unsigned getVoxelType(const unsigned& x, const unsigned& y, const unsigned& z);
  27. void rebuildLighting();
  28. glm::ivec3 getWorldCoords(const int& x, const int& y, const int& z);
  29. unsigned getLightLevel(const glm::ivec3& pos);
  30. unsigned short getLightPacked(const glm::ivec3& pos);
  31. void setLightPacked(const glm::ivec3& pos, const unsigned short& light);
  32. HeightMap* getHeightMap();
  33. void setPos(const glm::ivec3& pos);
  34. glm::ivec3 getPos();
  35. World& getWorld();
  36. protected:
  37. typedef std::tuple<short, Chunk*> LightIndexTup;
  38. void setQueuedForMeshRebuild(const bool& rebuild = true);
  39. bool isQueuedForMeshRebuild();
  40. std::array<util::MobileAtomic<unsigned>, 4096> mData;
  41. std::array<util::MobileAtomic<unsigned short>, 4096> mLighting;
  42. World& mLinkedWorld;
  43. glm::ivec3 mPos;
  44. std::atomic<bool> mLoaded;
  45. std::atomic<bool> mQueuedForMeshRebuild;
  46. };
  47. }