Why is there a need for 2 Event Queues?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Why is there a need for 2 Event Queues?

      I am reading the Game Event Management chapter which is very well written.

      Regarding the event queue, why is there a need for two queues?
      Does having a single event queue not work?

      There is a short explanation on how there could be an infinite loop when 2 events queue up each other. I am not sure what that means. ?(
    • int m_activeQueue; // index of actively processing queue; events
      // enque to the opposing queue

      There are two event queues here so that delegate
      methods can safely queue up new events. You can imagine an infinite loop where
      two events queue up each other. Without two queues, the program would hang in
      an infinite loop and never break out of the event VTickVUpdate() function. The
      m_activeQueue member is the index of the currently active queue.

      As stated, they enqueue new events in a new queue so it doesn't loop forever. I would assume it also helps multihreading. Think of double buffering.
    • Not sure if that helps but this is also stated in the book that older events could never be processed (Or too late) if new events keep coming in one queue since queue is LIFO.
      And yes it is also stated in the book to think like double buffering to speed up the processing.

      So yes one queue would be enough for a simple program but in the context of a game events coming at a fast rate, you will prevent scenarios described in the book.