From 10f4fe05513759c02d9f195800c84097f56cb6db Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 29 May 2024 20:23:59 +0200 Subject: [PATCH] chore: updated doxygen-styled docs --- game_state.hpp | 4 ++++ player_input.hpp | 53 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/game_state.hpp b/game_state.hpp index 1947285..9d46415 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -4,6 +4,10 @@ #include namespace utils { +/*! Parent class for saved game state. + * + * Inherit and add godot properties to save persistently. + */ class GameState : public godot::Resource { GDCLASS(GameState, godot::Resource); static void _bind_methods(); diff --git a/player_input.hpp b/player_input.hpp index 90de3d4..1fe3936 100644 --- a/player_input.hpp +++ b/player_input.hpp @@ -20,6 +20,7 @@ class PlayerInput : public gd::Node { static void _bind_methods(); public: /*! A PlayerInput action listener. + * * A listener is a combination of a positive and negative action and a callable. * The expected callable signature is `void (godot::Ref event, float value)` * actions can also be "special" actions prefixed with `_`. @@ -28,14 +29,18 @@ public: struct Listener { friend class PlayerInput; private: - // the two actions, evaluated as positive - negative + //! Negative action on axis, evaluates to -1. gd::String actionNegative{""}; + //! Positive action on axis, evaluates to +1. gd::String actionPositive{""}; - // the last cached action, if the newest result matches this, the event will be considered - // duplicate and ignored (not passed to listener) + /*! The last cached action. + * + * If the newest result matches this, the event will be considered duplicate and ignored (not passed to listener) + */ float lastCached{0.f}; + //! The listening function. gd::Callable callable; - // if either actionNegative or actionPositive is a _mouse_ event this will be true + //! If either actionNegative or actionPositive is a _mouse_ event this will be true bool isMouseEvent{false}; public: @@ -44,15 +49,17 @@ public: Listener(gd::String action, gd::Callable callable); // evaluate the current state of an action. static std::optional evaluate_action(gd::String const &action); - // check if this event has any chance to result in a trigger, does not evaluate the event or - // poll current input state + /*! Check if this event has any chance to result in a trigger. + * + * Does not evaluate the event or poll current input state + */ bool has_changed(gd::Ref const &event); - // evaluate the event for changes to either actionPositive or actionNegative + //! evaluate the event for changes to either actionPositive or actionNegative float evaluate(gd::Ref const &event); - bool operator==(PlayerInput::Listener const& b) const; }; public: + //! Returns the last stored mouse delta. static gd::Vector2 get_last_mouse_motion(); virtual void _enter_tree() override; @@ -60,27 +67,41 @@ public: virtual void _unhandled_input(gd::Ref const &event) override; virtual void _process(double deltaTime) override; + //! Start listening for action. void listen_to(Listener const &listener); + /*! Start listening for action. + * + * Shorthand for `listen_to(Listener(action, callable))`. + */ void listen_to(gd::String action, gd::Callable callable); + /*! Start listening for action. + * + * Shorthand for `listen_to(Listener(negative, positive, callable))`. + */ void listen_to(gd::String negative, gd::String positive, gd::Callable callable); + //! Remove any listeners related to node. void stop_listening(Node *node); + //! Remove listeners exactly equal to listener. void stop_listening(Listener const &listener); + //! Remove all listeners. void clear_listeners(); - + //! set the device observe events from. void set_device(int id); private: - // the last mouse motion, updated by the primary instance + //! The last mouse motion, updated by the primary instance static gd::Vector2 lastMouseMotion; - // does a primary instance exist + //! Does a primary instance exist static bool primaryExists; - // is this the primary instance - // the primary instance is responsible for updating static - // variables like lastMouseMotion + /*! Is this the primary instance. + * + * The primary instance is responsible for updating static variables like lastMouseMotion. + */ bool isPrimary{false}; - int device{-1}; + //! which device to observe events from. + int device{-1}; - // current listeners for this instance + //! current listeners for this instance gd::Vector listeners{}; }; }