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

Port/inputsource: Refactor Abstracted Input Handler #558

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

Conversation

Yangff
Copy link
Contributor

@Yangff Yangff commented Jun 11, 2024

Description

The original Input Handler only accepted input from Win32. In the refactoring we have defined the input source as Input Source, which allows different input sources to be defined for different scenarios. QueueInputSource allows messages from other threads to generate keyboard input and be dispatched and responded to by the process_event thread via the SPSC queue.

Almost all of the definitions remain unchanged, with the only exception that get_events() has been replaced by get_events_safe(), which allows the use of mutex protection when accessing m_key_set.

ModifierKeys are re-implemented using bitwise operations on uint32_t, which simplifies storing and comparing modifier keys.

This PR depends on the string change so you can see those commits...

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Compiled and tested on Palworld, may need extra tests to ensure keys are responsed correctly as I only tested basic ones.

Checklist

Please delete options that are not relevant. Update the list as the PR progresses.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have added the necessary description of this PR to the changelog, and I have followed the same format as other entries.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots (if appropriate)

Additional context

Add any other context about the pull request here.

Yangff added 30 commits June 10, 2024 20:21
Define prupose driven string types in Macros.hpp

Use IOSTR/File::StringType for IO purpose, it's pinned to utf8/string type
Use SYSSTR/SystemStringType for interacting with STL, it's the prefer type
based on platform; On windows this is wchar_t/wstring and on Linux
this is char/string
Use STR/UEStringType for interacting with Unreal Engine, it's utf16.
On Windows we uses wchar_t/wstring to avoid extra copy/casting from u16string
On Linux we uses u16string which cannot be used in many STL functions.

With this patch, the only changes on string type on Windows should just be the
type aliases, and almost all actual types should stay unchanged.

For the IO, write_string_to_file will keep receiving utf16, aka wchar_t on windows.
A new write_file_string_to_file is added to allow receiving of utf8 string

A new WinFile using WinAPI is provided and to avoid the buggy BOM detection on the old code.
It also avoids the use of wstring to handle UTF-8 chars.
A new sets of to_xxxx/[_string] functions is provided

* to_ue/to_system/to_file can easily turn a string-like type to its new type
For a string view or XXchar* that doesn't need to be encoded for conversion,
these functions return it as is, so its return type may be the corresponding
string or string view (see can_be_string_view_t)
For a different underlying type of string, they create a new string
to hold the converted result

* to_ue_string/to_system_string/to_file_string will force
the corresponding string type to be returned,
which is appropriate if your target can't accept a string view.
@UE4SS
Copy link
Collaborator

UE4SS commented Jun 11, 2024

This PR is effectively impossible to review in its current state because it's based on #557.
Looking past the #557 changes to try to find what this PR actually changes is not reasonable.
My suggestion is to leave it alone for now, and when #557 has been merged, we can rebase this one back onto main to make the review process more sane.

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.

2 participants