COMBUF.H (8141B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\combuf.h_v 1.6 16 Oct 1995 16:46:00 JOE_BOSTIC $ */ 17 /*************************************************************************** 18 ** 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 ** 19 *************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : COMBUF.H * 24 * * 25 * Programmer : Bill Randolph * 26 * * 27 * Start Date : December 19, 1994 * 28 * * 29 * Last Update : April 1, 1995 [BR] * 30 * * 31 *-------------------------------------------------------------------------* 32 * * 33 * This class's job is to store outgoing messages & incoming messages, * 34 * and serves as a storage area for various flags for ACK & Retry logic. * 35 * * 36 * This class stores buffers in a non-sequenced order; it allows freeing * 37 * any entry, so the buffers can be kept clear, even if packets come in * 38 * out of order. * 39 * * 40 * The class also contains routines to maintain a cumulative response time * 41 * for this queue. It's up to the caller to call Add_Delay() whenever * 42 * it detects that an outgoing message has been ACK'd; this class adds * 43 * that delay into a computed average delay over the last few message * 44 * delays. * 45 * * 46 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 47 48 #ifndef COMBUF_H 49 #define COMBUF_H 50 51 52 /* 53 ********************************** Defines ********************************** 54 */ 55 /*--------------------------------------------------------------------------- 56 This is one output queue entry 57 ---------------------------------------------------------------------------*/ 58 typedef struct { 59 unsigned int IsActive : 1; // 1 = this entry is ready to be processed 60 unsigned int IsACK : 1; // 1 = ACK received for this packet 61 unsigned long FirstTime; // time this packet was first sent 62 unsigned long LastTime; // time this packet was last sent 63 unsigned long SendCount; // # of times this packet has been sent 64 int BufLen; // size of the packet stored in this entry 65 char *Buffer; // the data packet 66 } SendQueueType; 67 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 } ReceiveQueueType; 78 79 /* 80 ***************************** Class Declaration ***************************** 81 */ 82 class CommBufferClass 83 { 84 /* 85 ---------------------------- Public Interface ---------------------------- 86 */ 87 public: 88 /* 89 ....................... Constructor/Destructor ........................ 90 */ 91 CommBufferClass(int numsend, int numrecieve, int maxlen); 92 virtual ~CommBufferClass(); 93 void Init(void); 94 void Init_Send_Queue(void); 95 96 /* 97 ......................... Send Queue routines ......................... 98 */ 99 int Queue_Send(void *buf, int buflen); // add to Send queue 100 int UnQueue_Send(void *buf, int *buflen, int index); // remove from Send queue 101 int Num_Send(void) {return (SendCount);} // # entries in queue 102 int Max_Send(void) { return (MaxSend);} // max # send queue entries 103 SendQueueType * Get_Send(int index); // random access to queue 104 unsigned long Send_Total(void) {return (SendTotal);} 105 106 /* 107 ....................... Receive Queue routines ........................ 108 */ 109 int Queue_Receive(void *buf, int buflen); // add to Receive queue 110 int UnQueue_Receive(void *buf, int *buflen, int index); // remove from Receive queue 111 int Num_Receive(void) {return (ReceiveCount);} // # entries in queue 112 int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries 113 ReceiveQueueType * Get_Receive(int index); // random access to queue 114 unsigned long Receive_Total(void) {return (ReceiveTotal);} 115 116 /* 117 ....................... Response time routines ........................ 118 */ 119 void Add_Delay(unsigned long delay); // accumulates response time 120 unsigned long Avg_Response_Time(void); // gets mean response time 121 unsigned long Max_Response_Time(void); // gets max response time 122 void Reset_Response_Time(void); // resets computations 123 124 /* 125 ........................ Debug output routines ........................ 126 */ 127 void Configure_Debug(int offset, int size, char **names, int maxnames); 128 void Mono_Debug_Print(int refresh = 0); 129 void Mono_Debug_Print2(int refresh = 0); 130 131 /* 132 --------------------------- Private Interface ---------------------------- 133 */ 134 private: 135 /* 136 .......................... Limiting variables ......................... 137 */ 138 int MaxSend; // max # send queue entries 139 int MaxReceive; // max # receive queue entries 140 int MaxPacketSize; // max size of a packet, in bytes 141 142 /* 143 ....................... Response time variables ....................... 144 */ 145 unsigned long DelaySum; // sum of last 4 delay times 146 unsigned long NumDelay; // current # delay times summed 147 unsigned long MeanDelay; // current average delay time 148 unsigned long MaxDelay; // max delay ever for this queue 149 150 /* 151 ........................ Send Queue variables ......................... 152 */ 153 SendQueueType * SendQueue; // incoming packets 154 int SendCount; // # packets in the queue 155 unsigned long SendTotal; // total # added to send queue 156 int *SendIndex; // array of Send entry indices 157 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 /* 167 ......................... Debugging Variables ......................... 168 */ 169 int DebugOffset; // offset into app's packet for ID 170 int DebugSize; // size of app's ID 171 char **DebugNames; // ptr to array of app-specific names 172 int DebugMaxNames; // max # of names in array 173 }; 174 175 #endif 176 177 /**************************** end of combuf.h ******************************/ 178