ryanisaacg / quicksilver

A simple framework for 2D games on desktop and web
https://ryanisaacg.github.io/quicksilver
Other
785 stars 77 forks source link

Add a way to inject events into the stream. #650

Open bwinton opened 3 years ago

bwinton commented 3 years ago

Describe the problem you want to solve So, using stdweb, I have some controls outside of the canvas, and I would like my app to respond to them when they change. I started by trying to keep circular references between the desktop or web config objects and the main game object, but of course they can't both own each other, so that didn't work out so well. My next thought was to add event listeners in Rust, and try and send a keyboard event to the canvas which I could respond to in my app, but that also didn't work (it couldn't seem to make it all the way from webstd through winit through blinds through quicksilver to my function. I'm not sure why).

I ended up just checking the state of the controls every time through the loop, but that feels less elegant than reacting when they change.

Describe the solution you'd like Some way to create and push events into the Input passed to the async function would have made this a little easier.

Are you interested in contributing? I think I have a workaround, and I still don't have a ton of time, so I don't think I'll be able to fix this myself.

ryanisaacg commented 3 years ago

You should be able to create a queue of your own events and check that in your loop somewhere, no? My instinct is to keep the Input event source solely focused on events that come into your code from system input, both for simplicity and correctness's sake.

bwinton commented 3 years ago

In theory, yes. In practice, I fought the borrow checker for half an hour or so trying to get that working before giving up and filing a bug report. 😉 (Also, it's admittedly a little uglier to have to check two separate queues for events. I suppose I could filter all the Input events into my queue, and only check the one, but that also feels a little weird…)

Having said that, if you wanted to resolve this "WONTFIX", I would totally understand. 🙂

ryanisaacg commented 3 years ago

I'm not morally opposed to it, but my first instinct is to push people towards solutions that don't involve threading their events through Quicksilver's internals. I will be thinking about a design that allows for passing user events without adding complexity, and I'll see what I come up with.