X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.hpp;h=0b1e5bdec20f79f65971e23234a5d77e04cd2dfd;hb=38abfe4f5342f20b56052ac3090694eabf028d16;hp=7e720bd84c5b49945f7dc7a45e6b2f0f1af9d699;hpb=3072e2cd49ad1614100d1a1c73afe6a4888fb875;p=blank.git diff --git a/src/chunk.hpp b/src/chunk.hpp index 7e720bd..0b1e5bd 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -76,6 +76,10 @@ public: (idx / Width()) % Height() == Height() - 1; // high Y plane } + bool IsSurface(int index) const { return IsSurface(ToPos(index)); } + bool IsSurface(const Block::Pos &pos) const { return IsSurface(Pos(pos)); } + bool IsSurface(const Pos &pos) const; + void SetNeighbor(Chunk &); bool HasNeighbor(Block::Face f) const { return neighbor[f]; } Chunk &GetNeighbor(Block::Face f) { return *neighbor[f]; } @@ -112,6 +116,8 @@ public: int GetLight(const Pos &pos) const { return GetLight(ToIndex(pos)); } int GetLight(const Block::Pos &pos) const { return GetLight(ToIndex(pos)); } + float GetVertexLight(int index, const BlockModel::Position &, const BlockModel::Normal &) const; + bool Intersection( const Ray &ray, const glm::mat4 &M, @@ -142,21 +148,44 @@ private: Chunk *neighbor[Block::FACE_COUNT]; std::vector blocks; std::vector light; - Model model; + BlockModel model; Pos position; bool dirty; }; +struct BlockLookup { + + Chunk *chunk; + Chunk::Pos pos; + const Block *result; + + // resolve chunk/position/block from oob coordinates + // result will be nullptr if unsuccessful + BlockLookup(Chunk *c, const Chunk::Pos &p); + + // resolve chunk/position/block from ib coordinates and direction + // result will be nullptr if unsuccessful + BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face dir); + +}; + + class Generator; class ChunkLoader { public: - ChunkLoader(const BlockTypeRegistry &, const Generator &); + struct Config { + int load_dist = 6; + int unload_dist = 8; + }; + + ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &); void Generate(const Chunk::Pos &from, const Chunk::Pos &to); + void GenerateSurrounding(const Chunk::Pos &); std::list &Loaded() { return loaded; }