123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #ifndef BLOCKSTORAGE_H
- #define BLOCKSTORAGE_H
- #include "common/block/BlockTypes.h"
- #include "common/world/BlockMap.h"
- template<int S, int H>
- class BlockStorage final {
- static constexpr int SIZE = 1 << S;
- static constexpr int HEIGHT = 1 << H;
- static constexpr int SIZE_MASK = SIZE - 1;
- BlockMap<SIZE * SIZE * HEIGHT, 1> data;
- public:
- BlockStorage() : data(0) {
- }
- BlockId get(int x, int y, int z) const {
- if(y < 0 || y >= HEIGHT) {
- return 0;
- }
- x &= SIZE_MASK;
- z &= SIZE_MASK;
- return data.get(x * SIZE * SIZE + y * SIZE + z);
- }
- void set(int x, int y, int z, BlockId id) {
- data.set(x * SIZE * SIZE + y * SIZE + z, id);
- }
- constexpr int getSize() const {
- return SIZE;
- }
- constexpr int getHeight() const {
- return HEIGHT;
- }
- };
- #endif
|