Help with my input sytem

Started by
12 comments, last by L. Spiro 11 years ago

OpenGL does allow enabling the context in a different thread and rendering there (at least on Windows), so I'm not sure if there's any additional limitation there or just a feature missing in SDL. It probably isn't safe though and I'm not sure if it'd work on mobile either (for the same reason as the events).

No devices have such a limitation. From the sounds of it it is nothing more than an SDL thing.

I would drop SDL, personally. No telling how many work-arounds will become necessary in the future.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

If you verify and find out that you are correct and that rendering must be on the same thread as input, you are basically screwed as far as getting smooth and reliable input until you drop SDL.
Dropping SDL would be my main recommendation, but you may be able to work around it with SetWindowsHook() or SetWindowsHookEx() and bypass the SDL method of handling recognized keyboard and mouse input (while letting it handle unrecognized keyboard input so it can continue to do its thing with maximizing/resizing windows, closing the game on Alf-F4, etc.)

Normally that's what I would do but dropping SDL would be catastrophic to the portability of my code. Right now my game is a unified codebase that compiles directly under a variety of operating systems (so far only tried it with Windows and Linux). For now I think I'll finish implementing this using SDL's event driven framework as opposed to reading from the keyboard buffer, this should be fine for now so that I can finish implementing the interface and work on other stuff until either I come up with a more novel solution or the SDL api changes.

Oh and I'm rendering with OpenGL if anyone was wondering and I'm using the 2.0 version of SDL.

No, it listens to WM_* Windows event messages. Polling means...

Windows messages only arrive when you poll the Windows message queue though, so unless you have an extremely high polling rate (>100Hz), your timestamps are going to be wrong anyway, right?


No, it listens to WM_* Windows event messages. Polling means...

Windows messages only arrive when you poll the Windows message queue though, so unless you have an extremely high polling rate (>100Hz), your timestamps are going to be wrong anyway, right?


In a basic game loop that most people use at the start of their learning experience you basically peek into the Windows message buffer and either eat the message or draw the frame.
Unless you purposely limit your framerate with sleeps it likely will be 100 Hz or more, or at least 60 Hz.

Of course the speed at which you can poll depends on your game speed which is why I suggest to move that to another thread and poll for input on the same thread that created the window.
This would be done with WaitMessage(), which will keep the thread on a low priority until an input has arrived and should immediately awaken the thread once it has. You should be able to keep the input thread on the highest priority as well since inside WaitMessage() it shouldn’t just be sleeping but in an “event-waiting” state, so it won’t be hogging the CPU but also won’t get drowned out by the other threads when an event does occur and it awakens.

In this case you aren’t really polling. You should be able to get all events within a millisecond of accuracy.


But there is still another option on Windows since you can get message timestamps (forgot the function).
Though it is tricky to synchronize with your game clock, which you would need to do for smooth integration.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement