Create DigitalAction and AnalogAction types

This errors at compile time if the wrong action is being used, instead
of at runtime.
This commit is contained in:
Vasily
2019-03-16 14:07:26 +01:00
parent ab69d3180c
commit a70fade089
4 changed files with 69 additions and 107 deletions
+13 -11
View File
@@ -24,8 +24,7 @@ with a name similar to that of the one in the actions manifest.
class Action
{
public:
Action( const char* const actionName, const ActionType type )
: m_name( actionName ), m_type( type )
Action( const char* const actionName ) : m_name( actionName )
{
auto error = vr::VRInput()->GetActionHandle( actionName, &m_handle );
@@ -49,19 +48,22 @@ public:
{
return m_name;
}
/*!
The type of the action. Used for runtime checking that the wrong functions
aren't called.
*/
ActionType type() const noexcept
{
return m_type;
}
private:
vr::VRActionHandle_t m_handle = 0;
const std::string m_name;
const ActionType m_type = ActionType::Undefined;
};
class DigitalAction : public Action
{
public:
DigitalAction( const char* const actionName ) : Action( actionName ) {}
};
class AnalogAction : public Action
{
public:
AnalogAction( const char* const actionName ) : Action( actionName ) {}
};
} // namespace input