Input binding format changed to allow custom values for bindings. Relevant code must clamp input values to prevent speedhaxx!

This commit is contained in:
2016-01-15 16:32:04 +01:00
parent 567173c565
commit 0469460029
3 changed files with 17 additions and 15 deletions
+1
View File
@@ -1,6 +1,7 @@
#ifndef InputProxy_h__ #ifndef InputProxy_h__
#define InputProxy_h__ #define InputProxy_h__
#include <boost/tokenizer.hpp>
#include "../Common.h" #include "../Common.h"
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "../Core/ConfigFile.h" #include "../Core/ConfigFile.h"
+4 -4
View File
@@ -6,10 +6,10 @@ InvertPitch=false
MouseLeft=PrimaryFire MouseLeft=PrimaryFire
MouseX=Yaw MouseX=Yaw
MouseY=Pitch MouseY=Pitch
W=+Forward W=Forward,1
S=-Forward S=Forward,-1
D=+Right D=Right,1
A=-Right A=Right,-1
R=Reload R=Reload
Space=Jump Space=Jump
LeftControl=Crouch LeftControl=Crouch
+12 -11
View File
@@ -20,15 +20,16 @@ void InputProxy::LoadBindings(std::string file)
for (auto& origin : config->GetAll<std::string>("Bindings")) { for (auto& origin : config->GetAll<std::string>("Bindings")) {
Events::BindOrigin e; Events::BindOrigin e;
e.Origin = origin.first; e.Origin = origin.first;
e.Command = origin.second; const std::string& command = origin.second;
e.Value = 1.f; if (!command.empty()) {
if (!e.Command.empty()) { boost::char_separator<char> separator(", ");
char prefix = e.Command.at(0); boost::tokenizer<decltype(separator)> tokenizer(command, separator);
if (prefix == '+' || prefix == '-') { auto token = tokenizer.begin();
e.Command = e.Command.substr(1); e.Command = *token;
if (prefix == '-') { if (++token != tokenizer.end()) {
e.Value *= -1.f; e.Value = boost::lexical_cast<float>(*token);
} } else {
e.Value = 1.f;
} }
OnBindOrigin(e); OnBindOrigin(e);
} }
@@ -62,7 +63,7 @@ void InputProxy::Process()
e.Command = command; e.Command = command;
e.Value = currentValue; e.Value = currentValue;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
m_LastCommandValues[command] = currentValue; m_LastCommandValues[command] = currentValue;
} }
} }
@@ -78,7 +79,7 @@ void InputProxy::Process()
} }
//e.Value = std::max(-1.f, std::min(e.Value, 1.f)); //e.Value = std::max(-1.f, std::min(e.Value, 1.f));
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
} }
m_CommandQueue.clear(); m_CommandQueue.clear();
} }