]> git.localhorst.tv Git - blank.git/blobdiff - src/chunk.hpp
use light levels for shading of blocks
[blank.git] / src / chunk.hpp
index 7e720bd84c5b49945f7dc7a45e6b2f0f1af9d699..0b1e5bdec20f79f65971e23234a5d77e04cd2dfd 100644 (file)
@@ -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<Block> blocks;
        std::vector<unsigned char> 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<Chunk> &Loaded() { return loaded; }