Groundwork for Steam Controller support
This commit is contained in:
+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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Rendering/RenderQueueFactory.h"
|
#include "Rendering/RenderQueueFactory.h"
|
||||||
#include "Input/InputProxy.h"
|
#include "Input/InputProxy.h"
|
||||||
#include "Input/KeyboardInputHandler.h"
|
#include "Input/KeyboardInputHandler.h"
|
||||||
|
#include "Input/SteamControllerInputHandler.h"
|
||||||
#include "Core/EKeyDown.h"
|
#include "Core/EKeyDown.h"
|
||||||
#include "Core/EntityXMLFile.h"
|
#include "Core/EntityXMLFile.h"
|
||||||
#include "Core/SystemPipeline.h"
|
#include "Core/SystemPipeline.h"
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Game::Game(int argc, char* argv[])
|
Game::Game(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
bool steamResult = SteamAPI_Init();
|
||||||
|
|
||||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||||
ResourceManager::RegisterType<Model>("Model");
|
ResourceManager::RegisterType<Model>("Model");
|
||||||
ResourceManager::RegisterType<Texture>("Texture");
|
ResourceManager::RegisterType<Texture>("Texture");
|
||||||
@@ -66,6 +68,8 @@ void Game::Tick()
|
|||||||
double dt = currentTime - m_LastTime;
|
double dt = currentTime - m_LastTime;
|
||||||
m_LastTime = currentTime;
|
m_LastTime = currentTime;
|
||||||
|
|
||||||
|
SteamAPI_RunCallbacks();
|
||||||
|
|
||||||
// Handle input in a weird looking but responsive way
|
// Handle input in a weird looking but responsive way
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
m_InputManager->Update(dt);
|
m_InputManager->Update(dt);
|
||||||
@@ -108,6 +112,28 @@ bool Game::testOnKeyUp(const Events::KeyUp& e)
|
|||||||
void Game::testIntialize()
|
void Game::testIntialize()
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Game::testOnKeyUp);
|
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)
|
void Game::testTick(double dt)
|
||||||
|
|||||||
Reference in New Issue
Block a user