diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-03 11:23:54 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-03 11:23:54 +0100 |
commit | 75cf0b8e72aff7072c25ab015ce5c9c64eb3ecc5 (patch) | |
tree | dd459130f169a924db0637146d31ed20aaa10d74 /mwe/events/include | |
parent | ed8534e2d150428bcbc4a6df8940323ae8db2925 (diff) | |
parent | 6aa8fdd04728b6a499f526de727514ae3d0490b4 (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/events-poc
Diffstat (limited to 'mwe/events/include')
-rw-r--r-- | mwe/events/include/customTypes.h | 55 | ||||
-rw-r--r-- | mwe/events/include/event.h | 10 | ||||
-rw-r--r-- | mwe/events/include/eventManager.h | 12 |
3 files changed, 40 insertions, 37 deletions
diff --git a/mwe/events/include/customTypes.h b/mwe/events/include/customTypes.h index 7217f8a..a5d8dc9 100644 --- a/mwe/events/include/customTypes.h +++ b/mwe/events/include/customTypes.h @@ -1,39 +1,38 @@ #pragma once #include <cmath> struct Vector2 { - float x; // X component of the vector - float y; // Y component of the vector + float x; // X component of the vector + float y; // Y component of the vector - // Vector subtraction - Vector2 operator-(const Vector2& other) const { - return {x - other.x, y - other.y}; - } + // Vector subtraction + Vector2 operator-(const Vector2 & other) const { + return {x - other.x, y - other.y}; + } - // Vector addition - Vector2 operator+(const Vector2& other) const { - return {x + other.x, y + other.y}; - } + // Vector addition + Vector2 operator+(const Vector2 & other) const { + return {x + other.x, y + other.y}; + } - // Scalar multiplication - Vector2 operator*(float scalar) const { - return {x * scalar, y * scalar}; - } + // Scalar multiplication + Vector2 operator*(float scalar) const { return {x * scalar, y * scalar}; } - // Normalize the vector - Vector2 normalize() const { - float length = std::sqrt(x * x + y * y); - if (length == 0) return {0, 0}; // Prevent division by zero - return {x / length, y / length}; - } + // Normalize the vector + Vector2 normalize() const { + float length = std::sqrt(x * x + y * y); + if (length == 0) return {0, 0}; // Prevent division by zero + return {x / length, y / length}; + } }; struct Collision { - int objectIdA; // ID of the first object - int objectIdB; // ID of the second object - Vector2 contactPoint; // Point of contact - Vector2 contactNormal; // Normal vector at the contact point - - // Constructor to initialize a Collision - Collision(int idA, int idB, const Vector2& point, const Vector2& normal, float depth) - : objectIdA(idA), objectIdB(idB), contactPoint(point), contactNormal(normal) {} + int objectIdA; // ID of the first object + int objectIdB; // ID of the second object + Vector2 contactPoint; // Point of contact + Vector2 contactNormal; // Normal vector at the contact point + // Constructor to initialize a Collision + Collision(int idA, int idB, const Vector2 & point, const Vector2 & normal, + float depth) + : objectIdA(idA), objectIdB(idB), contactPoint(point), + contactNormal(normal) {} }; diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index b1b6867..62d8974 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -1,4 +1,5 @@ #pragma once +#include "customTypes.h" #include "keyCodes.h" #include <cstdint> #include <iostream> @@ -129,15 +130,14 @@ private: }; class CollisionEvent : public Event { public: - CollisionEvent(Collision); + CollisionEvent(Collision); - REGISTER_EVENT_TYPE(CollisionEvent) + REGISTER_EVENT_TYPE(CollisionEvent) - Collision getCollisionData() const; + Collision getCollisionData() const; private: - Collision collisionData; - + Collision collisionData; }; class TextSubmitEvent : public Event { public: diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h index 61e8c01..508a5e2 100644 --- a/mwe/events/include/eventManager.h +++ b/mwe/events/include/eventManager.h @@ -28,10 +28,14 @@ public: void dispatchEvents(); private: - EventManager() = default; - std::vector<std::pair<std::unique_ptr<Event>, int>> eventsQueue; - std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> subscribers; - std::unordered_map<int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>> subscribersByEventId; + EventManager() = default; + std::vector<std::pair<std::unique_ptr<Event>, int>> eventsQueue; + std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> + subscribers; + std::unordered_map< + int, std::unordered_map< + int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>> + subscribersByEventId; }; template <typename EventType> |