]> git.localhorst.tv Git - blank.git/blob - src/world/BlockLookup.hpp
increase progress line split to 32 frames
[blank.git] / src / world / BlockLookup.hpp
1 #ifndef BLANK_WORLD_BLOCKLOOKUP_HPP_
2 #define BLANK_WORLD_BLOCKLOOKUP_HPP_
3
4 #include "Block.hpp"
5 #include "Chunk.hpp"
6
7
8 namespace blank {
9
10 class BlockLookup {
11
12 public:
13         /// resolve chunk/position from oob coordinates
14         BlockLookup(Chunk *c, const RoughLocation::Fine &p) noexcept;
15
16         /// resolve chunk/position from ib coordinates and direction
17         BlockLookup(Chunk *c, const RoughLocation::Fine &p, Block::Face dir) noexcept;
18
19         /// check if lookup was successful
20         operator bool() const { return chunk; }
21
22         // only valid if lookup was successful
23         Chunk &GetChunk() const noexcept { return *chunk; }
24         const RoughLocation::Fine &GetBlockPos() const noexcept { return pos; }
25         int GetBlockIndex() const noexcept { return Chunk::ToIndex(pos); }
26         ExactLocation::Fine GetBlockCoords() const noexcept { return Chunk::ToCoords(pos); }
27         const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); }
28         const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
29         int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); }
30
31         void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(GetBlockPos(), b); }
32
33         // traverse in given direction
34         BlockLookup Next(Block::Face f) const { return BlockLookup(chunk, pos, f); }
35
36 private:
37         Chunk *chunk;
38         RoughLocation::Fine pos;
39
40 };
41
42 }
43
44 #endif