Press, Held, and Release events from Steam API controllers properly respond. Fix a bug involving the steam input API not returning handles properly on initialization. Release Build 8281.

This commit is contained in:
2024-03-24 03:18:25 -05:00
parent 7b3c6adcc5
commit 1d1929a1cc
4 changed files with 37 additions and 29 deletions
+16 -15
View File
@@ -98,24 +98,25 @@ void Input::UpdateSteamInput(){
HWButton prevState=data.second;
InputDigitalActionHandle_t inputHnd=SteamInput()->GetDigitalActionHandle(data.first.c_str());
InputDigitalActionData_t buttonData=SteamInput()->GetDigitalActionData(steamControllers[i],inputHnd);
if(!buttonData.bActive)continue; //Ignore inputs that are not active.
data.second.bPressed=data.second.bReleased=false;
if(!data.second.bHeld&&buttonData.bState){
data.second.bPressed=true;
activeSteamControllerIndex=i;
}
data.second.bHeld=buttonData.bState;
if(data.second.bHeld&&!buttonData.bState){
data.second.bReleased=true;
activeSteamControllerIndex=i;
}
data.second.bHeld=buttonData.bState;
}
}
}
}
bool Input::Pressed(){
if(!game->IsFocused())return false;
//if(!game->IsFocused())return false;
bool inputPressed=false;
switch(type){
case KEY:{
@@ -132,7 +133,7 @@ bool Input::Pressed(){
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed;
if(enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed)inputPressed=true;
}break;
case ANALOG:{
//An analog input can never be "pressed". No-op.
@@ -142,7 +143,7 @@ bool Input::Pressed(){
}
}
if(inputPressed){
usingGamepad=type==CONTROLLER;
usingGamepad=type==CONTROLLER||type==STEAM;
return true;
}
return false;
@@ -153,20 +154,20 @@ bool Input::Held(){
bool inputHeld=false;
switch(type){
case KEY:{
inputHeld=game->GetKey(Key(key)).bHeld;
inputHeld|=game->GetKey(Key(key)).bHeld;
}break;
case MOUSE:{
inputHeld=game->GetMouse(key).bHeld;
inputHeld|=game->GetMouse(key).bHeld;
}break;
case CONTROLLER:{
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true;
if(gamepad->stillConnected)inputHeld|=gamepad->getButton(static_cast<GPButtons>(key)).bHeld;
}
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
inputHeld|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
}break;
case ANALOG:{
//An analog input can never be "held". No-op.
@@ -176,31 +177,31 @@ bool Input::Held(){
}
}
if(inputHeld){
usingGamepad=type==CONTROLLER;
usingGamepad=type==CONTROLLER||type==STEAM;
return true;
}
return false;
}
bool Input::Released(){
if(!game->IsFocused())return false;
//if(!game->IsFocused())return false;
bool inputReleased=false;
switch(type){
case KEY:{
inputReleased=game->GetKey(Key(key)).bReleased;
inputReleased|=game->GetKey(Key(key)).bReleased;
}break;
case MOUSE:{
inputReleased=game->GetMouse(key).bReleased;
inputReleased|=game->GetMouse(key).bReleased;
}break;
case CONTROLLER:{
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true;
if(gamepad->stillConnected)inputReleased|=gamepad->getButton(static_cast<GPButtons>(key)).bReleased;
}
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
inputReleased|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
}break;
case ANALOG:{
//An analog input can never be "released". No-op.
@@ -210,7 +211,7 @@ bool Input::Released(){
}
}
if(inputReleased){
usingGamepad=type==CONTROLLER;
usingGamepad=type==CONTROLLER||type==STEAM;
return true;
}
return false;