Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KBM-only remapping #1797

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

kalaposfos13
Copy link
Contributor

This is a modified version of my remapping PR that only contains the keyboard and mouse part, as this is already complete and has proven to be mostly bug-free, as it has been extensively tested by people using @diegolix29's fork. The controller part is still WIP and is not ready for merging yet, so until that's ready too, I'll just put this out here following @rainmakerv3's advice. The code still has some controller remapping elements left in, but they aren't hooked up to the main input loop. If I left in anything that I shouldn't have, please let me know.

@rainmakerv3
Copy link
Contributor

rainmakerv3 commented Dec 16, 2024

image

This was my attempt at designing a GUI for this. Since there's so many functions (ability to add up to 3 inputs per output is the most painful one to design), I can't seem to make it take a smaller space.

The intended use for this is that the dropdown boxes list down the possible inputs per output (since there can be up to three), and the user can press the corresponding input button, then input up to three keystrokes to fill in each combobox. Design wise this seems to be the only thing I can think of to support the things this program wants to do, but I am unable to code it this way.

As such, I'm at least putting the UI file here, and maybe someone else can code in the input saving and such.

(saved as txt file, rename to ui to use)

kbm_config_dialog.txt

@GHU7924
Copy link

GHU7924 commented Dec 16, 2024

@rainmakerv3 I think it's worth combining at least the keyboard, since some people can play on laptops or they don't have a controller, it should have been added a long time ago, and as for the graphical interface, we haven't made significant progress in this direction yet, let's leave it for later.

@rainmakerv3
Copy link
Contributor

Yes I agree. My thought is that this would be a good place to leave this for anyone who wants to use it. But like you, I also believe this is good enough to merge in its current state

src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
Comment on lines +292 to +283
BindingConnection toggle_connection =
BindingConnection(InputBinding(toggle_keys.key2), toggle_out, toggle_keys.key3);
connections.insert(connections.end(), toggle_connection);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BindingConnection toggle_connection =
BindingConnection(InputBinding(toggle_keys.key2), toggle_out, toggle_keys.key3);
connections.insert(connections.end(), toggle_connection);
connections.emplace_back(InputBinding(toggle_keys.key2), toggle_out, toggle_keys.key3);

Less lines and constructs object in-place. Ditto for all other cases of insert() like this

return GetMouseWheelEvent(e);
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
return (u32)e.gbutton.button + 0x10000000; // I believe this range is unused
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (u32)e.gbutton.button + 0x10000000; // I believe this range is unused
return (u32)e.gbutton.button + 0x10000000; // I believe this range is unused

What is this magic value? Could we get a constexpr variable with a name instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an offset so the SDL ranges for different types of inputs don't overlap (they all start at 0, and I have to differentiate between them somehow) Keyboard and mouse got the no offset range, as they were the first to be implemented, then for controller buttons, I just chose this as it didn't overlap with anything, and for axes I chose a large offset (0x80000000) so when sorting them they will be at the end of the list, and that is important for reasons. I think a cleaner way to do it would be to finally make this a struct and just give up on storing everything in a single u32 (id, input type, analog value for axes)

// solution 1: add it to the keycode as a 0x0FF00000 (a bit hacky but works I guess?)
// I guess in software developement, there really is nothing more permanent than a temporary
// solution
value_mask = (u32)((e.gaxis.value / 256 + 128) << 20); // +-32000 to +-128 to 0-255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for above, this code is hard to understand at a glance

src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
src/input/input_handler.cpp Outdated Show resolved Hide resolved
using Libraries::Pad::OrbisPadButtonDataOffset;

// get the event's id, if it's keyup or keydown
bool input_down = event->type == SDL_EVENT_KEY_DOWN ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool input_down = event->type == SDL_EVENT_KEY_DOWN ||
const bool input_down = event->type == SDL_EVENT_KEY_DOWN ||

Ditto for other cases of const correctness

}
}
// LOG_DEBUG(Input, "Input activated for the first time, adding it to the list");
pressed_keys.insert(pressed_keys.end(), {value, false});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inserts the key into pressed_keys without checking is_pressed, is it okay?

Suggested change
pressed_keys.insert(pressed_keys.end(), {value, false});
pressed_keys.emplace_back(value, false);

if (value == (u32)-1) {
return false;
}
if ((value & 0x80000000) != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value seems has special meaning depending some bits. Please make a bitfield struct describing its layout and use that. Manual bit parsing of random parts can be hard to memorize

Comment on lines +175 to +168
if (!key1)
key1 = key_id;
else if (!key2)
key2 = key_id;
else if (!key3)
key3 = key_id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a lambda defined in the function to reduce code duplication

src/input/input_handler.cpp Outdated Show resolved Hide resolved
@kalaposfos13
Copy link
Contributor Author

@raphaelthegreat I did the easy changes, and I'll do the rest tomorrow. So far I've only one comment on this:
std::ranges::find does indeed do what my function does, but &*std::ranges::find(output_array, ControllerOutput(button_it->second)) just looks cursed.

@raphaelthegreat
Copy link
Collaborator

raphaelthegreat commented Dec 20, 2024

You can use projections in ranges to simplify it to

const auto it = std::ranges::find(output_array, &ControllerOutput::button, button_it->second);
return &*it;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants