Advertisement Jump to content
Sign in to follow this  
fir

can I go without events?

This topic is 1768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i wonder if in winapi win32 game programming I can go without events

for keyboard and for mouse - If i would like to ask for keyboard and mouse state in each frame and totally ignore events?

 

- are there easy ways to read mouse position in other way than by event?

- are some things worse when i would use each frame checking than events servicing?

 

Share this post


Link to post
Share on other sites
Advertisement

In Khan Academy's Javascript programs there are native "mouseX" and "mouseY" variables that, when used, already give you the actual mouse position. I don't know the API you've mentioned, but It's not common to have these variables by default. Events are the main way to deal with it. Nevertheless, take a good look at the API and search for it.

Edited by EricsonWillians

Share this post


Link to post
Share on other sites
I use GetAsyncKeyState on my update loop directly. If you implement this with events you normally end up just reimplementing an array of bools for each key state anyway so seems pointless.

The problems arise when it comes to abstracting input away from being directly tied to a given device. Event based approach can be easier to decouple.

Share this post


Link to post
Share on other sites

You will at least have to handle the events for the window, or you will be unable to move or close it.

 

Other than that, you can do completely without events, but it is a really, really, really bad idea. User uses a different keyboard (different, as in language) and you're screwed. User clicks very fast, and you miss the click. User does <insert one of 1000 other things> and you're screwed.

 

Events work, and they work well. Plus, they work with different languages, with different devices, mappings, resolutions, different anything. And they don't burn CPU time polling.

 

One good example where polling keyboard state results in a total fuckup is when e.g. US American programmers assume that "/" is a proper key and uses it for some interactive control, and your end user has a German keyboard. With events, it is a nuisance since you must hold down shift before pressing the key (holding it works, at least), but if the program samples the keyboard state, the program is totally unusable (there simply isn't a way to press any combination of keys that works). Similar for []{}\.

Edited by samoth

Share this post


Link to post
Share on other sites

It is certainly much easier to handle input with events. Events are built into the library and will make your programming journey slightly easier. The only thing you need to handle yourself is how to apply the correct logic given the built-in event functionality.

Edited by warnexus

Share this post


Link to post
Share on other sites

You will at least have to handle the events for the window, or you will be unable to move or close it.

 

Other than that, you can do completely without events, but it is a really, really, really bad idea. User uses a different keyboard (different, as in language) and you're screwed. User clicks very fast, and you miss the click. User does <insert one of 1000 other things> and you're screwed.

 

Events work, and they work well. Plus, they work with different languages, with different devices, mappings, resolutions, different anything. And they don't burn CPU time polling.

 

especially interesting is this 'user clicks to fast' - keyboard and mouse, Do mouse programmed by polling can fail in some cases? Or in general it would work ok?

Share this post


Link to post
Share on other sites

Do mouse programmed by polling can fail in some cases? Or in general it would work ok?
If you have a reasonable frame rate, it will in general (most of the time) work. But what if your frame rate isn't so great or you have a bit of lag for some reason? If the state that you are looking for (say, button down) isn't there the very moment you look, you will miss it.

 

The nature of polling is "right now, check what the state is" whereas the nature of events is "whenever user clicks, you get exactly 1 event, and you can consume it any time you want". With polling, it is in principle always possible to miss something. With events, it just isn't possible (unless the operating system is FUBAR).

Share this post


Link to post
Share on other sites

 

Do mouse programmed by polling can fail in some cases? Or in general it would work ok?
If you have a reasonable frame rate, it will in general (most of the time) work. But what if your frame rate isn't so great or you have a bit of lag for some reason? If the state that you are looking for (say, button down) isn't there the very moment you look, you will miss it.

 

The nature of polling is "right now, check what the state is" whereas the nature of events is "whenever user clicks, you get exactly 1 event, and you can consume it any time you want". With polling, it is in principle always possible to miss something. With events, it just isn't possible (unless the operating system is FUBAR).

 

 

so say i got a 5 seconds lag in my app and user types the tekst

(say 30 keystrokes) will it be queued in windows and then flushed as a set of 30 keydowns ?

 

it was always unclear to me 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!