Nugget
Classes | Public Types | Public Member Functions | List of all members
psyqo::SimplePad Class Reference

A simple class to access the pads. More...

#include <simplepad.hh>

Classes

struct  Event
 

Public Types

enum  Pad { Pad1 , Pad2 }
 
enum  Button {
  Select = 0 , L3 = 1 , R3 = 2 , Start = 3 ,
  Up = 4 , Right = 5 , Down = 6 , Left = 7 ,
  L2 = 8 , R2 = 9 , L1 = 10 , R1 = 11 ,
  Triangle = 12 , Circle = 13 , Cross = 14 , Square = 15
}
 

Public Member Functions

void initialize ()
 Initializes the pads. More...
 
void setOnEvent (eastl::function< void(Event)> &&callback)
 Sets the event callback function. More...
 
bool isPadConnected (Pad pad) const
 Returns the state of a pad. More...
 
bool isButtonPressed (Pad pad, Button button) const
 Returns the state of a button. More...
 

Detailed Description

A simple class to access the pads.

This class is meant to be used as a singleton, probably in the Application derived class. It is a simple thunk to the BIOS' PAD interface, and has the same caveats, namely that it should be initialized prior using the BIOS' memory card functions, and that polling will alternate between the two pads at each frame when two pads are connected, which can introduce input lags.

Member Function Documentation

◆ initialize()

void psyqo::SimplePad::initialize ( )

Initializes the pads.

This will initialize the pads polling by calling the BIOS' interface. This means this method cannot be called from the prepare method of the Application class, but rather from the start method of the root Scene object. Also, there can be interference with the BIOS' memory card functions, so this method is explicit to be called in the right order.

◆ isButtonPressed()

bool psyqo::SimplePad::isButtonPressed ( Pad  pad,
Button  button 
) const
inline

Returns the state of a button.

Returns the state of a button. The state is a boolean value that is true if the button is pressed, and false otherwise.

Parameters
padThe pad to query.
buttonThe button to query.
Returns
A boolean value indicating whether the button is pressed.

◆ isPadConnected()

bool psyqo::SimplePad::isPadConnected ( Pad  pad) const
inline

Returns the state of a pad.

Returns the state of a pad. The state is a boolean value that is true if the pad is connected, and false otherwise.

Parameters
padThe pad to query.
Returns
A boolean value indicating whether the pad is connected.

◆ setOnEvent()

void psyqo::SimplePad::setOnEvent ( eastl::function< void(Event)> &&  callback)
inline

Sets the event callback function.

The event callback will be called for each pad-related event, such as pad connection / disconnection, or button press / release. The callback will only be called between frames.

Scenes that are calling setOnEvent during their start method should call setOnEvent again in their teardown method with the nullptr value in order to unregister the event callback cleanly.

Only one callback can be registered at a time, so setting a new callback will simply remove the previous one.

Careful about what is called from the callback: pushing or popping scenes might call into setOnEvent as a result, and could end up corrupting memory as a result of the callback being deleted while being executed.


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