Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
InputSystem Class Reference

SDL-backed implementation of the input provider interface. More...

#include <input_system.h>

Inheritance diagram for InputSystem:
[legend]

Public Member Functions

bool is_key_held (KeyCode key) const override
 Returns whether the specified key is currently held down.
 
KeyCode get_pressed_key () const override
 Returns the first key pressed this frame.
 
bool is_key_pressed (KeyCode key) const override
 Returns true on the frame the specified key transitions to pressed.
 
bool is_key_released (KeyCode key) const override
 Returns true on the frame the specified key transitions to released.
 
bool any_key_held () const override
 Returns true if any key is currently held down.
 
bool any_key_pressed () const override
 Returns true if any key was pressed this frame.
 
bool any_key_released () const override
 Returns true on the frame any key transitions to released.
 
bool is_mouse_held (MouseButton button) const override
 Returns whether the specified mouse button is currently held down.
 
bool is_mouse_pressed (MouseButton button) const override
 Returns true on the frame the specified mouse button transitions to pressed.
 
bool is_mouse_released (MouseButton button) const override
 Returns true on the frame the specified mouse button transitions to released.
 
bool any_mouse_held () const override
 Returns true if any mouse button is currently held down.
 
bool any_mouse_pressed () const override
 Returns true if any mouse button was pressed this frame.
 
bool any_mouse_released () const override
 Returns true on the frame any mouse button transitions to released.
 
const Pointmouse_position () const override
 Returns the current mouse cursor position (X, Y) in window coordinates.
 
std::pair< float, float > mouse_delta () const override
 Returns the change in mouse position since the last frame (deltaX, deltaY).
 
bool mouse_moved () const override
 Returns true if the mouse moved during the current frame.
 
std::pair< float, float > mouse_scroll () const override
 Returns the accumulated scroll offset along X and Y axes.
 
std::pair< float, float > mouse_scroll_delta () const override
 Returns the scroll delta since the last frame (deltaX, deltaY).
 
MouseDirection mouse_scroll_direction () const override
 Returns the last detected scroll direction as an integer enum.
 
void reset_state () override
 Clears all input states (useful when changing scenes or focus).
 
void register_events () override
 Registers necessary event listeners with the underlying system.
 
void update () override
 Polls the underlying system for input updates.
 
- Public Member Functions inherited from IInputProvider
virtual ~IInputProvider ()=default
 
void set_input (std::unique_ptr< IInput > input)
 
std::optional< std::reference_wrapper< IInput > > input () const
 

Protected Attributes

std::map< KeyCode, KeyStatekey_states_
 Per-key state cache for frame-level input tracking.
 
MouseState mouse_state_
 Mouse state cache for frame-level input tracking.
 

Detailed Description

SDL-backed implementation of the input provider interface.

Polls keyboard state from SDL each frame and tracks key transitions. Acts as the bridge between SDL event data and the engine’s logical input model.

Member Function Documentation

◆ any_key_held()

bool InputSystem::any_key_held ( ) const
overridevirtual

Returns true if any key is currently held down.

Handy for pausing or skipping scenes on any user interaction.

Implements IInputProvider.

◆ any_key_pressed()

bool InputSystem::any_key_pressed ( ) const
overridevirtual

Returns true if any key was pressed this frame.

Used for detecting first input or simple "Press any key" prompts.

Implements IInputProvider.

◆ any_key_released()

bool InputSystem::any_key_released ( ) const
overridevirtual

Returns true on the frame any key transitions to released.

Useful for detecting global input releases or cancellation events.

Implements IInputProvider.

◆ any_mouse_held()

bool InputSystem::any_mouse_held ( ) const
overridevirtual

Returns true if any mouse button is currently held down.

Useful for generic interaction detection or camera controls.

Implements IInputProvider.

◆ any_mouse_pressed()

bool InputSystem::any_mouse_pressed ( ) const
overridevirtual

Returns true if any mouse button was pressed this frame.

Detects first mouse interaction or UI click triggers.

Implements IInputProvider.

◆ any_mouse_released()

bool InputSystem::any_mouse_released ( ) const
overridevirtual

Returns true on the frame any mouse button transitions to released.

Helps detect end of drag or click-release events.

Implements IInputProvider.

◆ get_pressed_key()

KeyCode InputSystem::get_pressed_key ( ) const
overridevirtual

