TriggerSystem implemented and working.

This commit is contained in:
William Moberg
2015-12-16 12:22:15 +01:00
parent 99b76d7ae1
commit d10df6ae09
5 changed files with 75 additions and 54 deletions
+8
View File
@@ -6,6 +6,10 @@
#include "Core/Ray.h"
#include "Core/AABB.h"
#include "Engine/Rendering/RawModel.h"
#include "Core/Entity.h"
class World;
struct ComponentWrapper;
namespace Collision
{
@@ -39,6 +43,10 @@ bool RayVsModel(const Ray& ray,
bool AABBVsAABB(const AABB& a, const AABB& b);
bool IsSameBoxProbably(const AABB& first, const AABB& second, const float epsilon = 0.0001f);
//Returns true if the entity has a boundingbox. Outputs the aabb in [outBox].
bool GetEntityBox(World* world, EntityID entity, AABB& outBox, bool forceBoxFromModel = false);
bool GetEntityBox(World* world, ComponentWrapper& AABBComponent, AABB& outBox);
}
#endif
+3 -5
View File
@@ -10,23 +10,21 @@
class AABB;
class TriggerSystem : public System
class TriggerSystem : public PureSystem
{
public:
TriggerSystem(EventBroker* eventBroker)
: System(eventBroker, "Trigger")
: PureSystem(eventBroker, "Trigger")
{}
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
virtual void UpdateComponent(World* world, ComponentWrapper& collision, double dt) override;
private:
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesTouchingTrigger;
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesCompletelyInTrigger;
bool getEntityBox(World* world, EntityID id, AABB& outBox);
//True if leave event was thrown.
bool throwLeaveIfWasInTrigger(std::unordered_set<EntityID>& triggerSet, EntityID pId, EntityID tId);
void attachAABBComponentFromModel(World* world, EntityID id);
template<typename Event>
void publish(EntityID pId, EntityID tId)
{