Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Controller Class Referenceabstract

Represents a joystick or any additional controller. More...

#include <Controller.hpp>

Classes

struct  ControllerButton
 The state of a controller button. More...
 

Public Types

enum  Input {
  ButtonX , ButtonY , ButtonA , ButtonB ,
  BumperL1 , TriggerL2 , ButtonL3 , BumperR1 ,
  TriggerR2 , ButtonR3 , ButtonUp , ButtonLeft ,
  ButtonDown , ButtonRight , ButtonLogo , ButtonMenu ,
  ButtonView , PadLeftX , PadLeftY , PadRightX ,
  PadRightY , InputCount
}
 Controller inputs, based on the Xbox controller layout.
 

Public Member Functions

 Controller ()
 Constructor.
 
virtual bool activate (int id)=0
 
virtual void deactivate ()=0
 
virtual void update ()=0
 
bool pressed (const Controller::Input &input) const
 
bool triggered (const Controller::Input &input, bool absorb=false)
 
float axis (const Controller::Input &input) const
 
int id () const
 
std::string name () const
 
std::string guid () const
 
virtual ~Controller ()=default
 Destructor.
 
 Controller (const Controller &)=delete
 
Controlleroperator= (const Controller &)=delete
 
 Controller (Controller &&)=delete
 
Controlleroperator= (Controller &&)=delete
 

Static Public Member Functions

static void saveConfiguration (const std::string &outputPath, const std::string &guid, const std::string &name, const std::vector< int > &axesMapping, const std::vector< int > &buttonsMapping)
 
static bool parseConfiguration (const std::string &settingsContent, std::vector< int > &axesMapping, std::vector< int > &buttonsMapping)
 

Protected Member Functions

void reset ()
 

Protected Attributes

ControllerButton _buttons [Controller::Input::InputCount]
 States of all possible buttons.
 
float _axes [Controller::Input::InputCount]
 States of all possible axis.
 
int _id = -1
 Joystick ID (or -1 if no joystick is connected).
 
std::string _name = "Unknown"
 Name of the joystick.
 
std::string _guid = "0x0"
 GUID of the joystick.
 

Detailed Description

Represents a joystick or any additional controller.

Inherited by GamepadController, and RawController.

Constructor & Destructor Documentation

◆ Controller() [1/2]

Controller::Controller ( const Controller )
delete

Copy constructor.

◆ Controller() [2/2]

Controller::Controller ( Controller &&  )
delete

Move constructor.

Member Function Documentation

◆ activate()

virtual bool Controller::activate ( int  id)
pure virtual

Enable the controller.

Parameters
idthe ID of the controller.
Returns
true if the controller was correctly setup

Implemented in GamepadController, and RawController.

◆ axis()

float Controller::axis ( const Controller::Input input) const

Query the amount of displacement along a given axis (for joysticks and triggers).

Parameters
inputthe button or pad
Returns
the current amount of displacement

◆ deactivate()

virtual void Controller::deactivate ( )
pure virtual

Disable the controller.

Implemented in GamepadController, and RawController.

◆ guid()

std::string Controller::guid ( ) const
inline

Query the SDL/GLFW GUID of the controller.

Returns
the guid

◆ id()

int Controller::id ( ) const
inline

Query the controller ID.

Returns
the id

◆ name()

std::string Controller::name ( ) const
inline

Query the name of the controller.

Returns
the name

◆ operator=() [1/2]

Controller & Controller::operator= ( const Controller )
delete

Copy assignment.

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Controller & Controller::operator= ( Controller &&  )
delete

Move assignment.

Returns
a reference to the object assigned to

◆ parseConfiguration()

bool Controller::parseConfiguration ( const std::string &  settingsContent,
std::vector< int > &  axesMapping,
std::vector< int > &  buttonsMapping 
)
static

Parse a buttons/axes mapping configuration from the given string.

Parameters
settingsContentthe string containing the configuration to parse
axesMappingthe axes mapping to populate
buttonsMappingthe buttons mapping to populate
Returns
true if the configuration was properly parsed

◆ pressed()

bool Controller::pressed ( const Controller::Input input) const

Query if a given button is currently held.

Parameters
inputthe button
Returns
true if the button is pressed

◆ reset()

void Controller::reset ( )
protected

Reset the controller state and mark it as disconnected.

◆ saveConfiguration()

void Controller::saveConfiguration ( const std::string &  outputPath,
const std::string &  guid,
const std::string &  name,
const std::vector< int > &  axesMapping,
const std::vector< int > &  buttonsMapping 
)
static

Save a configuration to a file on disk.

Parameters
outputPaththe file to write the configuration to
guidthe GLFW/SDL GUID
namethe user-readable name
axesMappingthe axes mapping to save
buttonsMappingthe buttons mapping to save

◆ triggered()

bool Controller::triggered ( const Controller::Input input,
bool  absorb = false 
)

Query if a given button was pressed at this frame precisely.

Parameters
inputthe button
absorbshould the press event be hidden from future queries during the current frame
Returns
true if the button was triggered at this frame.

◆ update()

virtual void Controller::update ( )
pure virtual

Update the internal controller state (once per frame).

Implemented in GamepadController, and RawController.


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