Amulets & Armor
v1.02
Open Source Game
|
Queue of Packets and Commands for Networking. More...
Data Structures | |
struct | T_cmdQPacketStructTag |
struct | T_cmdQStruct |
struct | T_cmdQueueInfo |
Typedefs | |
typedef struct T_cmdQPacketStructTag | T_cmdQPacketStruct |
typedef T_cmdQActionRoutine * | T_comQActionList |
Enumerations | |
enum | E_packetCommandType { PACKET_COMMAND_TYPE_LOSSLESS, PACKET_COMMAND_TYPE_LOSSFUL } |
Functions | |
T_void | CmdQClearAllPorts (T_void) |
T_void | CmdQFinish (T_void) |
T_void | CmdQForcedReceive (T_packetEitherShortOrLong *p_packet) |
T_word16 | CmdQGetActivePortNum (T_void) |
T_void | CmdQInitialize (T_void) |
T_void | CmdQRegisterClientCallbacks (T_cmdQActionRoutine *callbacks) |
T_void | CmdQSendLongPacket (T_packetLong *p_packet, T_word16 retryTime, T_word32 extraData, T_cmdQPacketCallback p_callback) |
T_void | CmdQSendPacket (T_packetEitherShortOrLong *p_packet, T_word16 retryTime, T_word32 extraData, T_cmdQPacketCallback p_callback) |
T_void | CmdQSendShortPacket (T_packetShort *p_packet, T_word16 retryTime, T_word32 extraData, T_cmdQPacketCallback p_callback) |
T_void | CmdQSetActivePortNum (T_word16 num) |
T_void | CmdQUpdateAllReceives (T_void) |
T_void | CmdQUpdateAllSends (T_void) |
T_void | ICmdQDiscardPacket (T_byte8 commandNum) |
T_void | ICmdQSendPacket (T_packetEitherShortOrLong *p_packet, T_word16 retryTime, T_word32 extraData, T_cmdQPacketCallback p_callback) |
T_void | ICmdQUpdateSendForPort (T_void) |
Variables | |
T_word32 | G_packetsAlloc = 0 |
T_word32 | G_packetsFree = 0 |
Queue of Packets and Commands for Networking.
The CmdQueue (or "Command Queue") is used to store up requests from the client to the server. As the commands are sent, an ACK packet must be received before the next one is processed. BUT, this isn't a linear list of commands, but a list per packet type allowing most commands to be handled in a mostly parallel format. Most of this is code has been replaced by the CSYNCPCK synchronized communication code and the rest is incorrectly implemented for a peer to peer network instead of a client/server network. MORE WORK GOES HERE!
typedef struct T_cmdQPacketStructTag T_cmdQPacketStruct |
typedef T_cmdQActionRoutine* T_comQActionList |
enum E_packetCommandType |
CmdQClearAllPorts goes through each port and clears out any packets that are waiting to be sent or are incoming. ACK packets are left alone.
NOTE: Make sure that this routine is only called when all communications are finalized.
CmdQFinish unallocates any memory or structures that are no longer need by the CmdQ module.
T_void CmdQForcedReceive | ( | T_packetEitherShortOrLong * | p_packet) |
CmdQForcedReceive makes the command queue act like it just received the packet from the inport. All processing is the same.
NOTE: NEVER PASS AN ACK PACKET TO THIS ROUTINE. It does not properly work with them. Be sure to make a call to CmdQSetActivePortNum or else this routine will be unpredictable.
p_packet | – Packet being forced in |
CmdQGetActivePortNum returns the number of the active port being used.
CmdQInitialize clears out all the variables that are necessary for the CmdQ module.
NOTE: This routine needs to be called AFTER all ports are opened.
T_void CmdQRegisterClientCallbacks | ( | T_cmdQActionRoutine * | callbacks) |
These functions each take a pointer to an array of function pointers, with PACKET_COMMAND_MAX entries. ..ServerCallbacks sets this pointer as the list of server packet callbacks, and ..ClientCallbacks sets this as the list of client packet callbacks.
T_void CmdQSendLongPacket | ( | T_packetLong * | p_packet, |
T_word16 | retryTime, | ||
T_word32 | extraData, | ||
T_cmdQPacketCallback | p_callback | ||
) |
CmdQSendLongPacket prepares a long packet for sending and sends it over to ICmdQSendPacket for processing.
p_packet | – Packet to send |
retryTime | – How long to wait for acknowledgement before trying to send again. |
extraData | – Extra data for the callback routine. |
p_callback | – Routine to be called when either the packet is lost or sent. |
T_void CmdQSendPacket | ( | T_packetEitherShortOrLong * | p_packet, |
T_word16 | retryTime, | ||
T_word32 | extraData, | ||
T_cmdQPacketCallback | p_callback | ||
) |
CmdQSendPacket sets up a short or long packet for sending (and does so by calling CmdQSendShortPacket or CmdQSendLongPacket).
NOTE: The packetLength field in the packet's header field MUST be set to either short or long.
p_packet | – Packet to send |
retryTime | – How long to wait for acknowledgement before trying to send again. |
extraData | – Extra data for the callback routine. |
p_callback | – Routine to be called when either the packet is lost or sent. |
T_void CmdQSendShortPacket | ( | T_packetShort * | p_packet, |
T_word16 | retryTime, | ||
T_word32 | extraData, | ||
T_cmdQPacketCallback | p_callback | ||
) |
CmdQSendShortPacket prepares a short packet for sending and sends it over to ICmdQSendPacket for processing.
p_packet | – Packet to send |
retryTime | – How long to wait for acknowledgement before trying to send again. |
extraData | – Extra data for the callback routine. |
p_callback | – Routine to be called when either the packet is lost or sent. |
CmdQSetActivePortNum sets up the Cmd Queue module for the given port (and makes the given port the active communications port).
num | – Number of port to make active. |
CmdQUpdateAllReceives goes through all the ports looking for data to take in. All data that is received is then processed and the appropriate action for the command is called.
If this is a lossful packet, always call the
callback routine.
CmdQUpdateAllSends goes through all the ports and determines what data needs to be sent and what should wait.
ICmdQDiscardPacket removes a packet from the given command queue in the current command queue list.
commandNum | – Command in command list to do a packet discard on. |
T_void ICmdQSendPacket | ( | T_packetEitherShortOrLong * | p_packet, |
T_word16 | retryTime, | ||
T_word32 | extraData, | ||
T_cmdQPacketCallback | p_callback | ||
) |
ICmdQSendPacket does all the work of placing a packet in one of the active command queues and prepares it for sending out.
p_packet | – Packet to send |
retryTime | – How long to wait for acknowledgement before trying to send again. |
extraData | – Extra data for the callback routine. |
p_callback | – Routine to be called when either the packet is lost or sent. |
Give the packet a unique packet ID
ICmdQUpdateSendForPort updates the sending of all packets for this single port (the currently active port). Packets that need to be transferred are sent. Those that don't, don't. The amount of packets sent depends on the baud rate and the last time this routine was called for this port.
(It's always time to send an ACK.)
– IFF the packet is lossless...
Now, if we aren't checking the ACK queue, we need
to break after the first send. If we are, we
want to dump everything in the queue.
T_word32 G_packetsAlloc = 0 |
T_word32 G_packetsFree = 0 |