EntityWrapper to uniquely identify entities and make using them a little easier

This commit is contained in:
2016-01-14 15:43:19 +01:00
parent 28392def79
commit d34470256b
20 changed files with 106 additions and 72 deletions
@@ -15,7 +15,7 @@ public:
{ }
virtual void Update(World* world, double dt) override;
virtual void UpdateComponent(World* world, ComponentWrapper& component, double dt) override;
virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt) override;
private:
Octree* m_Octree;
+2 -1
View File
@@ -13,6 +13,7 @@
#include "../Rendering/RawModel.h"
#include "../Rendering/RenderQueueFactory.h"
#include "../Core/Entity.h"
#include "../Core/EntityWrapper.h"
class World;
struct ComponentWrapper;
@@ -59,7 +60,7 @@ bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation);
bool IsSameBoxProbably(const AABB& first, const AABB& second, const float epsilon = 0.0001f);
// Calculates an absolute AABB from an entity AABB component
boost::optional<AABB> EntityAbsoluteAABB(World* world, EntityID entity);
boost::optional<AABB> EntityAbsoluteAABB(EntityWrapper& entity);
}
+1 -1
View File
@@ -23,7 +23,7 @@ public:
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &CollisionSystem::OnKeyUp);
}
virtual void UpdateComponent(World* world, ComponentWrapper& cAABB, double dt) override;
virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt) override;
private:
Octree* m_Octree;
+1 -1
View File
@@ -20,7 +20,7 @@ public:
, m_Octree(octree)
{ }
virtual void UpdateComponent(World* world, ComponentWrapper& collision, double dt) override;
virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt) override;
private:
Octree* m_Octree;
-17
View File
@@ -4,22 +4,5 @@
typedef unsigned int EntityID;
const static unsigned int EntityID_Invalid = -1;
class World;
struct EntityWrapper
{
EntityWrapper(::World* world, EntityID id)
: World(world)
, ID(id)
{ }
::World* World;
EntityID ID;
bool operator==(const EntityWrapper& e)
{
return (this->World == e.World) && (this->ID == e.ID);
}
operator EntityID() { return this->ID; }
};
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef EntityWrapper_h__
#define EntityWrapper_h__
#include <boost/optional.hpp>
#include "ComponentWrapper.h"
class World;
struct EntityWrapper
{
EntityWrapper(::World* world, EntityID id)
: World(world)
, ID(id)
{ }
::World* World;
EntityID ID;
bool HasComponent(const std::string& componentName);
ComponentWrapper operator[](const std::string& componentName);
bool operator==(const EntityWrapper& e);
explicit operator EntityID();
};
#endif
+2 -1
View File
@@ -3,6 +3,7 @@
#include "EventBroker.h"
#include "World.h"
#include "EntityWrapper.h"
#include "ComponentWrapper.h"
class System
@@ -33,7 +34,7 @@ protected:
const std::string m_ComponentType;
virtual void UpdateComponent(World* world, ComponentWrapper& component, double dt) = 0;
virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt) = 0;
};
class ImpureSystem : public virtual System
+1 -1
View File
@@ -68,7 +68,7 @@ public:
}
for (auto& component : *pool) {
for (auto& system : systems) {
system->UpdateComponent(world, component, dt);
system->UpdateComponent(world, EntityWrapper(world, component.EntityID), component, dt);
}
}
}