aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-14 13:52:56 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-14 13:52:56 +0100
commitdbe779ca850ec0bf5d9b5066a7a6df44f3762e4d (patch)
treefe87bdbf86017ee1ee5fe75d89f599f5ae8a5be1
parentc17233b10bd8e35bead60c5f44bb8a14836d755f (diff)
make format
-rw-r--r--src/crepe/api/Event.h10
-rw-r--r--src/crepe/api/Script.cpp6
-rw-r--r--src/crepe/api/Script.h4
-rw-r--r--src/crepe/facade/EventData.h89
-rw-r--r--src/crepe/facade/SDLContext.cpp9
-rw-r--r--src/crepe/facade/SDLContext.h8
-rw-r--r--src/crepe/system/InputSystem.cpp10
-rw-r--r--src/example/button.cpp12
-rw-r--r--src/test/InputTest.cpp3
9 files changed, 72 insertions, 79 deletions
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index 4e57b45..73bf461 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -39,7 +39,7 @@ public:
*/
class MousePressEvent : public Event {
public:
- //! mouse position in game units
+ //! mouse position in world coordinates (game units).
vec2 mouse_pos = {0, 0};
//! The mouse button that was pressed.
@@ -51,7 +51,7 @@ public:
*/
class MouseClickEvent : public Event {
public:
- //! mouse position in game units
+ //! mouse position in world coordinates (game units).
vec2 mouse_pos = {0, 0};
//! The mouse button that was clicked.
@@ -63,7 +63,7 @@ public:
*/
class MouseReleaseEvent : public Event {
public:
- //! mouse position in game units
+ //! mouse position in world coordinates (game units).
vec2 mouse_pos = {0, 0};
//! The mouse button that was released.
@@ -75,7 +75,7 @@ public:
*/
class MouseMoveEvent : public Event {
public:
- //! mouse position in game units
+ //! mouse position in world coordinates (game units).
vec2 mouse_pos = {0, 0};
//! The change in mouse position relative to the last position (in pixels).
ivec2 mouse_delta = {0, 0};
@@ -86,7 +86,7 @@ public:
*/
class MouseScrollEvent : public Event {
public:
- //! mouse position in game units when the scroll happened.
+ //! mouse position in world coordinates (game units) when the scroll happened.
vec2 mouse_pos = {0, 0};
//! scroll direction (-1 = down, 1 = up)
int scroll_direction = 0;
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index 7b56f61..638cca7 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -1,7 +1,7 @@
#include <string>
-#include "../manager/SceneManager.h"
#include "../facade/SDLContext.h"
+#include "../manager/SceneManager.h"
#include "Script.h"
using namespace crepe;
@@ -26,7 +26,7 @@ void Script::set_next_scene(const string & name) {
SaveManager & Script::get_save_manager() const { return this->mediator->save_manager; }
-const keyboard_state_t& Script::get_keyboard_state() const{
- SDLContext& sdl_context = this->mediator->sdl_context;
+const keyboard_state_t & Script::get_keyboard_state() const {
+ SDLContext & sdl_context = this->mediator->sdl_context;
return sdl_context.get_keyboard_state();
}
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 4fbf344..dcecc07 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -2,11 +2,11 @@
#include <vector>
+#include "../api/KeyCodes.h"
#include "../manager/EventManager.h"
#include "../manager/Mediator.h"
#include "../system/CollisionSystem.h"
#include "../types.h"
-#include "../api/KeyCodes.h"
#include "../util/OptionalRef.h"
namespace crepe {
@@ -142,7 +142,7 @@ protected:
* \return current keyboard state map with Keycode as key and bool as value(true = pressed, false = not pressed)
*
*/
- const keyboard_state_t& get_keyboard_state() const;
+ const keyboard_state_t & get_keyboard_state() const;
//! \}
private:
diff --git a/src/crepe/facade/EventData.h b/src/crepe/facade/EventData.h
index d0ca07f..a7526b4 100644
--- a/src/crepe/facade/EventData.h
+++ b/src/crepe/facade/EventData.h
@@ -3,53 +3,52 @@
#include "../types.h"
namespace crepe {
//! EventType enum for passing eventType
- enum EventType {
- NONE = 0,
- MOUSE_DOWN,
- MOUSE_UP,
- MOUSE_MOVE,
- MOUSE_WHEEL,
- KEY_UP,
- KEY_DOWN,
- SHUTDOWN,
- WINDOW_MINIMIZE,
- WINDOW_MAXIMIZE,
- WINDOW_FOCUS_GAIN,
- WINDOW_FOCUS_LOST,
- WINDOW_MOVE,
- WINDOW_RESIZE,
- WINDOW_EXPOSE,
- };
+enum EventType {
+ NONE = 0,
+ MOUSE_DOWN,
+ MOUSE_UP,
+ MOUSE_MOVE,
+ MOUSE_WHEEL,
+ KEY_UP,
+ KEY_DOWN,
+ SHUTDOWN,
+ WINDOW_MINIMIZE,
+ WINDOW_MAXIMIZE,
+ WINDOW_FOCUS_GAIN,
+ WINDOW_FOCUS_LOST,
+ WINDOW_MOVE,
+ WINDOW_RESIZE,
+ WINDOW_EXPOSE,
+};
- //! Struct for storing key data.
- struct KeyData {
- Keycode key = Keycode::NONE;
- bool key_repeat = false;
- };
+//! Struct for storing key data.
+struct KeyData {
+ Keycode key = Keycode::NONE;
+ bool key_repeat = false;
+};
- //! Struct for storing mouse data.
- struct MouseData {
- MouseButton mouse_button = MouseButton::NONE;
- ivec2 mouse_position = {-1, -1};
- int scroll_direction = -1;
- float scroll_delta = INFINITY;
- ivec2 rel_mouse_move = {-1, -1};
- };
+//! Struct for storing mouse data.
+struct MouseData {
+ MouseButton mouse_button = MouseButton::NONE;
+ ivec2 mouse_position = {-1, -1};
+ int scroll_direction = -1;
+ float scroll_delta = INFINITY;
+ ivec2 rel_mouse_move = {-1, -1};
+};
- //! Struct for storing window data.
- struct WindowData {
- ivec2 move_delta;
- ivec2 resize_dimension;
- };
-
- //! EventData struct for passing event data from facade
- struct EventData {
- EventType event_type = EventType::NONE;
- union {
- KeyData key_data;
- MouseData mouse_data;
- WindowData window_data;
- } data;
+//! Struct for storing window data.
+struct WindowData {
+ ivec2 move_delta;
+ ivec2 resize_dimension;
+};
- };
+//! EventData struct for passing event data from facade
+struct EventData {
+ EventType event_type = EventType::NONE;
+ union {
+ KeyData key_data;
+ MouseData mouse_data;
+ WindowData window_data;
+ } data;
+};
} // namespace crepe
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index e5b0284..7ccc243 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -75,18 +75,17 @@ SDLContext::~SDLContext() {
}
Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) {
- if (!LOOKUP_TABLE.contains(sdl_key))
- return Keycode::NONE;
+ if (!LOOKUP_TABLE.contains(sdl_key)) return Keycode::NONE;
return LOOKUP_TABLE.at(sdl_key);
}
-const keyboard_state_t& SDLContext::get_keyboard_state(){
+const keyboard_state_t & SDLContext::get_keyboard_state() {
SDL_PumpEvents();
const Uint8 * current_state = SDL_GetKeyboardState(nullptr);
for (int i = 0; i < SDL_NUM_SCANCODES; ++i) {
-
+
Keycode key = sdl_to_keycode(static_cast<SDL_Scancode>(i));
if (key != Keycode::NONE) {
this->keyboard_state[key] = current_state[i] != 0;
@@ -283,7 +282,7 @@ std::vector<EventData> SDLContext::get_events() {
case SDL_QUIT:
event_list.push_back({.event_type = EventType::SHUTDOWN});
break;
- case SDL_KEYDOWN:
+ case SDL_KEYDOWN:
event_list.push_back(EventData{
.event_type = EventType::KEY_DOWN,
.data = {
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 3531680..8f4760e 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -5,19 +5,18 @@
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_video.h>
-#include <array>
#include <cmath>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
+#include "../types.h"
#include "api/Camera.h"
#include "api/Color.h"
#include "api/KeyCodes.h"
#include "api/Sprite.h"
#include "api/Transform.h"
-#include "../types.h"
#include "EventData.h"
@@ -71,7 +70,6 @@ public:
};
public:
-
/**
* \brief Gets the singleton instance of SDLContext.
* \return Reference to the SDLContext instance.
@@ -146,8 +144,8 @@ public:
* \return A constant reference to the `keyboard_state_t`, which holds the state
* of each key (true = pressed, false = not pressed).
*/
- const keyboard_state_t& get_keyboard_state();
-
+ const keyboard_state_t & get_keyboard_state();
+
public:
/**
* \brief Gets the current SDL ticks since the program started.
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 1427adf..fca540f 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -1,7 +1,7 @@
#include "../api/Button.h"
+#include "../facade/SDLContext.h"
#include "../manager/ComponentManager.h"
#include "../manager/EventManager.h"
-#include "../facade/SDLContext.h"
#include "util/Log.h"
#include "InputSystem.h"
@@ -47,8 +47,8 @@ void InputSystem::update() {
}
}
-void InputSystem::handle_mouse_event(const EventData & event,
- const vec2 & camera_origin, const Camera & current_cam) {
+void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camera_origin,
+ const Camera & current_cam) {
EventManager & event_mgr = this->mediator.event_manager;
vec2 adjusted_mouse;
adjusted_mouse.x = event.data.mouse_data.mouse_position.x + camera_origin.x;
@@ -153,9 +153,7 @@ void InputSystem::handle_non_mouse_event(const EventData & event) {
}
}
-
-void InputSystem::handle_move(const EventData & event_data,
- const vec2 & mouse_pos) {
+void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos) {
ComponentManager & mgr = this->mediator.component_manager;
RefVector<Button> buttons = mgr.get_components_by_type<Button>();
diff --git a/src/example/button.cpp b/src/example/button.cpp
index c4e9a47..6c8b1bc 100644
--- a/src/example/button.cpp
+++ b/src/example/button.cpp
@@ -1,18 +1,18 @@
#include <SDL2/SDL_timer.h>
#include <chrono>
#include <crepe/Component.h>
-#include <crepe/manager/ComponentManager.h>
#include <crepe/api/Animator.h>
#include <crepe/api/Button.h>
#include <crepe/api/Camera.h>
#include <crepe/api/Color.h>
-#include <crepe/manager/EventManager.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Texture.h>
#include <crepe/api/Transform.h>
-#include <crepe/system/AnimatorSystem.h>
#include <crepe/facade/SDLContext.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/EventManager.h>
+#include <crepe/system/AnimatorSystem.h>
#include <crepe/system/InputSystem.h>
#include <crepe/system/RenderSystem.h>
#include <crepe/types.h>
@@ -27,8 +27,8 @@ int main(int argc, char * argv[]) {
InputSystem input_sys{mediator};
SDLContext sdl_context{mediator};
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(ivec2{500, 500}, vec2{500, 500},
- Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{500, 500}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
// GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
// auto s2 = Texture("asset/texture/test_ap43.png");
@@ -46,7 +46,7 @@ int main(int argc, char * argv[]) {
// button.active = true;
auto start = std::chrono::steady_clock::now();
while (true) {
- const keyboard_state_t& keyboard_state = sdl_context.get_keyboard_state();
+ const keyboard_state_t & keyboard_state = sdl_context.get_keyboard_state();
input_sys.update();
sys.update();
event_mgr.dispatch_events();
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index f974d0c..d893276 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -13,9 +13,9 @@
#include <crepe/api/Camera.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
-#include <crepe/facade/SDLContext.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
+#include <crepe/facade/SDLContext.h>
#include <gmock/gmock.h>
using namespace std;
@@ -260,4 +260,3 @@ TEST_F(InputTest, testButtonHover) {
event_manager.dispatch_events();
EXPECT_TRUE(button.hover);
}
-