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

Use SDL2 mouse input on Windows #443

Merged
merged 8 commits into from
Apr 28, 2024
Merged

Conversation

FreeSlave
Copy link
Member

@FreeSlave FreeSlave commented Mar 13, 2024

Dynamically load SDL2 on Windows and use its functions for mouse handling. If SDL2 is not available (i.e. the mod is running on pre-SDL2 version of Half-Life), it fallbacks to the pre-SDL2 mouse input.
USE_SDL2 macro is removed and replaced with dynamic checks for the presence of sdl2Lib.

Without SDL_SetRelativeMouseMode and SDL_GetRelativeMouseState the raw input doesn't really seem to work, so I decided it could be useful to have this option working in this hlsdk. But we need to figure out the reliable way to check if raw input works without relying on "feelings".

Although it works, you can consider this merge request as WIP, because I left joystick input the same as in pre-SDL2 Half-Life versions on Windows regardless of whether SDL2 is available or not. I don't have a joystick currently, so I can't test anything related to it. Someone else can change and test such things and add commits to this PR.

I also haven't tested it on Xash3D-FWGS yet (just to make sure it doesn't cause any troubles while building without GoldSource input support) and on the vanilla Xash3D.

I also added SDL2 headers (copied from valve's repo external/ subdirectory), so the user is not required to install SDL2 headers on Windows. On Linux you still need to download a dev package to SDL2. But we can rely on the headers bundled in the repository for Linux build too.

Thoughts:
We probably can remove some SDL2 .h files to minimize their presence in the repo.

@FreeSlave
Copy link
Member Author

FreeSlave commented Apr 7, 2024

Deleted redundant SDL2 headers

Also checked this doesn't affect building and running on Xash3D-FWGS. So it doesn't break anything.

@a1batross
Copy link
Member

I wonder what we're going to do when SDL3 will come out. Will Valve upgrade GoldSrc to it? I hope not...

Though for us, it has some interesting features I would like to leverage in the engine, mostly supporting multi-monitor setups. But I don't think we will migrate to it anytime soon, as SDL2 will continue to exist and packaged on modern systems, like SDL 1.2 is still required by some software.

@a1batross
Copy link
Member

I think there are few more redundant headers:

  • SDL_config_iphoneos.h: not supported by GoldSrc
  • SDL_config_android.h: not supported by GoldSrc
  • SDL_config_psp.h: not supported by GoldSrc
  • SDL_config_nintendods.h: not referenced by anything
  • SDL_config_pandora.h: not referenced by anything
  • SDL_config_wiz.h: not referenced by anything

@FreeSlave
Copy link
Member Author

I think there are few more redundant headers:

  • SDL_config_iphoneos.h: not supported by GoldSrc
  • SDL_config_android.h: not supported by GoldSrc
  • SDL_config_psp.h: not supported by GoldSrc
  • SDL_config_nintendods.h: not referenced by anything
  • SDL_config_pandora.h: not referenced by anything
  • SDL_config_wiz.h: not referenced by anything

Removed them as well

@FreeSlave
Copy link
Member Author

FreeSlave commented Apr 7, 2024

I pushed changes that makes the game use SDL2 joystick code on Windows as well.
I don't have a joystick myself, so it all needs to be re-tested (on Linux too).

If you want to check if winapi joystick still works, you can change UseSDL2Joystick to always return false (just for a test) or run the client on some pre-SDL2 version of GoldSource.
We could also provide a cvar to let user decide what joystick input they prefer (e.g. joy_prefer_winapi). But I think it's better if someone with joystick device makes these changes.

Btw Half-Life anniversary page mentions some changes to mouse and joystick input. I don't know it's something on game library side or in the engine.

Fixed issues that caused jerky mouse / joystick input.
(We basically rewrote it all - if you've got a custom Steam Input controller configuration, you should rebuild it from our newly published Official Configuration).

@FreeSlave
Copy link
Member Author

@a1batross any progress with testing on your side? Can it be merged?

@a1batross
Copy link
Member

I will look into that soon.

@a1batross
Copy link
Member

I forgot. What exactly I should look for?

It builds and runs on Linux versions of GoldSrc and Xash3D just fine.

@FreeSlave
Copy link
Member Author

FreeSlave commented Apr 14, 2024

@a1batross

  • Check that raw input now works correctly on Windows on GoldSource.
  • Check if joystick still works on Windows and Linux on GoldSource.
  • Check if joystick still works on pre-SDL2 version of Half-Life.
  • Optionally check if mouse works on vanilla Xash3D (which doesn't use FWGS specific input).

The raw mouse input seems to work correctly. If I move camera to the side and back very fast the crosshair ends up approximately at the same position (while without raw input it shifts with every "swing" due to acceleration).

I don't have any game controller, so I can't check joystick inputs.

@a1batross
Copy link
Member

Everything works. LGTM

@FreeSlave
Copy link
Member Author

@nekonomicon merge it?

@nekonomicon nekonomicon merged commit 7a75ec5 into FWGS:master Apr 28, 2024
4 checks passed
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.

None yet

3 participants