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

Kill Bizware .NET Framework deps #3702

Merged

Conversation

CasualPokePlayer
Copy link
Member

Only has a WinForms dep for GraphicsControls now

Supersedes #3622

Only has a WinForms dep for GraphicsControls now
@nattthebear
Copy link
Contributor

Could you build out a description for this PR? Include all of the libraries we're removing, the ones we're replacing them with, and the basic objective here.

@CasualPokePlayer
Copy link
Member Author

CasualPokePlayer commented Jul 11, 2023

The main objective in this PR is to get rid of the main .NET Framework dependencies in Bizware packages. This PR doesn't do that completely per se, still having .NET Framework used for WinForms Controls, but that can easily be swapped over for whatever UI framework we use next as long as it exposes native window handles in some way.

For this PR, it does some reorganizing of Bizware, splitting Bizware.OpenTK3 and Bizware.DirectX into 3 packages based on usage; Bizware.Audio, Bizware.Graphics, and Bizware.Input. These packages in the future probably could have more functionality moved into them, but for now they are largely just a reshuffling of the Bizware.OpenTK3 and Bizware.DirectX packages.

As both SlimDX and OpenTK3 are .NET Framework, they have been removed in this PR. Their replacements are as follows:

SharpDX: DirectSound, Direct3D9
Vortice: XAudio2, DirectInput/XInput
Silk.NET: OpenAL, OpenGL
SDL2-CS / native SDL2: OpenGL context management, new gamepad backend (replacing OpenTK's role for gamepads)
native X11: New key input backend (replacing one of OpenTK's roles for keyboards)

GLControl has been replaced by custom made control which just uses SDL2 for context management.

The OpenTK input backend has been replaced with a combination of SDL2 and an OS tailored key input backend (DirectInput on Windows, X11 on Linux, and planned to be Quartz on macOS). This is just represented on the user side as "SDL2" without mentioning the key input backend. This does mean for a while DirectX will be mandatory on Windows again, until a RAWINPUT backend is written for handling key input on Windows for the SDL2 input backend.

@YoshiRulz
Copy link
Member

YoshiRulz commented Jul 12, 2023

[...] still having .NET Framework used for WinForms Controls [...for its] native window handles [...]

If this is just IWin32Window.Handle, the existing IDialogParent abstraction covers that.

For this PR, it does some reorganizing of Bizware, splitting Bizware.OpenTK3 and Bizware.DirectX into 3 packages based on usage; Bizware.Audio, Bizware.Graphics, and Bizware.Input.

The reason I split them by ~platform in the first place was so the whole project could be deleted once it was no longer needed. It's not like the frontend can selectively import just graphics or just input, and we're not publishing them, so why split them this way? Was it annoying having an interface and its implementations in separate projects?

edit: Also, is this ready to merge today? If so I'll start testing.

@CasualPokePlayer
Copy link
Member Author

CasualPokePlayer commented Jul 12, 2023

One of the first reasons I ended up going for this design was due to how the SDL2 input backend ended up turning out, where it ended up using DirectInput anyways potentially (and even in the future it would just go ahead and use the Windows specific RAWINPUT API).

Another reason was just due to the amount of different libraries that ended up used, if I were to split it up by each library (and maybe charitably combine SharpDX and Vortice usage in a single library), that'd still end with 3 or maybe 4? And that's tricky to even do with the cross library use of the SDL2 backend.

There is also the matter of dependencies. At the moment this doesn't mean much, as this is largely just a reshuffling of files with some cleanups, and so dependency chains are largely the same. However, the Bizware.Audio only depends on Client.Common for ISoundOutput and IHostAudioManager, interfaces which can be moved over to Bizware.Audio in the future. Bizware.Input only depends on Client.Common for IHostInputAdapter, ClientInputFocus, KeyEvent, DistinctKey, and Config, mostly stuff which could be moved over to Bizware.Input (along with a lot of other functionality with input for that matter), and Config can probably be abstracted so Bizware.Input doesn't need to be dependant on the entire Config. In the end, these two could be made to depend on at most on BizHawk.Common and nothing else.

Also yes, assuming everything works fine it could be merged. As a note, I don't have any game controllers to test with so I'm completely blind on that front.

@Morilli
Copy link
Collaborator

Morilli commented Jul 13, 2023

Using my PlayStation 4 controller, I can't get any button pressed to get recognized with the SDL input backend.

make SDL2 input probably work? also make it much cleaner
@CasualPokePlayer
Copy link
Member Author

@Morilli Please re-try on the latest commit.

@Morilli
Copy link
Collaborator

Morilli commented Jul 14, 2023

Okay so apparently sometimes when connecting or dis- and reconnecting the controller too fast it can hardcrash bizhawk:

System.ArgumentException: Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt.
   bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   bei BizHawk.Bizware.Input.SDL2Gamepad.AddDevice(Int32 deviceIndex) in /src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs:Zeile 70.
   bei BizHawk.Bizware.Input.SDL2InputAdapter.SDLThread() in /src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs:Zeile 88.
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()

I'm not sure whether this is ultimately SDLs fault or not, but it would be great if BizHawk didn't hardcrash when e.g. the controller disconnects.

Aside from that though, input now also does not work.

@CasualPokePlayer
Copy link
Member Author

CasualPokePlayer commented Jul 14, 2023

Seems that is due to SDL pushing an event which has a joystick with an identical instance id added, which doesn't really make sense I guess (disconnect event never occurs I guess?) should be trivial to just check if it exists and ignore the request to add it(?)

@CasualPokePlayer
Copy link
Member Author

Some debug printing is in the console now, if it doesn't work, please post what gets shoved into the console.

@Morilli
Copy link
Collaborator

Morilli commented Jul 14, 2023

I'm getting some problems with bizhawk freezing completely which is probably also caused by some of the SDL code.
Also this part of the logging does not seem right to me:

Using SDL2 for host input (keyboard + gamepads)
Connected SDL gamepad, device index 0, instance ID 0, name PS4 Controller
Disconnecting SDL gamepad, device index 0, instance ID -1, name
Connected SDL gamepad, device index 0, instance ID 1, name PS4 Controller
Disconnecting SDL gamepad, device index 0, instance ID -1, name
Connected SDL gamepad, device index 0, instance ID 2, name PS4 Controller
Disconnecting SDL gamepad, device index 0, instance ID -1, name
Connected SDL gamepad, device index 0, instance ID 3, name PS4 Controller
Disconnecting SDL gamepad, device index 0, instance ID -1, name
Connected SDL gamepad, device index 0, instance ID 4, name PS4 Controller

@CasualPokePlayer
Copy link
Member Author

CasualPokePlayer commented Jul 15, 2023

The logging isn't super strange outside of disconnect and reconnecting (assuming you aren't doing that yourself), the -1 and name being blank for disconnect is more indicating you can't use device indexes for retrieving device info once it's disconnected (should be simple enough to fix anyways)

Not sure why it'd end up freezing completely, perhaps the SDL events are locking up?

@Morilli
Copy link
Collaborator

Morilli commented Jul 15, 2023

The freeze seemingly comes from a deadlock in Input.cs because of an infinite wait on the lock(this); I'm not sure why or when this happens but I can still occasionally reproduce this:
image

Logging now matches connect with disconnect nicely, so that's good.
However input still is not working.

@Morilli
Copy link
Collaborator

Morilli commented Jul 15, 2023

With additional logging:

...
Entering SDL event loop
Exiting SDL event loop
Entering SDL event loop
Exiting SDL event loop
Entering SDL event loop
Exiting SDL event loop
Entering SDL event loop
Exiting SDL event loop
Entering SDL event loop
Connected SDL gamepad, device index 0, instance ID 10, name PS4 Controller
Exiting SDL event loop
Entering SDL event loop
[freeze]

@kalimag
Copy link
Contributor

kalimag commented Jul 17, 2023

On SDL2, the up and down direction for the analog sticks are reversed, both for digital input (left stick forward binds LStickDown) and analog input (stick forward is bound to negative axis input by default).

Win10 with a wireless Xbox One controller in case it makes a difference.

@CasualPokePlayer
Copy link
Member Author

That seems to be an intentional detail in SDL2, it defines joystick Y axis the opposite way from XInput. We probably could just internally flip it back around here.

SDL maps game controller axes as RightDown instead of RightUp like XInput and the like
…e rumble doesn't work (also, this means Linux gets rumble for the first time in hawk!)
@CasualPokePlayer
Copy link
Member Author

If there aren't any objections, I'll be merging this soon (I do need at least the OpenGL part merged for a core port I'm currently doing).

@CasualPokePlayer CasualPokePlayer merged commit 78f5e75 into TASEmulators:master Jul 23, 2023
@YoshiRulz
Copy link
Member

YoshiRulz commented Aug 6, 2023

SUPER late, but can confirm gamepads work on Win10, including haptic feedback, and also everything else from this PR. I used an XBone gamepad 045E:02FF on the dev build ca756a2.

edit: And everything except haptic feedback on Linux.
edit edit: Can also confirm haptic feedback works on Linux \o/

@CasualPokePlayer CasualPokePlayer deleted the kill_bizware_netframework branch August 7, 2023 00:01
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.

5 participants