structure.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <blocks.h>
  3. #include <vector>
  4. struct StructureData
  5. {
  6. glm::ivec3 size;
  7. int unused = 0;
  8. //data is held outside
  9. BlockType &unsafeGet(int x, int y, int z)
  10. {
  11. assert(x >= 0 && y >= 0 && z >= 0 && x < size.x && y < size.y && z < size.z);
  12. return ((BlockType*)(this + 1))[y + z * size.y + x * size.y*size.z];
  13. }
  14. BlockType &unsafeGetRotated(int x, int y, int z, int r)
  15. {
  16. if (r == 0)
  17. {
  18. return unsafeGet(x, y, z);
  19. }
  20. else if (r == 1)
  21. {
  22. return unsafeGet(size.z - 1 - z, y, x);
  23. }
  24. else if (r == 2)
  25. {
  26. return unsafeGet(size.x - x - 1, y, size.z - z - 1);
  27. }
  28. else if (r == 3)
  29. {
  30. return unsafeGet(z, y, size.x - x - 1);
  31. }
  32. else
  33. {
  34. assert(0);
  35. }
  36. }
  37. BlockType *safeGet(int x, int y, int z)
  38. {
  39. if (x < 0 || y < 0 || z < 0 || x >= size.x || y >= size.y || z >= size.z)
  40. {
  41. return nullptr;
  42. }
  43. return &unsafeGet(x, y, z);
  44. }
  45. };
  46. struct StructuresManager
  47. {
  48. bool loadAllStructures();
  49. std::vector<StructureData *> trees;
  50. std::vector<StructureData *> jungleTrees;
  51. std::vector<StructureData *> palmTrees;
  52. std::vector<StructureData *> treeHouses;
  53. std::vector<StructureData *> smallPyramids;
  54. std::vector<StructureData *> birchTrees;
  55. std::vector<StructureData *> igloos;
  56. std::vector<StructureData *> spruceTrees;
  57. void clear();
  58. };