Merge branch 'havok' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance into havok
Conflicts: src/GameWorld.cpp vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
+92
-10
@@ -10,12 +10,17 @@ void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
||||
void Systems::InputSystem::Initialize()
|
||||
{
|
||||
// Subscribe to events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadAxis, &Systems::InputSystem::OnGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonDown, &Systems::InputSystem::OnGamepadButtonDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonUp, &Systems::InputSystem::OnGamepadButtonUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadAxis, &Systems::InputSystem::OnBindGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadButton, &Systems::InputSystem::OnBindGamepadButton);
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Update(double dt)
|
||||
@@ -47,8 +52,8 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_KeyBindingValues[command] += value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_KeyBindingValues[command], 1.f)));
|
||||
m_CommandValues[command] += value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -62,8 +67,8 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_KeyBindingValues[command] -= value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_KeyBindingValues[command], 1.f)));
|
||||
m_CommandValues[command] -= value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -91,6 +96,51 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadAxisBindings.find(event.Axis);
|
||||
if (bindingIt != m_GamepadAxisBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
PublishCommand(event.GamepadID + 1, command, event.Value * value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_GamepadButtonBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] += value;
|
||||
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_GamepadButtonBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] -= value;
|
||||
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
||||
{
|
||||
if (event.Command.empty())
|
||||
@@ -121,6 +171,36 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
|
||||
{
|
||||
if (event.Command.empty())
|
||||
{
|
||||
m_GamepadAxisBindings.erase(event.Axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GamepadAxisBindings[event.Axis] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event)
|
||||
{
|
||||
if (event.Command.empty())
|
||||
{
|
||||
m_GamepadButtonBindings.erase(event.Button);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GamepadButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
|
||||
{
|
||||
Events::InputCommand e;
|
||||
@@ -131,3 +211,5 @@ void Systems::InputSystem::PublishCommand(int playerID, std::string command, flo
|
||||
|
||||
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
#include "Events/KeyDown.h"
|
||||
#include "Events/MousePress.h"
|
||||
#include "Events/MouseRelease.h"
|
||||
#include "Events/GamepadAxis.h"
|
||||
#include "Events/GamepadButton.h"
|
||||
#include "Events/BindKey.h"
|
||||
#include "Events/BindMouseButton.h"
|
||||
#include "Events/BindGamepadAxis.h"
|
||||
#include "Events/BindGamepadButton.h"
|
||||
#include "Events/InputCommand.h"
|
||||
|
||||
namespace Systems
|
||||
@@ -30,10 +34,12 @@ public:
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, float> m_CommandValues; // command string -> command current value
|
||||
// Input binding tables
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<std::string, float> m_KeyBindingValues; // command string -> command value
|
||||
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||
|
||||
// Input events
|
||||
EventRelay<Events::KeyDown> m_EKeyDown;
|
||||
@@ -44,11 +50,21 @@ private:
|
||||
bool OnMousePress(const Events::MousePress &event);
|
||||
EventRelay<Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease &event);
|
||||
EventRelay<Events::GamepadAxis> m_EGamepadAxis;
|
||||
bool OnGamepadAxis(const Events::GamepadAxis &event);
|
||||
EventRelay<Events::GamepadButtonDown> m_EGamepadButtonDown;
|
||||
bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
|
||||
EventRelay<Events::GamepadButtonUp> m_EGamepadButtonUp;
|
||||
bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
|
||||
// Input binding events
|
||||
EventRelay<Events::BindKey> m_EBindKey;
|
||||
bool OnBindKey(const Events::BindKey &event);
|
||||
EventRelay<Events::BindMouseButton> m_EBindMouseButton;
|
||||
bool OnBindMouseButton(const Events::BindMouseButton &event);
|
||||
EventRelay<Events::BindGamepadAxis> m_EBindGamepadAxis;
|
||||
bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
|
||||
EventRelay<Events::BindGamepadButton> m_EBindGamepadButton;
|
||||
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||
|
||||
void PublishCommand(int playerID, std::string command, float value);
|
||||
};
|
||||
|
||||
@@ -90,12 +90,12 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
|
||||
}
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
m_Vertical = val;
|
||||
m_Vertical = -val;
|
||||
}
|
||||
|
||||
else if (event.Command == "handbrake")
|
||||
{
|
||||
Handbrake = val;
|
||||
Handbrake = val > 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -106,7 +106,7 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
|
||||
float val = event.Value;
|
||||
if(event.Command == "tower_rotation")
|
||||
{
|
||||
m_TowerDirection = val;
|
||||
m_TowerDirection = -val;
|
||||
}
|
||||
else if(event.Command == "barrel_rotation")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user