Using Input Queues
Earlier, the chapter discussed how massive amounts of user input can freeze a game and cause it to stall. You can address this possibility with the very handy InputObject class. Basically, you’re trying to limit the strain that is put on your main thread when input events happen. Recall that Figure 3-2 showed how you hold input events before responding to them. This is exactly what you do here. Instead of waiting to lock up the entire thread, you do the majority of the work in the background.
This system was originally introduced to me by Robert Green, and it’s so efficient and simple that I have used it ever since. (You can read Robert’s blog about Android development and other musings at www.rbgrn.net/.) An ArrayBlockingQueue ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access