Browse Source

Rename input events

master
C. J. Howard 1 year ago
parent
commit
7f9eba6cda
15 changed files with 126 additions and 133 deletions
  1. +1
    -1
      src/app/sdl/sdl-input-manager.cpp
  2. +8
    -10
      src/game/context.hpp
  3. +10
    -7
      src/game/state/boot.cpp
  4. +18
    -18
      src/input/control-map.cpp
  5. +10
    -10
      src/input/control-map.hpp
  6. +10
    -10
      src/input/control.hpp
  7. +5
    -5
      src/input/device.hpp
  8. +7
    -7
      src/input/gamepad.hpp
  9. +19
    -25
      src/input/input-events.hpp
  10. +5
    -5
      src/input/keyboard.hpp
  11. +12
    -12
      src/input/mapper.cpp
  12. +9
    -9
      src/input/mapper.hpp
  13. +9
    -9
      src/input/mouse.hpp
  14. +2
    -2
      src/main.cpp
  15. +1
    -3
      src/ui/ui.hpp

+ 1
- 1
src/app/sdl/sdl-input-manager.cpp View File

@ -86,7 +86,7 @@ void sdl_input_manager::update()
{ {
case SDL_QUIT: case SDL_QUIT:
debug::log::debug("Application quit requested"); debug::log::debug("Application quit requested");
this->event_queue.enqueue<input::event::application_quit>({});
this->event_queue.enqueue<input::application_quit_event>({});
break; break;
default: default:

+ 8
- 10
src/game/context.hpp View File

@ -134,6 +134,14 @@ struct context
// Resource management and paths // Resource management and paths
resource_manager* resource_manager; resource_manager* resource_manager;
std::filesystem::path data_path;
std::filesystem::path local_config_path;
std::filesystem::path shared_config_path;
std::filesystem::path mods_path;
std::filesystem::path saves_path;
std::filesystem::path screenshots_path;
std::filesystem::path controls_path;
std::filesystem::path data_package_path;
// Persistent settings // Persistent settings
dict<std::uint32_t>* settings; dict<std::uint32_t>* settings;
@ -199,16 +207,6 @@ struct context
/// Game loop /// Game loop
game::loop loop; game::loop loop;
// Paths
std::filesystem::path data_path;
std::filesystem::path local_config_path;
std::filesystem::path shared_config_path;
std::filesystem::path mods_path;
std::filesystem::path saves_path;
std::filesystem::path screenshots_path;
std::filesystem::path controls_path;
std::filesystem::path data_package_path;
// Framebuffers // Framebuffers
gl::texture_2d* hdr_color_texture; gl::texture_2d* hdr_color_texture;
gl::texture_2d* hdr_depth_texture; gl::texture_2d* hdr_depth_texture;

+ 10
- 7
src/game/state/boot.cpp View File

@ -187,7 +187,7 @@ void boot::parse_options(int argc, char** argv)
("n,new-game", "Starts a new game") ("n,new-game", "Starts a new game")
("q,quick-start", "Skips to the main menu") ("q,quick-start", "Skips to the main menu")
("r,reset", "Resets all settings to default") ("r,reset", "Resets all settings to default")
("v,vsync", "Enables or disables v-sync", cxxopts::value<int>())
("v,v-sync", "Enables or disables v-sync", cxxopts::value<int>())
("w,windowed", "Starts in windowed mode"); ("w,windowed", "Starts in windowed mode");
auto result = options.parse(argc, argv); auto result = options.parse(argc, argv);
@ -227,10 +227,10 @@ void boot::parse_options(int argc, char** argv)
ctx.option_reset = true; ctx.option_reset = true;
} }
// --v_sync
if (result.count("vsync"))
// --v-sync
if (result.count("v-sync"))
{ {
ctx.option_v_sync = result["vsync"].as<int>();
ctx.option_v_sync = result["v-sync"].as<int>();
} }
// --window // --window
@ -249,7 +249,7 @@ void boot::parse_options(int argc, char** argv)
void boot::setup_resources() void boot::setup_resources()
{ {
// Setup resource manager
// Allocate resource manager
ctx.resource_manager = new resource_manager(); ctx.resource_manager = new resource_manager();
// Detect paths // Detect paths
@ -312,9 +312,12 @@ void boot::setup_resources()
// Determine data package path // Determine data package path
if (ctx.option_data) if (ctx.option_data)
{ {
ctx.data_package_path = std::filesystem::path(ctx.option_data.value());
// Handle command-line data package path option
ctx.data_package_path = ctx.option_data.value();
if (ctx.data_package_path.is_relative()) if (ctx.data_package_path.is_relative())
{
ctx.data_package_path = ctx.data_path / ctx.data_package_path; ctx.data_package_path = ctx.data_path / ctx.data_package_path;
}
} }
else else
{ {
@ -450,7 +453,7 @@ void boot::setup_input()
ctx.input_manager = app::input_manager::instance(); ctx.input_manager = app::input_manager::instance();
// Setup application quit callback // Setup application quit callback
ctx.application_quit_subscription = ctx.input_manager->get_event_queue().subscribe<input::event::application_quit>
ctx.application_quit_subscription = ctx.input_manager->get_event_queue().subscribe<input::application_quit_event>
( (
[&](const auto& event) [&](const auto& event)
{ {

+ 18
- 18
src/input/control-map.cpp View File

@ -27,15 +27,15 @@ namespace input {
void control_map::connect(::event::queue& queue) void control_map::connect(::event::queue& queue)
{ {
subscriptions.emplace_back(queue.subscribe<event::gamepad_axis_moved>(std::bind_front(&control_map::handle_gamepad_axis_moved, this)));
subscriptions.emplace_back(queue.subscribe<event::gamepad_button_pressed>(std::bind_front(&control_map::handle_gamepad_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::gamepad_button_released>(std::bind_front(&control_map::handle_gamepad_button_released, this)));
subscriptions.emplace_back(queue.subscribe<event::key_pressed>(std::bind_front(&control_map::handle_key_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::key_released>(std::bind_front(&control_map::handle_key_released, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_button_pressed>(std::bind_front(&control_map::handle_mouse_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_button_released>(std::bind_front(&control_map::handle_mouse_button_released, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_moved>(std::bind_front(&control_map::handle_mouse_moved, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_scrolled>(std::bind_front(&control_map::handle_mouse_scrolled, this)));
subscriptions.emplace_back(queue.subscribe<gamepad_axis_moved_event>(std::bind_front(&control_map::handle_gamepad_axis_moved, this)));
subscriptions.emplace_back(queue.subscribe<gamepad_button_pressed_event>(std::bind_front(&control_map::handle_gamepad_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<gamepad_button_released_event>(std::bind_front(&control_map::handle_gamepad_button_released, this)));
subscriptions.emplace_back(queue.subscribe<key_pressed_event>(std::bind_front(&control_map::handle_key_pressed, this)));
subscriptions.emplace_back(queue.subscribe<key_released_event>(std::bind_front(&control_map::handle_key_released, this)));
subscriptions.emplace_back(queue.subscribe<mouse_button_pressed_event>(std::bind_front(&control_map::handle_mouse_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<mouse_button_released_event>(std::bind_front(&control_map::handle_mouse_button_released, this)));
subscriptions.emplace_back(queue.subscribe<mouse_moved_event>(std::bind_front(&control_map::handle_mouse_moved, this)));
subscriptions.emplace_back(queue.subscribe<mouse_scrolled_event>(std::bind_front(&control_map::handle_mouse_scrolled, this)));
} }
void control_map::disconnect() void control_map::disconnect()
@ -171,7 +171,7 @@ void control_map::remove_mappings()
mouse_scroll_mappings.clear(); mouse_scroll_mappings.clear();
} }
void control_map::handle_gamepad_axis_moved(const event::gamepad_axis_moved& event)
void control_map::handle_gamepad_axis_moved(const gamepad_axis_moved_event& event)
{ {
for (const auto& [control, mapping]: gamepad_axis_mappings) for (const auto& [control, mapping]: gamepad_axis_mappings)
{ {
@ -190,7 +190,7 @@ void control_map::handle_gamepad_axis_moved(const event::gamepad_axis_moved& eve
} }
} }
void control_map::handle_gamepad_button_pressed(const event::gamepad_button_pressed& event)
void control_map::handle_gamepad_button_pressed(const gamepad_button_pressed_event& event)
{ {
for (const auto& [control, mapping]: gamepad_button_mappings) for (const auto& [control, mapping]: gamepad_button_mappings)
{ {
@ -202,7 +202,7 @@ void control_map::handle_gamepad_button_pressed(const event::gamepad_button_pres
} }
} }
void control_map::handle_gamepad_button_released(const event::gamepad_button_released& event)
void control_map::handle_gamepad_button_released(const gamepad_button_released_event& event)
{ {
for (const auto& [control, mapping]: gamepad_button_mappings) for (const auto& [control, mapping]: gamepad_button_mappings)
{ {
@ -214,7 +214,7 @@ void control_map::handle_gamepad_button_released(const event::gamepad_button_rel
} }
} }
void control_map::handle_key_pressed(const event::key_pressed& event)
void control_map::handle_key_pressed(const key_pressed_event& event)
{ {
for (const auto& [control, mapping]: key_mappings) for (const auto& [control, mapping]: key_mappings)
{ {
@ -226,7 +226,7 @@ void control_map::handle_key_pressed(const event::key_pressed& event)
} }
} }
void control_map::handle_key_released(const event::key_released& event)
void control_map::handle_key_released(const key_released_event& event)
{ {
for (const auto& [control, mapping]: key_mappings) for (const auto& [control, mapping]: key_mappings)
{ {
@ -238,7 +238,7 @@ void control_map::handle_key_released(const event::key_released& event)
} }
} }
void control_map::handle_mouse_moved(const event::mouse_moved& event)
void control_map::handle_mouse_moved(const mouse_moved_event& event)
{ {
for (const auto& [control, mapping]: mouse_motion_mappings) for (const auto& [control, mapping]: mouse_motion_mappings)
{ {
@ -255,7 +255,7 @@ void control_map::handle_mouse_moved(const event::mouse_moved& event)
} }
} }
void control_map::handle_mouse_scrolled(const event::mouse_scrolled& event)
void control_map::handle_mouse_scrolled(const mouse_scrolled_event& event)
{ {
for (const auto& [control, mapping]: mouse_scroll_mappings) for (const auto& [control, mapping]: mouse_scroll_mappings)
{ {
@ -272,7 +272,7 @@ void control_map::handle_mouse_scrolled(const event::mouse_scrolled& event)
} }
} }
void control_map::handle_mouse_button_pressed(const event::mouse_button_pressed& event)
void control_map::handle_mouse_button_pressed(const mouse_button_pressed_event& event)
{ {
for (const auto& [control, mapping]: mouse_button_mappings) for (const auto& [control, mapping]: mouse_button_mappings)
{ {
@ -284,7 +284,7 @@ void control_map::handle_mouse_button_pressed(const event::mouse_button_pressed&
} }
} }
void control_map::handle_mouse_button_released(const event::mouse_button_released& event)
void control_map::handle_mouse_button_released(const mouse_button_released_event& event)
{ {
for (const auto& [control, mapping]: mouse_button_mappings) for (const auto& [control, mapping]: mouse_button_mappings)
{ {

+ 10
- 10
src/input/control-map.hpp View File

@ -23,7 +23,7 @@
#include "event/subscription.hpp" #include "event/subscription.hpp"
#include "event/queue.hpp" #include "event/queue.hpp"
#include "input/control.hpp" #include "input/control.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "input/mapping.hpp" #include "input/mapping.hpp"
#include <memory> #include <memory>
#include <tuple> #include <tuple>
@ -87,15 +87,15 @@ public:
void remove_mappings(); void remove_mappings();
private: private:
void handle_gamepad_axis_moved(const event::gamepad_axis_moved& event);
void handle_gamepad_button_pressed(const event::gamepad_button_pressed& event);
void handle_gamepad_button_released(const event::gamepad_button_released& event);
void handle_key_pressed(const event::key_pressed& event);
void handle_key_released(const event::key_released& event);
void handle_mouse_button_pressed(const event::mouse_button_pressed& event);
void handle_mouse_button_released(const event::mouse_button_released& event);
void handle_mouse_moved(const event::mouse_moved& event);
void handle_mouse_scrolled(const event::mouse_scrolled& event);
void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event);
void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event);
void handle_gamepad_button_released(const gamepad_button_released_event& event);
void handle_key_pressed(const key_pressed_event& event);
void handle_key_released(const key_released_event& event);
void handle_mouse_button_pressed(const mouse_button_pressed_event& event);
void handle_mouse_button_released(const mouse_button_released_event& event);
void handle_mouse_moved(const mouse_moved_event& event);
void handle_mouse_scrolled(const mouse_scrolled_event& event);
std::vector<std::shared_ptr<::event::subscription>> subscriptions; std::vector<std::shared_ptr<::event::subscription>> subscriptions;
std::vector<std::tuple<control*, gamepad_axis_mapping>> gamepad_axis_mappings; std::vector<std::tuple<control*, gamepad_axis_mapping>> gamepad_axis_mappings;

+ 10
- 10
src/input/control.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_INPUT_CONTROL_HPP #ifndef ANTKEEPER_INPUT_CONTROL_HPP
#define ANTKEEPER_INPUT_CONTROL_HPP #define ANTKEEPER_INPUT_CONTROL_HPP
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
#include <functional> #include <functional>
@ -69,19 +69,19 @@ public:
} }
/// Returns the channel through which control activated events are published. /// Returns the channel through which control activated events are published.
[[nodiscard]] inline ::event::channel<event::control_activated>& get_activated_channel() noexcept
[[nodiscard]] inline ::event::channel<control_activated_event>& get_activated_channel() noexcept
{ {
return activated_publisher.channel(); return activated_publisher.channel();
} }
/// Returns the channel through which control active events are published. /// Returns the channel through which control active events are published.
[[nodiscard]] inline ::event::channel<event::control_active>& get_active_channel() noexcept
[[nodiscard]] inline ::event::channel<control_active_event>& get_active_channel() noexcept
{ {
return active_publisher.channel(); return active_publisher.channel();
} }
/// Returns the channel through which control deactivated events are published. /// Returns the channel through which control deactivated events are published.
[[nodiscard]] inline ::event::channel<event::control_deactivated>& get_deactivated_channel() noexcept
[[nodiscard]] inline ::event::channel<control_deactivated_event>& get_deactivated_channel() noexcept
{ {
return deactivated_publisher.channel(); return deactivated_publisher.channel();
} }
@ -90,13 +90,13 @@ private:
threshold_function_type threshold_function; threshold_function_type threshold_function;
bool active; bool active;
event::control_activated activated_event;
event::control_active active_event;
event::control_deactivated deactivated_event;
control_activated_event activated_event;
control_active_event active_event;
control_deactivated_event deactivated_event;
::event::publisher<event::control_activated> activated_publisher;
::event::publisher<event::control_active> active_publisher;
::event::publisher<event::control_deactivated> deactivated_publisher;
::event::publisher<control_activated_event> activated_publisher;
::event::publisher<control_active_event> active_publisher;
::event::publisher<control_deactivated_event> deactivated_publisher;
}; };
} // namespace input } // namespace input

+ 5
- 5
src/input/device.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_INPUT_DEVICE_HPP #define ANTKEEPER_INPUT_DEVICE_HPP
#include "input/device-type.hpp" #include "input/device-type.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
#include "utility/uuid.hpp" #include "utility/uuid.hpp"
#include <optional> #include <optional>
@ -73,13 +73,13 @@ public:
} }
/// Returns the channel through which device connected events are published. /// Returns the channel through which device connected events are published.
[[nodiscard]] inline ::event::channel<event::device_connected>& get_connected_channel() noexcept
[[nodiscard]] inline ::event::channel<device_connected_event>& get_connected_channel() noexcept
{ {
return connected_publisher.channel(); return connected_publisher.channel();
} }
/// Returns the channel through which device disconnected events are published. /// Returns the channel through which device disconnected events are published.
[[nodiscard]] inline ::event::channel<event::device_disconnected>& get_disconnected_channel() noexcept
[[nodiscard]] inline ::event::channel<device_disconnected_event>& get_disconnected_channel() noexcept
{ {
return disconnected_publisher.channel(); return disconnected_publisher.channel();
} }
@ -91,8 +91,8 @@ private:
::uuid uuid; ::uuid uuid;
bool connected; bool connected;
::event::publisher<event::device_connected> connected_publisher;
::event::publisher<event::device_disconnected> disconnected_publisher;
::event::publisher<device_connected_event> connected_publisher;
::event::publisher<device_disconnected_event> disconnected_publisher;
}; };
} // namespace input } // namespace input

+ 7
- 7
src/input/gamepad.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_INPUT_GAMEPAD_HPP #define ANTKEEPER_INPUT_GAMEPAD_HPP
#include "input/device.hpp" #include "input/device.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "input/gamepad-axis.hpp" #include "input/gamepad-axis.hpp"
#include "input/gamepad-button.hpp" #include "input/gamepad-button.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
@ -123,19 +123,19 @@ public:
void move(gamepad_axis axis, float position); void move(gamepad_axis axis, float position);
/// Returns the channel through which gamepad button pressed events are published. /// Returns the channel through which gamepad button pressed events are published.
[[nodiscard]] inline ::event::channel<event::gamepad_button_pressed>& get_button_pressed_channel() noexcept
[[nodiscard]] inline ::event::channel<gamepad_button_pressed_event>& get_button_pressed_channel() noexcept
{ {
return button_pressed_publisher.channel(); return button_pressed_publisher.channel();
} }
/// Returns the channel through which gamepad button released events are published. /// Returns the channel through which gamepad button released events are published.
[[nodiscard]] inline ::event::channel<event::gamepad_button_released>& get_button_released_channel() noexcept
[[nodiscard]] inline ::event::channel<gamepad_button_released_event>& get_button_released_channel() noexcept
{ {
return button_released_publisher.channel(); return button_released_publisher.channel();
} }
/// Returns the channel through which gamepad axis moved events are published. /// Returns the channel through which gamepad axis moved events are published.
[[nodiscard]] inline ::event::channel<event::gamepad_axis_moved>& get_axis_moved_channel() noexcept
[[nodiscard]] inline ::event::channel<gamepad_axis_moved_event>& get_axis_moved_channel() noexcept
{ {
return axis_moved_publisher.channel(); return axis_moved_publisher.channel();
} }
@ -161,9 +161,9 @@ private:
float left_deadzone_roundness; float left_deadzone_roundness;
float right_deadzone_roundness; float right_deadzone_roundness;
::event::publisher<event::gamepad_button_pressed> button_pressed_publisher;
::event::publisher<event::gamepad_button_released> button_released_publisher;
::event::publisher<event::gamepad_axis_moved> axis_moved_publisher;
::event::publisher<gamepad_button_pressed_event> button_pressed_publisher;
::event::publisher<gamepad_button_released_event> button_released_publisher;
::event::publisher<gamepad_axis_moved_event> axis_moved_publisher;
}; };
} // namespace input } // namespace input

src/input/event.hpp → src/input/input-events.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_INPUT_EVENT_HPP
#define ANTKEEPER_INPUT_EVENT_HPP
#ifndef ANTKEEPER_INPUT_INPUT_EVENTS_HPP
#define ANTKEEPER_INPUT_INPUT_EVENTS_HPP
#include "input/gamepad-axis.hpp" #include "input/gamepad-axis.hpp"
#include "input/gamepad-button.hpp" #include "input/gamepad-button.hpp"
@ -39,15 +39,10 @@ class gamepad;
class keyboard; class keyboard;
class mouse; class mouse;
/**
* Input events.
*/
namespace event {
/** /**
* Event generated when a control has been activated. * Event generated when a control has been activated.
*/ */
struct control_activated
struct control_activated_event
{ {
/// Control that was activated. /// Control that was activated.
control* control; control* control;
@ -56,7 +51,7 @@ struct control_activated
/** /**
* Event generated while a control is active. * Event generated while a control is active.
*/ */
struct control_active
struct control_active_event
{ {
/// Active control. /// Active control.
control* control; control* control;
@ -68,7 +63,7 @@ struct control_active
/** /**
* Event generated when a control has been deactivated. * Event generated when a control has been deactivated.
*/ */
struct control_deactivated
struct control_deactivated_event
{ {
/// Control that was deactivated. /// Control that was deactivated.
control* control; control* control;
@ -77,7 +72,7 @@ struct control_deactivated
/** /**
* Event generated when an input mapping has been generated. * Event generated when an input mapping has been generated.
*/ */
struct input_mapped
struct input_mapped_event
{ {
/// Input mapping that was generated. /// Input mapping that was generated.
std::shared_ptr<mapping> mapping; std::shared_ptr<mapping> mapping;
@ -86,7 +81,7 @@ struct input_mapped
/** /**
* Event generated when an input device has been connected. * Event generated when an input device has been connected.
*/ */
struct device_connected
struct device_connected_event
{ {
/// Device that was connected. /// Device that was connected.
device* device; device* device;
@ -95,7 +90,7 @@ struct device_connected
/** /**
* Event generated when an input device has been disconnected. * Event generated when an input device has been disconnected.
*/ */
struct device_disconnected
struct device_disconnected_event
{ {
/// Device that was disconnected. /// Device that was disconnected.
device* device; device* device;
@ -104,7 +99,7 @@ struct device_disconnected
/** /**
* Event generated when a gamepad button has been pressed. * Event generated when a gamepad button has been pressed.
*/ */
struct gamepad_button_pressed
struct gamepad_button_pressed_event
{ {
/// Gamepad that generated the event. /// Gamepad that generated the event.
gamepad* gamepad; gamepad* gamepad;
@ -116,7 +111,7 @@ struct gamepad_button_pressed
/** /**
* Event generated when a gamepad button has been released. * Event generated when a gamepad button has been released.
*/ */
struct gamepad_button_released
struct gamepad_button_released_event
{ {
/// Gamepad that generated the event. /// Gamepad that generated the event.
gamepad* gamepad; gamepad* gamepad;
@ -128,7 +123,7 @@ struct gamepad_button_released
/** /**
* Event generated when a gamepad axis has been moved. * Event generated when a gamepad axis has been moved.
*/ */
struct gamepad_axis_moved
struct gamepad_axis_moved_event
{ {
/// Gamepad that generated the event. /// Gamepad that generated the event.
gamepad* gamepad; gamepad* gamepad;
@ -143,7 +138,7 @@ struct gamepad_axis_moved
/** /**
* Event generated when a keyboard key has been pressed. * Event generated when a keyboard key has been pressed.
*/ */
struct key_pressed
struct key_pressed_event
{ {
/// Keyboard that generated the event. /// Keyboard that generated the event.
keyboard* keyboard; keyboard* keyboard;
@ -161,7 +156,7 @@ struct key_pressed
/** /**
* Event generated when a keyboard key has been released. * Event generated when a keyboard key has been released.
*/ */
struct key_released
struct key_released_event
{ {
/// Keyboard that generated the event. /// Keyboard that generated the event.
keyboard* keyboard; keyboard* keyboard;
@ -179,7 +174,7 @@ struct key_released
/** /**
* Event generated when a mouse has been moved. * Event generated when a mouse has been moved.
*/ */
struct mouse_moved
struct mouse_moved_event
{ {
/// Mouse that generated the event. /// Mouse that generated the event.
mouse* mouse; mouse* mouse;
@ -194,7 +189,7 @@ struct mouse_moved
/** /**
* Event generated when a mouse button has been pressed. * Event generated when a mouse button has been pressed.
*/ */
struct mouse_button_pressed
struct mouse_button_pressed_event
{ {
/// Mouse that generated the event. /// Mouse that generated the event.
mouse* mouse; mouse* mouse;
@ -209,7 +204,7 @@ struct mouse_button_pressed
/** /**
* Event generated when a mouse button has been released. * Event generated when a mouse button has been released.
*/ */
struct mouse_button_released
struct mouse_button_released_event
{ {
/// Mouse that generated the event. /// Mouse that generated the event.
mouse* mouse; mouse* mouse;
@ -224,7 +219,7 @@ struct mouse_button_released
/** /**
* Event generated when a mouse has been scrolled. * Event generated when a mouse has been scrolled.
*/ */
struct mouse_scrolled
struct mouse_scrolled_event
{ {
/// Mouse that generated the event. /// Mouse that generated the event.
mouse* mouse; mouse* mouse;
@ -239,9 +234,8 @@ struct mouse_scrolled
/** /**
* Event generated when the application has been requested to quit. * Event generated when the application has been requested to quit.
*/ */
struct application_quit {};
struct application_quit_event {};
} // namespace event
} // namespace input } // namespace input
#endif // ANTKEEPER_INPUT_EVENT_HPP
#endif // ANTKEEPER_INPUT_INPUT_EVENTS_HPP

+ 5
- 5
src/input/keyboard.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_INPUT_KEYBOARD_HPP #define ANTKEEPER_INPUT_KEYBOARD_HPP
#include "input/device.hpp" #include "input/device.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "input/scancode.hpp" #include "input/scancode.hpp"
#include "input/modifier-key.hpp" #include "input/modifier-key.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
@ -61,13 +61,13 @@ public:
void release(scancode scancode, bool repeat = false, std::uint16_t modifiers = modifier_key::none); void release(scancode scancode, bool repeat = false, std::uint16_t modifiers = modifier_key::none);
/// Returns the channel through which key pressed events are published. /// Returns the channel through which key pressed events are published.
[[nodiscard]] inline ::event::channel<event::key_pressed>& get_key_pressed_channel() noexcept
[[nodiscard]] inline ::event::channel<key_pressed_event>& get_key_pressed_channel() noexcept
{ {
return key_pressed_publisher.channel(); return key_pressed_publisher.channel();
} }
/// Returns the channel through which key released events are published. /// Returns the channel through which key released events are published.
[[nodiscard]] inline ::event::channel<event::key_released>& get_key_released_channel() noexcept
[[nodiscard]] inline ::event::channel<key_released_event>& get_key_released_channel() noexcept
{ {
return key_released_publisher.channel(); return key_released_publisher.channel();
} }
@ -79,8 +79,8 @@ public:
} }
private: private:
::event::publisher<event::key_pressed> key_pressed_publisher;
::event::publisher<event::key_released> key_released_publisher;
::event::publisher<key_pressed_event> key_pressed_publisher;
::event::publisher<key_released_event> key_released_publisher;
}; };
} // namespace input } // namespace input

+ 12
- 12
src/input/mapper.cpp View File

@ -24,12 +24,12 @@ namespace input {
void mapper::connect(::event::queue& queue) void mapper::connect(::event::queue& queue)
{ {
subscriptions.emplace_back(queue.subscribe<event::gamepad_axis_moved>(std::bind_front(&mapper::handle_gamepad_axis_moved, this)));
subscriptions.emplace_back(queue.subscribe<event::gamepad_button_pressed>(std::bind_front(&mapper::handle_gamepad_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::key_pressed>(std::bind_front(&mapper::handle_key_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_button_pressed>(std::bind_front(&mapper::handle_mouse_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_moved>(std::bind_front(&mapper::handle_mouse_moved, this)));
subscriptions.emplace_back(queue.subscribe<event::mouse_scrolled>(std::bind_front(&mapper::handle_mouse_scrolled, this)));
subscriptions.emplace_back(queue.subscribe<gamepad_axis_moved_event>(std::bind_front(&mapper::handle_gamepad_axis_moved, this)));
subscriptions.emplace_back(queue.subscribe<gamepad_button_pressed_event>(std::bind_front(&mapper::handle_gamepad_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<key_pressed_event>(std::bind_front(&mapper::handle_key_pressed, this)));
subscriptions.emplace_back(queue.subscribe<mouse_button_pressed_event>(std::bind_front(&mapper::handle_mouse_button_pressed, this)));
subscriptions.emplace_back(queue.subscribe<mouse_moved_event>(std::bind_front(&mapper::handle_mouse_moved, this)));
subscriptions.emplace_back(queue.subscribe<mouse_scrolled_event>(std::bind_front(&mapper::handle_mouse_scrolled, this)));
} }
void mapper::disconnect() void mapper::disconnect()
@ -37,27 +37,27 @@ void mapper::disconnect()
subscriptions.clear(); subscriptions.clear();
} }
void mapper::handle_gamepad_axis_moved(const event::gamepad_axis_moved& event)
void mapper::handle_gamepad_axis_moved(const gamepad_axis_moved_event& event)
{ {
input_mapped_publisher.publish({std::shared_ptr<mapping>(new gamepad_axis_mapping(event.gamepad, event.axis, std::signbit(event.position)))}); input_mapped_publisher.publish({std::shared_ptr<mapping>(new gamepad_axis_mapping(event.gamepad, event.axis, std::signbit(event.position)))});
} }
void mapper::handle_gamepad_button_pressed(const event::gamepad_button_pressed& event)
void mapper::handle_gamepad_button_pressed(const gamepad_button_pressed_event& event)
{ {
input_mapped_publisher.publish({std::shared_ptr<mapping>(new gamepad_button_mapping(event.gamepad, event.button))}); input_mapped_publisher.publish({std::shared_ptr<mapping>(new gamepad_button_mapping(event.gamepad, event.button))});
} }
void mapper::handle_key_pressed(const event::key_pressed& event)
void mapper::handle_key_pressed(const key_pressed_event& event)
{ {
input_mapped_publisher.publish({std::shared_ptr<mapping>(new key_mapping(event.keyboard, event.scancode))}); input_mapped_publisher.publish({std::shared_ptr<mapping>(new key_mapping(event.keyboard, event.scancode))});
} }
void mapper::handle_mouse_button_pressed(const event::mouse_button_pressed& event)
void mapper::handle_mouse_button_pressed(const mouse_button_pressed_event& event)
{ {
input_mapped_publisher.publish({std::shared_ptr<mapping>(new mouse_button_mapping(event.mouse, event.button))}); input_mapped_publisher.publish({std::shared_ptr<mapping>(new mouse_button_mapping(event.mouse, event.button))});
} }
void mapper::handle_mouse_moved(const event::mouse_moved& event)
void mapper::handle_mouse_moved(const mouse_moved_event& event)
{ {
if (event.difference.x()) if (event.difference.x())
{ {
@ -70,7 +70,7 @@ void mapper::handle_mouse_moved(const event::mouse_moved& event)
} }
} }
void mapper::handle_mouse_scrolled(const event::mouse_scrolled& event)
void mapper::handle_mouse_scrolled(const mouse_scrolled_event& event)
{ {
if (event.velocity.x()) if (event.velocity.x())
{ {

+ 9
- 9
src/input/mapper.hpp View File

@ -23,7 +23,7 @@
#include "event/subscription.hpp" #include "event/subscription.hpp"
#include "event/queue.hpp" #include "event/queue.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "input/mapping.hpp" #include "input/mapping.hpp"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -49,21 +49,21 @@ public:
void disconnect(); void disconnect();
/// Returns the channel through which input mapped events are published. /// Returns the channel through which input mapped events are published.
[[nodiscard]] inline ::event::channel<event::input_mapped>& get_input_mapped_channel() noexcept
[[nodiscard]] inline ::event::channel<input_mapped_event>& get_input_mapped_channel() noexcept
{ {
return input_mapped_publisher.channel(); return input_mapped_publisher.channel();
} }
private: private:
void handle_gamepad_axis_moved(const event::gamepad_axis_moved& event);
void handle_gamepad_button_pressed(const event::gamepad_button_pressed& event);
void handle_key_pressed(const event::key_pressed& event);
void handle_mouse_button_pressed(const event::mouse_button_pressed& event);
void handle_mouse_moved(const event::mouse_moved& event);
void handle_mouse_scrolled(const event::mouse_scrolled& event);
void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event);
void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event);
void handle_key_pressed(const key_pressed_event& event);
void handle_mouse_button_pressed(const mouse_button_pressed_event& event);
void handle_mouse_moved(const mouse_moved_event& event);
void handle_mouse_scrolled(const mouse_scrolled_event& event);
std::vector<std::shared_ptr<::event::subscription>> subscriptions; std::vector<std::shared_ptr<::event::subscription>> subscriptions;
::event::publisher<event::input_mapped> input_mapped_publisher;
::event::publisher<input_mapped_event> input_mapped_publisher;
}; };
} // namespace input } // namespace input

+ 9
- 9
src/input/mouse.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_INPUT_MOUSE_HPP #define ANTKEEPER_INPUT_MOUSE_HPP
#include "input/device.hpp" #include "input/device.hpp"
#include "input/event.hpp"
#include "input/input-events.hpp"
#include "input/mouse-button.hpp" #include "input/mouse-button.hpp"
#include "event/publisher.hpp" #include "event/publisher.hpp"
#include "math/vector.hpp" #include "math/vector.hpp"
@ -79,25 +79,25 @@ public:
} }
/// Returns the channel through which mouse button pressed events are published. /// Returns the channel through which mouse button pressed events are published.
[[nodiscard]] inline ::event::channel<event::mouse_button_pressed>& get_button_pressed_channel() noexcept
[[nodiscard]] inline ::event::channel<mouse_button_pressed_event>& get_button_pressed_channel() noexcept
{ {
return button_pressed_publisher.channel(); return button_pressed_publisher.channel();
} }
/// Returns the channel through which mouse button released events are published. /// Returns the channel through which mouse button released events are published.
[[nodiscard]] inline ::event::channel<event::mouse_button_released>& get_button_released_channel() noexcept
[[nodiscard]] inline ::event::channel<mouse_button_released_event>& get_button_released_channel() noexcept
{ {
return button_released_publisher.channel(); return button_released_publisher.channel();
} }
/// Returns the channel through which mouse moved events are published. /// Returns the channel through which mouse moved events are published.
[[nodiscard]] inline ::event::channel<event::mouse_moved>& get_moved_channel() noexcept
[[nodiscard]] inline ::event::channel<mouse_moved_event>& get_moved_channel() noexcept
{ {
return moved_publisher.channel(); return moved_publisher.channel();
} }
/// Returns the channel through which mouse scrolled events are published. /// Returns the channel through which mouse scrolled events are published.
[[nodiscard]] inline ::event::channel<event::mouse_scrolled>& get_scrolled_channel() noexcept
[[nodiscard]] inline ::event::channel<mouse_scrolled_event>& get_scrolled_channel() noexcept
{ {
return scrolled_publisher.channel(); return scrolled_publisher.channel();
} }
@ -111,10 +111,10 @@ public:
private: private:
math::vector<std::int32_t, 2> position; math::vector<std::int32_t, 2> position;
::event::publisher<event::mouse_button_pressed> button_pressed_publisher;
::event::publisher<event::mouse_button_released> button_released_publisher;
::event::publisher<event::mouse_moved> moved_publisher;
::event::publisher<event::mouse_scrolled> scrolled_publisher;
::event::publisher<mouse_button_pressed_event> button_pressed_publisher;
::event::publisher<mouse_button_released_event> button_released_publisher;
::event::publisher<mouse_moved_event> moved_publisher;
::event::publisher<mouse_scrolled_event> scrolled_publisher;
}; };
} // namespace input } // namespace input

+ 2
- 2
src/main.cpp View File

@ -67,12 +67,12 @@ int main(int argc, char* argv[])
std::osyncstream(std::cout) << std::format std::osyncstream(std::cout) << std::format
( (
"{:8.03f} {}:{}:{}: {}{}: {}{}\n",
"{}{:8.03f} {}:{}:{}: {}: {}{}\n",
colors[static_cast<int>(event.severity)],
std::chrono::duration<float>(event.time - launch_time).count(), std::chrono::duration<float>(event.time - launch_time).count(),
std::filesystem::path(event.location.file_name()).filename().string(), std::filesystem::path(event.location.file_name()).filename().string(),
event.location.line(), event.location.line(),
event.location.column(), event.location.column(),
colors[static_cast<int>(event.severity)],
severities[static_cast<int>(event.severity)], severities[static_cast<int>(event.severity)],
event.message, event.message,
ansi::reset ansi::reset

+ 1
- 3
src/ui/ui.hpp View File

@ -20,9 +20,7 @@
#ifndef ANTKEEPER_UI_HPP #ifndef ANTKEEPER_UI_HPP
#define ANTKEEPER_UI_HPP #define ANTKEEPER_UI_HPP
/// UI elements
/// UI elements.
namespace ui {} namespace ui {}
#include "ui/element.hpp"
#endif // ANTKEEPER_UI_HPP #endif // ANTKEEPER_UI_HPP

Loading…
Cancel
Save