[Gcblue-commits] gcb_wx/src/network tcConnectionData.cpp,1.5,1.6 tcMultiplayerInterface.cpp,1.12,1.1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-05-02 16:22:53
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11419/src/network Modified Files: tcConnectionData.cpp tcMultiplayerInterface.cpp tcNetworkInterface.cpp tcUpdateMessageHandler.cpp Log Message: Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcUpdateMessageHandler.cpp 1 May 2004 21:49:06 -0000 1.5 --- tcUpdateMessageHandler.cpp 2 May 2004 16:22:45 -0000 1.6 *************** *** 94,98 **** { stream << obj->mnID; // write id ! // write obj state to stream *obj >> stream; --- 94,98 ---- { stream << obj->mnID; // write id ! // write obj state to stream *obj >> stream; *************** *** 108,128 **** switch (messageType) { ! case CREATE: ! break; ! case CREATE_REQUEST: ! break; ! case UPDATE: ! // update messages start with time and time acceleration info ! tcSimState::Get()->SaveTimeToStream(stream); ! break; ! case COMMAND_UPDATE: ! break; ! case COMMAND_ACK: ! break; ! case DESTROY: ! break; ! default: ! fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type\n"); ! break; } --- 108,128 ---- switch (messageType) { ! case CREATE: ! break; ! case CREATE_REQUEST: ! break; ! case UPDATE: ! // update messages start with time and time acceleration info ! tcSimState::Get()->SaveTimeToStream(stream); ! break; ! case COMMAND_UPDATE: ! break; ! case COMMAND_ACK: ! break; ! case DESTROY: ! break; ! default: ! fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type\n"); ! break; } *************** *** 135,139 **** tcSimState* simState = tcSimState::Get(); wxASSERT(simState); ! // end up creating stream twice. could split to use multiple handlers to avoid this tcStream stream((const char*)data, messageSize); --- 135,139 ---- tcSimState* simState = tcSimState::Get(); wxASSERT(simState); ! // end up creating stream twice. could split to use multiple handlers to avoid this tcStream stream((const char*)data, messageSize); *************** *** 142,147 **** stream >> messageType; ! switch (messageType) { case CREATE: { --- 142,178 ---- stream >> messageType; ! if (isServer) { + switch (messageType) + { + case CREATE: + case UPDATE: + case DESTROY: + fprintf(stderr, "tcUpdateMessageHandler::Handle - " + "illegal msg type for server (%d)\n", messageType); + return; + case COMMAND_UPDATE: + { + tcCommandStream stream((const char*)data, messageSize); + stream >> messageType; + HandleCommandUpdate(stream, connectionId); + } + break; + case COMMAND_ACK: + { + tcCommandStream stream((const char*)data, messageSize); + stream >> messageType; + HandleCommandAck(stream); + } + break; + default: + fprintf(stderr, "tcUpdateMessageHandler::Handle - unknown msg type for server\n"); + break; + } + } + else + { + switch (messageType) + { case CREATE: { *************** *** 155,159 **** tcUpdateStream stream((const char*)data, messageSize); stream >> messageType; ! HandleUpdate(stream); } break; --- 186,190 ---- tcUpdateStream stream((const char*)data, messageSize); stream >> messageType; ! HandleUpdate(stream, connectionId); } break; *************** *** 180,185 **** break; default: ! fprintf(stderr, "tcUpdateMessageHandler::Handle - bad message type\n"); break; } --- 211,218 ---- break; default: ! fprintf(stderr, "tcUpdateMessageHandler::Handle - " ! "unknown msg type for client (%d)\n", messageType); break; + } } *************** *** 196,200 **** wxASSERT(simState); ! fprintf(stdout, "Upding obj cmd acks, time %.1f: ", simState->GetTime()); long id; --- 229,233 ---- wxASSERT(simState); ! fprintf(stdout, "<< Received obj cmd acks, time %.1f: ", simState->GetTime()); long id; *************** *** 231,235 **** ! // Init ack messag tcCommandStream commandStream; tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::COMMAND_ACK, commandStream); --- 264,268 ---- ! // Init ack message tcCommandStream commandStream; tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::COMMAND_ACK, commandStream); *************** *** 238,242 **** unsigned nAcks = 0; ! fprintf(stdout, "Updating obj cmds, time %.1f: ", simState->GetTime()); long id; --- 271,275 ---- unsigned nAcks = 0; ! fprintf(stdout, "<< Received obj cmds, time %.1f: ", simState->GetTime()); long id; *************** *** 270,274 **** tcMultiplayerInterface::Get()->SendUpdateMessage(connectionId, commandStream); #ifdef _DEBUG ! fprintf(stdout, "Sent obj command update ack, time: %.1f\n", simState->GetTime()); #endif } --- 303,307 ---- tcMultiplayerInterface::Get()->SendUpdateMessage(connectionId, commandStream); #ifdef _DEBUG ! fprintf(stdout, ">> Sent obj command update ack, time: %.1f\n", simState->GetTime()); #endif } *************** *** 284,288 **** tcDatabase* database = simState->mpDatabase; // convert database to singleton eventually ! fprintf(stdout, "Creating objs, time %.1f: ", simState->GetTime()); long id; --- 317,321 ---- tcDatabase* database = simState->mpDatabase; // convert database to singleton eventually ! fprintf(stdout, "<< Received obj create msg, time %.1f: ", simState->GetTime()); long id; *************** *** 326,331 **** * Handle CREATE_REQUEST message (server only) */ ! void tcUpdateMessageHandler::HandleCreateRequest(tcStream& stream) { } --- 359,380 ---- * Handle CREATE_REQUEST message (server only) */ ! void tcUpdateMessageHandler::HandleCreateRequest(tcStream& stream, int connectionId) { + wxASSERT(isServer); + + tcPlayerStatus& pstatus = + tcMultiplayerInterface::Get()->GetPlayerStatus(connectionId); + + long id; + + fprintf(stdout, "<< Received create req for objs: "); + + while ((stream >> id).eof() == false) + { + pstatus.EraseEntry(id); + fprintf(stdout, "%d ", id); + } + + fprintf(stdout, "\n"); } *************** *** 338,342 **** wxASSERT(simState); ! fprintf(stdout, "Destroying objs, time %.1f: ", simState->GetTime()); long id; --- 387,391 ---- wxASSERT(simState); ! fprintf(stdout, "<< Received destroy objs msg, time %.1f: ", simState->GetTime()); long id; *************** *** 366,378 **** * Handle UPDATE update message (client only) */ ! void tcUpdateMessageHandler::HandleUpdate(tcUpdateStream& stream) { tcSimState* simState = tcSimState::Get(); wxASSERT(simState); // Load time info from stream tcSimState::Get()->LoadTimeFromStream(stream); ! fprintf(stdout, "Updating objs, time %.1f: ", simState->GetTime()); long id; --- 415,433 ---- * Handle UPDATE update message (client only) */ ! void tcUpdateMessageHandler::HandleUpdate(tcUpdateStream& stream, int connectionId) { + wxASSERT(!isServer); + tcSimState* simState = tcSimState::Get(); wxASSERT(simState); + + std::queue<long> missingIds; // queue to keep track of ids that are missing locally + + // Load time info from stream tcSimState::Get()->LoadTimeFromStream(stream); ! fprintf(stdout, "<< Received obj update msg, time %.1f: ", simState->GetTime()); long id; *************** *** 391,394 **** --- 446,450 ---- else { + missingIds.push(id); fprintf(stderr, "Error - HandleUpdate - obj %d not found\n", id); fprintf(stdout, "\n"); *************** *** 397,400 **** --- 453,477 ---- } fprintf(stdout, "\n"); + + /** + ** if any missing ids occurred, send a create request message back to the server + **/ + if (!missingIds.empty()) + { + // Init ack message + tcStream createReqStream; + tcUpdateMessageHandler::InitializeMessage( + tcUpdateMessageHandler::CREATE_REQUEST, createReqStream); + fprintf(stdout, ">> Sending create request msg, time %.1f, ids: ", simState->GetTime()); + while (missingIds.empty()) + { + long id = missingIds.front(); + missingIds.pop(); + tcUpdateMessageHandler::AddCreateRequest(id, createReqStream); + fprintf(stdout, "%d ", id); + } + tcMultiplayerInterface::Get()->SendUpdateMessage(connectionId, createReqStream); + fprintf(stdout, "\n"); + } } Index: tcConnectionData.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcConnectionData.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcConnectionData.cpp 13 Apr 2004 21:37:41 -0000 1.5 --- tcConnectionData.cpp 2 May 2004 16:22:45 -0000 1.6 *************** *** 37,40 **** --- 37,56 ---- /** + * @return total number of bytes read from this connection + */ + unsigned long tcConnectionData::GetReadCount() const + { + return readCount; + } + + /** + * @return total number of bytes written to this connection + */ + unsigned long tcConnectionData::GetWriteCount() const + { + return writeCount; + } + + /** * Attempts to read next whole message. If message is incomplete, the partial * message is returned to the socket read buffer. This method does not block. *************** *** 100,107 **** --- 116,126 ---- readQueueTCP.push(bufferIdx); + readCount += message->GetMessageSize(); #ifdef _DEBUG + /* fprintf(stdout, " Received message, size: %d, id:%d, t:%d data:%s\n", message->GetMessageSize(), message->GetMessageId(), message->GetMessageTimestamp(), testString.c_str()); + */ #endif *************** *** 145,152 **** readQueueUDP.push(bufferIdx); fprintf(stdout, " Received UDP message, size: %d, id:%d, t:%d\n", ! message->GetMessageSize(), message->GetMessageId(), ! message->GetMessageTimestamp()); ! } --- 164,173 ---- readQueueUDP.push(bufferIdx); + /* fprintf(stdout, " Received UDP message, size: %d, id:%d, t:%d\n", ! message->GetMessageSize(), message->GetMessageId(), ! message->GetMessageTimestamp()); ! */ ! readCount += message->GetMessageSize(); } *************** *** 228,233 **** if (message->bufferIdx >= message->data.header.messageSize) { ! fprintf(stdout,"Sent message, size:%d, id:%d, t:%d\n", ! message->GetMessageSize(), message->GetMessageId(), tcTime::Get30HzCount()); writeQueueTCP.pop(); networkInterface->ReturnMessage(bufferId); --- 249,255 ---- if (message->bufferIdx >= message->data.header.messageSize) { ! //fprintf(stdout,"Sent message, size:%d, id:%d, t:%d\n", ! // message->GetMessageSize(), message->GetMessageId(), tcTime::Get30HzCount()); ! writeCount += message->GetMessageSize(); writeQueueTCP.pop(); networkInterface->ReturnMessage(bufferId); *************** *** 279,284 **** } ! fprintf(stdout,"Sent UDP packet to %s, size:%d, id:%d, t:%d\n", ! peerName.c_str(), message->GetMessageSize(), message->GetMessageId(), tcTime::Get30HzCount()); writeQueueUDP.pop(); --- 301,307 ---- } ! writeCount += message->GetMessageSize(); ! //fprintf(stdout,"Sent UDP packet to %s, size:%d, id:%d, t:%d\n", ! // peerName.c_str(), message->GetMessageSize(), message->GetMessageId(), tcTime::Get30HzCount()); writeQueueUDP.pop(); *************** *** 296,299 **** --- 319,324 ---- idString = "Err"; id = -1; + readCount = 0; + writeCount = 0; } Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcMultiplayerInterface.cpp 1 May 2004 21:49:06 -0000 1.12 --- tcMultiplayerInterface.cpp 2 May 2004 16:22:45 -0000 1.13 *************** *** 44,47 **** --- 44,65 ---- /** + * Erases map entry for id. Used to force server to resend + * create message for id. + */ + void tcPlayerStatus::EraseEntry(long id) + { + std::map<long, double>::iterator iter; + + if (id == -1) return; + + iter = lastUpdate.find(id); + if (iter == lastUpdate.end()) + { + return; + } + lastUpdate.erase(iter); // erase entry + } + + /** * Gets time of last update to player for a game object * @param updateTime set to last updateTime for obj id Index: tcNetworkInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcNetworkInterface.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tcNetworkInterface.cpp 23 Apr 2004 00:15:17 -0000 1.10 --- tcNetworkInterface.cpp 2 May 2004 16:22:45 -0000 1.11 *************** *** 161,168 **** if (connectionIdx >= GetNumConnections()) return "Error"; float dt_sec = (1.0f/30.0f)* ! (float)(tcTime::Get30HzCount() - connectionData[connectionIdx].timestamp); ! wxString status = wxString::Format("%s (%.0f)", ! connectionData[connectionIdx].idString.c_str(), dt_sec); return status.c_str(); } --- 161,173 ---- if (connectionIdx >= GetNumConnections()) return "Error"; + tcConnectionData& connData = connectionData[connectionIdx]; + float dt_sec = (1.0f/30.0f)* ! (float)(tcTime::Get30HzCount() - connData.timestamp); ! unsigned long bytesIn = connData.GetReadCount(); ! unsigned long bytesOut = connData.GetWriteCount(); ! ! wxString status = wxString::Format("%s (%.0f) %07d %07d", ! connData.idString.c_str(), dt_sec, bytesIn, bytesOut); return status.c_str(); } *************** *** 364,369 **** void tcNetworkInterface::OnSocketEvent(wxSocketEvent& event) { ! std::cout << "Socket event: "; ! switch(event.GetSocketEvent()) { --- 369,376 ---- void tcNetworkInterface::OnSocketEvent(wxSocketEvent& event) { ! #ifdef _DEBUG ! // std::cout << "Socket event: "; ! #endif ! switch(event.GetSocketEvent()) { *************** *** 373,377 **** { #ifdef _DEBUG ! std::cout << "wxSOCKET_INPUT - UDP"; #endif RouteUDP(); --- 380,384 ---- { #ifdef _DEBUG ! // std::cout << "wxSOCKET_INPUT - UDP"; #endif RouteUDP(); *************** *** 380,384 **** { #ifdef _DEBUG ! std::cout << "wxSOCKET_INPUT - TCP"; #endif int connectionIdx = LookupConnectionIndex(event.m_id); --- 387,391 ---- { #ifdef _DEBUG ! // std::cout << "wxSOCKET_INPUT - TCP"; #endif int connectionIdx = LookupConnectionIndex(event.m_id); *************** *** 393,406 **** break; case wxSOCKET_LOST: ! std::cout << "wxSOCKET_LOST"; break; case wxSOCKET_CONNECTION: ! std::cout << "wxSOCKET_CONNECTION"; break; default: ! std::cout << "Unexpected event!"; break; } - std::cout << std::endl; } --- 400,412 ---- break; case wxSOCKET_LOST: ! std::cout << "wxSOCKET_LOST" << std::endl; break; case wxSOCKET_CONNECTION: ! std::cout << "wxSOCKET_CONNECTION" << std::endl; break; default: ! std::cout << "Unexpected event!" << std::endl; break; } } *************** *** 584,589 **** #ifdef _DEBUG ! fprintf(stdout, " Received UDP from %s, size: %d, data: %s\n", ! peerName.c_str(), readCount, (char*)buff); #endif --- 590,595 ---- #ifdef _DEBUG ! // fprintf(stdout, " Received UDP from %s, size: %d, data: %s\n", ! // peerName.c_str(), readCount, (char*)buff); #endif |