add entity library
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
#define OBJECTS_ENTITIES_HPP_
|
||||
|
||||
#include "../typedefs.hpp"
|
||||
#include "../physics/Hitbox.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <glm/glm.hpp>
|
||||
#include <unordered_map>
|
||||
#include <entt/entity/registry.hpp>
|
||||
@@ -28,9 +30,9 @@ class Rig;
|
||||
|
||||
class Entity {
|
||||
entt::registry& registry;
|
||||
entt::entity entity;
|
||||
const entt::entity entity;
|
||||
public:
|
||||
Entity(entt::registry& registry, entt::entity entity)
|
||||
Entity(entt::registry& registry, const entt::entity entity)
|
||||
: registry(registry), entity(entity) {}
|
||||
|
||||
bool isValid() const {
|
||||
@@ -41,6 +43,10 @@ public:
|
||||
return registry.get<Transform>(entity);
|
||||
}
|
||||
|
||||
Hitbox& getHitbox() const {
|
||||
return registry.get<Hitbox>(entity);
|
||||
}
|
||||
|
||||
entityid_t getUID() const {
|
||||
return registry.get<EntityId>(entity).uid;
|
||||
}
|
||||
@@ -50,12 +56,21 @@ class Entities {
|
||||
entt::registry registry;
|
||||
Level* level;
|
||||
std::unordered_map<entityid_t, entt::entity> entities;
|
||||
entityid_t nextID = 1;
|
||||
public:
|
||||
Entities(Level* level);
|
||||
void updatePhysics(float delta);
|
||||
void render(Assets* assets, ModelBatch& batch, Frustum& frustum);
|
||||
|
||||
void drop(glm::vec3 pos, glm::vec3 vel);
|
||||
entityid_t drop(glm::vec3 pos);
|
||||
|
||||
std::optional<Entity> get(entityid_t id) {
|
||||
const auto& found = entities.find(id);
|
||||
if (found != entities.end()) {
|
||||
return Entity(registry, found->second);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OBJECTS_ENTITIES_HPP_
|
||||
|
||||
Reference in New Issue
Block a user