]> git.localhorst.tv Git - blank.git/commitdiff
add some light blocks to generated surfaces
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 18 Mar 2015 18:48:58 +0000 (19:48 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 18 Mar 2015 18:48:58 +0000 (19:48 +0100)
src/chunk.cpp
src/chunk.hpp
src/generator.cpp
src/generator.hpp
src/world.cpp

index 81c8698db803dbcc3a1e99a4ebe1a9226bf15976..51694221b8a1c4acb359feb3a7b05ca5efe5024e 100644 (file)
@@ -263,6 +263,21 @@ int Chunk::GetLight(int index) const {
 }
 
 
 }
 
 
+bool Chunk::IsSurface(const Pos &pos) const {
+       const Block &block = BlockAt(pos);
+       if (!Type(block).visible) {
+               return false;
+       }
+       for (int face = 0; face < Block::FACE_COUNT; ++face) {
+               const Block *next = FindNext(pos, Block::Face(face));
+               if (!next || !Type(*next).visible) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+
 void Chunk::Allocate() {
        blocks.resize(Size(), Block(0));
        light.resize(Size(), 0);
 void Chunk::Allocate() {
        blocks.resize(Size(), Block(0));
        light.resize(Size(), 0);
index 7e720bd84c5b49945f7dc7a45e6b2f0f1af9d699..c7bcd2ffe7313e5c2c1542f2b13b4962c5f8fd10 100644 (file)
@@ -76,6 +76,10 @@ public:
                        (idx / Width()) % Height() == Height() - 1;    // high Y plane
        }
 
                        (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]; }
        void SetNeighbor(Chunk &);
        bool HasNeighbor(Block::Face f) const { return neighbor[f]; }
        Chunk &GetNeighbor(Block::Face f) { return *neighbor[f]; }
index f701230de014a4fee02e0ea372e810c4e694d149..c1a7a0801198de34e3a4b8b3d0bdddd70f334ba4 100644 (file)
@@ -11,6 +11,7 @@ Generator::Generator(unsigned int seed)
 , stretch(64.0f)
 , solid_threshold(0.8f)
 , space(0)
 , stretch(64.0f)
 , solid_threshold(0.8f)
 , space(0)
+, light(0)
 , solids() {
 
 }
 , solids() {
 
 }
@@ -35,6 +36,15 @@ void Generator::operator ()(Chunk &chunk) const {
                        }
                }
        }
                        }
                }
        }
+       unsigned int random = 263167 * pos.x + 2097593 * pos.y + 426389 * pos.z;
+       for (int index = 0; index < Chunk::Size(); ++index) {
+               if (chunk.IsSurface(index)) {
+                       random = random * 666649 + 7778777;
+                       if ((random % 32) == 0) {
+                               chunk.SetBlock(index, Block(light));
+                       }
+               }
+       }
        chunk.Invalidate();
        chunk.CheckUpdate();
 }
        chunk.Invalidate();
        chunk.CheckUpdate();
 }
index 9dc39cb54a30bbdd19d59ab79506898472c6c523..b3e8ffb0ad2f55045986eaca85d95d365fa80722 100644 (file)
@@ -18,16 +18,18 @@ public:
        void operator ()(Chunk &) const;
 
        void Space(Block::Type t) { space = t; }
        void operator ()(Chunk &) const;
 
        void Space(Block::Type t) { space = t; }
+       void Light(Block::Type t) { light = t; }
        void Solids(const std::vector<Block::Type> &s) { solids = s; }
 
 private:
        SimplexNoise solidNoise;
        void Solids(const std::vector<Block::Type> &s) { solids = s; }
 
 private:
        SimplexNoise solidNoise;
-       SimplexNoise typeNoise;
+       WorleyNoise typeNoise;
 
        float stretch;
        float solid_threshold;
 
        Block::Type space;
 
        float stretch;
        float solid_threshold;
 
        Block::Type space;
+       Block::Type light;
        std::vector<Block::Type> solids;
 
 };
        std::vector<Block::Type> solids;
 
 };
index f0d96f8d4e931f87077f47607d77d003322f2150..e4e382642be47a7b225d1abc33ad90a0d1889501 100644 (file)
@@ -103,6 +103,7 @@ World::World()
        }
 
        generate.Space(0);
        }
 
        generate.Space(0);
+       generate.Light(13);
        generate.Solids({ 1, 4, 7, 10 });
 
        player = &AddEntity();
        generate.Solids({ 1, 4, 7, 10 });
 
        player = &AddEntity();