VoxelEngine
 
Loading...
Searching...
No Matches
IChunkData.h
1#pragma once
2
3#include <glm/glm.hpp>
4#include "../../Globals.h"
5#include "../../block/Block.h"
6#include "../../block/BlockState.h"
7
8#include "../../serialize/ISerializable.h"
9
10
11namespace engine {
12 class MultiBlock;
13
17 class IChunkData : public ISerializable {
18 public:
19 glm::ivec3 dims;
20 bool populated = false;
21
22 virtual ~IChunkData() = default;
23 IChunkData(glm::ivec3 dims) : dims(dims) {}
24
25 void serialize(std::ostream& out) const override = 0;
26 void deserialize(std::istream& in) override = 0;
27
29 virtual BlockID getBlock(const glm::ivec3& pos) const = 0;
30 virtual MultiBlock* getMultiBlock(const glm::ivec3& pos) = 0;
31
32 virtual void setBlock(const glm::ivec3& pos, BlockID block) = 0;
33 virtual void setBlock(const glm::ivec3& pos, BlockID block, BlockState state) = 0;
34 virtual void setMultiBlock(const glm::ivec3& pos, MultiBlock&& multiBlock) = 0;
35
36
38 virtual BlockState* getState(const glm::ivec3& pos) = 0;
39 virtual const BlockState* getState(const glm::ivec3& pos) const = 0;
40 virtual BlockState* getOrCreateState(const glm::ivec3& pos) = 0;
41
42 virtual void setState(const glm::ivec3& pos, BlockState&& state) = 0;
43 virtual void clearState(const glm::ivec3& pos) = 0;
44
46 void clear(const glm::ivec3& pos) {
47 setBlock(pos, Block::AirID);
48 clearState(pos);
49 // TODO clear multiblock somehow
50 }
51
52 bool isEmpty(const glm::ivec3& pos) const { return getBlock(pos) == Block::AirID; }
53
54 BlockID getBlockAndState(const glm::ivec3& pos, BlockState*& state) {
55 state = getState(pos);
56 return getBlock(pos);
57 }
58
59 BlockID getBlockAndState(const glm::ivec3& pos, const BlockState*& state) const {
60 state = getState(pos);
61 return getBlock(pos);
62 }
63
64 BlockID getAll(const glm::ivec3& pos, BlockState*& state, MultiBlock*& multiBlock) {
65 state = getState(pos);
66 multiBlock = getMultiBlock(pos);
67 return getBlock(pos);
68 }
69 };
70} // namespace engine
Definition BlockState.h:17
static constexpr BlockID AirID
Reserved block ID range: 0-8 (inclusive).
Definition Block.h:38
Interface for chunk data representation.
Definition IChunkData.h:17
void clear(const glm::ivec3 &pos)
Definition IChunkData.h:46
virtual BlockID getBlock(const glm::ivec3 &pos) const =0
virtual BlockState * getState(const glm::ivec3 &pos)=0
Definition ISerializable.h:6
A MultiBlock represents multiple blocks at the same position.
Definition MultiBlock.h:19