|
@@ -1,42 +1,25 @@
|
|
|
#ifndef BLOCKSTORAGE_H
|
|
|
#define BLOCKSTORAGE_H
|
|
|
|
|
|
-#include "common/block/BlockTypes.h"
|
|
|
#include "common/world/BlockMap.h"
|
|
|
+#include "gaming-core/memory/UniquePointer.h"
|
|
|
+#include "gaming-core/utils/HeapArray.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;
|
|
|
+ int size;
|
|
|
+ int height;
|
|
|
+ int sizeMask;
|
|
|
|
|
|
- BlockMap<SIZE * SIZE * HEIGHT, 1> data;
|
|
|
+ HeapArray<UniquePointer<BlockMap>> maps;
|
|
|
|
|
|
public:
|
|
|
+ BlockStorage(int sizeBits, int heightBits);
|
|
|
|
|
|
- BlockStorage() : data(0) {
|
|
|
- }
|
|
|
+ BlockId get(int x, int y, int z) const;
|
|
|
+ void set(int x, int y, int z, BlockId id);
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ int getSize() const;
|
|
|
+ int getHeight() const;
|
|
|
};
|
|
|
|
|
|
#endif
|