Nugget
|
A simple class to access the pads. More...
#include <psyqo/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. | |
void | setOnEvent (eastl::function< void(Event)> &&callback) |
Sets the event callback function. | |
bool | isPadConnected (Pad pad) const |
Returns the state of a pad. | |
bool | isButtonPressed (Pad pad, Button button) const |
Returns the state of a button. | |
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. This class will not be able to be used if the kernel is taken over. See the Kernel
namespace for more information.
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.
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.
pad | The pad to query. |
button | The button to query. |
|
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.
pad | The pad to query. |
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.