[Gcblue-commits] gcb_wx/include/network tcConnectionData.h,1.2,1.3 tcMessage.h,1.2,1.3 tcMultiplayer
Status: Alpha
Brought to you by:
ddcforge
|
From: <ddc...@us...> - 2004-03-06 21:07:38
|
Update of /cvsroot/gcblue/gcb_wx/include/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9771/include/network Modified Files: tcConnectionData.h tcMessage.h tcMultiplayerInterface.h tcNetworkInterface.h Log Message: Index: tcConnectionData.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcConnectionData.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcConnectionData.h 2 Mar 2004 02:52:14 -0000 1.2 --- tcConnectionData.h 6 Mar 2004 20:52:29 -0000 1.3 *************** *** 55,66 **** ! void ReadNextMessage(); void SendTCP(unsigned int idx); void Update(); ///< read and write data from socket ! void WriteQueuedMessage(); tcConnectionData(); private: tcMessage tempMessage; ///< message to use for temporary storage }; --- 55,71 ---- ! void ReadNextMessageTCP(); ! void ReadNextMessageUDP(unsigned int messageSize, unsigned char *buffer); void SendTCP(unsigned int idx); + void SendUDP(unsigned int idx, bool useAck = false); void Update(); ///< read and write data from socket ! void WriteQueuedMessages(); tcConnectionData(); private: tcMessage tempMessage; ///< message to use for temporary storage + + void WriteTCP(); + void WriteUDP(); }; Index: tcMessage.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcMessage.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcMessage.h 2 Mar 2004 02:52:14 -0000 1.2 --- tcMessage.h 6 Mar 2004 20:52:29 -0000 1.3 *************** *** 36,49 **** enum { ! BUFFER_SIZE = 1024, }; - int id; ///< id of message - int sourceId; ///< connection id of source of message unsigned int timestamp; unsigned short bufferIdx; ! unsigned short messageSize; ///< size of data portion of message in bytes ! unsigned char buffer[BUFFER_SIZE]; void Reset(); tcMessage(); tcMessage(const tcMessage& source); --- 36,67 ---- enum { ! BUFFER_SIZE = 1024, /// < max size in bytes of total message including header ! HEADER_SIZE = 8, ! SIZE_SIZE = 2, ///< size of messageSize field (first field in header) ! MESSAGE_SIZE = BUFFER_SIZE - HEADER_SIZE, }; unsigned int timestamp; unsigned short bufferIdx; ! union DATA_UNION ! { ! struct HEADER ! { ! unsigned int messageSize : 16; ///< size of message in bytes (including all header fields) ! int sourceId : 16; ///< connection id of source of message ! unsigned int : 0; ! int id : 32; ///< id of message ! } header; ! unsigned char buffer[BUFFER_SIZE]; ! } data; + const unsigned char* GetMessageData(); + int GetMessageId(); + unsigned int GetMessageSize(); + unsigned int GetMessageTimestamp(); + void PopulateMessage(int sourceId, int messageId, unsigned messageSize, + const unsigned char *messageData); void Reset(); + void StampTime(); + tcMessage(); tcMessage(const tcMessage& source); Index: tcMultiplayerInterface.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcMultiplayerInterface.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcMultiplayerInterface.h 2 Mar 2004 02:52:14 -0000 1.2 --- tcMultiplayerInterface.h 6 Mar 2004 20:52:29 -0000 1.3 *************** *** 41,44 **** --- 41,52 ---- class tcNetworkInterface; + + class tcPlayerStatus + { + public: + std::string name; ///< handle for player + unsigned timestamp; ///< time of last update + }; + /** * Singleton multiplayer interface class to manage connections, *************** *** 55,58 **** --- 63,67 ---- { MSG_CHATTEXT = 1, + MSG_USERNAME = 2, }; static tcMultiplayerInterface& Get(); *************** *** 65,73 **** bool IsChatTextAvail(); ! void MakeClient(); void MakeServer(); void OpenConnection(std::string hostName); void SendChatText(int destination, std::string message); void Update(); --- 74,84 ---- bool IsChatTextAvail(); ! bool IsServer(); void MakeClient(); void MakeServer(); void OpenConnection(std::string hostName); void SendChatText(int destination, std::string message); + void SendTestUDP(int destination, std::string message); + void SetChatProtocol(int code); void Update(); *************** *** 75,82 **** tcNetworkInterface *networkInterface; std::queue<std::string> chatText; ///< chat text to display void ProcessMessage(int connectionId, int messageId, ! unsigned messageSize, unsigned char *data); void ProcessReceiveMessages(); tcMultiplayerInterface(); tcMultiplayerInterface(const tcMultiplayerInterface& source); --- 86,99 ---- tcNetworkInterface *networkInterface; std::queue<std::string> chatText; ///< chat text to display + std::string myName; + std::map<int, tcPlayerStatus> playerInfo; ///< map of (connection id, tcPlayerStatus) pairs + bool tcpChat; ///< true to use TCP for chat protocol, otherwise UDP + bool IsNewPlayer(int id); void ProcessMessage(int connectionId, int messageId, ! unsigned messageSize, const unsigned char *data); void ProcessReceiveMessages(); + void UpdatePlayerInfo(); + tcMultiplayerInterface(); tcMultiplayerInterface(const tcMultiplayerInterface& source); Index: tcNetworkInterface.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcNetworkInterface.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcNetworkInterface.h 2 Mar 2004 02:52:14 -0000 1.5 --- tcNetworkInterface.h 6 Mar 2004 20:52:29 -0000 1.6 *************** *** 31,34 **** --- 31,35 ---- #include <queue> #include <map> + #include <string> #include "tcConnectionData.h" #include "tcMessage.h" *************** *** 51,54 **** --- 52,57 ---- UDP_PORT = 3011, MESSAGE_BUFFER_SIZE = 128, + UDP_EVENT_ID = -123, + MAX_UDP_SIZE = 4096, }; *************** *** 63,67 **** void OpenConnection(wxString hostName); ! unsigned char* ReceiveMessage(int connectionId, int& messageId, unsigned& messageSize, int protocol = TCP); bool SendMessage(int connectionId, int messageId, unsigned messageSize, --- 66,70 ---- void OpenConnection(wxString hostName); ! const unsigned char* ReceiveMessage(int connectionId, int& messageId, unsigned& messageSize, int protocol = TCP); bool SendMessage(int connectionId, int messageId, unsigned messageSize, *************** *** 88,95 **** wxSocketClient *clientSock; ///< single socket that will be used in client mode wxSocketServer *serverSock; ///< server socket for server mode std::vector<tcConnectionData> connectionData; ///< vector of connection data std::vector<tcMessage> messageBuffer; std::queue<unsigned int> available; ///< fifo of free slot indices ! std::map<int, int> connectionLookup; ///< connection id key, connectionData idx (-1 invalid) void AddConnection(wxSocketBase *socket); // adds socket to connectionData --- 91,101 ---- wxSocketClient *clientSock; ///< single socket that will be used in client mode wxSocketServer *serverSock; ///< server socket for server mode + wxDatagramSocket *datagramSock; ///< UDP socket + std::vector<tcConnectionData> connectionData; ///< vector of connection data std::vector<tcMessage> messageBuffer; std::queue<unsigned int> available; ///< fifo of free slot indices ! std::map<int, int> connectionLookup; ///< (connection id key, connectionData idx (-1 invalid)) ! std::map<std::string, int> peerMap; ///< another lookup (peername, connectionData idx) void AddConnection(wxSocketBase *socket); // adds socket to connectionData *************** *** 98,101 **** --- 104,110 ---- int CheckoutMessage(); tcConnectionData* GetConnection(int idx); + tcConnectionData* GetConnection(std::string peerName); + wxDatagramSocket* GetDatagramSocket() {return datagramSock;} + void InitializeUDP(); int LookupConnectionIndex(int id); void OnSocketEvent(wxSocketEvent& event); *************** *** 104,107 **** --- 113,117 ---- void ReturnMessage(unsigned int idx); void ReturnMessagesFromQueue(std::queue<unsigned int>& q); + void RouteUDP(); void UpdateClient(); void UpdateClientConnection(); |