Sunday 27 April 2014

Event Queue (brainstorming)

This will probably be my last post for a few weeks. The week after next the school component of my German internship continues. I've been living in Germany now for about 13 months now, and while I can speak and understand enough German to get by it's still quite a challenge for me. Learning content intended for native German speakers in a German school when I'm someone who's just been learning German for about a year is taxing. Although this is certainly a great way to get better at speaking a foreign language, it unfortunately also means that I have too little time and energy to progress much with my gaming projects.

Anyway, back to the topic at hand: the Event Queue. Early on in my gaming efforts I noticed this need for some kind of queue. Especially when thinking about AI and keeping all the actions that the player and AI make in sync. Up until now I'd been messily getting by without this system but my Wanderer game has grown to the extent that I really do need to implement a queue system. The need for it is so paramount that it will be the next thing I do.

Now what this queue would do is allow me to do is queue up a bunch of actions to happen per game loop cycle. This means that instead of pressing the left arrow key and having the key handler call a method that moves the character west for me, the key event handler simply adds a movement order to the event queue. The event queue has units subscribed to it, and the event queue finds the right unit and informs it that it has been instructed to move. The main advantage of this for me now is that I then don't have to consider time when moving many different objects and characters. They will all move at the same rate because the event queue will ensure that they move at the same rate by only updating them once per game cycle. It also means that I can pause the game by issuing a hold on this queue for a specified time period or indefinitely.

There are more benefits to using queuing system but I've yet to realise and consider those. If you wish to read further I recommend this article. It explains the queue system but also much more. I would also suggest looking at an observer pattern. My understanding of a queue in a game is that it's an observer pattern that updates with every cycle of the game's loop.

After I've developed a prototype I'll write about it here to let you know if it was successful and I'll discuss more about it.

No comments:

Post a Comment