JTalton's picture

GameWindow. ProcessEvents - Lost events

In my update function I check for Keyboard[OpenTK.Input.Key.Escape].
The problem is that when I hit ESC it does not get triggered.
This is because I was only doing updates every second, and by time the update happens the key is not marked as pressed anymore.

ProcessEvents should queue events for processing by a users Update function.
This would guarantee that no events were missed because of timing.
It would also be nice if the events were time stamped.

Maybe there is Queue already, but I didn't find one.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler.'s picture

I see what you mean. There is no queue at that level (the ProcessEvents() call updates input devices instantly), and I cannot think how to do this without adding a rather large amount of overhead.

However, maybe this is a non-issue? Is there any reason why you only update 1 time/sec? This is a non-interactive rate - upping that to at least 15-30 updates/sec will take care of the problem (at least if you aren't writing an FPS or a music sequencer :) ). Even AAA titles suffer from this (Crysis comes to mind): if fps fall below a limit, some input events will not get registered.

JTalton's picture

It seems that any time a user is tapping keys or buttons that there is the possibility that they may be missed. On top of that if the key or button may cause an action the user is going to have to track when it is detected as not pressed before they handle it pressed again. I could see this affecting typing text into the application.

SDL queues up the events and lets the user dequeue and handle them. The only problem I see with SDLs implementation is that it does not put time stamps on the events. Sometimes I would like to track exactly how long a key has been pressed.

Calling update at fast rates may work pretty well in most cases but if someone has a slow computer and rendering takes a long time, then any press release during that rendering will not register.

The overhead of queueing up the events should not be too large. When I was using SDL I actually dequeued events constantly and added them to my own internal queue. This allowed me to move the event processing off the main thread.

the Fiddler.'s picture

Now that I think of it, the problem you describe has already been solved in OpenTK! Check the KeyDown and KeyUp events in KeyboardDevice - they do exactly what you describe, only much better than SDL. I think I need some sleep...

Edit: Set the KeyRepeat property to true for text input (default is false).

JTalton's picture

Wonderful! Yes, sleep is good, just hard to get.

It would be nice to have the example code use the Keyboard and Mouse events so that people looking at the examples can find out about them. Just a thought.

the Fiddler.'s picture

Agreed. The examples will receive a dramatic facelift in the next few versions, more info soon.