diff --git a/src/Events/CastRay.h b/src/Events/CastRay.h new file mode 100644 index 0000000..adaba7f --- /dev/null +++ b/src/Events/CastRay.h @@ -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__ \ No newline at end of file diff --git a/src/Events/MousePress.h b/src/Events/MousePress.h index 3116edb..75b31d7 100644 --- a/src/Events/MousePress.h +++ b/src/Events/MousePress.h @@ -9,6 +9,7 @@ namespace Events struct MousePress : Event { int Button; + double X, Y; }; } diff --git a/src/Events/MouseRelease.h b/src/Events/MouseRelease.h index 7249dcd..588b06b 100644 --- a/src/Events/MouseRelease.h +++ b/src/Events/MouseRelease.h @@ -9,6 +9,7 @@ namespace Events struct MouseRelease : Event { int Button; + double X, Y; }; } diff --git a/src/Events/RayIntersection.h b/src/Events/RayIntersection.h new file mode 100644 index 0000000..9b9d74f --- /dev/null +++ b/src/Events/RayIntersection.h @@ -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__ \ No newline at end of file diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index 19f534a..76bf98b 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -6,6 +6,9 @@ #include "Util/Rectangle.h" #include "EventBroker.h" +// HACK: Decouple renderer plz +#include "Renderer.h" + namespace GUI { @@ -31,17 +34,41 @@ public: { SetParent(parent); Initialize(); } virtual void Initialize() { } + std::shared_ptr Parent() const { return m_Parent; } void SetParent(std::shared_ptr parent) { + parent->AddChild(std::shared_ptr(this)); m_Parent = parent; EventBroker = parent->EventBroker; } + + void AddChild(std::shared_ptr child) + { + m_Children.push_back(child); + if (m_Parent != nullptr) + { + m_Parent->AddChild(child); + } + } + + typedef std::list>::const_iterator FrameChildrenIterator; + FrameChildrenIterator begin() + { + return m_Children.begin(); + } + FrameChildrenIterator end() + { + return m_Children.end(); + } + virtual void Update(double dt) { } + virtual void Draw(Renderer* renderer) { } protected: std::shared_ptr<::EventBroker> EventBroker; std::shared_ptr m_Parent; + std::list> m_Children; }; } diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 9f09b1c..c5509c0 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -36,17 +36,23 @@ void InputManager::Update(double dt) m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i); if (m_CurrentMouseState[i] != m_LastMouseState[i]) { + double x, y; + glfwGetCursorPos(m_GLFWWindow, &x, &y); // Publish mouse button events if (m_CurrentMouseState[i]) { Events::MousePress e; e.Button = i; + e.X = x; + e.Y = y; m_EventBroker->Publish(e); } else { Events::MouseRelease e; e.Button = i; + e.X = x; + e.Y = y; m_EventBroker->Publish(e); } } diff --git a/src/Systems/RaySystem.cpp b/src/Systems/RaySystem.cpp new file mode 100644 index 0000000..8f09fe0 --- /dev/null +++ b/src/Systems/RaySystem.cpp @@ -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; +} \ No newline at end of file diff --git a/src/Systems/RaySystem.h b/src/Systems/RaySystem.h new file mode 100644 index 0000000..51010d2 --- /dev/null +++ b/src/Systems/RaySystem.h @@ -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 m_ECastRay; + bool OnCastRay(const Events::CastRay &event); + + std::list m_UnresolvedRays; + //void UpdateEntity(double dt, EntityID entity, EntityID parent) override; +}; + +} +#endif // DebugSystem_h__ \ No newline at end of file diff --git a/vs11/Returngeance/EntityWrapper.h b/vs11/Returngeance/EntityWrapper.h new file mode 100644 index 0000000..37e7ffb --- /dev/null +++ b/vs11/Returngeance/EntityWrapper.h @@ -0,0 +1,44 @@ +#include + +#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 + std::shared_ptr AddComponent(std::string componentType) + { + return World->AddComponent(m_ID, componentType); + } + std::shared_ptr 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; +}; \ No newline at end of file