1234567891011121314151617181920212223242526272829 |
- #include "common/world/BlockMap.h"
- static constexpr BlockId EMPTY_BLOCK = 65535;
- BlockMap::BlockMap(int length, BlockId id) : blocks(length, 1), map(2, EMPTY_BLOCK) {
- map[0] = id;
- }
- BlockId BlockMap::get(int index) const {
- return map[blocks.get(index)];
- }
- void BlockMap::set(int index, BlockId id) {
- for(int i = 0; i < map.getLength(); i++) {
- if(map[i] == id) {
- blocks.set(index, i);
- return;
- } else if(map[i] == EMPTY_BLOCK) {
- map[i] = id;
- blocks.set(index, i);
- return;
- }
- }
- blocks.resize(blocks.getBits() + 1);
- int i = map.getLength();
- map.grow(map.getLength(), EMPTY_BLOCK);
- map[i] = id;
- blocks.set(index, i);
- }
|