Started on CollisionSystem and TriggerSystem. Moved collision code to Collision folder.
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef CollisionSystem_h__
|
||||||
|
#define CollisionSystem_h__
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glm/common.hpp>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
|
||||||
|
class CollisionSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CollisionSystem(EventBroker* eventBroker)
|
||||||
|
: System(eventBroker, "AABB")
|
||||||
|
{
|
||||||
|
//TODO: Debug stuff, remove later.
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &CollisionSystem::OnKeyUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
EventRelay<CollisionSystem, Events::KeyUp> m_EKeyUp;
|
||||||
|
bool OnKeyUp(const Events::KeyUp &event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef Events_TriggerEnter_h__
|
||||||
|
#define Events_TriggerEnter_h__
|
||||||
|
|
||||||
|
#include "../Core/EventBroker.h"
|
||||||
|
#include "../Core/Entity.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Thrown once, when an entity is completely inside a trigger. */
|
||||||
|
struct TriggerTouch : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that touches the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Thrown once, when an entity has completely left a trigger. */
|
||||||
|
struct TriggerLeave : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that left the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Thrown when an entity is completely inside a trigger. */
|
||||||
|
struct TriggerEnter : Event
|
||||||
|
{
|
||||||
|
/** The id of the entity that entered the trigger. */
|
||||||
|
EntityID Entity;
|
||||||
|
/** The id of the trigger entity. */
|
||||||
|
EntityID Trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef PlayerSystem_h__
|
||||||
|
#define PlayerSystem_h__
|
||||||
|
|
||||||
|
#include <glm/common.hpp>
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "ETrigger.h"
|
||||||
|
|
||||||
|
class TriggerSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TriggerSystem(EventBroker* eventBroker)
|
||||||
|
: System(eventBroker, "Trigger")
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,4 +6,6 @@
|
|||||||
<xs:include schemaLocation="Components/Test.xsd"/>
|
<xs:include schemaLocation="Components/Test.xsd"/>
|
||||||
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Player.xsd"/>
|
<xs:include schemaLocation="Components/Player.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/AABB.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/Trigger.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<c:AABB>
|
||||||
|
<BoxCenter X="0" Y="0" Z="0"/>
|
||||||
|
<BoxSize X="1" Y="1" Z="1"/>
|
||||||
|
</c:AABB>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="AABB">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="BoxCenter" type="t:Vector" minOccurs="0"/>
|
||||||
|
<xs:element name="BoxSize" type="t:Vector" minOccurs="0"/>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<c:Trigger>
|
||||||
|
</c:Trigger>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="Trigger">
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "Collision/CollisionSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
void CollisionSystem::Update(World * world, ComponentWrapper & collision, double dt)
|
||||||
|
{
|
||||||
|
m_EventBroker->Process<CollisionSystem>();
|
||||||
|
(glm::vec3&)collision["Center"] = (glm::vec3)world->GetComponent(collision.EntityID, "Transform")["Position"];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CollisionSystem::OnKeyUp(const Events::KeyUp & event)
|
||||||
|
{
|
||||||
|
if (event.KeyCode == GLFW_KEY_Z) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include "Collision/TriggerSystem.h"
|
||||||
|
#include "Core/AABB.h"
|
||||||
|
|
||||||
|
void TriggerSystem::Update(World* world, ComponentWrapper& trigger, double dt)
|
||||||
|
{
|
||||||
|
auto players = world->GetComponents("Player");
|
||||||
|
if (players == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//WTODO: Assumes box exists.
|
||||||
|
ComponentWrapper& cBox = world->GetComponent(trigger.EntityID, "AABB");
|
||||||
|
AABB aabb;
|
||||||
|
aabb.CreateFromCenter(cBox["BoxCenter"], cBox["BoxSize"]);
|
||||||
|
for (auto& c : *players) {
|
||||||
|
|
||||||
|
Events::TriggerEnter e;
|
||||||
|
e.Trigger = trigger.EntityID;
|
||||||
|
e.Entity = 41;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+2
-2
@@ -1,4 +1,5 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "Collision/TriggerSystem.h"
|
||||||
|
|
||||||
Game::Game(int argc, char* argv[])
|
Game::Game(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
@@ -46,8 +47,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
||||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
m_SystemPipeline->AddSystem<PlayerSystem>();
|
||||||
|
m_SystemPipeline->AddSystem<TriggerSystem>();
|
||||||
|
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user