NetCommandList.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #pragma once
  24. #ifndef __NETCOMMANDLIST_H
  25. #define __NETCOMMANDLIST_H
  26. #include "Common/GameMemory.h"
  27. #include "GameNetwork/NetCommandRef.h"
  28. /**
  29. * The NetCommandList is a ordered linked list of NetCommandRef objects.
  30. * The list is ordered based on the command id, player id, and command type.
  31. * It is ordered in this way to aid in constructing the packets efficiently.
  32. * The list keeps track of the last message inserted in order to accommodate
  33. * adding commands in order more efficiently since that is whats going to be
  34. * done most of the time. If the new message doesn't go after the last message
  35. * inserted, then the list will be traversed linearly until the proper spot is
  36. * found. We can get away with this inefficient method since these occurances
  37. * will be rare. Also, the list is not expected to ever have more than 30 or so
  38. * commands on it at a time. Five commands would probably be a normal amount.
  39. */
  40. class NetCommandList : public MemoryPoolObject
  41. {
  42. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetCommandList, "NetCommandList")
  43. public:
  44. NetCommandList();
  45. //virtual ~NetCommandList();
  46. void init(); ///< Initialize the list
  47. void reset(); ///< Reset the list to the initial state.
  48. NetCommandRef * addMessage(NetCommandMsg *cmdMsg); ///< Add message to the list in its properly ordered place.
  49. Bool isEqualCommandMsg(NetCommandMsg *msg1, NetCommandMsg *msg2);
  50. NetCommandRef * getFirstMessage(); ///< Get the first message on the list.
  51. NetCommandRef * findMessage(NetCommandMsg *msg); ///< Find and return a reference to the given message if one exists.
  52. NetCommandRef * findMessage(UnsignedShort commandID, UnsignedByte playerID); ///< Find and return a reference to the
  53. ///< message given the player id and the command id.
  54. ///< This will only check against messages of types that require
  55. ///< a command id.
  56. void removeMessage(NetCommandRef *msg); ///< Remove the given message from the list.
  57. void appendList(NetCommandList *list); ///< Append the given list to the end of this list.
  58. Int length(); ///< Returns the number of nodes in this list. This is inefficient and is meant to be a debug tool.
  59. protected:
  60. NetCommandRef *m_first; ///< Head of the list.
  61. NetCommandRef *m_last; ///< Tail of the list.
  62. NetCommandRef *m_lastMessageInserted; ///< The last message that was inserted to this list.
  63. };
  64. #endif