BlockStorage.h 865 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef BLOCKSTORAGE_H
  2. #define BLOCKSTORAGE_H
  3. #include "common/Block.h"
  4. #include "memory/UniquePointer.h"
  5. #include "utils/BitArray.h"
  6. #include "utils/List.h"
  7. class BlockStorage final {
  8. int size;
  9. int height;
  10. int sizeMask;
  11. class Map {
  12. BitArray blocks;
  13. List<Block::Id> map;
  14. public:
  15. Map(int length, Block::Id id);
  16. Block::Id get(int index) const;
  17. void set(int index, Block::Id id);
  18. };
  19. List<UniquePointer<Map>> maps;
  20. static constexpr int SEGMENT_BITS = 4;
  21. static constexpr int SEGMENT_MASK = (1 << SEGMENT_BITS) - 1;
  22. public:
  23. static constexpr int SEGMENT = 1 << SEGMENT_BITS;
  24. BlockStorage(int sizeBits, int heightBits);
  25. Block::Id get(int x, int y, int z) const;
  26. void set(int x, int y, int z, Block::Id id);
  27. int getSize() const;
  28. int getHeight() const;
  29. };
  30. #endif