]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Entity.hpp
give unique IDs to entities
[blank.git] / src / world / Entity.hpp
index ae14297bb0baf282a3ddef142285a262a95c11b6..c0d9a0bd858159bbd969f225d15abf16f689fa92 100644 (file)
@@ -2,9 +2,10 @@
 #define BLANK_WORLD_ENTITY_HPP_
 
 #include "Chunk.hpp"
-#include "../model/CompositeModel.hpp"
+#include "../model/CompositeInstance.hpp"
 #include "../model/geometry.hpp"
 
+#include <cstdint>
 #include <string>
 #include <glm/glm.hpp>
 #include <glm/gtc/quaternion.hpp>
@@ -20,8 +21,11 @@ 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; }
+
+       std::uint32_t ID() const noexcept { return id; }
+       void ID(std::uint32_t i) noexcept { id = i; }
 
        const std::string &Name() const noexcept { return name; }
        void Name(const std::string &n) { name = n; }
@@ -61,18 +65,23 @@ 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::uint32_t id;
        std::string name;
 
        AABB bounds;
@@ -82,8 +91,10 @@ private:
 
        glm::vec3 angular_velocity;
 
+       int ref_count;
+
        bool world_collision;
-       bool remove;
+       bool dead;
 
 };