CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

COMBUF.H (8518B)


      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: /CounterStrike/COMBUF.H 1     3/03/97 10:24a 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 	int ExtraLen;						// size of extra data
     67 	char *ExtraBuffer;				// extra data buffer
     68 } SendQueueType;
     69 
     70 /*---------------------------------------------------------------------------
     71 This is one input queue entry
     72 ---------------------------------------------------------------------------*/
     73 typedef struct {
     74 	unsigned int IsActive	: 1;	// 1 = this entry is ready to be processed
     75 	unsigned int IsRead		: 1;	// 1 = caller has read this entry
     76 	unsigned int IsACK		: 1;	// 1 = ACK sent for this packet
     77 	int BufLen;							// size of the packet stored in this entry
     78 	char *Buffer;						// the data packet
     79 	int ExtraLen;						// size of extra data
     80 	char *ExtraBuffer;				// extra data buffer
     81 } ReceiveQueueType;
     82 
     83 /*
     84 ***************************** Class Declaration *****************************
     85 */
     86 class CommBufferClass
     87 {
     88 	/*
     89 	---------------------------- Public Interface ----------------------------
     90 	*/
     91 	public:
     92 		/*
     93 		....................... Constructor/Destructor ........................
     94 		*/
     95 		CommBufferClass(int numsend, int numrecieve, int maxlen, 
     96 			int extralen = 0);
     97 		virtual ~CommBufferClass();
     98 		void Init(void);
     99 		void Init_Send_Queue(void);
    100 
    101 		/*
    102 		......................... Send Queue routines .........................
    103 		*/
    104 		int Queue_Send(void *buf, int buflen, void *extrabuf = NULL,
    105 			int extralen = 0);
    106 		int UnQueue_Send(void *buf, int *buflen, int index, 
    107 			void *extrabuf = NULL, int *extralen = NULL);
    108 		int Num_Send(void) {return (SendCount);}		// # entries in queue
    109 		int Max_Send(void) { return (MaxSend);}		// max # send queue entries
    110 		SendQueueType * Get_Send(int index);			// random access to queue
    111 		unsigned long Send_Total(void) {return (SendTotal);}
    112 
    113 		/*
    114 		....................... Receive Queue routines ........................
    115 		*/
    116 		int Queue_Receive(void *buf, int buflen, void *extrabuf = NULL,
    117 			int extralen = 0);
    118 		int UnQueue_Receive(void *buf, int *buflen, int index, 
    119 			void *extrabuf = NULL, int *extralen = NULL);
    120 		int Num_Receive(void) {return (ReceiveCount);}	// # entries in queue
    121 		int Max_Receive(void) { return (MaxReceive); }	// max # recv queue entries
    122 		ReceiveQueueType * Get_Receive(int index);	// random access to queue
    123 		unsigned long Receive_Total(void) {return (ReceiveTotal);}
    124 
    125 		/*
    126 		....................... Response time routines ........................
    127 		*/
    128 		void Add_Delay(unsigned long delay);	// accumulates response time
    129 		unsigned long Avg_Response_Time(void);	// gets mean response time
    130 		unsigned long Max_Response_Time(void);	// gets max response time
    131 		void Reset_Response_Time(void);			// resets computations
    132 
    133 		/*
    134 		........................ Debug output routines ........................
    135 		*/
    136 		void Configure_Debug(int type_offset, int type_size, char **names, 
    137 			int namestart, int namecount);
    138 		void Mono_Debug_Print(int refresh = 0);
    139 		void Mono_Debug_Print2(int refresh = 0);
    140 
    141 	/*
    142 	--------------------------- Private Interface ----------------------------
    143 	*/
    144 	private:
    145 		/*
    146 		.......................... Limiting variables .........................
    147 		*/
    148 		int MaxSend;							// max # send queue entries
    149 		int MaxReceive;						// max # receive queue entries
    150 		int MaxPacketSize;					// max size of a packet, in bytes
    151 		int MaxExtraSize;						// max size of extra bytes
    152 
    153 		/*
    154 		....................... Response time variables .......................
    155 		*/
    156 		unsigned long DelaySum;				// sum of last 4 delay times
    157 		unsigned long NumDelay;				// current # delay times summed
    158 		unsigned long MeanDelay;			// current average delay time
    159 		unsigned long MaxDelay;				// max delay ever for this queue
    160 
    161 		/*
    162 		........................ Send Queue variables .........................
    163 		*/
    164 		SendQueueType * SendQueue;			// incoming packets
    165 		int SendCount; 						// # packets in the queue
    166 		unsigned long SendTotal;			// total # added to send queue
    167 		int *SendIndex;						// array of Send entry indices
    168 
    169 		/*
    170 		....................... Receive Queue variables .......................
    171 		*/
    172 		ReceiveQueueType * ReceiveQueue;		// outgoing packets
    173 		int ReceiveCount;							// # packets in the queue
    174 		unsigned long ReceiveTotal;			// total # added to receive queue
    175 		int *ReceiveIndex;						// array of Receive entry indices
    176 
    177 		/*
    178 		......................... Debugging Variables .........................
    179 		*/
    180 		int DebugOffset;							// offset into app's packet for ID
    181 		int DebugSize;								// size of app's ID
    182 		char **DebugNames;						// ptr to array of app-specific names
    183 		int DebugNameStart;						// number of 1st ID
    184 		int DebugNameCount;						// # of names in array
    185 };
    186 
    187 #endif
    188 
    189 /**************************** end of combuf.h ******************************/
    190