WIP ECS GUI
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef Events_CastRay_h__
|
||||||
|
#define Events_CastRay_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct CastRay : Event
|
||||||
|
{
|
||||||
|
glm::vec3 Direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_CastRay_h__
|
||||||
@@ -9,6 +9,7 @@ namespace Events
|
|||||||
struct MousePress : Event
|
struct MousePress : Event
|
||||||
{
|
{
|
||||||
int Button;
|
int Button;
|
||||||
|
double X, Y;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Events
|
|||||||
struct MouseRelease : Event
|
struct MouseRelease : Event
|
||||||
{
|
{
|
||||||
int Button;
|
int Button;
|
||||||
|
double X, Y;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef Events_RayIntersection_h__
|
||||||
|
#define Events_RayIntersection_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct RayIntersection : Event
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_RayIntersection_h__
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
#include "Util/Rectangle.h"
|
#include "Util/Rectangle.h"
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
// HACK: Decouple renderer plz
|
||||||
|
#include "Renderer.h"
|
||||||
|
|
||||||
namespace GUI
|
namespace GUI
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -31,17 +34,41 @@ public:
|
|||||||
{ SetParent(parent); Initialize(); }
|
{ SetParent(parent); Initialize(); }
|
||||||
|
|
||||||
virtual void Initialize() { }
|
virtual void Initialize() { }
|
||||||
|
|
||||||
std::shared_ptr<Frame> Parent() const { return m_Parent; }
|
std::shared_ptr<Frame> Parent() const { return m_Parent; }
|
||||||
void SetParent(std::shared_ptr<Frame> parent)
|
void SetParent(std::shared_ptr<Frame> parent)
|
||||||
{
|
{
|
||||||
|
parent->AddChild(std::shared_ptr<Frame>(this));
|
||||||
m_Parent = parent;
|
m_Parent = parent;
|
||||||
EventBroker = parent->EventBroker;
|
EventBroker = parent->EventBroker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddChild(std::shared_ptr<Frame> child)
|
||||||
|
{
|
||||||
|
m_Children.push_back(child);
|
||||||
|
if (m_Parent != nullptr)
|
||||||
|
{
|
||||||
|
m_Parent->AddChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
|
||||||
|
FrameChildrenIterator begin()
|
||||||
|
{
|
||||||
|
return m_Children.begin();
|
||||||
|
}
|
||||||
|
FrameChildrenIterator end()
|
||||||
|
{
|
||||||
|
return m_Children.end();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void Update(double dt) { }
|
virtual void Update(double dt) { }
|
||||||
|
virtual void Draw(Renderer* renderer) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<::EventBroker> EventBroker;
|
std::shared_ptr<::EventBroker> EventBroker;
|
||||||
std::shared_ptr<Frame> m_Parent;
|
std::shared_ptr<Frame> m_Parent;
|
||||||
|
std::list<std::shared_ptr<Frame>> m_Children;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,17 +36,23 @@ void InputManager::Update(double dt)
|
|||||||
m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i);
|
m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i);
|
||||||
if (m_CurrentMouseState[i] != m_LastMouseState[i])
|
if (m_CurrentMouseState[i] != m_LastMouseState[i])
|
||||||
{
|
{
|
||||||
|
double x, y;
|
||||||
|
glfwGetCursorPos(m_GLFWWindow, &x, &y);
|
||||||
// Publish mouse button events
|
// Publish mouse button events
|
||||||
if (m_CurrentMouseState[i])
|
if (m_CurrentMouseState[i])
|
||||||
{
|
{
|
||||||
Events::MousePress e;
|
Events::MousePress e;
|
||||||
e.Button = i;
|
e.Button = i;
|
||||||
|
e.X = x;
|
||||||
|
e.Y = y;
|
||||||
m_EventBroker->Publish<Events::MousePress>(e);
|
m_EventBroker->Publish<Events::MousePress>(e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Events::MouseRelease e;
|
Events::MouseRelease e;
|
||||||
e.Button = i;
|
e.Button = i;
|
||||||
|
e.X = x;
|
||||||
|
e.Y = y;
|
||||||
m_EventBroker->Publish<Events::MouseRelease>(e);
|
m_EventBroker->Publish<Events::MouseRelease>(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "RaySystem.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
void Systems::RaySystem::Initialize()
|
||||||
|
{
|
||||||
|
// Subscribe to events
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ECastRay, &Systems::RaySystem::OnCastRay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::RaySystem::Update(double dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::RaySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Systems::RaySystem::OnCastRay(const Events::CastRay &event)
|
||||||
|
{
|
||||||
|
Ray r;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef DebugSystem_h__
|
||||||
|
#define DebugSystem_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Events/CastRay.h"
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class RaySystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RaySystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
|
void Update(double dt) override;
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Ray
|
||||||
|
{
|
||||||
|
glm::vec3 Direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
EventRelay<Events::CastRay> m_ECastRay;
|
||||||
|
bool OnCastRay(const Events::CastRay &event);
|
||||||
|
|
||||||
|
std::list<Ray> m_UnresolvedRays;
|
||||||
|
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // DebugSystem_h__
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "World.h"
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
// A slower wrapper class for EntityID to make
|
||||||
|
// creation of pre-defined entity hierarchies easier
|
||||||
|
class EntityGroup
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EntityGroup(World* world, EntityID parent = 0)
|
||||||
|
: World(world)
|
||||||
|
, EventBroker(world->EventBroker())
|
||||||
|
{
|
||||||
|
m_ID = World->CreateEntity(parent);
|
||||||
|
Initialize();
|
||||||
|
World->CommitEntity(m_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
~EntityGroup()
|
||||||
|
{
|
||||||
|
World->RemoveEntity(m_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Initialize() { }
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
std::shared_ptr<T> AddComponent(std::string componentType)
|
||||||
|
{
|
||||||
|
return World->AddComponent<T>(m_ID, componentType);
|
||||||
|
}
|
||||||
|
std::shared_ptr<Component> AddComponent(std::string componentType)
|
||||||
|
{
|
||||||
|
return World->AddComponent(m_ID, componentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator EntityID () const { return m_ID; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
EntityID m_ID;
|
||||||
|
::World* World;
|
||||||
|
std::shared_ptr<::EventBroker> EventBroker;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user