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. 130
      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){
SteamInput()->Init(false);
SteamInput()->RunFrame();
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls");
}
@ -356,7 +356,11 @@ bool AiL::OnUserCreate(){
bool AiL::OnUserUpdate(float fElapsedTime){
levelTime+=fElapsedTime;
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){
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){
@ -3298,6 +3305,8 @@ void AiL::RenderVersionInfo(){
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));
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 "Menu.h"
#include "GameSettings.h"
#include <isteaminput.h>
INCLUDE_game
INCLUDE_GFX
bool Input::usingGamepad;
uint64_t Input::ingameControlsHandle;
uint64_t Input::menuControlsHandle;
uint64_t Input::ingameControlsHandle{0};
uint64_t Input::menuControlsHandle{0};
uint8_t activeSteamControllerIndex{0};
safemap<std::string,InputGroup*>InputGroup::menuNamesToInputGroups;
std::vector<std::string>InputGroup::menuInputGroups;
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)
:type(type),key(key){}
void Input::Initialize(){
enumToActionName[Steam::MOVE]="Move";
enumToActionName[Steam::MANUAL_AIM]="Manual Aim";
enumToActionName[Steam::BASIC_ATTACK]="Basic_Attack";
enumToActionName[Steam::DEFENSIVE]="Defensive";
enumToActionName[Steam::MENU_PAUSE]="Menu/Pause";
enumToActionName[Steam::ABILITY_1]="Ability_1";
enumToActionName[Steam::ABILITY_2]="Ability_2";
enumToActionName[Steam::ABILITY_3]="Ability_3";
enumToActionName[Steam::ABILITY_4]="Ability_4";
enumToActionName[Steam::ITEM_1]="Item_1";
enumToActionName[Steam::ITEM_2]="Item_2";
enumToActionName[Steam::ITEM_3]="Item_3";
enumToActionName[Steam::NAVIGATE]="Navigate";
enumToActionName[Steam::SCROLL]="Scroll";
enumToActionName[Steam::CONFIRM]="Confirm";
enumToActionName[Steam::BACK]="Back";
enumToActionName[Steam::FUNCTION_1]="Function_1";
enumToActionName[Steam::FUNCTION_2]="Function_2";
enumToActionName[Steam::UP]="Up";
enumToActionName[Steam::DOWN]="Down";
enumToActionName[Steam::LEFT]="Left";
enumToActionName[Steam::RIGHT]="Right";
enumToActionName[Steam::LOCK_UNLOCK_ACC]="Lock/Unlock Accessory";
enumToActionName[Steam::FAST_SCROLL_UP]="Fast_Scroll_Up";
enumToActionName[Steam::FAST_SCROLL_DOWN]="Fast_Scroll_Down";
enumToActionName.SetInitialized();
for(int i=0;i<16;i++){
enumToActionName[i][Steam::MOVE]={"Move",{}};
enumToActionName[i][Steam::MANUAL_AIM]={"Manual Aim",{}};
enumToActionName[i][Steam::BASIC_ATTACK]={"Basic_Attack",{}};
enumToActionName[i][Steam::DEFENSIVE]={"Defensive",{}};
enumToActionName[i][Steam::MENU_PAUSE]={"Menu/Pause",{}};
enumToActionName[i][Steam::ABILITY_1]={"Ability_1",{}};
enumToActionName[i][Steam::ABILITY_2]={"Ability_2",{}};
enumToActionName[i][Steam::ABILITY_3]={"Ability_3",{}};
enumToActionName[i][Steam::ABILITY_4]={"Ability_4",{}};
enumToActionName[i][Steam::ITEM_1]={"Item_1",{}};
enumToActionName[i][Steam::ITEM_2]={"Item_2",{}};
enumToActionName[i][Steam::ITEM_3]={"Item_3",{}};
enumToActionName[i][Steam::NAVIGATE]={"Navigate",{}};
enumToActionName[i][Steam::SCROLL]={"Scroll",{}};
enumToActionName[i][Steam::CONFIRM]={"Confirm",{}};
enumToActionName[i][Steam::BACK]={"Back",{}};
enumToActionName[i][Steam::FUNCTION_1]={"Function_1",{}};
enumToActionName[i][Steam::FUNCTION_2]={"Function_2",{}};
enumToActionName[i][Steam::UP]={"Up",{}};
enumToActionName[i][Steam::DOWN]={"Down",{}};
enumToActionName[i][Steam::LEFT]={"Left",{}};
enumToActionName[i][Steam::RIGHT]={"Right",{}};
enumToActionName[i][Steam::LOCK_UNLOCK_ACC]={"Lock/Unlock Accessory",{}};
enumToActionName[i][Steam::FAST_SCROLL_UP]={"Fast_Scroll_Up",{}};
enumToActionName[i][Steam::FAST_SCROLL_DOWN]={"Fast_Scroll_Down",{}};
}
}
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(){
@ -99,12 +125,14 @@ bool Input::Pressed(){
inputPressed=game->GetMouse(key).bPressed;
}break;
case CONTROLLER:{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true;
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true;
}
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed;
}break;
case ANALOG:{
//An analog input can never be "pressed". No-op.
@ -121,7 +149,7 @@ bool Input::Pressed(){
}
bool Input::Held(){
if(!game->IsFocused())return false;
//if(!game->IsFocused())return false;
bool inputHeld=false;
switch(type){
case KEY:{
@ -131,12 +159,14 @@ bool Input::Held(){
inputHeld=game->GetMouse(key).bHeld;
}break;
case CONTROLLER:{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true;
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true;
}
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
}break;
case ANALOG:{
//An analog input can never be "held". No-op.
@ -163,12 +193,14 @@ bool Input::Released(){
inputReleased=game->GetMouse(key).bReleased;
}break;
case CONTROLLER:{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true;
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true;
}
}
}break;
case STEAM:{
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
}break;
case ANALOG:{
//An analog input can never be "released". No-op.
@ -188,14 +220,18 @@ float Input::Analog(){
if(!game->IsFocused())return false;
switch(type){
case ANALOG:{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key));
if(axisVal!=0.f){
usingGamepad=true;
return axisVal;
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key));
if(axisVal!=0.f){
usingGamepad=true;
return axisVal;
}
}
}
}else{
}
}break;
case KEY:

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

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

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