diff --git a/Source_Files/Network/NetworkGameProtocol.h b/Source_Files/Network/NetworkGameProtocol.h index ca380a2e3..582077070 100644 --- a/Source_Files/Network/NetworkGameProtocol.h +++ b/Source_Files/Network/NetworkGameProtocol.h @@ -33,9 +33,6 @@ class NetworkGameProtocol public: /* Distribute information to the whole net. */ virtual bool Enter(short* inNetStatePtr) = 0; - virtual void Exit1() = 0; - virtual void Exit2() = 0; - virtual void DistributeInformation(short type, void *buffer, short buffer_size, bool send_to_self, bool only_send_to_team) = 0; virtual bool Sync(NetTopology* inTopology, int32 inSmallestGameTick, int inLocalPlayerIndex, bool isServer) = 0; virtual bool UnSync(bool inGraceful, int32 inSmallestPostgameTick) = 0; virtual int32 GetNetTime() = 0; diff --git a/Source_Files/Network/StarGameProtocol.cpp b/Source_Files/Network/StarGameProtocol.cpp index 21ca613d3..d65b7d862 100644 --- a/Source_Files/Network/StarGameProtocol.cpp +++ b/Source_Files/Network/StarGameProtocol.cpp @@ -76,34 +76,6 @@ StarGameProtocol::Enter(short* inNetStatePtr) return true; } - - -void -StarGameProtocol::Exit1() -{ -// return true; -} - - - -void -StarGameProtocol::Exit2() -{ -// return true; -} - - - -void -StarGameProtocol::DistributeInformation(short type, void *buffer, short buffer_size, bool send_to_self, bool only_send_to_team) -{ - const NetDistributionInfo* theInfo = NetGetDistributionInfoForType(type); - if(theInfo != NULL && theInfo->lossy) - spoke_distribute_lossy_streaming_bytes_to_everyone(type, static_cast(buffer), buffer_size, !send_to_self, only_send_to_team); -} - - - void StarGameProtocol::PacketHandler(DDPPacketBufferPtr packet) { @@ -248,18 +220,6 @@ make_player_really_net_dead(size_t inPlayerIndex) sTopology->players[inPlayerIndex].net_dead = true; } - - -void -call_distribution_response_function_if_available(byte* inBuffer, uint16 inBufferSize, int16 inDistributionType, uint8 inSendingPlayerIndex) -{ - const NetDistributionInfo* theInfo = NetGetDistributionInfoForType(inDistributionType); - if(theInfo != NULL) - theInfo->distribution_proc(inBuffer, inBufferSize, inSendingPlayerIndex); -} - - - void StarGameProtocol::ParsePreferencesTree(InfoTree prefs, std::string version) { diff --git a/Source_Files/Network/StarGameProtocol.h b/Source_Files/Network/StarGameProtocol.h index bee6bc936..3d2e7ea82 100644 --- a/Source_Files/Network/StarGameProtocol.h +++ b/Source_Files/Network/StarGameProtocol.h @@ -36,9 +36,6 @@ class StarGameProtocol : public NetworkGameProtocol { public: bool Enter(short* inNetStatePtr); - void Exit1(); - void Exit2(); - void DistributeInformation(short type, void *buffer, short buffer_size, bool send_to_self, bool only_send_to_team); bool Sync(NetTopology* inTopology, int32 inSmallestGameTick, int inLocalPlayerIndex, bool isServer); bool UnSync(bool inGraceful, int32 inSmallestPostgameTick); int32 GetNetTime(); diff --git a/Source_Files/Network/network.cpp b/Source_Files/Network/network.cpp index 3c9678f47..d5780662a 100644 --- a/Source_Files/Network/network.cpp +++ b/Source_Files/Network/network.cpp @@ -270,10 +270,6 @@ struct ignore_lua // ZZZ note: read this externally with the NetState() function. static short netState= netUninitialized; -// ZZZ change: now using an STL 'map' to, well, _map_ distribution types to info records. -typedef std::map distribution_info_map_t; -static distribution_info_map_t distribution_info_map; - // ZZZ: are we trying to start a new game or resume a saved-game? // This is only valid on the gatherer after NetGather() is called; // only valid on a joiner once he receives the final topology (tagRESUME_GAME) @@ -1349,9 +1345,7 @@ void NetExit( void) { OSErr error = noErr; - - sCurrentGameProtocol->Exit1(); - + // ZZZ: clean up SDL Time Manager emulation. // true says wait for any late finishers to finish // (but does NOT say to kill anyone not already removed.) @@ -1362,9 +1356,6 @@ void NetExit( if (!error) { free(topology); topology= NULL; - - sCurrentGameProtocol->Exit2(); - netState= netUninitialized; } else { logAnomaly("NetDDPCloseSocket returned %i", error); @@ -1447,56 +1438,6 @@ NetRemovePinger() } -/* Add a function for a distribution type. returns the type, or NONE if it can't be - * installed. It's safe to call this function multiple times for the same proc. */ -// ZZZ: changed to take in the desired type, so a given machine can handle perhaps only some -// of the distribution types. -void -NetAddDistributionFunction(int16 inDataTypeID, NetDistributionProc inProc, bool inLossy) { - // We don't support lossless distribution yet. - assert(inLossy); - - // Prepare a NetDistributionInfo with the desired data. - NetDistributionInfo theInfo; - theInfo.lossy = inLossy; - theInfo.distribution_proc = inProc; - - // Insert or update a map entry - distribution_info_map[inDataTypeID] = theInfo; -} - - -/* Remove a distribution proc that has been installed. */ -void -NetRemoveDistributionFunction(int16 inDataTypeID) { - distribution_info_map.erase(inDataTypeID); -} - - -const NetDistributionInfo* -NetGetDistributionInfoForType(int16 inType) -{ - distribution_info_map_t::const_iterator theEntry = distribution_info_map.find(inType); - if(theEntry != distribution_info_map.end()) - return &(theEntry->second); - else - return NULL; -} - - - - -void NetDistributeInformation( - short type, - void *buffer, - short buffer_size, - bool send_to_self, - bool only_send_to_team) -{ - sCurrentGameProtocol->DistributeInformation(type, buffer, buffer_size, send_to_self, only_send_to_team); -} - - short NetState( void) { diff --git a/Source_Files/Network/network.h b/Source_Files/Network/network.h index ad44aaf10..d78342fba 100644 --- a/Source_Files/Network/network.h +++ b/Source_Files/Network/network.h @@ -53,10 +53,6 @@ Tuesday, June 21, 1994 3:26:46 PM // change this if you make a major change to the way the setup messages work #define kNetworkSetupProtocolID "Aleph One WonderNAT V2" -// ZZZ: there probably should be a published max size somewhere, but this isn't used anywhere; better -// not to pretend it's real. -//#define MAX_NET_DISTRIBUTION_BUFFER_SIZE 512 - enum // base network speeds { _appletalk_remote, // ARA @@ -187,8 +183,6 @@ enum /* states */ }; /* -------- typedefs */ -// player index is the index of the player that is sending the information -typedef void (*NetDistributionProc)(void *buffer, short buffer_size, short player_index); typedef void (*CheckPlayerProcPtr)(short player_index, short num_players); /* --------- prototypes/NETWORK.C */ @@ -235,19 +229,6 @@ std::weak_ptr NetGetPinger(); void NetCreatePinger(); void NetRemovePinger(); -// ghs: these are obsolete, I'll get rid of them when I'm sure I won't want -// to refer back to them - -// ZZZ addition - pre-game/(eventually) postgame chat -// Returns true if there was a pending message. -// Returns pointer to chat text. -// Returns pointer to sending player's data (does not copy player data). -// Data returned in pointers is only good until the next call to NetUpdateJoinState or NetCheckForIncomingMessages. -bool NetGetMostRecentChatMessage(player_info** outSendingPlayerData, char** outMessage); - -// Gatherer should use this to send out his messages or to broadcast a message received from a joiner -OSErr NetDistributeChatMessage(short sender_identifier, const char* message); - void NetProcessMessagesInGame(); short NetGetLocalPlayerIndex(void); @@ -284,13 +265,6 @@ void construct_multiplayer_starts(player_start_data* outStartArray, short* outSt void match_starts_with_existing_players(player_start_data* ioStartArray, short* ioStartCount); void display_net_game_stats(void); -// ZZZ change: caller specifies int16 ID for distribution type. Unknown types (when received) are -// passed along but ignored. Uses an STL 'map' so ID's need not be consecutive or in any particular -// sub-range. -void NetAddDistributionFunction(int16 type, NetDistributionProc proc, bool lossy); -void NetDistributeInformation(short type, void *buffer, short buffer_size, bool send_to_self, bool send_only_to_team = false); -void NetRemoveDistributionFunction(short type); - // disable "cheats" bool NetAllowCrosshair(); bool NetAllowOverlayMap(); diff --git a/Source_Files/Network/network_private.h b/Source_Files/Network/network_private.h index 919b05c83..8036d8603 100644 --- a/Source_Files/Network/network_private.h +++ b/Source_Files/Network/network_private.h @@ -96,10 +96,10 @@ enum /* error string for user */ #define MAP_TRANSFER_TIME_OUT (MACHINE_TICKS_PER_SECOND*70) // 70 seconds to wait for map. enum /* tag */ -{ // ZZZ annotation: these (in NetPacketHeader) indicate the rest of the datagram is a NetPacket (i.e. a ring packet). - tagRING_PACKET, - tagACKNOWLEDGEMENT, - tagCHANGE_RING_PACKET, // to tell a player to change his downring address. also has action flags. +{ + tagRING_PACKET, //obsolete + tagACKNOWLEDGEMENT, //obsolete + tagCHANGE_RING_PACKET, //obsolete // ZZZ annotation: these should only be found in streaming data (in a NetTopology). tagNEW_PLAYER, @@ -109,8 +109,8 @@ enum /* tag */ tagCHANGED_PLAYER, // ZZZ annotation: these (in NetPacketHeader) indicate the rest of the datagram is a NetDistributionPacket. - tagLOSSY_DISTRIBUTION, // for transfer data other than action flags - tagLOSSLESS_DISTRIBUTION, // ditto, but currently unimplemented + tagLOSSY_DISTRIBUTION, //obsolete + tagLOSSLESS_DISTRIBUTION, //obsolete // ZZZ: more streaming data (topology) packet types tagRESUME_GAME // ZZZ addition: trying to resume a saved-game rather than start a new netgame. @@ -159,15 +159,6 @@ struct NetTopology }; typedef struct NetTopology NetTopology, *NetTopologyPtr; -// ZZZ: same here (should be safe to alter) -struct NetDistributionInfo -{ - bool lossy; - NetDistributionProc distribution_proc; -}; - -typedef struct NetDistributionInfo NetDistributionInfo, *NetDistributionInfoPtr; - /* ===== application specific data structures/enums */ // Altering these constants requires changes to get_network_version(). - Woody @@ -193,12 +184,8 @@ enum { class CommunicationsChannel; class MessageDispatcher; class MessageHandler; - class Message; - -const NetDistributionInfo* NetGetDistributionInfoForType(int16 inType); - struct ClientChatInfo { std::string name; diff --git a/Source_Files/Network/network_star.h b/Source_Files/Network/network_star.h index e54191b88..729be0e5f 100644 --- a/Source_Files/Network/network_star.h +++ b/Source_Files/Network/network_star.h @@ -44,8 +44,6 @@ enum { kEndOfMessagesMessageType = 0x454d, // 'EM' kTimingAdjustmentMessageType = 0x5441, // 'TA' kPlayerNetDeadMessageType = 0x4e44, // 'ND' - kSpokeToHubLossyByteStreamMessageType = 0x534c, // 'SL' - kHubToSpokeLossyByteStreamMessageType = 0x484c, // 'HL' kSpokeToHubIdentification = 0x4944, // 'ID' kSpokeToHubGameDataPacketV1Magic = 0x5331, // 'S1' @@ -79,13 +77,7 @@ extern void spoke_initialize(const NetAddrBlock& inHubAddress, int32 inFirstTick extern void spoke_cleanup(bool inGraceful); extern void spoke_received_network_packet(DDPPacketBufferPtr inPacket); extern int32 spoke_get_net_time(); -// "Distribute to everyone" helps to match the existing (legacy) interfaces etc. -extern void spoke_distribute_lossy_streaming_bytes_to_everyone(int16 inDistributionType, byte* inBytes, uint16 inLength, bool inExcludeLocalPlayer, bool onlySendToTeam); -// distribute_lossy_streaming_bytes offers a more direct interface (not yet used) to star's lossy -// distribution mechanism. (e.g., can select certain recipients, send unregistered dist types, etc.) -extern void spoke_distribute_lossy_streaming_bytes(int16 inDistributionType, uint32 inDestinationsBitmask, byte* inBytes, uint16 inLength); extern int32 spoke_latency(); // in ms, kNetLatencyInvalid if not yet valid -extern int32 hub_latency(int player_index); // in ms, kNetLatencyInvalid if not valid, kNetLatencyDisconnected if d/c extern TickBasedActionQueue* spoke_get_unconfirmed_flags_queue(); extern int32 spoke_get_smallest_unconfirmed_tick(); extern bool spoke_check_world_update(); diff --git a/Source_Files/Network/network_star_hub.cpp b/Source_Files/Network/network_star_hub.cpp index 6c3ba8335..bde71344d 100644 --- a/Source_Files/Network/network_star_hub.cpp +++ b/Source_Files/Network/network_star_hub.cpp @@ -149,10 +149,6 @@ enum { kDefaultSendPeriod = 1, kDefaultRecoverySendPeriod = TICKS_PER_SECOND / 2, kDefaultMinimumSendPeriod = 3, - kLossyByteStreamDataBufferSize = 1280, - kTypicalLossyByteStreamChunkSize = 56, - kLossyByteStreamDescriptorCount = kLossyByteStreamDataBufferSize / kTypicalLossyByteStreamChunkSize, - kLatencyBufferSize = TICKS_PER_SECOND * 5, // store 5 seconds of ping counts kDisplayLatencyWindow = TICKS_PER_SECOND * 1, // display last second's ping kJitterUpdateInterval = TICKS_PER_SECOND * 1 / 2 @@ -313,30 +309,9 @@ static DDPPacketBuffer sLocalOutgoingBuffer; static bool sNeedToSendLocalOutgoingBuffer = false; #endif - -struct HubLossyByteStreamChunkDescriptor -{ - uint16 mLength; - int16 mType; - uint32 mDestinations; - uint8 mSender; -}; - -// This holds outgoing lossy byte stream data -static CircularByteBuffer sOutgoingLossyByteStreamData(kLossyByteStreamDataBufferSize); - -// This holds a descriptor for each chunk of lossy byte stream data held in the above buffer -static CircularQueue sOutgoingLossyByteStreamDescriptors(kLossyByteStreamDescriptorCount); - -// This is used to copy between AStream and CircularByteBuffer -// It's used in both directions, but that's ok because the routines that do so are mutex. -static byte sScratchBuffer[kLossyByteStreamDataBufferSize]; - - static myTMTaskPtr sHubTickTask = NULL; static std::atomic_bool sHubActive = { false }; // used to enable the packet handler -static bool sHubInitialized = false; - +static bool sHubInitialized = false; static void hub_check_for_completion(); @@ -348,7 +323,6 @@ static void hub_update_player_pregame_state(int inPlayerIndex, int16 state); static void hub_received_ping_request(AIStream& ps, NetAddrBlock address); static void hub_received_ping_response(AIStream& ps, NetAddrBlock address); static void process_messages(AIStream& ps, int inSenderIndex); -static void process_optional_message(AIStream& ps, int inSenderIndex, uint16 inMessageType); static void make_player_netdead(int inPlayerIndex); static bool hub_tick(); static void send_packets(); @@ -490,9 +464,6 @@ hub_initialize(int32 inStartingTick, int inNumPlayers, const NetAddrBlock* const sAddressToPlayerIndex.clear(); sConnectedPlayersBitmask = 0; - sOutgoingLossyByteStreamDescriptors.reset(); - sOutgoingLossyByteStreamData.reset(); - for(size_t i = 0; i < inNumPlayers; i++) { NetworkPlayer_hub& thePlayer = sNetworkPlayers[i]; @@ -1204,86 +1175,11 @@ process_messages(AIStream& ps, int inSenderIndex) break; default: - process_optional_message(ps, inSenderIndex, theMessageType); break; } } } - - -static void -process_lossy_byte_stream_message(AIStream& ps, int inSenderIndex, uint16 inLength) -{ - assert(inSenderIndex >= 0 && inSenderIndex < static_cast(sNetworkPlayers.size())); - - HubLossyByteStreamChunkDescriptor theDescriptor; - - size_t theHeaderStreamPosition = ps.tellg(); - ps >> theDescriptor.mType >> theDescriptor.mDestinations; - theDescriptor.mLength = inLength - (ps.tellg() - theHeaderStreamPosition); - theDescriptor.mSender = inSenderIndex; - - logDumpNMT("got %d bytes of lossy stream type %d from player %d for destinations 0x%x", theDescriptor.mLength, theDescriptor.mType, theDescriptor.mSender, theDescriptor.mDestinations); - - bool canEnqueue = true; - - if(sOutgoingLossyByteStreamDescriptors.getRemainingSpace() < 1) - { - logNoteNMT("no descriptor space remains; discarding (%uh) bytes of lossy streaming data of distribution type %hd from player %hu destined for 0x%lx", theDescriptor.mLength, theDescriptor.mType, theDescriptor.mSender, theDescriptor.mDestinations); - canEnqueue = false; - } - - // We avoid enqueueing a partial chunk to make things easier on code that uses us - if(theDescriptor.mLength > sOutgoingLossyByteStreamData.getRemainingSpace()) - { - logNoteNMT("insufficient buffer space for %uh bytes of lossy streaming data of distribution type %hd from player %hu destined for 0x%lx; discarded", theDescriptor.mLength, theDescriptor.mType, theDescriptor.mSender, theDescriptor.mDestinations); - canEnqueue = false; - } - - if(canEnqueue) - { - if(theDescriptor.mLength > 0) - { - // This is an assert, not a test, because the data buffer should be no - // bigger than the scratch buffer (and if it didn't fit into the data buffer, - // canEnqueue would be false). - assert(theDescriptor.mLength <= sizeof(sScratchBuffer)); - - // XXX extraneous copy, needed given the current interfaces to these things - ps.read(sScratchBuffer, theDescriptor.mLength); - - sOutgoingLossyByteStreamData.enqueueBytes(sScratchBuffer, theDescriptor.mLength); - sOutgoingLossyByteStreamDescriptors.enqueue(theDescriptor); - } - } - else - // We still have to gobble up the entire message, even if we can't use it. - ps.ignore(theDescriptor.mLength); -} - - - -static void -process_optional_message(AIStream& ps, int inSenderIndex, uint16 inMessageType) -{ - // All optional messages are required to give their length in the two bytes - // immediately following their type. (The message length value does not include - // the space required for the message type ID or the encoded message length.) - uint16 theMessageLength; - ps >> theMessageLength; - - if(inMessageType == kSpokeToHubLossyByteStreamMessageType) - process_lossy_byte_stream_message(ps, inSenderIndex, theMessageLength); - else - { - // Currently we ignore (skip) all optional messages - ps.ignore(theMessageLength); - } -} - - - static void make_player_netdead(int inPlayerIndex) { @@ -1486,21 +1382,6 @@ hub_tick() static void send_packets() { - // Currently, at most one lossy data descriptor is used per trip through this function. So, - // we do some processing here outside the loop since the results'd be the same every time. - HubLossyByteStreamChunkDescriptor theDescriptor = { 0, 0, 0, 0 }; - bool haveLossyData = false; - if(sOutgoingLossyByteStreamDescriptors.getCountOfElements() > 0) - { - haveLossyData = true; - theDescriptor = sOutgoingLossyByteStreamDescriptors.peek(); - - // XXX extraneous copy due to limited interfaces - // We assert here; the real "test" happened when it was enqueued. - assert(theDescriptor.mLength <= sizeof(sScratchBuffer)); - sOutgoingLossyByteStreamData.peekBytes(sScratchBuffer, theDescriptor.mLength); - } - // remember when we sent flags for the first time for (int32 i = sFlagSendTimeQueue.getWriteTick(); i < sSmallestIncompleteTick; i++) { @@ -1538,21 +1419,6 @@ send_packets() << sNetworkPlayers[j].mNetDeadTick; } } - - // Lossy streaming data? - if(haveLossyData && ((theDescriptor.mDestinations & (((uint32)1) << i)) != 0)) - { - logDumpNMT("packet to player %d will contain %d bytes of lossy byte stream type %d from player %d", i, theDescriptor.mLength, theDescriptor.mType, theDescriptor.mSender); - // In AStreams, sizeof(packed scalar) == sizeof(unpacked scalar) - uint16 theMessageLength = sizeof(theDescriptor.mType) + sizeof(theDescriptor.mSender) + theDescriptor.mLength; - - ps << (uint16)kHubToSpokeLossyByteStreamMessageType - << theMessageLength - << theDescriptor.mType - << theDescriptor.mSender; - - ps.write(sScratchBuffer, theDescriptor.mLength); - } // End of messages ps << (uint16)kEndOfMessagesMessageType; @@ -1685,12 +1551,6 @@ send_packets() sLastNetworkTickSent = sNetworkTicker; sSmallestUnsentTick = sSmallestIncompleteTick; - - if(haveLossyData) - { - sOutgoingLossyByteStreamData.dequeue(theDescriptor.mLength); - sOutgoingLossyByteStreamDescriptors.dequeue(); - } } // send_packets() diff --git a/Source_Files/Network/network_star_spoke.cpp b/Source_Files/Network/network_star_spoke.cpp index 378b88d8e..5c38b1ebf 100644 --- a/Source_Files/Network/network_star_spoke.cpp +++ b/Source_Files/Network/network_star_spoke.cpp @@ -49,8 +49,6 @@ #include extern void make_player_really_net_dead(size_t inPlayerIndex); -extern void call_distribution_response_function_if_available(byte* inBuffer, uint16 inBufferSize, int16 inDistributionType, uint8 inSendingPlayerIndex); - enum { kDefaultPregameTicksBeforeNetDeath = 90 * TICKS_PER_SECOND, @@ -58,10 +56,7 @@ enum { kDefaultOutgoingFlagsQueueSize = TICKS_PER_SECOND / 2, kDefaultRecoverySendPeriod = TICKS_PER_SECOND / 2, kDefaultTimingWindowSize = 3 * TICKS_PER_SECOND, - kDefaultTimingNthElement = kDefaultTimingWindowSize / 2, - kLossyByteStreamDataBufferSize = 1280, - kTypicalLossyByteStreamChunkSize = 56, - kLossyByteStreamDescriptorCount = kLossyByteStreamDataBufferSize / kTypicalLossyByteStreamChunkSize + kDefaultTimingNthElement = kDefaultTimingWindowSize / 2 }; struct SpokePreferences @@ -130,23 +125,6 @@ static int32 sDisplayLatencyTicks = 0; // sum of the latency ticks from the last static int32 sSmallestUnconfirmedTick; -struct SpokeLossyByteStreamChunkDescriptor -{ - uint16 mLength; - int16 mType; - uint32 mDestinations; -}; - -// This holds outgoing lossy byte stream data -static CircularByteBuffer sOutgoingLossyByteStreamData(kLossyByteStreamDataBufferSize); - -// This holds a descriptor for each chunk of lossy byte stream data held in the above buffer -static CircularQueue sOutgoingLossyByteStreamDescriptors(kLossyByteStreamDescriptorCount); - -// This is currently used only to hold incoming streaming data until it's passed to the upper-level code -static byte sScratchBuffer[kLossyByteStreamDataBufferSize]; - - static void spoke_became_disconnected(); static void spoke_received_game_data_packet_v1(AIStream& ps, bool reflected_flags); static void spoke_received_ping_request(AIStream& ps, NetAddrBlock address); @@ -155,8 +133,6 @@ static void process_messages(AIStream& ps, IncomingGameDataPacketProcessingConte static void handle_end_of_messages_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context); static void handle_player_net_dead_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context); static void handle_timing_adjustment_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context); -static void handle_lossy_byte_stream_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context); -static void process_optional_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context, uint16 inMessageType); static bool spoke_tick(); static void send_packet(); static void send_identification_packet(); @@ -259,15 +235,10 @@ spoke_initialize(const NetAddrBlock& inHubAddress, int32 inFirstTick, size_t inN sNthElementFinder.reset(sSpokePreferences.mTimingWindowSize); sTimingMeasurementValid = false; - sOutgoingLossyByteStreamDescriptors.reset(); - sOutgoingLossyByteStreamData.reset(); - sMessageTypeToMessageHandler.clear(); sMessageTypeToMessageHandler[kEndOfMessagesMessageType] = handle_end_of_messages_message; sMessageTypeToMessageHandler[kTimingAdjustmentMessageType] = handle_timing_adjustment_message; sMessageTypeToMessageHandler[kPlayerNetDeadMessageType] = handle_player_net_dead_message; - sMessageTypeToMessageHandler[kHubToSpokeLossyByteStreamMessageType] = handle_lossy_byte_stream_message; - sNeedToSendLocalOutgoingBuffer = false; sSpokeActive = true; @@ -332,71 +303,6 @@ spoke_get_net_time() return (sConnected ? sOutgoingFlags.getWriteTick() - theDelay : getNetworkPlayer(sLocalPlayerIndex).mQueue->getWriteTick()); } - - -void -spoke_distribute_lossy_streaming_bytes_to_everyone(int16 inDistributionType, byte* inBytes, uint16 inLength, bool inExcludeLocalPlayer, bool onlySendToTeam) -{ - - int16 local_team; - if (onlySendToTeam) - { - player_info* player = (player_info *)NetGetPlayerData(sLocalPlayerIndex); - local_team = player->team; - } - - uint32 theDestinations = 0; - for(size_t i = 0; i < sNetworkPlayers.size(); i++) - { - if((i != sLocalPlayerIndex || !inExcludeLocalPlayer) && !sNetworkPlayers[i].mZombie && sNetworkPlayers[i].mConnected) - { - if (onlySendToTeam) - { - player_info* player = (player_info *)NetGetPlayerData(i); - if (player->team == local_team) - theDestinations |= (((uint32)1) << i); - - } - else - { - theDestinations |= (((uint32)1) << i); - } - } - } - - spoke_distribute_lossy_streaming_bytes(inDistributionType, theDestinations, inBytes, inLength); -} - - - -void -spoke_distribute_lossy_streaming_bytes(int16 inDistributionType, uint32 inDestinationsBitmask, byte* inBytes, uint16 inLength) -{ - if(inLength > sOutgoingLossyByteStreamData.getRemainingSpace()) - { - logNoteNMT("spoke has insufficient buffer space for %hu bytes of outgoing lossy streaming type %hd; discarded", inLength, inDistributionType); - return; - } - - if(sOutgoingLossyByteStreamDescriptors.getRemainingSpace() < 1) - { - logNoteNMT("spoke has exhausted descriptor buffer space; discarding %hu bytes of outgoing lossy streaming type %hd", inLength, inDistributionType); - return; - } - - struct SpokeLossyByteStreamChunkDescriptor theDescriptor; - theDescriptor.mLength = inLength; - theDescriptor.mDestinations = inDestinationsBitmask; - theDescriptor.mType = inDistributionType; - - logDumpNMT("spoke application decided to send %d bytes of lossy streaming type %d destined for players 0x%x", inLength, inDistributionType, inDestinationsBitmask); - - sOutgoingLossyByteStreamData.enqueueBytes(inBytes, inLength); - sOutgoingLossyByteStreamDescriptors.enqueue(theDescriptor); -} - - - static void spoke_became_disconnected() { @@ -793,18 +699,16 @@ spoke_received_ping_response(AIStream& ps, NetAddrBlock address) static void process_messages(AIStream& ps, IncomingGameDataPacketProcessingContext& context) { - while(!context.mMessagesDone) - { - uint16 theMessageType; - ps >> theMessageType; + while(!context.mMessagesDone) + { + uint16 theMessageType; + ps >> theMessageType; - MessageTypeToMessageHandler::iterator i = sMessageTypeToMessageHandler.find(theMessageType); + MessageTypeToMessageHandler::iterator i = sMessageTypeToMessageHandler.find(theMessageType); - if(i == sMessageTypeToMessageHandler.end()) - process_optional_message(ps, context, theMessageType); - else - i->second(ps, context); - } + if(i != sMessageTypeToMessageHandler.end()) + i->second(ps, context); + } } @@ -853,53 +757,6 @@ handle_timing_adjustment_message(AIStream& ps, IncomingGameDataPacketProcessingC context.mGotTimingAdjustmentMessage = true; } - - -static void -handle_lossy_byte_stream_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context) -{ - uint16 theMessageLength; - ps >> theMessageLength; - - size_t theStartOfMessage = ps.tellg(); - - int16 theDistributionType; - uint8 theSendingPlayer; - ps >> theDistributionType >> theSendingPlayer; - - uint16 theDataLength = theMessageLength - (ps.tellg() - theStartOfMessage); - uint16 theSpilloverDataLength = 0; - if(theDataLength > sizeof(sScratchBuffer)) - { - logNoteNMT("received too many bytes (%d) of lossy streaming data type %d from player %d; truncating", theDataLength, theDistributionType, theSendingPlayer); - theSpilloverDataLength = theDataLength - sizeof(sScratchBuffer); - theDataLength = sizeof(sScratchBuffer); - } - ps.read(sScratchBuffer, theDataLength); - ps.ignore(theSpilloverDataLength); - - logDumpNMT("received %d bytes of lossy streaming type %d data from player %d", theDataLength, theDistributionType, theSendingPlayer); - - call_distribution_response_function_if_available(sScratchBuffer, theDataLength, theDistributionType, theSendingPlayer); -} - - - -static void -process_optional_message(AIStream& ps, IncomingGameDataPacketProcessingContext& context, uint16 inMessageType) -{ - // We don't know of any optional messages, so we just skip any we encounter. - // (All optional messages are required to encode their length (not including the - // space required for the message type or length) in the two bytes immediately - // following the message type.) - uint16 theLength; - ps >> theLength; - - ps.ignore(theLength); -} - - - static bool spoke_tick() { @@ -969,9 +826,6 @@ spoke_tick() logDumpNMT("sOutstandingTimingAdjustment is now %d", sOutstandingTimingAdjustment); - if(sOutgoingLossyByteStreamDescriptors.getCountOfElements() > 0) - shouldSend = true; - // If we're connected and (we generated new data or if it's been long enough since we last sent), send. if(sConnected) { @@ -1045,36 +899,7 @@ send_packet() // Acknowledgement ps << sSmallestUnreceivedTick; - - // Messages - // Outstanding lossy streaming bytes? - if(sOutgoingLossyByteStreamDescriptors.getCountOfElements() > 0) - { - // Note: we make a conscious decision here to dequeue these things before - // writing to ps, so that if the latter operation exhausts ps's buffer and - // throws, we have less data to mess with next time, and shouldn't end up - // throwing every time we try to send here. - // If we eventually got smarter about managing packet space, we could try - // harder to preserve and pace data - e.g. change the 'if' immediately before this - // comment to a 'while', only put in as much data as we think we can fit, etc. - SpokeLossyByteStreamChunkDescriptor theDescriptor = sOutgoingLossyByteStreamDescriptors.peek(); - sOutgoingLossyByteStreamDescriptors.dequeue(); - - uint16 theMessageLength = theDescriptor.mLength + sizeof(theDescriptor.mType) + sizeof(theDescriptor.mDestinations); - ps << (uint16)kSpokeToHubLossyByteStreamMessageType - << theMessageLength - << theDescriptor.mType - << theDescriptor.mDestinations; - - // XXX unnecessary copy due to overly restrictive interfaces (retaining for clarity) - assert(theDescriptor.mLength <= sizeof(sScratchBuffer)); - sOutgoingLossyByteStreamData.peekBytes(sScratchBuffer, theDescriptor.mLength); - sOutgoingLossyByteStreamData.dequeue(theDescriptor.mLength); - - ps.write(sScratchBuffer, theDescriptor.mLength); - } - // No more messages ps << (uint16)kEndOfMessagesMessageType;