2020-12-31 07:32:16 -08:00
|
|
|
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
|
2018-09-06 04:15:17 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
|
|
|
|
|
|
|
#include "Input.h"
|
2020-11-08 21:02:27 -08:00
|
|
|
#include "AnimationCurves.h"
|
2019-01-13 11:21:00 -08:00
|
|
|
#include "GameConfig.h"
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
#include "InputBindings.h"
|
2019-01-20 14:05:47 -08:00
|
|
|
#include "Pi.h"
|
2020-03-25 21:32:52 -07:00
|
|
|
#include "SDL.h"
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
#include "SDL_events.h"
|
|
|
|
#include "SDL_joystick.h"
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2019-06-02 09:11:17 -07:00
|
|
|
#include <array>
|
2020-11-08 21:02:27 -08:00
|
|
|
#include <regex>
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
#include <sstream>
|
|
|
|
#include <type_traits>
|
2019-06-02 09:11:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
using namespace Input;
|
|
|
|
|
|
|
|
namespace Input {
|
2020-11-20 12:00:06 -08:00
|
|
|
std::vector<sigc::slot<void, Input::Manager *>> *m_registrations;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
|
2020-11-20 12:00:06 -08:00
|
|
|
std::vector<sigc::slot<void, Input::Manager *>> &GetBindingRegistration()
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
{
|
|
|
|
return *m_registrations;
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:00:06 -08:00
|
|
|
bool AddBindingRegistrar(sigc::slot<void, Input::Manager *> &&fn)
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
{
|
2020-11-20 12:00:06 -08:00
|
|
|
static std::vector<sigc::slot<void, Input::Manager *>> registrations;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
m_registrations = ®istrations;
|
|
|
|
|
|
|
|
registrations.push_back(fn);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // namespace Input
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
STATIC JOYSTICK HANDLING
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Input {
|
|
|
|
std::map<SDL_JoystickID, JoystickInfo> m_joysticks;
|
|
|
|
|
|
|
|
InputBindings::Action nullAction;
|
|
|
|
InputBindings::Axis nullAxis;
|
|
|
|
} // namespace Input
|
|
|
|
|
|
|
|
std::string Input::JoystickName(int joystick)
|
|
|
|
{
|
2020-11-08 21:02:27 -08:00
|
|
|
return m_joysticks[joystick].name;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Input::JoystickGUIDString(int joystick)
|
|
|
|
{
|
|
|
|
const int guidBufferLen = 33; // as documented by SDL
|
|
|
|
char guidBuffer[guidBufferLen];
|
|
|
|
|
|
|
|
SDL_JoystickGetGUIDString(m_joysticks[joystick].guid, guidBuffer, guidBufferLen);
|
|
|
|
return std::string(guidBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// conveniance version of JoystickFromGUID below that handles the string mangling.
|
|
|
|
int Input::JoystickFromGUIDString(const std::string &guid)
|
|
|
|
{
|
|
|
|
return JoystickFromGUIDString(guid.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// conveniance version of JoystickFromGUID below that handles the string mangling.
|
|
|
|
int Input::JoystickFromGUIDString(const char *guid)
|
|
|
|
{
|
|
|
|
return JoystickFromGUID(SDL_JoystickGetGUIDFromString(guid));
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the internal ID of the stated joystick guid.
|
|
|
|
// returns -1 if we couldn't find the joystick in question.
|
|
|
|
int Input::JoystickFromGUID(SDL_JoystickGUID guid)
|
|
|
|
{
|
|
|
|
const int guidLength = 16; // as defined
|
|
|
|
for (auto pair : m_joysticks) {
|
|
|
|
JoystickInfo &state = pair.second;
|
|
|
|
if (0 == memcmp(state.guid.data, guid.data, guidLength)) {
|
|
|
|
return static_cast<int>(pair.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_JoystickGUID Input::JoystickGUID(int joystick)
|
|
|
|
{
|
|
|
|
return m_joysticks[joystick].guid;
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:02:27 -08:00
|
|
|
static std::string saveAxisConfig(const Input::JoystickInfo::Axis &axis)
|
|
|
|
{
|
|
|
|
return fmt::format("DZ{:.1f} CV{:.1f}{}", axis.deadzone, axis.curve, (axis.zeroToOne ? " Half" : ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadAxisConfig(const std::string &str, Input::JoystickInfo::Axis &outAxis)
|
|
|
|
{
|
|
|
|
std::regex matcher("DZ([\\d\\.]+)\\s*(?:CV(-?[\\d\\.]+))?\\s*(Half)?", std::regex::icase);
|
|
|
|
std::smatch match_results;
|
|
|
|
if (std::regex_search(str, match_results, matcher)) {
|
|
|
|
outAxis.deadzone = std::stof(match_results[1].str());
|
|
|
|
outAxis.curve = match_results[2].matched ? std::stof(match_results[2].str()) : 1.0;
|
|
|
|
outAxis.zeroToOne = match_results[3].matched;
|
|
|
|
}
|
|
|
|
outAxis.value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::InitJoysticks(IniConfig *config)
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
{
|
|
|
|
SDL_Init(SDL_INIT_JOYSTICK);
|
|
|
|
|
|
|
|
int joy_count = SDL_NumJoysticks();
|
|
|
|
Output("Initializing joystick subsystem.\n");
|
2020-11-08 21:02:27 -08:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
for (int n = 0; n < joy_count; n++) {
|
|
|
|
JoystickInfo state;
|
|
|
|
|
|
|
|
state.joystick = SDL_JoystickOpen(n);
|
|
|
|
if (!state.joystick) {
|
|
|
|
Warning("SDL_JoystickOpen(%i): %s\n", n, SDL_GetError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:02:27 -08:00
|
|
|
state.name = SDL_JoystickName(state.joystick);
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
state.guid = SDL_JoystickGetGUID(state.joystick);
|
|
|
|
state.axes.resize(SDL_JoystickNumAxes(state.joystick));
|
|
|
|
state.buttons.resize(SDL_JoystickNumButtons(state.joystick));
|
|
|
|
state.hats.resize(SDL_JoystickNumHats(state.joystick));
|
|
|
|
|
|
|
|
std::array<char, 33> joystickGUIDName;
|
|
|
|
SDL_JoystickGetGUIDString(state.guid, joystickGUIDName.data(), joystickGUIDName.size());
|
|
|
|
Output("Found joystick '%s' (GUID: %s)\n", SDL_JoystickName(state.joystick), joystickGUIDName.data());
|
|
|
|
Output(" - %ld axes, %ld buttons, %ld hats\n", state.axes.size(), state.buttons.size(), state.hats.size());
|
|
|
|
|
2020-11-08 21:02:27 -08:00
|
|
|
std::string joystickName = "Joystick." + std::string(joystickGUIDName.data());
|
|
|
|
config->SetString(joystickName, "Name", state.name);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < state.axes.size(); i++) {
|
|
|
|
std::string axisName = "Axis" + std::to_string(i);
|
|
|
|
if (!config->HasEntry(joystickName, axisName)) {
|
|
|
|
config->SetString(joystickName, axisName, saveAxisConfig(state.axes[i]));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadAxisConfig(config->String(joystickName, axisName, ""), state.axes[i]);
|
|
|
|
Output(" - axis %ld: deadzone %.2f, curve: %.2f, half-axis mode: %b\n",
|
|
|
|
i, state.axes[i].deadzone, state.axes[i].curve, state.axes[i].zeroToOne);
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
SDL_JoystickID joyID = SDL_JoystickInstanceID(state.joystick);
|
|
|
|
m_joysticks[joyID] = state;
|
|
|
|
}
|
2020-11-08 21:02:27 -08:00
|
|
|
|
|
|
|
config->Save();
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<SDL_JoystickID, JoystickInfo> &Input::GetJoysticks()
|
|
|
|
{
|
|
|
|
return m_joysticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
INPUT MANAGER INITIALIZATION
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Manager::Manager(IniConfig *config) :
|
2020-04-01 14:02:12 -07:00
|
|
|
m_config(config),
|
2020-03-30 21:59:44 -07:00
|
|
|
keyModState(0),
|
|
|
|
mouseButton(),
|
2020-04-24 15:33:07 -07:00
|
|
|
mouseMotion(),
|
|
|
|
m_capturingMouse(false),
|
|
|
|
joystickEnabled(true),
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
mouseYInvert(false),
|
|
|
|
m_enableBindings(true)
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
2020-04-01 14:02:12 -07:00
|
|
|
joystickEnabled = (m_config->Int("EnableJoystick")) ? true : false;
|
|
|
|
mouseYInvert = (m_config->Int("InvertMouseY")) ? true : false;
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2020-11-08 21:02:27 -08:00
|
|
|
Input::InitJoysticks(m_config);
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
void Manager::InitGame()
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
2019-01-02 08:59:07 -08:00
|
|
|
//reset input states
|
2018-09-06 04:15:17 -07:00
|
|
|
keyState.clear();
|
|
|
|
keyModState = 0;
|
2020-03-30 21:59:44 -07:00
|
|
|
mouseButton.fill(0);
|
|
|
|
mouseMotion.fill(0);
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
|
|
|
|
// Force a rebuild of key chords and modifier state
|
|
|
|
m_frameListChanged = true;
|
|
|
|
|
|
|
|
for (auto &pair : Input::GetJoysticks()) {
|
|
|
|
JoystickInfo &state = pair.second;
|
2018-09-06 04:15:17 -07:00
|
|
|
std::fill(state.buttons.begin(), state.buttons.end(), false);
|
|
|
|
std::fill(state.hats.begin(), state.hats.end(), 0);
|
2020-11-08 21:02:27 -08:00
|
|
|
for (auto &ax : state.axes) {
|
|
|
|
ax.value = 0.0;
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
BINDING AND INPUT FRAME HANDLING
|
|
|
|
|
|
|
|
*/
|
2020-03-30 21:59:44 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
InputBindings::Action *InputFrame::AddAction(std::string id)
|
2019-02-14 17:14:15 -08:00
|
|
|
{
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
auto *action = manager->GetActionBinding(id);
|
|
|
|
if (!action)
|
|
|
|
throw std::runtime_error("Adding unknown action binding to InputFrame, id: " + id);
|
2019-02-14 17:14:15 -08:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
actions.push_back(action);
|
|
|
|
return action;
|
|
|
|
}
|
2019-02-14 17:14:15 -08:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
InputBindings::Axis *InputFrame::AddAxis(std::string id)
|
|
|
|
{
|
|
|
|
auto *axis = manager->GetAxisBinding(id);
|
|
|
|
if (!axis)
|
|
|
|
throw std::runtime_error("Adding unknown axis binding to an InputFrame, id: " + id);
|
2019-02-14 17:14:15 -08:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
axes.push_back(axis);
|
|
|
|
return axis;
|
2019-02-14 17:14:15 -08:00
|
|
|
}
|
|
|
|
|
2020-11-14 00:33:40 -08:00
|
|
|
bool Manager::AddInputFrame(InputFrame *frame)
|
2019-02-14 17:14:15 -08:00
|
|
|
{
|
2020-11-14 00:33:40 -08:00
|
|
|
auto iter = std::find(m_inputFrames.begin(), m_inputFrames.end(), frame);
|
|
|
|
if (iter != m_inputFrames.end()) {
|
|
|
|
m_inputFrames.erase(iter);
|
2019-02-14 17:14:15 -08:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
m_inputFrames.push_back(frame);
|
2019-03-09 16:05:42 -08:00
|
|
|
frame->active = true;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
frame->onFrameAdded.emit(frame);
|
|
|
|
m_frameListChanged = true;
|
|
|
|
|
2019-02-14 17:14:15 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:15:16 -08:00
|
|
|
// When an input frame is removed or masked by a modal frame,
|
|
|
|
// its actions and axes are no longer active and bindings need
|
|
|
|
// to be cleared to avoid orphaned state.
|
|
|
|
void ClearInputFrameState(InputFrame *frame)
|
|
|
|
{
|
|
|
|
for (auto *action : frame->actions) {
|
|
|
|
action->binding.m_active = false;
|
|
|
|
action->binding.m_queuedEvents = 0;
|
|
|
|
action->binding2.m_active = false;
|
|
|
|
action->binding2.m_queuedEvents = 0;
|
|
|
|
|
|
|
|
if (action->m_active) {
|
|
|
|
action->m_active = false;
|
|
|
|
action->onReleased.emit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto *axis : frame->axes) {
|
|
|
|
axis->negative.m_active = false;
|
|
|
|
axis->negative.m_queuedEvents = false;
|
|
|
|
axis->positive.m_active = false;
|
|
|
|
axis->positive.m_queuedEvents = false;
|
|
|
|
|
|
|
|
if (axis->m_value != 0.0) {
|
|
|
|
axis->m_value = 0.0;
|
|
|
|
axis->onAxisValue.emit(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
void Manager::RemoveInputFrame(InputFrame *frame)
|
2019-02-14 17:14:15 -08:00
|
|
|
{
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
auto it = std::find(m_inputFrames.begin(), m_inputFrames.end(), frame);
|
|
|
|
if (it != m_inputFrames.end()) {
|
|
|
|
m_inputFrames.erase(it);
|
|
|
|
|
2020-11-14 16:15:16 -08:00
|
|
|
ClearInputFrameState(frame);
|
2019-03-09 16:05:42 -08:00
|
|
|
frame->active = false;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
frame->onFrameRemoved.emit(frame);
|
|
|
|
m_frameListChanged = true;
|
2019-02-15 21:33:06 -08:00
|
|
|
}
|
2019-02-14 17:14:15 -08:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
InputBindings::Action *Manager::AddActionBinding(std::string id, BindingGroup *group, InputBindings::Action &&binding)
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
2019-06-01 10:44:26 -07:00
|
|
|
// throw an error if we attempt to bind an action onto an already-bound axis in the same group.
|
|
|
|
if (group->bindings.count(id) && group->bindings[id] != BindingGroup::ENTRY_ACTION)
|
|
|
|
Error("Attempt to bind already-registered axis %s as an action.\n", id.c_str());
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
group->bindings[id] = BindingGroup::ENTRY_ACTION;
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
// Load from the config
|
2020-04-01 14:02:12 -07:00
|
|
|
std::string config_str = m_config->String(id.c_str());
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!config_str.empty()) {
|
2021-01-23 22:47:30 -08:00
|
|
|
std::string_view str(config_str);
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
str >> binding;
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
return &(actionBindings[id] = binding);
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
InputBindings::Axis *Manager::AddAxisBinding(std::string id, BindingGroup *group, InputBindings::Axis &&binding)
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
2019-06-01 10:44:26 -07:00
|
|
|
// throw an error if we attempt to bind an axis onto an already-bound action in the same group.
|
|
|
|
if (group->bindings.count(id) && group->bindings[id] != BindingGroup::ENTRY_AXIS)
|
|
|
|
Error("Attempt to bind already-registered action %s as an axis.\n", id.c_str());
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
group->bindings[id] = BindingGroup::ENTRY_AXIS;
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
// Load from the config
|
2020-04-01 14:02:12 -07:00
|
|
|
std::string config_str = m_config->String(id.c_str());
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!config_str.empty()) {
|
2021-01-23 22:47:30 -08:00
|
|
|
std::string_view str(config_str);
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
str >> binding;
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
return &(axisBindings[id] = binding);
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
InputBindings::Action *Manager::GetActionBinding(std::string id)
|
|
|
|
{
|
|
|
|
return actionBindings.count(id) ? &actionBindings[id] : &Input::nullAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputBindings::Axis *Manager::GetAxisBinding(std::string id)
|
|
|
|
{
|
|
|
|
return axisBindings.count(id) ? &axisBindings[id] : &Input::nullAxis;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
STATE MANAGEMENT
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Manager::GetBindingState(InputBindings::KeyBinding &key)
|
|
|
|
{
|
|
|
|
using Type = InputBindings::KeyBinding::Type;
|
|
|
|
|
|
|
|
switch (key.type) {
|
|
|
|
case Type::Disabled:
|
|
|
|
return false;
|
|
|
|
case Type::KeyboardKey:
|
|
|
|
return KeyState(key.keycode);
|
|
|
|
case Type::JoystickButton:
|
|
|
|
return JoystickButtonState(key.joystick.id, key.joystick.button);
|
|
|
|
case Type::JoystickHat:
|
|
|
|
return (JoystickHatState(key.joystick.id, key.joystick.hat) & key.joystick.button) == key.joystick.button;
|
|
|
|
case Type::MouseButton:
|
|
|
|
return MouseButtonState(key.mouse.button);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float Manager::GetAxisState(InputBindings::JoyAxis &axis)
|
|
|
|
{
|
|
|
|
if (axis.direction == 0)
|
|
|
|
return 0.0; // disabled
|
|
|
|
|
|
|
|
return JoystickAxisState(axis.joystickId, axis.axis) * float(axis.direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Manager::GetModifierState(InputBindings::KeyChord *chord)
|
|
|
|
{
|
|
|
|
bool mod1 = chord->modifier1.Enabled() ? m_modifiers[chord->modifier1] : true;
|
|
|
|
bool mod2 = chord->modifier2.Enabled() ? m_modifiers[chord->modifier2] : true;
|
|
|
|
return mod1 && mod2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Manager::JoystickButtonState(int joystick, int button)
|
|
|
|
{
|
|
|
|
if (!joystickEnabled) return 0;
|
|
|
|
if (joystick < 0 || joystick >= int(GetJoysticks().size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (button < 0 || button >= int(GetJoysticks()[joystick].buttons.size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return GetJoysticks()[joystick].buttons[button];
|
|
|
|
}
|
|
|
|
|
|
|
|
int Manager::JoystickHatState(int joystick, int hat)
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!joystickEnabled) return 0;
|
|
|
|
if (joystick < 0 || joystick >= int(GetJoysticks().size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hat < 0 || hat >= int(GetJoysticks()[joystick].hats.size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return GetJoysticks()[joystick].hats[hat];
|
|
|
|
}
|
|
|
|
|
|
|
|
float Manager::JoystickAxisState(int joystick, int axis)
|
|
|
|
{
|
|
|
|
if (!joystickEnabled) return 0;
|
|
|
|
if (joystick < 0 || joystick >= int(GetJoysticks().size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (axis < 0 || axis >= int(GetJoysticks()[joystick].axes.size()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return GetJoysticks()[joystick].axes[axis].value;
|
|
|
|
}
|
|
|
|
|
2020-09-12 15:18:56 -07:00
|
|
|
void Manager::SetJoystickEnabled(bool state)
|
|
|
|
{
|
|
|
|
joystickEnabled = state;
|
|
|
|
if (m_enableConfigSaving) {
|
|
|
|
m_config->SetInt("EnableJoystick", joystickEnabled);
|
|
|
|
m_config->Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::SetMouseYInvert(bool state)
|
|
|
|
{
|
|
|
|
mouseYInvert = state;
|
|
|
|
if (m_enableConfigSaving) {
|
|
|
|
m_config->SetInt("InvertMouseY", mouseYInvert);
|
|
|
|
m_config->Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
FRAME AND EVENT HANDLING
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Manager::NewFrame()
|
|
|
|
{
|
|
|
|
mouseMotion.fill(0);
|
|
|
|
mouseWheel = 0;
|
|
|
|
for (auto &k : keyState) {
|
|
|
|
auto &val = keyState[k.first];
|
|
|
|
switch (k.second) {
|
|
|
|
case 1: // if we were just pressed last frame, migrate to held state
|
|
|
|
val = 2;
|
|
|
|
break;
|
|
|
|
case 4: // if we were just released last frame, migrate to empty state
|
|
|
|
val = 0;
|
|
|
|
break;
|
|
|
|
default: // otherwise, no need to do anything
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_frameListChanged) {
|
|
|
|
RebuildInputFrames();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::RebuildInputFrames()
|
|
|
|
{
|
|
|
|
// Reset the list of active chords.
|
|
|
|
m_chords.clear();
|
|
|
|
m_activeActions.clear();
|
|
|
|
m_activeAxes.clear();
|
|
|
|
|
2020-11-14 00:33:40 -08:00
|
|
|
bool hasModal = false;
|
|
|
|
for (auto *frame : reverse_container(m_inputFrames)) {
|
|
|
|
// Disable all frames that are masked by a modal frame
|
2020-11-14 16:15:16 -08:00
|
|
|
// We reset all binding state here, because otherwise state is orphaned when events come in
|
|
|
|
// while the modal is active and binding state no longer matches the actual hardware state
|
|
|
|
// TODO: track when a frame is activated / deactivated and update state there?
|
2020-11-14 00:33:40 -08:00
|
|
|
frame->active = !hasModal;
|
2020-11-14 16:15:16 -08:00
|
|
|
if (hasModal) {
|
|
|
|
ClearInputFrameState(frame);
|
2020-11-14 00:33:40 -08:00
|
|
|
continue;
|
2020-11-14 16:15:16 -08:00
|
|
|
}
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
|
|
|
|
// Push all enabled key chords onto the key chord stack.
|
|
|
|
for (auto *action : frame->actions) {
|
|
|
|
if (!action->Enabled())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_activeActions.push_back(action);
|
|
|
|
assert(m_activeActions.back() == action);
|
|
|
|
if (action->binding.Enabled())
|
|
|
|
m_chords.push_back(&action->binding);
|
|
|
|
|
|
|
|
if (action->binding2.Enabled())
|
|
|
|
m_chords.push_back(&action->binding2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto *axis : frame->axes) {
|
|
|
|
if (!axis->Enabled())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_activeAxes.push_back(axis);
|
|
|
|
if (axis->positive.Enabled())
|
|
|
|
m_chords.push_back(&axis->positive);
|
|
|
|
|
|
|
|
if (axis->negative.Enabled())
|
|
|
|
m_chords.push_back(&axis->negative);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a modal frame, it prevents input from passing through it to frames below
|
|
|
|
if (frame->modal) { // modal frame blocks all inputs below it
|
2020-11-14 00:33:40 -08:00
|
|
|
hasModal = true;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group all chords with the same number of modifiers together, in descending order.
|
|
|
|
std::sort(m_chords.begin(), m_chords.end(), [](const InputBindings::KeyChord *a, const InputBindings::KeyChord *b) { return *a < *b; });
|
|
|
|
|
|
|
|
// Reinitialize the modifier list, preserving key state.
|
|
|
|
m_modifiers.clear();
|
|
|
|
for (auto *chord : m_chords) {
|
2020-11-14 00:33:40 -08:00
|
|
|
if (chord->modifier1.Enabled())
|
|
|
|
m_modifiers.emplace(chord->modifier1, GetBindingState(chord->modifier1));
|
|
|
|
if (chord->modifier2.Enabled())
|
|
|
|
m_modifiers.emplace(chord->modifier2, GetBindingState(chord->modifier2));
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t keys_in_chord(InputBindings::KeyChord *chord)
|
|
|
|
{
|
|
|
|
return chord->activator.Enabled() + chord->modifier1.Enabled() + chord->modifier2.Enabled();
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:02:27 -08:00
|
|
|
static float applyDeadzoneAndCurve(const JoystickInfo::Axis &axis, float value)
|
|
|
|
{
|
|
|
|
float absVal = std::fabs(value);
|
|
|
|
float sign = value < 0.0 ? 1.0 : -1.0;
|
|
|
|
if (absVal < axis.deadzone) return 0.0f;
|
|
|
|
// renormalize value to 0..1 after deadzone
|
|
|
|
absVal = (absVal - axis.deadzone) * (1.0 / (1.0 - axis.deadzone));
|
|
|
|
return AnimationCurves::SmoothEasing(absVal, axis.curve) * sign;
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
void Manager::HandleSDLEvent(SDL_Event &event)
|
|
|
|
{
|
|
|
|
using namespace InputBindings;
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
2020-04-01 14:02:12 -07:00
|
|
|
// Set key state to "just pressed"
|
|
|
|
keyState[event.key.keysym.sym] = 1;
|
2019-01-02 08:59:07 -08:00
|
|
|
keyModState = event.key.keysym.mod;
|
|
|
|
onKeyPress.emit(&event.key.keysym);
|
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
2020-04-01 14:02:12 -07:00
|
|
|
// Set key state to "just released"
|
|
|
|
keyState[event.key.keysym.sym] = 4;
|
2019-01-02 08:59:07 -08:00
|
|
|
keyModState = event.key.keysym.mod;
|
|
|
|
onKeyRelease.emit(&event.key.keysym);
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2020-03-30 21:59:44 -07:00
|
|
|
if (event.button.button < mouseButton.size()) {
|
2019-01-02 08:59:07 -08:00
|
|
|
mouseButton[event.button.button] = 1;
|
|
|
|
onMouseButtonDown.emit(event.button.button,
|
|
|
|
event.button.x, event.button.y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2020-03-30 21:59:44 -07:00
|
|
|
if (event.button.button < mouseButton.size()) {
|
2019-01-02 08:59:07 -08:00
|
|
|
mouseButton[event.button.button] = 0;
|
|
|
|
onMouseButtonUp.emit(event.button.button,
|
|
|
|
event.button.x, event.button.y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEWHEEL:
|
2020-04-01 14:02:12 -07:00
|
|
|
mouseWheel = event.wheel.y;
|
2019-01-02 08:59:07 -08:00
|
|
|
onMouseWheel.emit(event.wheel.y > 0); // true = up
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
mouseMotion[0] += event.motion.xrel;
|
|
|
|
mouseMotion[1] += event.motion.yrel;
|
|
|
|
break;
|
2020-11-08 21:02:27 -08:00
|
|
|
case SDL_JOYAXISMOTION: {
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!GetJoysticks()[event.jaxis.which].joystick)
|
2019-01-02 08:59:07 -08:00
|
|
|
break;
|
2020-11-08 21:02:27 -08:00
|
|
|
auto &axis = GetJoysticks()[event.jaxis.which].axes[event.jaxis.axis];
|
|
|
|
if (axis.zeroToOne)
|
|
|
|
// assume -32768 == 0.0 in half-axis mode (this is true for most controllers)
|
|
|
|
axis.value = applyDeadzoneAndCurve(axis, (event.jaxis.value + 32768) / 65535.f);
|
2019-01-02 08:59:07 -08:00
|
|
|
else
|
2020-11-08 21:02:27 -08:00
|
|
|
axis.value = applyDeadzoneAndCurve(axis, (event.jaxis.value == -32768 ? -1.f : event.jaxis.value / 32767.f));
|
|
|
|
} break;
|
2019-01-02 08:59:07 -08:00
|
|
|
case SDL_JOYBUTTONUP:
|
|
|
|
case SDL_JOYBUTTONDOWN:
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!GetJoysticks()[event.jaxis.which].joystick)
|
2019-01-02 08:59:07 -08:00
|
|
|
break;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
GetJoysticks()[event.jbutton.which].buttons[event.jbutton.button] = event.jbutton.state != 0;
|
2019-01-02 08:59:07 -08:00
|
|
|
break;
|
|
|
|
case SDL_JOYHATMOTION:
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (!GetJoysticks()[event.jaxis.which].joystick)
|
2019-01-02 08:59:07 -08:00
|
|
|
break;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
GetJoysticks()[event.jhat.which].hats[event.jhat.hat] = event.jhat.value;
|
2019-01-02 08:59:07 -08:00
|
|
|
break;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
default:
|
|
|
|
// Don't process non-input events any further.
|
|
|
|
return;
|
2019-01-02 08:59:07 -08:00
|
|
|
}
|
2019-02-14 17:14:15 -08:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
// if bindings are disabled, don't process the event any further
|
|
|
|
if (!m_enableBindings)
|
|
|
|
return;
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
// Update the modifier status from this event
|
|
|
|
for (auto &pair : m_modifiers) {
|
|
|
|
auto r = pair.first.Matches(event);
|
|
|
|
if (r != Response::Ignored) {
|
|
|
|
pair.second = r == Response::Pressed ? true : false;
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
// If the event matches one of the key chords we care about, update that chord
|
|
|
|
int num_keys_in_chord = 0;
|
|
|
|
for (auto *chord : m_chords) {
|
|
|
|
Response activator = chord->activator.Matches(event);
|
|
|
|
if (activator == Response::Ignored)
|
|
|
|
continue;
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
if (chord->IsActive()) {
|
|
|
|
// Another press event came in for a key that's currently pressed right now.
|
|
|
|
// This should be sufficiently rare that it won't be happening.
|
|
|
|
if (activator == Response::Pressed)
|
|
|
|
break;
|
|
|
|
else { // clear the active state, continue processing the release event
|
|
|
|
chord->m_active = false;
|
|
|
|
// in case of a press-release sequence in the same frame, make sure to properly send updates.
|
|
|
|
chord->m_queuedEvents |= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Key-release event for a non-active chord. Don't handle it, but pass it on so
|
|
|
|
// another key chord (with fewer / different modifiers) can handle it.
|
|
|
|
if (activator == Response::Released)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Break here to prevent CTRL+ALT+X from activating <CTRL>+X / <ALT>+X / <NONE>+X
|
|
|
|
// when there's a CTRL+ALT+X binding
|
|
|
|
if (keys_in_chord(chord) < num_keys_in_chord)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool mod1 = chord->modifier1.Enabled() ? m_modifiers[chord->modifier1] : true;
|
|
|
|
bool mod2 = chord->modifier2.Enabled() ? m_modifiers[chord->modifier2] : true;
|
|
|
|
if (mod1 && mod2) {
|
|
|
|
// Modifiers are pressed, we can activate the chord.
|
|
|
|
chord->m_active = true;
|
|
|
|
// in the case of a press-release in the same frame, make sure to properly send updates
|
|
|
|
chord->m_queuedEvents |= 1;
|
|
|
|
// all copies of this chord should be notified, but don't propagate to chords with fewer modifiers
|
|
|
|
num_keys_in_chord = keys_in_chord(chord);
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
void Manager::DispatchEvents()
|
2018-09-06 04:15:17 -07:00
|
|
|
{
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
// Chords which have had their modifier keys released this frame get updated all at once
|
|
|
|
for (auto *chord : m_chords) {
|
|
|
|
if (chord->IsActive() && !GetModifierState(chord)) {
|
|
|
|
chord->m_active = false;
|
|
|
|
chord->m_queuedEvents |= 2;
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
for (auto *action : m_activeActions) {
|
|
|
|
// if we have queued events for this binding, make sure to
|
|
|
|
uint8_t queued = action->binding.m_queuedEvents | action->binding2.m_queuedEvents;
|
|
|
|
if (queued) {
|
|
|
|
bool wasActive = action->m_active;
|
2020-11-14 00:33:40 -08:00
|
|
|
bool nowActive = action->binding.IsActive() || action->binding2.IsActive();
|
|
|
|
action->m_active = nowActive;
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
|
|
|
|
// if at least one of the bindings was pressed this frame and the action was not
|
|
|
|
// previously active, call the pressed event
|
|
|
|
if (queued & 1 && !wasActive)
|
|
|
|
action->onPressed.emit();
|
|
|
|
|
|
|
|
// if at least one of the bindings was released this frame but are not pressed currently,
|
|
|
|
// call the released event
|
2020-11-14 00:33:40 -08:00
|
|
|
if (queued & 2 && !nowActive)
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
action->onReleased.emit();
|
|
|
|
|
|
|
|
// clear queued events
|
|
|
|
action->binding.m_queuedEvents = action->binding2.m_queuedEvents = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
for (auto *axis : m_activeAxes) {
|
|
|
|
float value = GetAxisState(axis->axis);
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
value += axis->positive.IsActive();
|
|
|
|
value -= axis->negative.IsActive();
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
value = Clamp(value, -1.0f, 1.0f);
|
|
|
|
if (value != 0.0 || axis->m_value != 0.0) {
|
|
|
|
axis->m_value = value;
|
|
|
|
axis->onAxisValue.emit(value);
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 04:15:17 -07:00
|
|
|
}
|
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
/*
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
INPUT DEVICE MANAGEMENT ROUTINES
|
2018-09-06 04:15:17 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
*/
|
2020-03-24 09:10:28 -07:00
|
|
|
|
Refactor to InputFrame 2.0
Significantly refactored the Input class, added Input::Manager to handle
most duties of the Input system.
Replaced the legacy KeyBindings system with the new InputBindings
(namespace subject to change) system for handling key state and key
chords - among other improvements, there is no longer a hardcoded
dependency on Pi::input anymore, as well as storing the binding state in
the binding itself, completely decoupling InputBindings from the input
system that handles input events and significantly reducing the
complexity of the binding system.
Input::Manager now is totally responsible for generating binding events,
removing the need for WorldView::HandleSDLEvent and its ilk - interested
parties can simply bind to the onPressed event and they will only be
notified when the binding in question is part of an active input frame
and nothing else has grabbed the input event, vastly simplifying control
flow.
Among other effects, this almost totally eradicates the need for
Pi::IsConsoleActive().
The lua Console widget is slightly broken as a result of this change,
it doesn't handle activation/deactivation state changes properly. The
solution to this seems to simply be a direct rewrite in PiGui, which
I don't expect to cause too many issues.
I've added a CMake option to use LLD to speed up incremental build link
times; this seems to be somewhat platform dependent and is not
implemented for windows at this time.
Serialization of key bindings to the config file is totally completed,
although support for a graphical method of binding multi-key chords is
not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
|
|
|
void Manager::SetCapturingMouse(bool grabbed)
|
2020-03-24 09:10:28 -07:00
|
|
|
{
|
2020-03-24 09:33:11 -07:00
|
|
|
// early-out to avoid changing (possibly) expensive WM state
|
|
|
|
if (grabbed == m_capturingMouse)
|
|
|
|
return;
|
|
|
|
|
2020-03-24 09:10:28 -07:00
|
|
|
SDL_SetWindowGrab(Pi::renderer->GetSDLWindow(), SDL_bool(grabbed));
|
|
|
|
SDL_SetRelativeMouseMode(SDL_bool(grabbed));
|
|
|
|
m_capturingMouse = grabbed;
|
|
|
|
}
|