MsgQueue.inl
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:2k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   MsgQueue.inl
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Contents: Inline functions implementations.
  11. *                                                                             
  12. *   Authors: Eran Yariv - 28484475                                           
  13. *            Moshe Zur  - 24070856                                           
  14. *                                                                            
  15. *                                                                            
  16. *   Date: 23/09/98                                                           
  17. *                                                                            
  18. ******************************************************************************/
  19. inline BOOL
  20. CMsgQueue::Enqueue (CMessage *pMsg, BOOL bSorted)
  21. {
  22.     ASSERT (pMsg->GetType() < CMessage::NUM_MSGS);
  23.     return bSorted ? CQueue::Enqueue(pMsg, pMsg->GetTime()) : CQueue::Enqueue(pMsg);
  24. }
  25.     
  26. inline BOOL 
  27. CMsgQueue::Enqueue (CMessage::MessageType MsgType, CMessage::MessageData& MsgUnion, GameMessageType t)
  28. {
  29.     ASSERT (MsgType < CMessage::NUM_MSGS);
  30.     CMessage *pMsg = new CMessage(MsgType, MsgUnion, t);
  31.     ASSERT(pMsg);
  32.     if (!pMsg)
  33.     {
  34.         AfxMessageBox(IDS_OUTOFMEMORY_ERR, MB_ICONSTOP | MB_OK, 0);
  35.         abort();
  36.     }
  37.     return Enqueue(pMsg);
  38. }
  39. inline BOOL 
  40. CMsgQueue::Dequeue (CMessage& Msg)
  41. {
  42.     CMessage *pDeadMsg;
  43.     if (CQueue::Dequeue((CObject*&)pDeadMsg)) {
  44.         // Copy message:
  45.         Msg.SetType(pDeadMsg->GetType());
  46.         ASSERT (Msg.GetType() < CMessage::NUM_MSGS);
  47.         Msg.SetTime(pDeadMsg->GetTime()); 
  48.         memcpy (&Msg.m_UnionData, &(pDeadMsg->m_UnionData), sizeof(CMessage::MessageData));
  49.         // It's OK now to free the dead message:
  50.         delete pDeadMsg;
  51.         return TRUE;
  52.     }
  53.     return FALSE;
  54. }