Get input detection from controllers configured through Steam Input. Release Build 8264.

mac-build
sigonasr2 8 months ago
parent 4520737042
commit 9fa6e7e44f
  1. 13
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 106
      Adventures in Lestoria/Key.cpp
  3. 10
      Adventures in Lestoria/Key.h
  4. 2
      Adventures in Lestoria/Version.h
  5. 7
      Adventures in Lestoria/controller_config/game_actions_2895980.vdf
  6. BIN
      x64/Release/Adventures in Lestoria.exe

@ -333,7 +333,7 @@ bool AiL::OnUserCreate(){
} }
if(SteamInput()!=nullptr){ if(SteamInput()!=nullptr){
SteamInput()->Init(false); SteamInput()->Init(false);
SteamInput()->RunFrame();
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls"); Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls"); Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls");
} }
@ -356,7 +356,11 @@ bool AiL::OnUserCreate(){
bool AiL::OnUserUpdate(float fElapsedTime){ bool AiL::OnUserUpdate(float fElapsedTime){
levelTime+=fElapsedTime; levelTime+=fElapsedTime;
SteamAPI_RunCallbacks(); SteamAPI_RunCallbacks();
if(SteamInput())SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle); if(SteamInput()){
SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle);
SteamInput()->RunFrame();
Input::UpdateSteamInput();
}
if(GetMousePos()!=lastMousePos){ if(GetMousePos()!=lastMousePos){
lastMouseMovement=0.f; lastMouseMovement=0.f;
@ -645,6 +649,9 @@ void AiL::HandleUserInput(float fElapsedTime){
} }
} }
} }
if(SteamInput())SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle);
} }
void AiL::UpdateCamera(float fElapsedTime){ void AiL::UpdateCamera(float fElapsedTime){
@ -3298,6 +3305,8 @@ void AiL::RenderVersionInfo(){
DrawShadowStringDecal({4.f,4.f},"Save Complete.",{255,255,255,alpha},{0,0,0,alpha}); DrawShadowStringDecal({4.f,4.f},"Save Complete.",{255,255,255,alpha},{0,0,0,alpha});
} }
DrawShadowStringDecal({0.f,0.f},"Holding down A: "+std::to_string(KEY_CONFIRM.Held()));
std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD)); std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD));
DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4f,versionStr,WHITE,BLACK,{0.4f,0.4f},std::numeric_limits<float>::max(),0.4f); DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4f,versionStr,WHITE,BLACK,{0.4f,0.4f},std::numeric_limits<float>::max(),0.4f);
} }

