]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Entity.hpp
split composite model in template and instance
[blank.git] / src / world / Entity.hpp
index ae14297bb0baf282a3ddef142285a262a95c11b6..a3811427332628250761bad32210bc64103ea9de 100644 (file)
@@ -2,7 +2,7 @@
 #define BLANK_WORLD_ENTITY_HPP_
 
 #include "Chunk.hpp"
-#include "../model/CompositeModel.hpp"
+#include "../model/CompositeInstance.hpp"
 #include "../model/geometry.hpp"
 
 #include <string>
@@ -20,8 +20,8 @@ class Entity {
 public:
        Entity() noexcept;
 
-       CompositeModel &GetModel() noexcept { return model; }
-       const CompositeModel &GetModel() const noexcept { return model; }
+       CompositeInstance &GetModel() noexcept { return model; }
+       const CompositeInstance &GetModel() const noexcept { return model; }
 
        const std::string &Name() const noexcept { return name; }
        void Name(const std::string &n) { name = n; }
@@ -61,17 +61,21 @@ 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;
 
        void Render(const glm::mat4 &M, DirectionalLighting &prog) noexcept {
-               model.Render(M, prog);
+               if (model) model.Render(M, prog);
        }
 
 private:
-       CompositeModel model;
+       CompositeInstance model;
 
        std::string name;
 
@@ -82,8 +86,10 @@ private:
 
        glm::vec3 angular_velocity;
 
+       int ref_count;
+
        bool world_collision;
-       bool remove;
+       bool dead;
 
 };