From 40181613a1e6835d7c0297019f95d32c3123d652 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 22 Mar 2026 00:20:11 -0400 Subject: [PATCH 1/4] feat: vec modulo --- include/asw/modules/geometry.h | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/asw/modules/geometry.h b/include/asw/modules/geometry.h index 0a84f4f..988a1c7 100644 --- a/include/asw/modules/geometry.h +++ b/include/asw/modules/geometry.h @@ -134,6 +134,16 @@ template class Vec2 { return Vec2(x / scalar, y / scalar); } + /// @brief Modulo the Vec2 object by a scalar + /// + /// @param scalar The scalar to modulo by + /// @return Vec2 The result of the modulo operation. + /// + Vec2 operator%(const T scalar) const + { + return Vec2(x % scalar, y % scalar); + } + /// @brief Addition assignment operator for the Vec2 class. /// /// @param other The vector to add. @@ -182,6 +192,18 @@ template class Vec2 { return *this; } + /// @brief Modulo assignment operator for the Vec2 class. + /// + /// @param scalar The scalar to modulo by. + /// @return Vec2& The result of the modulo operation. + /// + Vec2& operator%=(const T scalar) + { + x %= scalar; + y %= scalar; + return *this; + } + /// @brief Equality operator for the Vec2 class. /// /// @param other The vector to compare. @@ -311,6 +333,16 @@ template class Vec3 { return Vec3(x / scalar, y / scalar, z / scalar); } + /// @brief Modulo the Vec3 object by a scalar + /// + /// @param scalar The scalar to modulo by + /// @return Vec3 The result of the modulo + /// + Vec3 operator%(const T scalar) const + { + return Vec3(x % scalar, y % scalar, z % scalar); + } + /// @brief Addition assignment operator for the Vec3 class. /// /// @param other The vector to add. @@ -363,6 +395,19 @@ template class Vec3 { return *this; } + /// @brief Modulo assignment operator for the Vec3 class. + /// + /// @param scalar The scalar to modulo by. + /// @return Vec3& The result of the modulo operation. + /// + Vec3& operator%=(const T scalar) + { + x %= scalar; + y %= scalar; + z %= scalar; + return *this; + } + /// @brief Equality operator for the Vec3 class. /// /// @param other The vector to compare. From eecc8fefe1300c8f36e5551cbd8bfef922d11464 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 22 Mar 2026 00:31:45 -0400 Subject: [PATCH 2/4] fix: create texture scaling --- src/modules/assets.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/assets.cpp b/src/modules/assets.cpp index eaec0a4..215ddb2 100644 --- a/src/modules/assets.cpp +++ b/src/modules/assets.cpp @@ -88,10 +88,13 @@ asw::Texture asw::assets::create_texture(int w, int h) asw::util::abort_on_error("Renderer not initialized"); } - SDL_Texture* text + SDL_Texture* txr = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h); - return { text, [](SDL_Texture* t) { + SDL_SetTextureScaleMode(txr, SDL_SCALEMODE_NEAREST); + SDL_SetTextureBlendMode(txr, SDL_BLENDMODE_BLEND); + + return { txr, [](SDL_Texture* t) { if (asw::display::get_renderer() != nullptr) { SDL_DestroyTexture(t); } From cd30241efcaba7fc98961ec1e66d5cddf5e19c41 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 22 Mar 2026 10:59:47 -0400 Subject: [PATCH 3/4] fix: action naming --- examples/actions/main.cpp | 12 ++++++------ include/asw/modules/action.h | 14 ++++++++------ include/asw/modules/input.h | 2 +- src/modules/action.cpp | 6 +++--- src/modules/core.cpp | 2 +- src/modules/input.cpp | 4 ++-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/actions/main.cpp b/examples/actions/main.cpp index 693d83f..338c5e5 100644 --- a/examples/actions/main.cpp +++ b/examples/actions/main.cpp @@ -4,7 +4,7 @@ /// Demonstrates: /// - Registering named actions with bind_action() /// - Binding the same action to multiple input sources (keyboard + controller) -/// - is_action_down(), is_action_pressed(), is_action_released() +/// - is_action_down(), is_action_up(), is_action() /// - get_action_strength() for analogue movement via a controller axis /// /// Bindings: @@ -73,7 +73,7 @@ int main() while (!asw::core::is_exiting()) { asw::core::update(); - if (asw::input::is_action_pressed("quit")) { + if (asw::input::is_action("quit")) { asw::core::exit(); } @@ -99,7 +99,7 @@ int main() } // Fire - if (asw::input::is_action_pressed("fire")) { + if (asw::input::is_action("fire")) { fire_frames = 12; asw::log::info("Fire!"); } @@ -118,9 +118,9 @@ int main() } // Player box - const bool moving = asw::input::is_action_down("move_left") - || asw::input::is_action_down("move_right") || asw::input::is_action_down("move_up") - || asw::input::is_action_down("move_down"); + const bool moving = asw::input::is_action("move_left") + || asw::input::is_action("move_right") || asw::input::is_action("move_up") + || asw::input::is_action("move_down"); asw::draw::rect_fill({ pos, { box_size, box_size } }, moving ? asw::color::cornflowerblue : asw::color::steelblue); asw::draw::rect({ pos, { box_size, box_size } }, asw::color::white); diff --git a/include/asw/modules/action.h b/include/asw/modules/action.h index 7897e5b..5dce968 100644 --- a/include/asw/modules/action.h +++ b/include/asw/modules/action.h @@ -11,10 +11,11 @@ /// Example: /// @code /// asw::input::bind_action("jump", asw::input::KeyBinding{asw::input::Key::Space}); -/// asw::input::bind_action("jump", asw::input::ControllerButtonBinding{asw::input::ControllerButton::A}); +/// asw::input::bind_action("jump", +/// asw::input::ControllerButtonBinding{asw::input::ControllerButton::A}); /// /// // In game loop: -/// if (asw::input::is_action_pressed("jump")) { /* ... */ } +/// if (asw::input::is_action_down("jump")) { /* ... */ } /// @endcode #ifndef ASW_ACTION_H @@ -56,7 +57,8 @@ struct ControllerAxisBinding { }; /// @brief A single input binding — keyboard, mouse button, controller button, or controller axis. -using ActionBinding = std::variant; +using ActionBinding + = std::variant; /// @brief Register a binding for a named action. /// @@ -83,21 +85,21 @@ void clear_actions(); /// @param name The action name. /// @return true if any binding transitioned to active this frame. /// -bool is_action_pressed(std::string_view name); +bool is_action_down(std::string_view name); /// @brief Check if an action was released this frame. /// /// @param name The action name. /// @return true if any binding transitioned to inactive this frame. /// -bool is_action_released(std::string_view name); +bool is_action_up(std::string_view name); /// @brief Check if an action is currently held down. /// /// @param name The action name. /// @return true if any binding is currently active. /// -bool is_action_down(std::string_view name); +bool is_action(std::string_view name); /// @brief Get the analogue strength of an action (0.0 – 1.0). /// diff --git a/include/asw/modules/input.h b/include/asw/modules/input.h index 197cac8..16a42bf 100644 --- a/include/asw/modules/input.h +++ b/include/asw/modules/input.h @@ -509,7 +509,7 @@ void _mouse_button_up(uint8_t button); void _mouse_motion(float x, float y, float delta_x, float delta_y); /// @brief Mouse wheel hook -void _mouse_wheel(float delta_x, float delta_y); +void _mouse_wheel(float delta_z); /// @brief Controller added hook void _controller_added(SDL_JoystickID id); diff --git a/src/modules/action.cpp b/src/modules/action.cpp index a76d286..3f09f02 100644 --- a/src/modules/action.cpp +++ b/src/modules/action.cpp @@ -138,19 +138,19 @@ void asw::input::clear_actions() action_map.clear(); } -bool asw::input::is_action_pressed(std::string_view name) +bool asw::input::is_action_down(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.pressed; } -bool asw::input::is_action_released(std::string_view name) +bool asw::input::is_action_up(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.released; } -bool asw::input::is_action_down(std::string_view name) +bool asw::input::is_action(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.down; diff --git a/src/modules/core.cpp b/src/modules/core.cpp index d47f8eb..1d731cd 100644 --- a/src/modules/core.cpp +++ b/src/modules/core.cpp @@ -89,7 +89,7 @@ void asw::core::update() } case SDL_EVENT_MOUSE_WHEEL: { - asw::input::_mouse_wheel(e.wheel.x, e.wheel.y); + asw::input::_mouse_wheel(e.wheel.y); break; } diff --git a/src/modules/input.cpp b/src/modules/input.cpp index 618998e..831311e 100644 --- a/src/modules/input.cpp +++ b/src/modules/input.cpp @@ -262,9 +262,9 @@ void asw::input::_mouse_motion(float x, float y, float delta_x, float delta_y) mouse.change.y = delta_y; } -void asw::input::_mouse_wheel(float x, float y) +void asw::input::_mouse_wheel(float delta_z) { - mouse.z = y; + mouse.z = delta_z; } void asw::input::_controller_added(SDL_JoystickID id) From 70cb47a6f68beab2100d0f43629f9cc000ff9fa9 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 22 Mar 2026 11:13:52 -0400 Subject: [PATCH 4/4] fix: action naming --- examples/actions/main.cpp | 12 ++++++------ include/asw/modules/action.h | 8 ++++---- src/modules/action.cpp | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/actions/main.cpp b/examples/actions/main.cpp index 338c5e5..0494528 100644 --- a/examples/actions/main.cpp +++ b/examples/actions/main.cpp @@ -4,7 +4,7 @@ /// Demonstrates: /// - Registering named actions with bind_action() /// - Binding the same action to multiple input sources (keyboard + controller) -/// - is_action_down(), is_action_up(), is_action() +/// - get_action_down(), get_action_up(), get_action() /// - get_action_strength() for analogue movement via a controller axis /// /// Bindings: @@ -73,7 +73,7 @@ int main() while (!asw::core::is_exiting()) { asw::core::update(); - if (asw::input::is_action("quit")) { + if (asw::input::get_action("quit")) { asw::core::exit(); } @@ -99,7 +99,7 @@ int main() } // Fire - if (asw::input::is_action("fire")) { + if (asw::input::get_action("fire")) { fire_frames = 12; asw::log::info("Fire!"); } @@ -118,9 +118,9 @@ int main() } // Player box - const bool moving = asw::input::is_action("move_left") - || asw::input::is_action("move_right") || asw::input::is_action("move_up") - || asw::input::is_action("move_down"); + const bool moving = asw::input::get_action("move_left") + || asw::input::get_action("move_right") || asw::input::get_action("move_up") + || asw::input::get_action("move_down"); asw::draw::rect_fill({ pos, { box_size, box_size } }, moving ? asw::color::cornflowerblue : asw::color::steelblue); asw::draw::rect({ pos, { box_size, box_size } }, asw::color::white); diff --git a/include/asw/modules/action.h b/include/asw/modules/action.h index 5dce968..50e95cd 100644 --- a/include/asw/modules/action.h +++ b/include/asw/modules/action.h @@ -15,7 +15,7 @@ /// asw::input::ControllerButtonBinding{asw::input::ControllerButton::A}); /// /// // In game loop: -/// if (asw::input::is_action_down("jump")) { /* ... */ } +/// if (asw::input::get_action_down("jump")) { /* ... */ } /// @endcode #ifndef ASW_ACTION_H @@ -85,21 +85,21 @@ void clear_actions(); /// @param name The action name. /// @return true if any binding transitioned to active this frame. /// -bool is_action_down(std::string_view name); +bool get_action_down(std::string_view name); /// @brief Check if an action was released this frame. /// /// @param name The action name. /// @return true if any binding transitioned to inactive this frame. /// -bool is_action_up(std::string_view name); +bool get_action_up(std::string_view name); /// @brief Check if an action is currently held down. /// /// @param name The action name. /// @return true if any binding is currently active. /// -bool is_action(std::string_view name); +bool get_action(std::string_view name); /// @brief Get the analogue strength of an action (0.0 – 1.0). /// diff --git a/src/modules/action.cpp b/src/modules/action.cpp index 3f09f02..fa718cd 100644 --- a/src/modules/action.cpp +++ b/src/modules/action.cpp @@ -138,19 +138,19 @@ void asw::input::clear_actions() action_map.clear(); } -bool asw::input::is_action_down(std::string_view name) +bool asw::input::get_action_down(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.pressed; } -bool asw::input::is_action_up(std::string_view name) +bool asw::input::get_action_up(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.released; } -bool asw::input::is_action(std::string_view name) +bool asw::input::get_action(std::string_view name) { auto it = action_map.find(std::string(name)); return it != action_map.end() && it->second.down;