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.

mac-build
sigonasr2 11 months ago
parent 7b3c6adcc5
commit 1d1929a1cc
  1. 33
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 31
      Adventures in Lestoria/Key.cpp
  3. 2
      Adventures in Lestoria/Version.h
  4. BIN
      x64/Release/Adventures in Lestoria.exe

@ -326,17 +326,6 @@ bool AiL::OnUserCreate(){
if(SteamAPI_RestartAppIfNecessary(2895980U))return false; //Immediately quit if steam is detected and can be started through it. if(SteamAPI_RestartAppIfNecessary(2895980U))return false; //Immediately quit if steam is detected and can be started through it.
if(Steam_Init()){ if(Steam_Init()){
std::cout<<"Steam API Initialized successfully!"<<std::endl; std::cout<<"Steam API Initialized successfully!"<<std::endl;
if(SteamUtils()!=nullptr){
SteamUtils()->SetWarningMessageHook([](int severity,const char*message){
std::cout<<std::format("STEAM[{}]: {}",severity,std::string(message))<<std::endl;
});
}
if(SteamInput()!=nullptr){
SteamInput()->Init(false);
SteamInput()->RunFrame();
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls");
}
}else{ }else{
std::cout<<"Steam API failed to initialize!"<<std::endl; std::cout<<"Steam API failed to initialize!"<<std::endl;
} }
@ -357,8 +346,13 @@ bool AiL::OnUserUpdate(float fElapsedTime){
levelTime+=fElapsedTime; levelTime+=fElapsedTime;
SteamAPI_RunCallbacks(); SteamAPI_RunCallbacks();
if(SteamInput()){ if(SteamInput()){
if(Input::ingameControlsHandle==Input::menuControlsHandle){
//Something went wrong so try initializing again...
std::cout<<"WARNING! Steam Input system was not ready and has not set the action set control handles properly! Trying again..."<<std::endl;
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls");
}
SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle); SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle);
SteamInput()->RunFrame();
Input::UpdateSteamInput(); Input::UpdateSteamInput();
} }
@ -3789,5 +3783,18 @@ int AiL::GetLoadoutSize()const{
} }
bool AiL::Steam_Init(){ bool AiL::Steam_Init(){
return SteamAPI_Init(); if(SteamAPI_Init()){
if(SteamUtils()!=nullptr){
SteamUtils()->SetWarningMessageHook([](int severity,const char*message){
std::cout<<std::format("STEAM[{}]: {}",severity,std::string(message))<<std::endl;
});
}
if(SteamInput()!=nullptr){
SteamInput()->Init(false);
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls");
}
return true;
}
return false;
} }

@ -98,24 +98,25 @@ void Input::UpdateSteamInput(){
HWButton prevState=data.second; HWButton prevState=data.second;
InputDigitalActionHandle_t inputHnd=SteamInput()->GetDigitalActionHandle(data.first.c_str()); InputDigitalActionHandle_t inputHnd=SteamInput()->GetDigitalActionHandle(data.first.c_str());
InputDigitalActionData_t buttonData=SteamInput()->GetDigitalActionData(steamControllers[i],inputHnd); 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; data.second.bPressed=data.second.bReleased=false;
if(!data.second.bHeld&&buttonData.bState){ if(!data.second.bHeld&&buttonData.bState){
data.second.bPressed=true; data.second.bPressed=true;
activeSteamControllerIndex=i; activeSteamControllerIndex=i;
} }
data.second.bHeld=buttonData.bState;
if(data.second.bHeld&&!buttonData.bState){ if(data.second.bHeld&&!buttonData.bState){
data.second.bReleased=true; data.second.bReleased=true;
activeSteamControllerIndex=i; activeSteamControllerIndex=i;
} }
data.second.bHeld=buttonData.bState;
} }
} }
} }
} }
bool Input::Pressed(){ bool Input::Pressed(){
if(!game->IsFocused())return false; //if(!game->IsFocused())return false;
bool inputPressed=false; bool inputPressed=false;
switch(type){ switch(type){
case KEY:{ case KEY:{
@ -132,7 +133,7 @@ bool Input::Pressed(){
} }
}break; }break;
case STEAM:{ case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed; if(enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed)inputPressed=true;
}break; }break;
case ANALOG:{ case ANALOG:{
//An analog input can never be "pressed". No-op. //An analog input can never be "pressed". No-op.
@ -142,7 +143,7 @@ bool Input::Pressed(){
} }
} }
if(inputPressed){ if(inputPressed){
usingGamepad=type==CONTROLLER; usingGamepad=type==CONTROLLER||type==STEAM;
return true; return true;
} }
return false; return false;
@ -153,20 +154,20 @@ bool Input::Held(){
bool inputHeld=false; bool inputHeld=false;
switch(type){ switch(type){
case KEY:{ case KEY:{
inputHeld=game->GetKey(Key(key)).bHeld; inputHeld|=game->GetKey(Key(key)).bHeld;
}break; }break;
case MOUSE:{ case MOUSE:{
inputHeld=game->GetMouse(key).bHeld; inputHeld|=game->GetMouse(key).bHeld;
}break; }break;
case CONTROLLER:{ case CONTROLLER:{
if(!SteamInput()){ if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){ 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; }break;
case STEAM:{ case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld; inputHeld|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
}break; }break;
case ANALOG:{ case ANALOG:{
//An analog input can never be "held". No-op. //An analog input can never be "held". No-op.
@ -176,31 +177,31 @@ bool Input::Held(){
} }
} }
if(inputHeld){ if(inputHeld){
usingGamepad=type==CONTROLLER; usingGamepad=type==CONTROLLER||type==STEAM;
return true; return true;
} }
return false; return false;
} }
bool Input::Released(){ bool Input::Released(){
if(!game->IsFocused())return false; //if(!game->IsFocused())return false;
bool inputReleased=false; bool inputReleased=false;
switch(type){ switch(type){
case KEY:{ case KEY:{
inputReleased=game->GetKey(Key(key)).bReleased; inputReleased|=game->GetKey(Key(key)).bReleased;
}break; }break;
case MOUSE:{ case MOUSE:{
inputReleased=game->GetMouse(key).bReleased; inputReleased|=game->GetMouse(key).bReleased;
}break; }break;
case CONTROLLER:{ case CONTROLLER:{
if(!SteamInput()){ if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){ 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; }break;
case STEAM:{ case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased; inputReleased|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
}break; }break;
case ANALOG:{ case ANALOG:{
//An analog input can never be "released". No-op. //An analog input can never be "released". No-op.
@ -210,7 +211,7 @@ bool Input::Released(){
} }
} }
if(inputReleased){ if(inputReleased){
usingGamepad=type==CONTROLLER; usingGamepad=type==CONTROLLER||type==STEAM;
return true; return true;
} }
return false; return false;

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 8264 #define VERSION_BUILD 8281
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save