COMBUF.H 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/COMBUF.H 1 3/03/97 10:24a Joe_bostic $ */
  19. /***************************************************************************
  20. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : COMBUF.H *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : December 19, 1994 *
  30. * *
  31. * Last Update : April 1, 1995 [BR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * *
  35. * This class's job is to store outgoing messages & incoming messages, *
  36. * and serves as a storage area for various flags for ACK & Retry logic. *
  37. * *
  38. * This class stores buffers in a non-sequenced order; it allows freeing *
  39. * any entry, so the buffers can be kept clear, even if packets come in *
  40. * out of order. *
  41. * *
  42. * The class also contains routines to maintain a cumulative response time *
  43. * for this queue. It's up to the caller to call Add_Delay() whenever *
  44. * it detects that an outgoing message has been ACK'd; this class adds *
  45. * that delay into a computed average delay over the last few message *
  46. * delays. *
  47. * *
  48. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  49. #ifndef COMBUF_H
  50. #define COMBUF_H
  51. /*
  52. ********************************** Defines **********************************
  53. */
  54. /*---------------------------------------------------------------------------
  55. This is one output queue entry
  56. ---------------------------------------------------------------------------*/
  57. typedef struct {
  58. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  59. unsigned int IsACK : 1; // 1 = ACK received for this packet
  60. unsigned long FirstTime; // time this packet was first sent
  61. unsigned long LastTime; // time this packet was last sent
  62. unsigned long SendCount; // # of times this packet has been sent
  63. int BufLen; // size of the packet stored in this entry
  64. char *Buffer; // the data packet
  65. int ExtraLen; // size of extra data
  66. char *ExtraBuffer; // extra data buffer
  67. } SendQueueType;
  68. /*---------------------------------------------------------------------------
  69. This is one input queue entry
  70. ---------------------------------------------------------------------------*/
  71. typedef struct {
  72. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  73. unsigned int IsRead : 1; // 1 = caller has read this entry
  74. unsigned int IsACK : 1; // 1 = ACK sent for this packet
  75. int BufLen; // size of the packet stored in this entry
  76. char *Buffer; // the data packet
  77. int ExtraLen; // size of extra data
  78. char *ExtraBuffer; // extra data buffer
  79. } ReceiveQueueType;
  80. /*
  81. ***************************** Class Declaration *****************************
  82. */
  83. class CommBufferClass
  84. {
  85. /*
  86. ---------------------------- Public Interface ----------------------------
  87. */
  88. public:
  89. /*
  90. ....................... Constructor/Destructor ........................
  91. */
  92. CommBufferClass(int numsend, int numrecieve, int maxlen,
  93. int extralen = 0);
  94. virtual ~CommBufferClass();
  95. void Init(void);
  96. void Init_Send_Queue(void);
  97. /*
  98. ......................... Send Queue routines .........................
  99. */
  100. int Queue_Send(void *buf, int buflen, void *extrabuf = NULL,
  101. int extralen = 0);
  102. int UnQueue_Send(void *buf, int *buflen, int index,
  103. void *extrabuf = NULL, int *extralen = NULL);
  104. int Num_Send(void) {return (SendCount);} // # entries in queue
  105. int Max_Send(void) { return (MaxSend);} // max # send queue entries
  106. SendQueueType * Get_Send(int index); // random access to queue
  107. unsigned long Send_Total(void) {return (SendTotal);}
  108. /*
  109. ....................... Receive Queue routines ........................
  110. */
  111. int Queue_Receive(void *buf, int buflen, void *extrabuf = NULL,
  112. int extralen = 0);
  113. int UnQueue_Receive(void *buf, int *buflen, int index,
  114. void *extrabuf = NULL, int *extralen = NULL);
  115. int Num_Receive(void) {return (ReceiveCount);} // # entries in queue
  116. int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries
  117. ReceiveQueueType * Get_Receive(int index); // random access to queue
  118. unsigned long Receive_Total(void) {return (ReceiveTotal);}
  119. /*
  120. ....................... Response time routines ........................
  121. */
  122. void Add_Delay(unsigned long delay); // accumulates response time
  123. unsigned long Avg_Response_Time(void); // gets mean response time
  124. unsigned long Max_Response_Time(void); // gets max response time
  125. void Reset_Response_Time(void); // resets computations
  126. /*
  127. ........................ Debug output routines ........................
  128. */
  129. void Configure_Debug(int type_offset, int type_size, char **names,
  130. int namestart, int namecount);
  131. void Mono_Debug_Print(int refresh = 0);
  132. void Mono_Debug_Print2(int refresh = 0);
  133. /*
  134. --------------------------- Private Interface ----------------------------
  135. */
  136. private:
  137. /*
  138. .......................... Limiting variables .........................
  139. */
  140. int MaxSend; // max # send queue entries
  141. int MaxReceive; // max # receive queue entries
  142. int MaxPacketSize; // max size of a packet, in bytes
  143. int MaxExtraSize; // max size of extra bytes
  144. /*
  145. ....................... Response time variables .......................
  146. */
  147. unsigned long DelaySum; // sum of last 4 delay times
  148. unsigned long NumDelay; // current # delay times summed
  149. unsigned long MeanDelay; // current average delay time
  150. unsigned long MaxDelay; // max delay ever for this queue
  151. /*
  152. ........................ Send Queue variables .........................
  153. */
  154. SendQueueType * SendQueue; // incoming packets
  155. int SendCount; // # packets in the queue
  156. unsigned long SendTotal; // total # added to send queue
  157. int *SendIndex; // array of Send entry indices
  158. /*
  159. ....................... Receive Queue variables .......................
  160. */
  161. ReceiveQueueType * ReceiveQueue; // outgoing packets
  162. int ReceiveCount; // # packets in the queue
  163. unsigned long ReceiveTotal; // total # added to receive queue
  164. int *ReceiveIndex; // array of Receive entry indices
  165. /*
  166. ......................... Debugging Variables .........................
  167. */
  168. int DebugOffset; // offset into app's packet for ID
  169. int DebugSize; // size of app's ID
  170. char **DebugNames; // ptr to array of app-specific names
  171. int DebugNameStart; // number of 1st ID
  172. int DebugNameCount; // # of names in array
  173. };
  174. #endif
  175. /**************************** end of combuf.h ******************************/