Returns the first key pressed this frame.

Useful for detecting initial input.

Implements IInputProvider.

◆ is_key_held()

bool InputSystem::is_key_held ( KeyCode  key) const
overridevirtual

Returns whether the specified key is currently held down.

Suitable for continuous input such as movement or sustained actions.

Implements IInputProvider.

◆ is_key_pressed()

bool InputSystem::is_key_pressed ( KeyCode  key) const
overridevirtual

Returns true on the frame the specified key transitions to pressed.

Supports one-shot actions such as jumping or confirming selections.

Implements IInputProvider.

◆ is_key_released()

bool InputSystem::is_key_released ( KeyCode  key) const
overridevirtual

Returns true on the frame the specified key transitions to released.

Useful for detecting input releases or cancellation events.

Implements IInputProvider.

◆ is_mouse_held()

bool InputSystem::is_mouse_held ( MouseButton  button) const
overridevirtual

Returns whether the specified mouse button is currently held down.

Suitable for continuous input such as aiming or dragging.

Implements IInputProvider.

◆ is_mouse_pressed()

bool InputSystem::is_mouse_pressed ( MouseButton  button) const
overridevirtual

Returns true on the frame the specified mouse button transitions to pressed.

Supports one-shot actions such as firing or selecting.

Implements IInputProvider.

◆ is_mouse_released()

bool InputSystem::is_mouse_released ( MouseButton  button) const
overridevirtual

Returns true on the frame the specified mouse button transitions to released.

Useful for detecting clicks, drops, or interaction ends.

Implements IInputProvider.

◆ mouse_delta()

std::pair< float, float > InputSystem::mouse_delta ( ) const
overridevirtual

Returns the change in mouse position since the last frame (deltaX, deltaY).

Can be used to detect relative movement for camera rotation or drag operations.

Implements IInputProvider.

◆ mouse_moved()

bool InputSystem::mouse_moved ( ) const
overridevirtual

Returns true if the mouse moved during the current frame.

Useful for conditional logic that only triggers when the cursor changes position.

Implements IInputProvider.

◆ mouse_position()

const Point & InputSystem::mouse_position ( ) const
overridevirtual

Returns the current mouse cursor position (X, Y) in window coordinates.

Useful for UI interaction, cursor tracking, or camera control.

Implements IInputProvider.

◆ mouse_scroll()

std::pair< float, float > InputSystem::mouse_scroll ( ) const
overridevirtual

Returns the accumulated scroll offset along X and Y axes.

Useful for continuous scrolling or zooming interactions.

Implements IInputProvider.

◆ mouse_scroll_delta()

std::pair< float, float > InputSystem::mouse_scroll_delta ( ) const
overridevirtual

Returns the scroll delta since the last frame (deltaX, deltaY).

Useful for detecting incremental scroll events for UI or gameplay.

Implements IInputProvider.

◆ mouse_scroll_direction()

MouseDirection InputSystem::mouse_scroll_direction ( ) const
overridevirtual

Returns the last detected scroll direction as an integer enum.

Can be used to determine the general scroll direction (up, down, left, right).

Implements IInputProvider.

◆ register_events()

void InputSystem::register_events ( )
overridevirtual

Registers necessary event listeners with the underlying system.

Must be called during initialization to ensure input events are captured.

Implements IInputProvider.

◆ reset_state()

void InputSystem::reset_state ( )
overridevirtual

Clears all input states (useful when changing scenes or focus).

Ensures stale input doesn’t carry over between menus or gameplay.

Implements IInputProvider.

◆ update()

void InputSystem::update ( )
overridevirtual

Polls the underlying system for input updates.

Usually called once per frame before querying input state.

Implements IInputProvider.

Member Data Documentation

◆ key_states_

std::map<KeyCode, KeyState> InputSystem::key_states_
protected

Per-key state cache for frame-level input tracking.

Indexed by logical key to decouple SDL scancodes from engine logic. Internal only—consumers should query through the public interface.

◆ mouse_state_

MouseState InputSystem::mouse_state_
protected

Mouse state cache for frame-level input tracking.

Tracks button states, cursor position, movement deltas, and scroll information. Indexed by logical mouse button to decouple backend events from engine logic. Internal only—consumers should query through the public interface.


The documentation for this class was generated from the following file: