]> git.localhorst.tv Git - blank.git/blobdiff - src/chunk.cpp
limit chunks allocated/freed per frame
[blank.git] / src / chunk.cpp
index e928a2199b80b2c007ef27d89446e9b41347fb85..483a4e5cd78ccea1f4722deb31ead2f3cfff0e4a 100644 (file)
@@ -7,9 +7,9 @@
 namespace blank {
 
 Chunk::Chunk()
-: blocks(Size())
+: blocks()
 , model()
-, transform(1.0f)
+, position(0, 0, 0)
 , dirty(false) {
 
 }
@@ -17,7 +17,6 @@ Chunk::Chunk()
 Chunk::Chunk(Chunk &&other)
 : blocks(std::move(other.blocks))
 , model(std::move(other.model))
-, transform(other.transform)
 , dirty(other.dirty) {
 
 }
@@ -25,12 +24,16 @@ Chunk::Chunk(Chunk &&other)
 Chunk &Chunk::operator =(Chunk &&other) {
        blocks = std::move(other.blocks);
        model = std::move(other.model);
-       transform = other.transform;
        dirty = other.dirty;
        return *this;
 }
 
 
+void Chunk::Allocate() {
+       blocks.resize(Size());
+}
+
+
 void Chunk::Draw() {
        if (dirty) {
                Update();
@@ -46,8 +49,7 @@ bool Chunk::Intersection(
        float *dist,
        glm::vec3 *normal) const {
        { // rough check
-               const AABB bb{{0, 0, 0}, {Width(), Height(), Depth()}};
-               if (!blank::Intersection(ray, bb, M)) {
+               if (!blank::Intersection(ray, Bounds(), M)) {
                        return false;
                }
        }
@@ -97,9 +99,12 @@ bool Chunk::Intersection(
        return true;
 }
 
-void Chunk::Position(const glm::vec3 &pos) {
+void Chunk::Position(const glm::tvec3<int> &pos) {
        position = pos;
-       transform = glm::translate(pos * Extent());
+}
+
+glm::mat4 Chunk::Transform(const glm::tvec3<int> &offset) const {
+       return glm::translate((position - offset) * Extent());
 }