home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / event / eventq.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  1.6 KB  |  82 lines

  1. #include "..\EVENT\EVENTQ.HPP"
  2.  
  3. // ------------------------------------------------------------------
  4. // File:        EVENTQ.CPP
  5. // Path:        ...\REHACK\EVENT\EVENTQ.CPP
  6. // Version:        0.01
  7. // Author:        Pat Reilly
  8. // CIS Id:        71333,2764
  9. // Created On:    6/15/93
  10. // Modified On:    6/28/93
  11. // Description:    EventQueue class for REHACK. See EVENTQ.TXT for
  12. //                more details.
  13. // Tabs:        4
  14. // ------------------------------------------------------------------
  15.  
  16. // static (local) functions used by EventQueue members. Inlined for speed.
  17. inline static void doInc(int& n)
  18. {
  19.     n++;
  20.     if(n >= StdEventQueueSize)
  21.         n = 0;
  22. }
  23.  
  24. inline static void doDec(int& n)
  25. {
  26.     n--;
  27.     if(n < 0)
  28.         n = StdEventQueueSize-1;
  29. }
  30.  
  31.  
  32. EventQueue::EventQueue() :
  33.     head(0), tail(0)
  34. {}
  35.  
  36. void EventQueue::put(const Event& event)
  37. {
  38.     if(!event.isNull())
  39.         {
  40.         // Special case - positional device moves should just update a
  41.         //    previous such event, as long as no other pos device events
  42.         //    have occurred between them.
  43.         if(event.type == PosDeviceMove)    // Should not be bit check!
  44.             {
  45.             int n = tail;
  46.             while(n != head)
  47.                 {
  48.                 doDec(n);
  49.                 if(buffer[n].type & PosDevice)
  50.                     if(buffer[n].type == PosDeviceMove)
  51.                         {
  52.                         buffer[n].ticks = event.ticks;
  53.                         buffer[n].posDevice.location = event.posDevice.location;
  54.                         return;
  55.                         }
  56.                     else
  57.                         break;
  58.                 }
  59.             }
  60.  
  61.         buffer[tail] = event;
  62.         doInc(tail);
  63.         if(head == tail)    // overwrote the 'last' event
  64.             doInc(head);
  65.         }
  66. }
  67.  
  68. bool EventQueue::get(Event& event)
  69. {
  70.     event.clear();
  71.  
  72.     if(head == tail)
  73.         return false;
  74.     else
  75.         {
  76.         event = buffer[head];
  77.         doInc(head);
  78.         return true;
  79.         }
  80. }
  81.  
  82.