Groundwork for Steam Controller support

This commit is contained in:
2015-12-11 00:41:51 +01:00
parent b4df0c49ae
commit 13a6cf5a9b
4 changed files with 126 additions and 1 deletions
+1 -1
Submodule deps updated: 1b478d3159...9861acd762
@@ -0,0 +1,98 @@
#include <steam/steam_api.h>
#include "InputProxy.h"
class SteamControllerInputHandler : public InputHandler
{
public:
SteamControllerInputHandler(EventBroker* eventBroker, InputProxy* inputProxy)
: InputHandler(eventBroker, inputProxy)
{
SteamController()->Init();
}
~SteamControllerInputHandler()
{
SteamController()->Shutdown();
}
void Update(double dt) override
{
std::array<ControllerHandle_t, STEAM_CONTROLLER_MAX_COUNT> controllers;
int numControllers = SteamController()->GetConnectedControllers(controllers.data());
for (int i = 0; i < numControllers; i++) {
auto controllerHandle = controllers.at(i);
auto actionSetHandle = SteamController()->GetActionSetHandle("InGameControls");
//SteamController()->ShowBindingPanel(controllerHandle);
SteamController()->ActivateActionSet(controllerHandle, actionSetHandle);
for (auto& command : m_Commands) {
Events::InputCommand ic;
ic.PlayerID = i + 1;
ic.Command = command.first;
auto digitalActionHandle = m_DigitalActionHandles.at(ic.Command);
auto handle = SteamController()->GetDigitalActionHandle("DebugReload");
auto data = SteamController()->GetDigitalActionData(controllerHandle, handle);
LOG_DEBUG("Controller %i, active %i, value %i", i, data.bActive, data.bState);
if (data.bState) {
ic.Value = command.second;
} else {
ic.Value = 0.f;
}
//m_InputProxy->Publish(ic);
}
}
}
bool BindOrigin(std::string origin, std::string command, float value) override
{
if (origin != "SteamController") {
return false;
}
m_Commands[command] = value;
m_DigitalActionHandles[command] = SteamController()->GetDigitalActionHandle(command.c_str());
return true;
}
private:
std::map<std::string, float> m_Commands;
std::map<std::string, ControllerDigitalActionHandle_t> m_DigitalActionHandles;
//std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
EventRelay<InputHandler, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown& e)
{
auto it = m_KeyBindings.find(e.KeyCode);
if (it == m_KeyBindings.end()) {
return false;
}
Events::InputCommand ic;
ic.PlayerID = 0;
std::tie(ic.Command, ic.Value) = it->second;
m_InputProxy->Publish(ic);
return true;
}
EventRelay<InputHandler, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp& e)
{
auto it = m_KeyBindings.find(e.KeyCode);
if (it == m_KeyBindings.end()) {
return false;
}
Events::InputCommand ic;
ic.PlayerID = 0;
std::tie(ic.Command, std::ignore) = it->second;
ic.Value = 0;
m_InputProxy->Publish(ic);
return true;
}
};
+1
View File
@@ -11,6 +11,7 @@
#include "Rendering/RenderQueueFactory.h"
#include "Input/InputProxy.h"
#include "Input/KeyboardInputHandler.h"
#include "Input/SteamControllerInputHandler.h"
#include "Core/EKeyDown.h"
#include "Core/EntityXMLFile.h"
#include "Core/SystemPipeline.h"
+26
View File
@@ -2,6 +2,8 @@
Game::Game(int argc, char* argv[])
{
bool steamResult = SteamAPI_Init();
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
ResourceManager::RegisterType<Model>("Model");
ResourceManager::RegisterType<Texture>("Texture");
@@ -66,6 +68,8 @@ void Game::Tick()
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
SteamAPI_RunCallbacks();
// Handle input in a weird looking but responsive way
m_EventBroker->Swap();
m_InputManager->Update(dt);
@@ -108,6 +112,28 @@ bool Game::testOnKeyUp(const Events::KeyUp& e)
void Game::testIntialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Game::testOnKeyUp);
{
Events::BindOrigin e;
e.Origin = "R";
e.Command = "DebugReload";
e.Value = 1.f;
m_EventBroker->Publish(e);
}
{
Events::BindOrigin e;
e.Origin = "SteamController";
e.Command = "DebugReload";
e.Value = 1.f;
m_EventBroker->Publish(e);
}
{
Events::BindOrigin e;
e.Origin = "X";
e.Command = "DebugReload";
e.Value = 1.f;
m_EventBroker->Publish(e);
}
}
void Game::testTick(double dt)