Finalize API and add comments
This commit is contained in:
@@ -6,6 +6,17 @@
|
||||
|
||||
namespace input
|
||||
{
|
||||
/*!
|
||||
Wrapper around the IVRInput GetAnalogActionData with error handling.
|
||||
|
||||
The struct is created and zero initalized in this function instead of being
|
||||
passed as reference since the size is currently only 28 bytes, and currently
|
||||
only two bools are used from the entire struct.
|
||||
MSVC on /O2 will likely completely optimize the function call away but even if
|
||||
it isn't the struct will still need to be created somewhere, and with move
|
||||
semantics it almost doesn't matter if the struct is created in the calling
|
||||
function and passed as reference, or created in this function.
|
||||
*/
|
||||
vr::InputDigitalActionData_t getDigitalActionData( Action& action )
|
||||
{
|
||||
if ( action.type() != ActionType::Digital )
|
||||
@@ -37,6 +48,17 @@ vr::InputDigitalActionData_t getDigitalActionData( Action& action )
|
||||
return handleData;
|
||||
}
|
||||
|
||||
/*!
|
||||
Wrapper around the IVRInput GetAnalogActionData with error handling.
|
||||
|
||||
The struct is created and zero initalized in this function instead of being
|
||||
passed as reference since the size is currently only 28 bytes, and currently
|
||||
only two bools are used from the entire struct.
|
||||
MSVC on /O2 will likely completely optimize the function call away but even if
|
||||
it isn't the struct will still need to be created somewhere, and with move
|
||||
semantics it almost doesn't matter if the struct is created in the calling
|
||||
function and passed as reference, or created in this function.
|
||||
*/
|
||||
vr::InputAnalogActionData_t getAnalogActionData( Action& action )
|
||||
{
|
||||
if ( action.type() != ActionType::Analog )
|
||||
@@ -68,6 +90,12 @@ vr::InputAnalogActionData_t getAnalogActionData( Action& action )
|
||||
return handleData;
|
||||
}
|
||||
|
||||
/*!
|
||||
Gets the action state of an Action.
|
||||
This will only return true the first time the button is released. It is
|
||||
necessary to release the button and the push it again in order for this function
|
||||
to return true again.
|
||||
*/
|
||||
bool isDigitalActionActivatedOnce( Action& action )
|
||||
{
|
||||
const auto handleData = getDigitalActionData( action );
|
||||
@@ -75,6 +103,10 @@ bool isDigitalActionActivatedOnce( Action& action )
|
||||
return handleData.bState && handleData.bChanged;
|
||||
}
|
||||
|
||||
/*!
|
||||
Gets the action state of an Action.
|
||||
This will continually return true while the button is held down.
|
||||
*/
|
||||
bool isDigitalActionActivatedConstant( Action& action )
|
||||
{
|
||||
const auto handleData = getDigitalActionData( action );
|
||||
@@ -82,6 +114,14 @@ bool isDigitalActionActivatedConstant( Action& action )
|
||||
return handleData.bState;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets up the input systems.
|
||||
Actions should be added to the initializer list before the body of the
|
||||
constructor. Actions should be certain that the action name strings are
|
||||
correctly input, and that the correct type is provided.
|
||||
Wrong action names may not result in direct error messages, but just features
|
||||
mystically not working.
|
||||
*/
|
||||
SteamIVRInput::SteamIVRInput()
|
||||
: m_manifest(), m_mainSet( input_strings::k_setMain ),
|
||||
m_nextTrack( input_strings::k_actionNextTrack, ActionType::Digital )
|
||||
@@ -90,13 +130,23 @@ SteamIVRInput::SteamIVRInput()
|
||||
m_activeActionSet.ulRestrictedToDevice = vr::k_ulInvalidInputValueHandle;
|
||||
m_activeActionSet.nPriority = 0;
|
||||
}
|
||||
/*!
|
||||
Returns true if the next media track should be played.
|
||||
|
||||
Will only return true the first time that the button is pressed. Holding the
|
||||
button down will result in false until it has been released and pushed again.
|
||||
*/
|
||||
bool SteamIVRInput::nextSong()
|
||||
{
|
||||
return isDigitalActionActivatedOnce( m_nextTrack );
|
||||
}
|
||||
|
||||
void SteamIVRInput::Loop()
|
||||
/*!
|
||||
Updates the active action set(s).
|
||||
Should be called every frame, or however often you want the input system to
|
||||
update state.
|
||||
*/
|
||||
void SteamIVRInput::UpdateStates()
|
||||
{
|
||||
constexpr auto numberOfSets = 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user