CnC_Remastered_Collection

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

COMQUEUE.H (9042B)


      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&c0\vcs\code\comqueue.h_v   4.1   11 Apr 1996 18:26:02   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 : COMQUEUE.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 queue up outgoing messages & incoming messages, 	*
     34  * and serves as a storage area for various flags for ACK & Retry logic.	*
     35  * It allows the application to keep track of how many messages have 		*
     36  * passed through this queue, in & out, so packets can use this as a 		*
     37  * unique ID.  (If packets have a unique ID, the application can use this 	*
     38  * to detect re-sends.)																		*
     39  *                                                                         *
     40  * The queues act as FIFO buffers (First-In, First-Out).  The first entry	*
     41  * placed in a queue is the first one read from it, and so on.  The			*
     42  * controlling application must ensure it places the entries on the queue	*
     43  * in the order it wants to access them.												*
     44  *                                                                         *
     45  * The queue is implemented as an array of Queue Entries.  Index 0 is the	*
     46  * first element placed on the queue, and is the first retrieved.  Index	*
     47  * 1 is the next, and so on.  When Index 0 is retrieved, the next-available*
     48  * entry becomes Index 1.  The array is circular; when the end is reached,	*
     49  * the indices wrap around to the beginning.											*
     50  *                                                                         *
     51  * The class also contains routines to maintain a cumulative response time	*
     52  * for this queue.  It's up to the caller to call Add_Delay() whenever		*
     53  * it detects that an outgoing message has been ACK'd; this class adds		*
     54  * that delay into a computed average delay over the last few message 		*
     55  * delays.																						*
     56  *                                                                         *
     57  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     58 
     59 #ifndef COMQUEUE_H
     60 #define COMQUEUE_H
     61 
     62 
     63 
     64 /*---------------------------------------------------------------------------
     65 This is one output queue entry
     66 ---------------------------------------------------------------------------*/
     67 typedef struct {
     68 	unsigned int IsActive	: 1;	// 1 = this entry is ready to be processed
     69 	unsigned int IsACK		: 1;	// 1 = ACK received for this packet
     70 	unsigned long FirstTime;		// time this packet was first sent
     71 	unsigned long LastTime;			// time this packet was last sent
     72 	unsigned long SendCount;		// # of times this packet has been sent
     73 	int BufLen;							// size of the packet stored in this entry
     74 	char *Buffer;						// the data packet
     75 } SendQueueType;
     76 
     77 /*---------------------------------------------------------------------------
     78 This is one input queue entry
     79 ---------------------------------------------------------------------------*/
     80 typedef struct {
     81 	unsigned int IsActive	: 1;	// 1 = this entry is ready to be processed
     82 	unsigned int IsRead		: 1;	// 1 = caller has read this entry
     83 	unsigned int IsACK		: 1;	// 1 = ACK sent for this packet
     84 	int BufLen;							// size of the packet stored in this entry
     85 	char *Buffer;						// the data packet
     86 } ReceiveQueueType;
     87 
     88 /*
     89 ***************************** Class Declaration *****************************
     90 */
     91 class CommQueueClass
     92 {
     93 	/*
     94 	---------------------------- Public Interface ----------------------------
     95 	*/
     96 	public:
     97 		/*
     98 		....................... Constructor/Destructor ........................
     99 		*/
    100 		CommQueueClass(int numsend, int numrecieve, int maxlen);
    101 		virtual ~CommQueueClass();
    102 		void Init(void);
    103 
    104 		/*
    105 		......................... Send Queue routines .........................
    106 		*/
    107 		int Queue_Send(void *buf, int buflen);			// add to Send queue
    108 		int UnQueue_Send(void *buf, int *buflen);		// remove from Send queue
    109 		SendQueueType * Next_Send(void);					// ptr to next avail entry
    110 		int Num_Send(void) {return (SendCount);}		// # entries in queue
    111 		int Max_Send(void) { return (MaxSend);}		// max # send queue entries
    112 		SendQueueType * Get_Send(int index);			// random access to queue
    113 		unsigned long Send_Total(void) {return (SendTotal);}
    114 
    115 		/*
    116 		....................... Receive Queue routines ........................
    117 		*/
    118 		int Queue_Receive(void *buf, int buflen);		// add to Receive queue
    119 		int UnQueue_Receive(void *buf, int *buflen);	// remove from Receive queue
    120 		ReceiveQueueType * Next_Receive(void);			// ptr to next avail entry
    121 		int Num_Receive(void) {return (ReceiveCount);}	// # entries in queue
    122 		int Max_Receive(void) { return (MaxReceive); }	// max # recv queue entries
    123 		ReceiveQueueType * Get_Receive(int index);	// random access to queue
    124 		unsigned long Receive_Total(void) {return (ReceiveTotal);}
    125 
    126 		/*
    127 		....................... Response time routines ........................
    128 		*/
    129 		void Add_Delay(unsigned long delay);	// accumulates response time
    130 		unsigned long Avg_Response_Time(void);	// gets mean response time
    131 		unsigned long Max_Response_Time(void);	// gets max response time
    132 		void Reset_Response_Time(void);			// resets computations
    133 
    134 		/*
    135 		........................ Debug output routines ........................
    136 		*/
    137 		void Configure_Debug(int offset, int size, char **names, int maxnames);
    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 
    152 		/*
    153 		....................... Response time variables .......................
    154 		*/
    155 		unsigned long DelaySum;				// sum of last 4 delay times
    156 		unsigned long NumDelay;				// current # delay times summed
    157 		unsigned long MeanDelay;			// current average delay time
    158 		unsigned long MaxDelay;				// max delay ever for this queue
    159 
    160 		/*
    161 		........................ Send Queue variables .........................
    162 		*/
    163 		SendQueueType * SendQueue;			// incoming packets
    164 		int SendCount; 						// # packets in the queue
    165 		int SendNext;							// next entry read from queue
    166 		int SendEmpty;							// next empty spot in queue
    167 		unsigned long SendTotal;			// total # added to send queue
    168 
    169 		/*
    170 		....................... Receive Queue variables .......................
    171 		*/
    172 		ReceiveQueueType * ReceiveQueue;		// outgoing packets
    173 		int ReceiveCount;							// # packets in the queue
    174 		int ReceiveNext;							// next entry read from queue
    175 		int ReceiveEmpty;							// next empty spot in queue
    176 		unsigned long ReceiveTotal;			// total # added to receive queue
    177 
    178 		/*
    179 		......................... Debugging Variables .........................
    180 		*/
    181 		int DebugOffset;							// offset into app's packet for ID
    182 		int DebugSize;								// size of app's ID
    183 		char **DebugNames;						// ptr to array of app-specific names
    184 		int DebugMaxNames;						// max # of names in array
    185 };
    186 
    187 #endif
    188 
    189 /*************************** end of comqueue.h *****************************/
    190