]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Entity.hpp
reference count entities for safer removal
[blank.git] / src / world / Entity.hpp
index ae14297bb0baf282a3ddef142285a262a95c11b6..ef5e4e32eb92ce4667e233d85f3b485a3aeffcf6 100644 (file)
@@ -61,8 +61,12 @@ public:
        glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept;
        Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
 
-       void Remove() noexcept { remove = true; }
-       bool CanRemove() const noexcept { return remove; }
+       void Ref() noexcept { ++ref_count; }
+       void UnRef() noexcept { --ref_count; }
+       void Kill() noexcept { dead = true; }
+       bool Referenced() const noexcept { return ref_count > 0; }
+       bool Dead() const noexcept { return dead; }
+       bool CanRemove() const noexcept { return dead && ref_count <= 0; }
 
        void Update(int dt) noexcept;
 
@@ -82,8 +86,10 @@ private:
 
        glm::vec3 angular_velocity;
 
+       int ref_count;
+
        bool world_collision;
-       bool remove;
+       bool dead;
 
 };