aboutsummaryrefslogtreecommitdiff
path: root/mwe/events
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-19 20:49:09 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-19 20:49:09 +0100
commit0f9f379a4dec7ad9d1dce30af5e2259931692c5f (patch)
treed84a76559d99fd6a3541d0087538564d79e39470 /mwe/events
parent38a2476bcfa41b6d83a9a72d35f5acb684dc87fd (diff)
parent0476a8e9dbe7afb422862f7b1c15aaed7f3c416e (diff)
merge with master
Diffstat (limited to 'mwe/events')
-rw-r--r--mwe/events/include/customTypes.h11
-rw-r--r--mwe/events/include/event.h10
-rw-r--r--mwe/events/include/eventManager.h30
-rw-r--r--mwe/events/src/event.cpp35
-rw-r--r--mwe/events/src/eventManager.cpp41
-rw-r--r--mwe/events/src/iKeyListener.cpp8
-rw-r--r--mwe/events/src/iMouseListener.cpp17
-rw-r--r--mwe/events/src/inputSystem.cpp14
-rw-r--r--mwe/events/src/keyListenerTest.cpp4
-rw-r--r--mwe/events/src/loopManager.cpp21
-rw-r--r--mwe/events/src/main.cpp7
-rw-r--r--mwe/events/src/mouseListenerTest.cpp12
-rw-r--r--mwe/events/src/timer.cpp3
-rw-r--r--mwe/events/src/uiRenderer.cpp13
-rw-r--r--mwe/events/src/window.cpp9
-rw-r--r--mwe/events/versions/delayBased.cpp3
16 files changed, 81 insertions, 157 deletions
diff --git a/mwe/events/include/customTypes.h b/mwe/events/include/customTypes.h
index 415b989..5a7851b 100644
--- a/mwe/events/include/customTypes.h
+++ b/mwe/events/include/customTypes.h
@@ -5,14 +5,10 @@ struct Vector2 {
float y; // Y component of the vector
// Vector subtraction
- Vector2 operator-(const Vector2 & other) const {
- return {x - other.x, y - other.y};
- }
+ 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};
- }
+ 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}; }
@@ -31,8 +27,7 @@ struct Collision {
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)
+ Collision(int idA, int idB, const Vector2 & point, const Vector2 & normal, float depth)
: objectIdA(idA),
objectIdB(idB),
contactPoint(point),
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h
index 3e70201..e1b220b 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -20,9 +20,7 @@ public: \
static std::uint32_t typeID = UUIDGenerator::getUniqueID(); \
return typeID; \
} \
- virtual std::uint32_t getEventType() const override { \
- return getStaticEventType(); \
- }
+ virtual std::uint32_t getEventType() const override { return getStaticEventType(); }
class Event {
public:
Event(std::string eventType);
@@ -32,16 +30,14 @@ public:
void addArgument(const std::string & key,
const std::variant<int, std::string, float> & value);
- std::variant<int, std::string, float>
- getArgument(const std::string & key) const;
+ std::variant<int, std::string, float> getArgument(const std::string & key) const;
std::string getType() const;
bool getHandled() const;
void markHandled();
private:
- std::unordered_map<std::string, std::variant<int, std::string, float>>
- eventData;
+ std::unordered_map<std::string, std::variant<int, std::string, float>> eventData;
bool isHandled = false;
};
diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h
index 508a5e2..30e927f 100644
--- a/mwe/events/include/eventManager.h
+++ b/mwe/events/include/eventManager.h
@@ -18,11 +18,9 @@ public:
}
void shutdown();
- void subscribe(int eventType,
- std::unique_ptr<IEventHandlerWrapper> && handler,
+ void subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler,
int eventId);
- void unsubscribe(int eventType, const std::string & handlerName,
- int eventId);
+ void unsubscribe(int eventType, const std::string & handlerName, int eventId);
void triggerEvent(const Event & event_, int eventId);
void queueEvent(std::unique_ptr<Event> && event_, int eventId);
void dispatchEvents();
@@ -30,11 +28,9 @@ public:
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::vector<std::unique_ptr<IEventHandlerWrapper>>> subscribers;
std::unordered_map<
- int, std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>
+ int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>
subscribersByEventId;
};
@@ -42,18 +38,16 @@ template <typename EventType>
inline void subscribe(const EventHandler<EventType> & callback, int eventId = 0,
const bool unsubscribeOnSuccess = false) {
std::unique_ptr<IEventHandlerWrapper> handler
- = std::make_unique<EventHandlerWrapper<EventType>>(
- callback, unsubscribeOnSuccess);
- EventManager::getInstance().subscribe(EventType::getStaticEventType(),
- std::move(handler), eventId);
+ = std::make_unique<EventHandlerWrapper<EventType>>(callback, unsubscribeOnSuccess);
+ EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler),
+ eventId);
}
template <typename EventType>
-inline void unsubscribe(const EventHandler<EventType> & callback,
- int eventId = 0) {
+inline void unsubscribe(const EventHandler<EventType> & callback, int eventId = 0) {
const std::string handlerName = callback.target_type().name();
- EventManager::getInstance().unsubscribe(EventType::getStaticEventType(),
- handlerName, eventId);
+ EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName,
+ eventId);
}
inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
@@ -61,6 +55,6 @@ inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
}
inline void queueEvent(std::unique_ptr<Event> && queuedEvent, int eventId = 0) {
- EventManager::getInstance().queueEvent(
- std::forward<std::unique_ptr<Event>>(queuedEvent), eventId);
+ EventManager::getInstance().queueEvent(std::forward<std::unique_ptr<Event>>(queuedEvent),
+ eventId);
}
diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp
index 8ffa0b1..0040c73 100644
--- a/mwe/events/src/event.cpp
+++ b/mwe/events/src/event.cpp
@@ -8,14 +8,11 @@ void Event::addArgument(const std::string & key,
eventData[key] = value;
}
-std::variant<int, std::string, float>
-Event::getArgument(const std::string & key) const {
+std::variant<int, std::string, float> Event::getArgument(const std::string & key) const {
return eventData.at(key);
}
-std::string Event::getType() const {
- return std::get<std::string>(eventData.at("eventType"));
-}
+std::string Event::getType() const { return std::get<std::string>(eventData.at("eventType")); }
std::string Event::toString() const { return std::to_string(getEventType()); }
bool Event::getHandled() const { return isHandled; }
@@ -32,9 +29,7 @@ Keycode KeyPressedEvent::getKeyCode() const { return key; }
int KeyPressedEvent::getRepeatCount() const { return repeatCount; }
// KeyReleasedEvent class methods
-KeyReleasedEvent::KeyReleasedEvent(int keycode)
- : Event("KeyReleasedEvent"),
- key(keycode) {}
+KeyReleasedEvent::KeyReleasedEvent(int keycode) : Event("KeyReleasedEvent"), key(keycode) {}
Keycode KeyReleasedEvent::getKeyCode() const { return key; }
@@ -44,22 +39,16 @@ MousePressedEvent::MousePressedEvent(int mouseX, int mouseY)
mouseX(mouseX),
mouseY(mouseY) {}
-std::pair<int, int> MousePressedEvent::getMousePosition() const {
- return {mouseX, mouseY};
-}
+std::pair<int, int> MousePressedEvent::getMousePosition() const { return {mouseX, mouseY}; }
//Collision event
CollisionEvent::CollisionEvent(Collision collision)
: collisionData(collision),
Event("CollisionEvent") {}
-Collision CollisionEvent::getCollisionData() const {
- return this->collisionData;
-}
+Collision CollisionEvent::getCollisionData() const { return this->collisionData; }
-TextSubmitEvent::TextSubmitEvent(std::string text)
- : text(text),
- Event("TextSubmitEvent") {}
+TextSubmitEvent::TextSubmitEvent(std::string text) : text(text), Event("TextSubmitEvent") {}
std::string TextSubmitEvent::getText() const { return this->text; }
@@ -68,9 +57,7 @@ MouseReleasedEvent::MouseReleasedEvent(int x, int y, MouseButton button)
mouseY(y),
button(button),
Event("MouseReleased") {}
-std::pair<int, int> MouseReleasedEvent::getMousePosition() const {
- return {mouseX, mouseY};
-}
+std::pair<int, int> MouseReleasedEvent::getMousePosition() const { return {mouseX, mouseY}; }
MouseClickEvent::MouseClickEvent(int x, int y, MouseButton button)
: mouseX(x),
mouseY(y),
@@ -80,9 +67,5 @@ MouseMovedEvent::MouseMovedEvent(int x, int y)
: mouseX(x),
mouseY(y),
Event("MouseMovedEvent") {}
-std::pair<int, int> MouseClickEvent::getMousePosition() const {
- return {mouseX, mouseY};
-}
-std::pair<int, int> MouseMovedEvent::getMousePosition() const {
- return {mouseX, mouseY};
-}
+std::pair<int, int> MouseClickEvent::getMousePosition() const { return {mouseX, mouseY}; }
+std::pair<int, int> MouseMovedEvent::getMousePosition() const { return {mouseX, mouseY}; }
diff --git a/mwe/events/src/eventManager.cpp b/mwe/events/src/eventManager.cpp
index 34a093d..9e7d880 100644
--- a/mwe/events/src/eventManager.cpp
+++ b/mwe/events/src/eventManager.cpp
@@ -2,33 +2,27 @@
void EventManager::shutdown() { subscribers.clear(); }
-void EventManager::subscribe(int eventType,
- std::unique_ptr<IEventHandlerWrapper> && handler,
+void EventManager::subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler,
int eventId) {
if (eventId) {
std::unordered_map<
- int, std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::
+ int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::
iterator subscribers
= subscribersByEventId.find(eventType);
if (subscribers != subscribersByEventId.end()) {
- std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> &
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> &
handlersMap
= subscribers->second;
std::unordered_map<
- int,
- std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator
- handlers
+ int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator handlers
= handlersMap.find(eventId);
if (handlers != handlersMap.end()) {
handlers->second.emplace_back(std::move(handler));
return;
}
}
- subscribersByEventId[eventType][eventId].emplace_back(
- std::move(handler));
+ subscribersByEventId[eventType][eventId].emplace_back(std::move(handler));
} else {
auto & handlers = subscribers[eventType];
@@ -36,29 +30,23 @@ void EventManager::subscribe(int eventType,
}
}
-void EventManager::unsubscribe(int eventType, const std::string & handlerName,
- int eventId) {
+void EventManager::unsubscribe(int eventType, const std::string & handlerName, int eventId) {
if (eventId) {
std::unordered_map<
- int, std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::
+ int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::
iterator subscriberList
= subscribersByEventId.find(eventType);
if (subscriberList != subscribersByEventId.end()) {
- std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> &
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>> &
handlersMap
= subscriberList->second;
std::unordered_map<
- int,
- std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator
- handlers
+ int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator handlers
= handlersMap.find(eventId);
if (handlers != handlersMap.end()) {
std::vector<std::unique_ptr<IEventHandlerWrapper>> & callbacks
= handlers->second;
- for (std::vector<
- std::unique_ptr<IEventHandlerWrapper>>::iterator it
+ for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator it
= callbacks.begin();
it != callbacks.end(); ++it) {
if (it->get()->getType() == handlerName) {
@@ -69,13 +57,11 @@ void EventManager::unsubscribe(int eventType, const std::string & handlerName,
}
}
} else {
- std::unordered_map<
- int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator
handlersIt
= subscribers.find(eventType);
if (handlersIt != subscribers.end()) {
- std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers
- = handlersIt->second;
+ std::vector<std::unique_ptr<IEventHandlerWrapper>> & handlers = handlersIt->second;
for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator it
= handlers.begin();
it != handlers.end(); ++it) {
@@ -90,8 +76,7 @@ void EventManager::unsubscribe(int eventType, const std::string & handlerName,
void EventManager::triggerEvent(const Event & event_, int eventId) {
if (eventId > 0) {
- auto handlersIt
- = subscribersByEventId[event_.getEventType()].find(eventId);
+ auto handlersIt = subscribersByEventId[event_.getEventType()].find(eventId);
if (handlersIt != subscribersByEventId[event_.getEventType()].end()) {
std::vector<std::unique_ptr<IEventHandlerWrapper>> & callbacks
= handlersIt->second;
diff --git a/mwe/events/src/iKeyListener.cpp b/mwe/events/src/iKeyListener.cpp
index 0235fab..d5d1d90 100644
--- a/mwe/events/src/iKeyListener.cpp
+++ b/mwe/events/src/iKeyListener.cpp
@@ -3,11 +3,9 @@
IKeyListener::~IKeyListener() { unsubscribeEvents(); }
void IKeyListener::subscribeEvents(int listenerId) {
- keyPressedHandler
- = [this](const KeyPressedEvent & event) { this->onKeyPressed(event); };
- keyReleasedHandler = [this](const KeyReleasedEvent & event) {
- this->onKeyReleased(event);
- };
+ keyPressedHandler = [this](const KeyPressedEvent & event) { this->onKeyPressed(event); };
+ keyReleasedHandler
+ = [this](const KeyReleasedEvent & event) { this->onKeyReleased(event); };
subscribe<KeyPressedEvent>(keyPressedHandler, listenerId);
subscribe<KeyReleasedEvent>(keyReleasedHandler, listenerId);
diff --git a/mwe/events/src/iMouseListener.cpp b/mwe/events/src/iMouseListener.cpp
index 69d8c9f..53e6f80 100644
--- a/mwe/events/src/iMouseListener.cpp
+++ b/mwe/events/src/iMouseListener.cpp
@@ -2,17 +2,12 @@
IMouseListener::~IMouseListener() { unsubscribeEvents(); }
void IMouseListener::subscribeEvents(int listenerId) {
- mouseClickHandler = [this](const MouseClickEvent & event) {
- this->onMouseClicked(event);
- };
- mousePressHandler = [this](const MousePressedEvent & event) {
- this->onMousePressed(event);
- };
- mouseReleaseHandler = [this](const MouseReleasedEvent & event) {
- this->onMouseReleased(event);
- };
- mouseMoveHandler
- = [this](const MouseMovedEvent & event) { this->onMouseMoved(event); };
+ mouseClickHandler = [this](const MouseClickEvent & event) { this->onMouseClicked(event); };
+ mousePressHandler
+ = [this](const MousePressedEvent & event) { this->onMousePressed(event); };
+ mouseReleaseHandler
+ = [this](const MouseReleasedEvent & event) { this->onMouseReleased(event); };
+ mouseMoveHandler = [this](const MouseMovedEvent & event) { this->onMouseMoved(event); };
subscribe<MouseClickEvent>(mouseClickHandler, listenerId);
subscribe<MousePressedEvent>(mousePressHandler, listenerId);
diff --git a/mwe/events/src/inputSystem.cpp b/mwe/events/src/inputSystem.cpp
index b87b12e..d740c9e 100644
--- a/mwe/events/src/inputSystem.cpp
+++ b/mwe/events/src/inputSystem.cpp
@@ -3,9 +3,7 @@
InputSystem::InputSystem() {}
void InputSystem::registerButton(Button * button) { buttons.push_back(button); }
-void InputSystem::registerTextInput(TextInput * input) {
- textInputs.push_back(input);
-}
+void InputSystem::registerTextInput(TextInput * input) { textInputs.push_back(input); }
void InputSystem::registerText(Text * label) { texts.push_back(label); }
void InputSystem::processInput() {
@@ -16,8 +14,7 @@ void InputSystem::processInput() {
triggerEvent(ShutDownEvent());
break;
case SDL_KEYDOWN:
- triggerEvent(
- KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
+ triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
processKeyPress(event.key.keysym.sym);
break;
case SDL_TEXTINPUT:
@@ -37,15 +34,14 @@ void InputSystem::processInput() {
void InputSystem::processMouseClick(int mouseX, int mouseY) {
for (auto * button : buttons) {
- if (mouseX >= button->x && mouseX <= (button->x + button->width)
- && mouseY >= button->y && mouseY <= (button->y + button->height)) {
+ if (mouseX >= button->x && mouseX <= (button->x + button->width) && mouseY >= button->y
+ && mouseY <= (button->y + button->height)) {
button->onClick();
}
}
for (auto * textInput : textInputs) {
if (mouseX >= textInput->x && mouseX <= textInput->x + textInput->width
- && mouseY >= textInput->y
- && mouseY <= textInput->y + textInput->height) {
+ && mouseY >= textInput->y && mouseY <= textInput->y + textInput->height) {
textInput->isActive = true;
} else {
textInput->isActive = false;
diff --git a/mwe/events/src/keyListenerTest.cpp b/mwe/events/src/keyListenerTest.cpp
index 8446dfa..f45dffd 100644
--- a/mwe/events/src/keyListenerTest.cpp
+++ b/mwe/events/src/keyListenerTest.cpp
@@ -1,8 +1,6 @@
#include "keyListenerTest.h"
-KeyListenerTest::KeyListenerTest(int listenerId) {
- subscribeEvents(listenerId);
-}
+KeyListenerTest::KeyListenerTest(int listenerId) { subscribeEvents(listenerId); }
KeyListenerTest::~KeyListenerTest() { unsubscribeEvents(); }
diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp
index 0b7d888..c58a5e7 100644
--- a/mwe/events/src/loopManager.cpp
+++ b/mwe/events/src/loopManager.cpp
@@ -1,8 +1,7 @@
#include "loopManager.h"
LoopManager::LoopManager() : inputSystem(std::make_unique<InputSystem>()) {
- shutdownHandler
- = [this](const ShutDownEvent & event) { this->onShutdown(event); };
+ shutdownHandler = [this](const ShutDownEvent & event) { this->onShutdown(event); };
subscribe(shutdownHandler);
}
void LoopManager::processInput() {
@@ -63,17 +62,15 @@ void LoopManager::setup() {
subscribe<KeyPressedEvent>(callback, false);
EventHandler<MousePressedEvent> mouseCallback = onMouse;
subscribe<MousePressedEvent>(mouseCallback, false);
- EventHandler<KeyPressedEvent> closeWindowCallback
- = [this](const KeyPressedEvent & e) {
- if (e.getKeyCode() == Escape) {
- this->setRunning(false);
- }
- };
+ EventHandler<KeyPressedEvent> closeWindowCallback = [this](const KeyPressedEvent & e) {
+ if (e.getKeyCode() == Escape) {
+ this->setRunning(false);
+ }
+ };
subscribe<KeyPressedEvent>(closeWindowCallback, false);
Button * testButton = new Button(200, 200);
testButton->color = {100, 0, 100};
- testButton->onClick
- = []() { std::cout << "Button was clicked" << std::endl; };
+ testButton->onClick = []() { std::cout << "Button was clicked" << std::endl; };
testButton->x = 200;
testButton->y = 200;
inputSystem->registerButton(testButton);
@@ -93,9 +90,7 @@ void LoopManager::render() {
window.renderUIObjects();
}
}
-void LoopManager::onShutdown(const ShutDownEvent & e) {
- this->gameRunning = false;
-}
+void LoopManager::onShutdown(const ShutDownEvent & e) { this->gameRunning = false; }
void LoopManager::update() {
//fprintf(stderr, "**********normal update********** \n");
LoopTimer & timer = LoopTimer::getInstance();
diff --git a/mwe/events/src/main.cpp b/mwe/events/src/main.cpp
index f4e7390..ad0fd69 100644
--- a/mwe/events/src/main.cpp
+++ b/mwe/events/src/main.cpp
@@ -25,8 +25,8 @@ private:
int playerID;
};
void onPlayerDamaged(const PlayerDamagedEvent & e) {
- std::cout << "Player " << e.getPlayerID() << " took " << e.getDamage()
- << " damage." << std::endl;
+ std::cout << "Player " << e.getPlayerID() << " took " << e.getDamage() << " damage."
+ << std::endl;
}
void onKeyPressed1(const KeyPressedEvent & e) {
@@ -38,8 +38,7 @@ void onKeyPressed(const KeyPressedEvent & e) {
fprintf(stderr, "second function KeyCode %d\n", keyCode);
}
void CollisionHandler(const CollisionEvent & e) {
- std::cout << "collision betwee object id: "
- << e.getCollisionData().objectIdA
+ std::cout << "collision betwee object id: " << e.getCollisionData().objectIdA
<< " and id: " << e.getCollisionData().objectIdB << std::endl;
}
void testCollisionEvent() {
diff --git a/mwe/events/src/mouseListenerTest.cpp b/mwe/events/src/mouseListenerTest.cpp
index a2a7e6d..7b35f4e 100644
--- a/mwe/events/src/mouseListenerTest.cpp
+++ b/mwe/events/src/mouseListenerTest.cpp
@@ -1,8 +1,6 @@
#include "mouseListenerTest.h"
-MouseListenerTest::MouseListenerTest(int listenerId) {
- subscribeEvents(listenerId);
-}
+MouseListenerTest::MouseListenerTest(int listenerId) { subscribeEvents(listenerId); }
MouseListenerTest::~MouseListenerTest() { unsubscribeEvents(); }
@@ -12,13 +10,13 @@ void MouseListenerTest::onMouseClicked(const MouseClickEvent & event) {
}
void MouseListenerTest::onMousePressed(const MousePressedEvent & event) {
- std::cout << "Mouse button pressed at: (" << event.getMousePosition().first
- << ", " << event.getMousePosition().second << ")" << std::endl;
+ std::cout << "Mouse button pressed at: (" << event.getMousePosition().first << ", "
+ << event.getMousePosition().second << ")" << std::endl;
}
void MouseListenerTest::onMouseReleased(const MouseReleasedEvent & event) {
- std::cout << "Mouse button released at: (" << event.getMousePosition().first
- << ", " << event.getMousePosition().second << ")" << std::endl;
+ std::cout << "Mouse button released at: (" << event.getMousePosition().first << ", "
+ << event.getMousePosition().second << ")" << std::endl;
}
void MouseListenerTest::onMouseMoved(const MouseMovedEvent & event) {
diff --git a/mwe/events/src/timer.cpp b/mwe/events/src/timer.cpp
index 0b89bf5..0f8339f 100644
--- a/mwe/events/src/timer.cpp
+++ b/mwe/events/src/timer.cpp
@@ -45,8 +45,7 @@ void LoopTimer::enforceFrameRate() {
double frameDuration = (currentFrameTime - lastFrameTime) / 1000.0;
if (frameDuration < frameTargetTime) {
- uint32_t delayTime
- = (uint32_t) ((frameTargetTime - frameDuration) * 1000.0);
+ uint32_t delayTime = (uint32_t) ((frameTargetTime - frameDuration) * 1000.0);
SDL_Delay(delayTime);
}
}
diff --git a/mwe/events/src/uiRenderer.cpp b/mwe/events/src/uiRenderer.cpp
index 9fec272..ca8d284 100644
--- a/mwe/events/src/uiRenderer.cpp
+++ b/mwe/events/src/uiRenderer.cpp
@@ -24,21 +24,18 @@ void UIRenderer::renderButton(Button * button) {
// Private helper function to render a Text
void UIRenderer::renderText(Text * text) {
if (text->font != nullptr) {
- SDL_Color sdlColor
- = {text->color.red, text->color.green, text->color.blue, 255};
+ SDL_Color sdlColor = {text->color.red, text->color.green, text->color.blue, 255};
SDL_Surface * textSurface
= TTF_RenderText_Blended(text->font, text->text.c_str(), sdlColor);
if (!textSurface) {
- std::cerr << "Error creating text surface: " << TTF_GetError()
- << std::endl;
+ std::cerr << "Error creating text surface: " << TTF_GetError() << std::endl;
return;
}
- SDL_Texture * textTexture
- = SDL_CreateTextureFromSurface(renderer, textSurface);
+ SDL_Texture * textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
if (!textTexture) {
- std::cerr << "Error creating texture from surface: "
- << SDL_GetError() << std::endl;
+ std::cerr << "Error creating texture from surface: " << SDL_GetError()
+ << std::endl;
SDL_FreeSurface(textSurface);
return;
}
diff --git a/mwe/events/src/window.cpp b/mwe/events/src/window.cpp
index f482b7f..af2b627 100644
--- a/mwe/events/src/window.cpp
+++ b/mwe/events/src/window.cpp
@@ -11,9 +11,8 @@ bool WindowManager::initWindow() {
return false;
}
- window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
- SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
+ window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (!window) {
std::cerr << "Error creating SDL Window.\n";
return false;
@@ -36,9 +35,7 @@ void WindowManager::destroyWindow() {
}
SDL_Renderer * WindowManager::getRenderer() { return renderer; }
-void WindowManager::addUIObject(UIObject * uiObject) {
- uiObjects.push_back(uiObject);
-}
+void WindowManager::addUIObject(UIObject * uiObject) { uiObjects.push_back(uiObject); }
void WindowManager::renderUIObjects() {
for (UIObject * obj : uiObjects) {
diff --git a/mwe/events/versions/delayBased.cpp b/mwe/events/versions/delayBased.cpp
index 253a03a..634de9c 100644
--- a/mwe/events/versions/delayBased.cpp
+++ b/mwe/events/versions/delayBased.cpp
@@ -32,8 +32,7 @@ void LoopManager::setup() {
LoopTimer::getInstance().setFPS(210);
for (int i = 0; i < 2; i++) {
- GameObject * square2
- = new GameObject("square2", i * 40, i * 40, 20, 20, 0, 0);
+ GameObject * square2 = new GameObject("square2", i * 40, i * 40, 20, 20, 0, 0);
objectList.push_back(square2);
}
}