aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-25 20:57:31 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-25 20:57:31 +0200
commitebd163e3aacac74df1772d5bd794d2691918d324 (patch)
tree7c71dfd6afa29a777018e5c804dff15c2a0f6ec2 /mwe/events/include
parentb5e83d076f356c6d01b7bbc1f033db4850356c0d (diff)
collision event added, multiple callbacks working, id trigger working
Diffstat (limited to 'mwe/events/include')
-rw-r--r--mwe/events/include/customTypes.h39
-rw-r--r--mwe/events/include/event.h13
-rw-r--r--mwe/events/include/eventManager.h6
-rw-r--r--mwe/events/include/userevent.h0
4 files changed, 55 insertions, 3 deletions
diff --git a/mwe/events/include/customTypes.h b/mwe/events/include/customTypes.h
new file mode 100644
index 0000000..7217f8a
--- /dev/null
+++ b/mwe/events/include/customTypes.h
@@ -0,0 +1,39 @@
+#pragma once
+#include <cmath>
+struct Vector2 {
+ 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 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};
+ }
+
+ // 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) {}
+
+};
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h
index 802140c..d060faa 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -5,6 +5,7 @@
#include <unordered_map>
#include <variant>
#include "keyCodes.h"
+#include "customTypes.h"
class UUIDGenerator {
public:
@@ -85,3 +86,15 @@ private:
int mouseX = 0;
int mouseY = 0;
};
+class CollisionEvent : public Event {
+public:
+ CollisionEvent(Collision);
+
+ REGISTER_EVENT_TYPE(CollisionEvent)
+
+ Collision getCollisionData() const;
+
+private:
+ Collision collisionData;
+
+};
diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h
index 709796a..b8abccc 100644
--- a/mwe/events/include/eventManager.h
+++ b/mwe/events/include/eventManager.h
@@ -26,9 +26,9 @@ public:
private:
EventManager() = default;
- std::vector<std::pair<std::unique_ptr<Event>, int>> m_eventsQueue;
- std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> m_subscribers;
- std::unordered_map<int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>> m_subscribersByEventId;
+ 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;
};
diff --git a/mwe/events/include/userevent.h b/mwe/events/include/userevent.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mwe/events/include/userevent.h