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.

pull/57/head
sigonasr2 10 months ago
parent 195ec1a0f8
commit fa79df59de
  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(Steam_Init()){
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{
std::cout<<"Steam API failed to initialize!"<<std::endl;
}
@ -357,8 +346,13 @@ bool AiL::OnUserUpdate(float fElapsedTime){
levelTime+=fElapsedTime;
SteamAPI_RunCallbacks();
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()->RunFrame();
Input::UpdateSteamInput();
}
@ -3789,5 +3783,18 @@ int AiL::GetLoadoutSize()const{
}
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;
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;

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

Loading…
Cancel
Save