Game Development Reference
In-Depth Information
Let's test out the preceding pseudocode. The midpoint between 32,677 and 3,000
is ~17,835, so a vector with that length should yield a percent of ~50%. One such
vector with that length would be x = 12,611 and y = 12,611. Because the length of
17,835 is greater than the dead zone of 3,000, the else case will be utilized and
the following calculations will occur:
Aftertheanalogfiltering isapplied,theresultant vectorhasalengthof~16,404.In
other words, a value that's 50% between 3,000 and 32,677 was adjusted to be the
value 50% between 0 and 32,677, which allows us to get the full range of move-
ment speeds from 0% all the way to 100%.
Event-Based Input Systems
Imagine you are driving a kid to an amusement park. The kid is very excited, so
every minute she asks, “Are we there yet?” She keeps asking this over and over
againuntilyoufinallyarrive,atwhichpointtheanswertoherquestionisyes.Now
imagine that instead of one kid, you're driving a car full of kids. Every single kid
is interested in going to the amusement park, so each of them repeatedly asks the
same question. Not only is this annoying for the driver, it's also a waste of energy
on the part of the kids.
This scenario is essentially a polling system in that each kid is polling for the res-
ult of the query. For an input system, a polling approach would be one where any
code interested in whether the spacebar was “just pressed” would have to manu-
ally check. Over and over again on every single frame, and in multiple locations,
GetKeyState would be called on K_SPACE . This not only leads to a duplica-
tion of effort, but it could also introduce bugs if the state of the keyboard changes
in the middle of the frame.
If we return to the amusement park analogy, imagine once again you have that car
full of kids. Rather than having the kids poll over and over again, you can employ
an event-based or push system. In an event-based system, the kids “register” to
an event that they care about (in this case, arrival at the amusement park) and are
Search WWH ::




Custom Search