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

Experimenting with generics for backend type passthrough #77

Closed
wants to merge 5 commits into from

Conversation

bhperry
Copy link
Contributor

@bhperry bhperry commented Oct 14, 2023

This is an alternative implementation to #76
And more importantly, an experiment in a different way to handle pixel's interactions with backends.

While working on the pixel Actions PR, it began to feel a bit like a hat on a hat on a hat as input arrays are passed up through the stack (OpenGL -> GLFW -> Pixel), copying at each level and creating more garbage to be collected. So I started experimenting with generics to see if I could get around that.

The idea is to store inputs in the backend's native type, and then when the user checks an input win.Pressed(pixel.MouseButton1) we do the mapping from pixel -> backend type instead of the other way around.

@bhperry bhperry marked this pull request as draft October 14, 2023 23:01
@bhperry
Copy link
Contributor Author

bhperry commented Oct 14, 2023

And a pixel code base would not be able to easily switch between backends, so that's a deal breaker. But ditching the generics this gives me an idea for a better way to handle it while still mapping to pixel types.

@dusk125
Copy link
Contributor

dusk125 commented Oct 14, 2023

And a pixel code base would not be able to easily switch between backends, so that's a deal breaker. But ditching the generics this gives me an idea for a better way to handle it while still mapping to pixel types.

Haven't been following along, but if you mean it should be able to switch after startup, we can ignore this. Once a user selects a backend, they're stuck with it unless they tear everything down and start again.

@bhperry
Copy link
Contributor Author

bhperry commented Oct 15, 2023

No didn't mean after startup, just that I think it's not a good design pattern for the project that you wouldn't be able to switch over to a different backend with relative ease.

@dusk125
Copy link
Contributor

dusk125 commented Oct 15, 2023

Makes sense!

@bhperry
Copy link
Contributor Author

bhperry commented Oct 15, 2023

Ok ignoring the stuff I said about the end-user referencing backend types directly, this could actually work. Store inputs as the backend native type, and then do the type mapping in the other direction at query time. WDYT?

@bhperry bhperry marked this pull request as ready for review October 15, 2023 00:31
@bhperry bhperry mentioned this pull request Oct 15, 2023
@bhperry
Copy link
Contributor Author

bhperry commented Oct 15, 2023

causes more problems than it solves

@bhperry bhperry closed this Oct 15, 2023
@bhperry bhperry deleted the generic-gamepad branch October 15, 2023 16:25
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