@ -41,51 +41,77 @@ All rights reserved.
#include "olcPGEX_Gamepad.h" #include "olcPGEX_Gamepad.h"
#include "Menu.h" #include "Menu.h"
#include "GameSettings.h" #include "GameSettings.h"
#include <isteaminput.h>
INCLUDE_game INCLUDE_game
INCLUDE_GFX INCLUDE_GFX
bool Input::usingGamepad; bool Input::usingGamepad;
uint64_t Input::ingameControlsHandle; uint64_t Input::ingameControlsHandle{0};
uint64_t Input::menuControlsHandle; uint64_t Input::menuControlsHandle{0};
uint8_t activeSteamControllerIndex{0};
safemap<std::string,InputGroup*>InputGroup::menuNamesToInputGroups; safemap<std::string,InputGroup*>InputGroup::menuNamesToInputGroups;
std::vector<std::string>InputGroup::menuInputGroups; std::vector<std::string>InputGroup::menuInputGroups;
std::vector<std::string>InputGroup::gameplayInputGroups; std::vector<std::string>InputGroup::gameplayInputGroups;
std::array<InputHandle_t,16>Input::steamControllers;
uint8_t Input::activeSteamControllerIndex;
safemap<Steam::SteamInput,std::string>Input::enumToActionName; std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,16>Input::enumToActionName;
Input::Input(InputType type,int key) Input::Input(InputType type,int key)
:type(type),key(key){} :type(type),key(key){}
void Input::Initialize(){ void Input::Initialize(){
enumToActionName[Steam::MOVE]="Move"; for(int i=0;i<16;i++){
enumToActionName[Steam::MANUAL_AIM]="Manual Aim"; enumToActionName[i][Steam::MOVE]={"Move",{}};
enumToActionName[Steam::BASIC_ATTACK]="Basic_Attack"; enumToActionName[i][Steam::MANUAL_AIM]={"Manual Aim",{}};
enumToActionName[Steam::DEFENSIVE]="Defensive"; enumToActionName[i][Steam::BASIC_ATTACK]={"Basic_Attack",{}};
enumToActionName[Steam::MENU_PAUSE]="Menu/Pause"; enumToActionName[i][Steam::DEFENSIVE]={"Defensive",{}};
enumToActionName[Steam::ABILITY_1]="Ability_1"; enumToActionName[i][Steam::MENU_PAUSE]={"Menu/Pause",{}};
enumToActionName[Steam::ABILITY_2]="Ability_2"; enumToActionName[i][Steam::ABILITY_1]={"Ability_1",{}};
enumToActionName[Steam::ABILITY_3]="Ability_3"; enumToActionName[i][Steam::ABILITY_2]={"Ability_2",{}};
enumToActionName[Steam::ABILITY_4]="Ability_4"; enumToActionName[i][Steam::ABILITY_3]={"Ability_3",{}};
enumToActionName[Steam::ITEM_1]="Item_1"; enumToActionName[i][Steam::ABILITY_4]={"Ability_4",{}};
enumToActionName[Steam::ITEM_2]="Item_2"; enumToActionName[i][Steam::ITEM_1]={"Item_1",{}};
enumToActionName[Steam::ITEM_3]="Item_3"; enumToActionName[i][Steam::ITEM_2]={"Item_2",{}};
enumToActionName[Steam::NAVIGATE]="Navigate"; enumToActionName[i][Steam::ITEM_3]={"Item_3",{}};
enumToActionName[Steam::SCROLL]="Scroll"; enumToActionName[i][Steam::NAVIGATE]={"Navigate",{}};
enumToActionName[Steam::CONFIRM]="Confirm"; enumToActionName[i][Steam::SCROLL]={"Scroll",{}};
enumToActionName[Steam::BACK]="Back"; enumToActionName[i][Steam::CONFIRM]={"Confirm",{}};
enumToActionName[Steam::FUNCTION_1]="Function_1"; enumToActionName[i][Steam::BACK]={"Back",{}};
enumToActionName[Steam::FUNCTION_2]="Function_2"; enumToActionName[i][Steam::FUNCTION_1]={"Function_1",{}};
enumToActionName[Steam::UP]="Up"; enumToActionName[i][Steam::FUNCTION_2]={"Function_2",{}};
enumToActionName[Steam::DOWN]="Down"; enumToActionName[i][Steam::UP]={"Up",{}};
enumToActionName[Steam::LEFT]="Left"; enumToActionName[i][Steam::DOWN]={"Down",{}};
enumToActionName[Steam::RIGHT]="Right"; enumToActionName[i][Steam::LEFT]={"Left",{}};
enumToActionName[Steam::LOCK_UNLOCK_ACC]="Lock/Unlock Accessory"; enumToActionName[i][Steam::RIGHT]={"Right",{}};
enumToActionName[Steam::FAST_SCROLL_UP]="Fast_Scroll_Up"; enumToActionName[i][Steam::LOCK_UNLOCK_ACC]={"Lock/Unlock Accessory",{}};
enumToActionName[Steam::FAST_SCROLL_DOWN]="Fast_Scroll_Down"; enumToActionName[i][Steam::FAST_SCROLL_UP]={"Fast_Scroll_Up",{}};
enumToActionName[i][Steam::FAST_SCROLL_DOWN]={"Fast_Scroll_Down",{}};
enumToActionName.SetInitialized(); }
}
void Input::UpdateSteamInput(){
if(SteamInput()){
int controllerCount=SteamInput()->GetConnectedControllers(steamControllers.data());
for(int i=0;i<controllerCount;i++){
for(auto&[input,data]:enumToActionName[i]){
HWButton prevState=data.second;
InputDigitalActionHandle_t inputHnd=SteamInput()->GetDigitalActionHandle(data.first.c_str());
InputDigitalActionData_t buttonData=SteamInput()->GetDigitalActionData(steamControllers[i],inputHnd);
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;
}
}
}
}
} }
bool Input::Pressed(){ bool Input::Pressed(){
@ -99,12 +125,14 @@ bool Input::Pressed(){
inputPressed=game->GetMouse(key).bPressed; inputPressed=game->GetMouse(key).bPressed;
}break; }break;
case CONTROLLER:{ case CONTROLLER:{
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){ for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true; if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true;
} }
}
}break; }break;
case STEAM:{ case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed;
}break; }break;
case ANALOG:{ case ANALOG:{
//An analog input can never be "pressed". No-op. //An analog input can never be "pressed". No-op.
@ -121,7 +149,7 @@ bool Input::Pressed(){
} }
bool Input::Held(){ bool Input::Held(){
if(!game->IsFocused())return false; //if(!game->IsFocused())return false;
bool inputHeld=false; bool inputHeld=false;
switch(type){ switch(type){
case KEY:{ case KEY:{
@ -131,12 +159,14 @@ bool Input::Held(){
inputHeld=game->GetMouse(key).bHeld; inputHeld=game->GetMouse(key).bHeld;
}break; }break;
case CONTROLLER:{ case CONTROLLER:{
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&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true;
} }
}
}break; }break;
case STEAM:{ case STEAM:{
return 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.
@ -163,12 +193,14 @@ bool Input::Released(){
inputReleased=game->GetMouse(key).bReleased; inputReleased=game->GetMouse(key).bReleased;
}break; }break;
case CONTROLLER:{ case CONTROLLER:{
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&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true;
} }
}
}break; }break;
case STEAM:{ case STEAM:{
return 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.
@ -188,6 +220,7 @@ float Input::Analog(){
if(!game->IsFocused())return false; if(!game->IsFocused())return false;
switch(type){ switch(type){
case ANALOG:{ case ANALOG:{
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){ for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){ if(gamepad->stillConnected){
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key)); float axisVal=gamepad->getAxis(static_cast<GPAxes>(key));
@ -197,6 +230,9 @@ float Input::Analog(){
} }
} }
} }
}else{
}
}break; }break;
case KEY: case KEY:
case MOUSE: case MOUSE:

@ -46,6 +46,7 @@ All rights reserved.
#include "IconType.h" #include "IconType.h"
#include "olcPGEX_ViewPort.h" #include "olcPGEX_ViewPort.h"
#include "UndefKeys.h" #include "UndefKeys.h"
#include <isteaminput.h>
class AiL; class AiL;
@ -61,7 +62,7 @@ enum InputType{
namespace Steam{ namespace Steam{
enum SteamInput{ enum SteamInput{
//Gameplay Inputs //Gameplay Inputs
MOVE, MOVE, //This is the left stick analog input. Whenever we use this, we assume left stick is being used.
MANUAL_AIM, MANUAL_AIM,
BASIC_ATTACK, BASIC_ATTACK,
DEFENSIVE, DEFENSIVE,
@ -75,7 +76,7 @@ namespace Steam{
ITEM_3, ITEM_3,
//Menu Inputs //Menu Inputs
NAVIGATE, NAVIGATE,
SCROLL, SCROLL, //This is the right stick analog input. Whenever we use this, we assume right stick is being used.
CONFIRM, CONFIRM,
BACK, BACK,
FUNCTION_1, FUNCTION_1,
@ -101,8 +102,11 @@ class Input{
static uint64_t menuControlsHandle; static uint64_t menuControlsHandle;
static bool usingGamepad; static bool usingGamepad;
static void SetUsingGamepad(const bool usingGamepad); static void SetUsingGamepad(const bool usingGamepad);
static safemap<Steam::SteamInput,std::string>enumToActionName; static std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,16>enumToActionName;
static void Initialize(); static void Initialize();
static void UpdateSteamInput();
static std::array<InputHandle_t,16>steamControllers;
static uint8_t activeSteamControllerIndex;
public: public:
Input(InputType type,int key); Input(InputType type,int key);
bool Pressed(); bool Pressed();

@ -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 8238 #define VERSION_BUILD 8264
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -116,5 +116,12 @@
"path" "controller_generic.vdf" "path" "controller_generic.vdf"
} }
} }
"controller_switch_pro"
{
"0"
{
"path" "controller_generic.vdf"
}
}
} }
} }
Loading…
Cancel
Save