aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include
diff options
context:
space:
mode:
Diffstat (limited to 'mwe/events/include')
-rw-r--r--mwe/events/include/customTypes.h39
-rw-r--r--mwe/events/include/event.h17
-rw-r--r--mwe/events/include/eventManager.h7
-rw-r--r--mwe/events/include/userevent.h0
4 files changed, 63 insertions, 0 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 5eef32f..b1d9cb9 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -5,6 +5,11 @@
#include <string>
#include <unordered_map>
#include <variant>
+<<<<<<< HEAD
+#include "keyCodes.h"
+#include "customTypes.h"
+=======
+>>>>>>> b3b762a34e7ccb4a0dcd041a693ac7180af16002
class UUIDGenerator {
public:
@@ -89,3 +94,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 af41b82..91bac8c 100644
--- a/mwe/events/include/eventManager.h
+++ b/mwe/events/include/eventManager.h
@@ -28,6 +28,12 @@ public:
void dispatchEvents();
private:
+<<<<<<< HEAD
+ 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>> m_eventsQueue;
std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>
@@ -36,6 +42,7 @@ private:
int, std::unordered_map<
int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>
m_subscribersByEventId;
+>>>>>>> b3b762a34e7ccb4a0dcd041a693ac7180af16002
};
template <typename EventType>
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