faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 245 forks source link

Add callback functionality for input events #293

Open trondhumbor opened 3 years ago

trondhumbor commented 3 years ago

Allows adding custom callback functions, which will be called when glfw fires an input event.

dusk125 commented 3 years ago

Thanks for the PR! Can you explain a bit of your use-case/thought process behind this change please? I'm interested to see how this differs from using the existing pixel.Window input functions.

cebarks commented 3 years ago

I was thinking this feature would be nice but came to the conclusion most things i would do with callbacks i could just do with checking an input loop. However, the best idea I had was for UI elements (checking every mouse click if you're over a button on the screen, etc.)

trondhumbor commented 3 years ago

The intention was to provide a way to make use of the callback methods already existing in glfw. Instead of exposing them raw, I wrapped them so that glfw elements won't leak into the pixel library. One of the main benefits with this change, as I see it, is that you can avoid using an input loop for something that is event-driven "under-the-hood".

dusk125 commented 3 years ago

So the thing I'm struggling with here is that I don't know if this actually buys you anything. GLFW might be able to send events async, but OpenGL is still single threaded and basically all calls in Pixel that go touch OpenGL are forcibly done in the main thread.

The thing I'm not sure about (given my inexperience with GLFW) is if the callbacks are actually done async or if they're also called single threaded-ly; maybe you can speak to that? In Pixel, we call glfw.PollEvents (on the main thread) and then update our internal structure.

cebarks commented 3 years ago

@trondhumbor what's your use case for this feature? i'm curious

Chillance commented 3 years ago

Related to https://github.com/dusk125/pixelui/issues ? If so, would be nice to get this merged so the others can also be.

dusk125 commented 3 years ago

Related to https://github.com/dusk125/pixelui/issues ? If so, would be nice to get this merged so the others can also be.

Thanks for reminding me to go through the PixelUI issues :D All of those issues were waiting on PRs that have now been accepted into Pixel (they've now been closed); that is to say, this isn't related to the issues I was having in PixelUI.

Chillance commented 3 years ago

Related to https://github.com/dusk125/pixelui/issues ? If so, would be nice to get this merged so the others can also be.

Thanks for reminding me to go through the PixelUI issues :D All of those issues were waiting on PRs that have now been accepted into Pixel (they've now been closed); that is to say, this isn't related to the issues I was having in PixelUI.

PixelUI is fantastic. Great addition to fantastic Pixel. Started to use PixelUI myself and noticed it needs to upgrade the underlying imgui-go (made an issue for it) Anyway, this is about Pixel so I hope this PR will be merged soon too.

duysqubix commented 1 year ago

@dusk125

Is this PR still relevant?