}
+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);
(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]; }
, stretch(64.0f)
, solid_threshold(0.8f)
, space(0)
+, light(0)
, solids() {
}
}
}
}
+ 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();
}
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;
- SimplexNoise typeNoise;
+ WorleyNoise typeNoise;
float stretch;
float solid_threshold;
Block::Type space;
+ Block::Type light;
std::vector<Block::Type> solids;
};
}
generate.Space(0);
+ generate.Light(13);
generate.Solids({ 1, 4, 7, 10 });
player = &AddEntity();