From 6f00ce0054079ed9d511eb61e3e04bcfa4fec870 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 12 Oct 2007 05:49:51 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1345 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/enet/callbacks.c | 1 - source/enet/configure | 20 +++++++------- source/enet/configure.in | 4 +-- source/enet/host.c | 4 ++- source/enet/include/enet/enet.h | 9 +++++-- source/enet/peer.c | 40 +++++++++++++++------------- source/enet/protocol.c | 47 +++++++++++++++++++++++++++------ 7 files changed, 83 insertions(+), 42 deletions(-) diff --git a/source/enet/callbacks.c b/source/enet/callbacks.c index 0bed048b..7f960af3 100644 --- a/source/enet/callbacks.c +++ b/source/enet/callbacks.c @@ -5,7 +5,6 @@ #define ENET_BUILDING_LIB 1 #include "enet/enet.h" - static ENetCallbacks callbacks = { malloc, free, rand }; int diff --git a/source/enet/configure b/source/enet/configure index 424f9e27..df9bf91b 100755 --- a/source/enet/configure +++ b/source/enet/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for libenet 10-02-2007. +# Generated by GNU Autoconf 2.61 for libenet 10-11-2007. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='libenet' PACKAGE_TARNAME='libenet' -PACKAGE_VERSION='10-02-2007' -PACKAGE_STRING='libenet 10-02-2007' +PACKAGE_VERSION='10-11-2007' +PACKAGE_STRING='libenet 10-11-2007' PACKAGE_BUGREPORT='' ac_subst_vars='SHELL @@ -1168,7 +1168,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libenet 10-02-2007 to adapt to many kinds of systems. +\`configure' configures libenet 10-11-2007 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1234,7 +1234,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libenet 10-02-2007:";; + short | recursive ) echo "Configuration of libenet 10-11-2007:";; esac cat <<\_ACEOF @@ -1318,7 +1318,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libenet configure 10-02-2007 +libenet configure 10-11-2007 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1332,7 +1332,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libenet $as_me 10-02-2007, which was +It was created by libenet $as_me 10-11-2007, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -2002,7 +2002,7 @@ fi # Define the identity of the package. PACKAGE=libenet.a - VERSION=10-02-2007 + VERSION=10-11-2007 cat >>confdefs.h <<_ACEOF @@ -4929,7 +4929,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libenet $as_me 10-02-2007, which was +This file was extended by libenet $as_me 10-11-2007, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4976,7 +4976,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -libenet config.status 10-02-2007 +libenet config.status 10-11-2007 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/source/enet/configure.in b/source/enet/configure.in index 8c56af63..81b8610d 100755 --- a/source/enet/configure.in +++ b/source/enet/configure.in @@ -1,5 +1,5 @@ -AC_INIT(libenet, 10-02-2007) -AM_INIT_AUTOMAKE(libenet.a, 10-02-2007) +AC_INIT(libenet, 10-11-2007) +AM_INIT_AUTOMAKE(libenet.a, 10-11-2007) AC_PROG_CC AC_PROG_RANLIB diff --git a/source/enet/host.c b/source/enet/host.c index 603ae323..9bab1a8c 100755 --- a/source/enet/host.c +++ b/source/enet/host.c @@ -165,10 +165,12 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC channel -> outgoingReliableSequenceNumber = 0; channel -> outgoingUnreliableSequenceNumber = 0; channel -> incomingReliableSequenceNumber = 0; - channel -> incomingUnreliableSequenceNumber = 0; enet_list_clear (& channel -> incomingReliableCommands); enet_list_clear (& channel -> incomingUnreliableCommands); + + channel -> usedReliableWindows = 0; + memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); } command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; diff --git a/source/enet/include/enet/enet.h b/source/enet/include/enet/enet.h index 2ba83408..d3bced86 100755 --- a/source/enet/include/enet/enet.h +++ b/source/enet/include/enet/enet.h @@ -143,6 +143,7 @@ typedef struct _ENetOutgoingCommand enet_uint32 roundTripTimeoutLimit; enet_uint32 fragmentOffset; enet_uint16 fragmentLength; + enet_uint16 sendAttempts; ENetProtocol command; ENetPacket * packet; } ENetOutgoingCommand; @@ -198,15 +199,19 @@ enum ENET_PEER_TIMEOUT_MINIMUM = 5000, ENET_PEER_TIMEOUT_MAXIMUM = 30000, ENET_PEER_PING_INTERVAL = 500, - ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 4 * 32 + ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 4 * 32, + ENET_PEER_RELIABLE_WINDOWS = 16, + ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000, + ENET_PEER_FREE_RELIABLE_WINDOWS = 8 }; typedef struct _ENetChannel { enet_uint16 outgoingReliableSequenceNumber; enet_uint16 outgoingUnreliableSequenceNumber; + enet_uint16 usedReliableWindows; + enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS]; enet_uint16 incomingReliableSequenceNumber; - enet_uint16 incomingUnreliableSequenceNumber; ENetList incomingReliableCommands; ENetList incomingUnreliableCommands; } ENetChannel; diff --git a/source/enet/peer.c b/source/enet/peer.c index 50df7740..3bd3ba63 100755 --- a/source/enet/peer.c +++ b/source/enet/peer.c @@ -145,6 +145,9 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet) command.header.channelID = channelID; + if (! (packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED)) && channel -> outgoingUnreliableSequenceNumber >= 0xFFFF) + packet -> flags |= ENET_PACKET_FLAG_RELIABLE; + if (packet -> flags & ENET_PACKET_FLAG_RELIABLE) { command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; @@ -189,8 +192,6 @@ enet_peer_receive (ENetPeer * peer, enet_uint8 channelID) { if (incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber) incomingCommand = NULL; - else - channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber; } } @@ -505,7 +506,8 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) { ++ channel -> outgoingReliableSequenceNumber; - + channel -> outgoingUnreliableSequenceNumber = 0; + outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber; outgoingCommand -> unreliableSequenceNumber = 0; } @@ -525,6 +527,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber; } + outgoingCommand -> sendAttempts = 0; outgoingCommand -> sentTime = 0; outgoingCommand -> roundTripTimeout = 0; outgoingCommand -> roundTripTimeoutLimit = 0; @@ -550,6 +553,7 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, { ENetChannel * channel = & peer -> channels [command -> header.channelID]; enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber; + enet_uint16 reliableWindow, currentWindow; ENetIncomingCommand * incomingCommand; ENetListIterator currentCommand; @@ -559,12 +563,16 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, if ((command -> header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED) { reliableSequenceNumber = command -> header.reliableSequenceNumber; + reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; + currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - if (channel -> incomingReliableSequenceNumber >= 0xF000 && reliableSequenceNumber < 0x1000) - reliableSequenceNumber += 0x10000; - - if (reliableSequenceNumber < channel -> incomingReliableSequenceNumber || - (channel -> incomingReliableSequenceNumber < 0x1000 && (reliableSequenceNumber & 0xFFFF) >= 0xF000)) + if (reliableSequenceNumber < channel -> incomingReliableSequenceNumber) + { + reliableWindow += ENET_PEER_RELIABLE_WINDOWS; + reliableSequenceNumber += 0x10000; + } + + if (reliableWindow < currentWindow || reliableWindow >= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS) goto freePacket; } @@ -581,7 +589,7 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, { incomingCommand = (ENetIncomingCommand *) currentCommand; - if (reliableSequenceNumber >= 0x10000 && incomingCommand -> reliableSequenceNumber < 0xF000) + if (reliableSequenceNumber >= 0x10000 && incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber) reliableSequenceNumber -= 0x10000; if (incomingCommand -> reliableSequenceNumber <= reliableSequenceNumber) @@ -597,13 +605,6 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE: unreliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> sendUnreliable.unreliableSequenceNumber); - if (channel -> incomingUnreliableSequenceNumber >= 0xF000 && unreliableSequenceNumber < 0x1000) - unreliableSequenceNumber += 0x10000; - - if (unreliableSequenceNumber <= channel -> incomingUnreliableSequenceNumber || - (channel -> incomingUnreliableSequenceNumber < 0x1000 && (unreliableSequenceNumber & 0xFFFF) >= 0xF000)) - goto freePacket; - for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingUnreliableCommands)); currentCommand != enet_list_end (& channel -> incomingUnreliableCommands); currentCommand = enet_list_previous (currentCommand)) @@ -613,8 +614,11 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE) continue; - if (unreliableSequenceNumber >= 0x10000 && incomingCommand -> unreliableSequenceNumber < 0xF000) - unreliableSequenceNumber -= 0x10000; + if (reliableSequenceNumber >= 0x10000 && incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber) + reliableSequenceNumber -= 0x10000; + + if (incomingCommand -> reliableSequenceNumber < reliableSequenceNumber) + break; if (incomingCommand -> unreliableSequenceNumber <= unreliableSequenceNumber) { diff --git a/source/enet/protocol.c b/source/enet/protocol.c index 03c9d3a5..e4262430 100755 --- a/source/enet/protocol.c +++ b/source/enet/protocol.c @@ -163,6 +163,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl ENetOutgoingCommand * outgoingCommand; ENetListIterator currentCommand; ENetProtocolCommand commandNumber; + ENetChannel * channel; + enet_uint16 reliableWindow; for (currentCommand = enet_list_begin (& peer -> sentReliableCommands); currentCommand != enet_list_end (& peer -> sentReliableCommands); @@ -178,8 +180,17 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl if (currentCommand == enet_list_end (& peer -> sentReliableCommands)) return ENET_PROTOCOL_COMMAND_NONE; - commandNumber = outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK; + reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; + channel = & peer -> channels [channelID]; + if (channel -> reliableWindows [reliableWindow] > 0) + { + -- channel -> reliableWindows [reliableWindow]; + if (! channel -> reliableWindows [reliableWindow]) + channel -> usedReliableWindows &= ~ (1 << reliableWindow); + } + commandNumber = outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK; + enet_list_remove (& outgoingCommand -> outgoingCommandList); if (outgoingCommand -> packet != NULL) @@ -280,10 +291,12 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet channel -> outgoingReliableSequenceNumber = 0; channel -> outgoingUnreliableSequenceNumber = 0; channel -> incomingReliableSequenceNumber = 0; - channel -> incomingUnreliableSequenceNumber = 0; enet_list_clear (& channel -> incomingReliableCommands); enet_list_clear (& channel -> incomingUnreliableCommands); + + channel -> usedReliableWindows = 0; + memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); } mtu = ENET_NET_TO_HOST_16 (command -> connect.mtu); @@ -1146,16 +1159,26 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) ENetBuffer * buffer = & host -> buffers [host -> bufferCount]; ENetOutgoingCommand * outgoingCommand; ENetListIterator currentCommand; + ENetChannel *channel; + enet_uint16 reliableWindow; + size_t commandSize; currentCommand = enet_list_begin (& peer -> outgoingReliableCommands); while (currentCommand != enet_list_end (& peer -> outgoingReliableCommands)) { - size_t commandSize; - outgoingCommand = (ENetOutgoingCommand *) currentCommand; + + channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL; + reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; + if (channel != NULL && + outgoingCommand -> sendAttempts < 1 && + ! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) && + channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) | + (((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow)))) + break; + commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK]; - if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || peer -> mtu - host -> packetSize < commandSize) @@ -1165,8 +1188,6 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) break; } - currentCommand = enet_list_next (currentCommand); - if (outgoingCommand -> packet != NULL) { if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize) @@ -1179,7 +1200,17 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) break; } } - + + currentCommand = enet_list_next (currentCommand); + + if (channel != NULL && outgoingCommand -> sendAttempts < 1) + { + channel -> usedReliableWindows |= 1 << reliableWindow; + ++ channel -> reliableWindows [reliableWindow]; + } + + ++ outgoingCommand -> sendAttempts; + if (outgoingCommand -> roundTripTimeout == 0) { outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;