home *** CD-ROM | disk | FTP | other *** search
- #include "..\EVENT\EVENTQ.HPP"
-
- // ------------------------------------------------------------------
- // File: EVENTQ.CPP
- // Path: ...\REHACK\EVENT\EVENTQ.CPP
- // Version: 0.01
- // Author: Pat Reilly
- // CIS Id: 71333,2764
- // Created On: 6/15/93
- // Modified On: 6/28/93
- // Description: EventQueue class for REHACK. See EVENTQ.TXT for
- // more details.
- // Tabs: 4
- // ------------------------------------------------------------------
-
- // static (local) functions used by EventQueue members. Inlined for speed.
- inline static void doInc(int& n)
- {
- n++;
- if(n >= StdEventQueueSize)
- n = 0;
- }
-
- inline static void doDec(int& n)
- {
- n--;
- if(n < 0)
- n = StdEventQueueSize-1;
- }
-
-
- EventQueue::EventQueue() :
- head(0), tail(0)
- {}
-
- void EventQueue::put(const Event& event)
- {
- if(!event.isNull())
- {
- // Special case - positional device moves should just update a
- // previous such event, as long as no other pos device events
- // have occurred between them.
- if(event.type == PosDeviceMove) // Should not be bit check!
- {
- int n = tail;
- while(n != head)
- {
- doDec(n);
- if(buffer[n].type & PosDevice)
- if(buffer[n].type == PosDeviceMove)
- {
- buffer[n].ticks = event.ticks;
- buffer[n].posDevice.location = event.posDevice.location;
- return;
- }
- else
- break;
- }
- }
-
- buffer[tail] = event;
- doInc(tail);
- if(head == tail) // overwrote the 'last' event
- doInc(head);
- }
- }
-
- bool EventQueue::get(Event& event)
- {
- event.clear();
-
- if(head == tail)
- return false;
- else
- {
- event = buffer[head];
- doInc(head);
- return true;
- }
- }
-
-