-
Notifications
You must be signed in to change notification settings - Fork 2
[outdated] ControllerManagement for iOS #168
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
[outdated] ControllerManagement for iOS #168
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements ControllerManagement for iOS to bring feature parity with Android and Windows platforms. It refactors the GameControllerServiceBase to use IGameController directly instead of generic types, enabling support for different controller types like MCP servers.
- Adds complete iOS GameController implementation with proper device management
- Removes generic constraint from GameControllerServiceBase to handle diverse controller types
- Cleans up unused properties and code across the codebase
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| IGameController.cs | Removes unused VendorId and ProductId properties from interface |
| GamepadControllerBase.cs | Updates generic parameter naming and removes unused properties |
| GameControllers.cs | Removes unused GetControllerIdFromIndex helper method |
| GameControllerServiceBase.cs | Removes generic constraint and adds proper disposal handling |
| GamepadController.cs (iOS) | New iOS controller implementation with complete input handling |
| GameControllerService.cs (iOS) | New iOS service implementation extending the base class |
| GamepadController.cs (WinUI) | Updates to use new ControllerDevice property naming |
| GameControllerService.cs (WinUI) | Updates method calls to use new generic TryRemove signature |
| GamepadController.cs (Android) | Removes unused properties and imports |
| GameControllerService.cs (Android) | Updates method calls to use new generic TryRemove signature |
| InputDeviceExtensions.cs (Android) | Removes entire unused extension class |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
e96e681 to
a76760d
Compare
BrickController2/BrickController2/PlatformServices/GameController/GamepadControllerBase.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.Android/PlatformServices/GameController/GamepadController.cs
Show resolved
Hide resolved
| _ = _mainThreadService.RunOnMainThread(() => | ||
| { | ||
| if (TryRemove(x => x.Gamepad == gamepad, out var controller)) | ||
| if (TryRemove<GamepadController>(x => x.ControllerDevice == gamepad, out var controller)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is type of GamepadController needed to be defined for TryRemove? What is the benefit of such change, if it has to be specified here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because we lost the generic in the base class - it's just the interface IGameController now
/// <summary>
/// Collection of available gamepads having <see cref="IGameController.ControllerId"/>
/// </summary>
private readonly List<IGameController> _availableControllers = [];
But to distinguish the controllers we neet to handle the real type to be able to access properties not defined in the interface.
If there is another remove-event for another controller type to handle - i.e. for the McpServer ;) - the generic paramater of TryRemove<> would be that special type of controller:
private void McpServerRemoved(object? sender, McpServer e)
{
lock (_lockObject)
{
// ensure stopped in UI thread
_ = _mainThreadService.RunOnMainThread(() =>
{
if (TryRemove<McpServerController>(x => x.ControllerDevice is McpServer, out var controller))
{
_logger.LogInformation("McpServer has been removed");
}
});
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I d not like this desgin as:
- it enforces hard coupling of MCP server to controller service for each platform
* additionally it seems to me in your follow up (#165), MCP platform inplementations are nearly the same. Is it?
Shortly said, it should be done differently. May be there might be some game controller providers, which are providing different types of game controllers, the gamepad ones, MCP ones. Just a quick idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if I understood you correctly, I see it that way too.
It would be a clean solution if there were a central instance that manages all types of input devices and handles event signaling (gamepad 🕹️ events, gyro events, mcp server events, etc.).
Then there should be providers for the different types of input devices that register and deregister the input devices with the central instance und call the event invoking methods...
If I find some time these days I'll suggest an implementation of that.
...kController2/BrickController2.WinUI/PlatformServices/GameController/GameControllerService.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GameControllerService.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Outdated
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Show resolved
Hide resolved
BrickController2/BrickController2.iOS/PlatformServices/GameController/GamepadController.cs
Show resolved
Hide resolved
cleanup code: * removed unused properties of IGameController and GamepadControllerBase * removed generic in GameControllerServiceBase; use IGameController
30147ed to
e3e78a2
Compare
|
It's included in #172 (comment) |
|
Please close this one as it's outdated due to the recent merge. |
I've added the missing ControllerManagement for iOS, as it's already implemented for Android and Windows.
Then, I've removed the generic parameter of GameControllerServiceBase to handle different types of input devices/controllers, such as MCPServer ;). IGameController is now used instead.
And I've cleaned up the code: