[Gcblue-commits] gcb_wx/src/network tcMultiplayerInterface.cpp,1.13,1.14 tcUpdateMessageHandler.cpp,
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-05-08 21:25:35
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19946/src/network Modified Files: tcMultiplayerInterface.cpp tcUpdateMessageHandler.cpp Log Message: Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcUpdateMessageHandler.cpp 2 May 2004 16:22:45 -0000 1.6 --- tcUpdateMessageHandler.cpp 8 May 2004 21:25:26 -0000 1.7 *************** *** 87,90 **** --- 87,99 ---- /** + * Adds header information to sensor update stream + * Currently this is just an alliance field + */ + void tcUpdateMessageHandler::AddSensorUpdateHeader(long alliance, tcStream& stream) + { + stream << alliance; + } + + /** * Saves update data for obj to stream. Obj must be * created first for this data to be applied. *************** *** 122,125 **** --- 131,136 ---- case DESTROY: break; + case SENSOR_UPDATE: + break; default: fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type\n"); *************** *** 149,152 **** --- 160,164 ---- case UPDATE: case DESTROY: + case SENSOR_UPDATE: fprintf(stderr, "tcUpdateMessageHandler::Handle - " "illegal msg type for server (%d)\n", messageType); *************** *** 210,213 **** --- 222,232 ---- } break; + case SENSOR_UPDATE: + { + tcUpdateStream stream((const char*)data, messageSize); + stream >> messageType; + HandleSensorUpdate(stream); + } + break; default: fprintf(stderr, "tcUpdateMessageHandler::Handle - " *************** *** 292,297 **** else { ! fprintf(stderr, "Error - HandleCommandUpdate - obj %d not found\n", id); ! fprintf(stdout, "\n"); return; } --- 311,315 ---- else { ! fprintf(stdout, "%d (unknown)\n", id); return; } *************** *** 412,415 **** --- 430,466 ---- } + + /** + * Handle SENSOR_UPDATE update message (client only) + */ + void tcUpdateMessageHandler::HandleSensorUpdate(tcUpdateStream& stream) + { + tcSimState* simState = tcSimState::Get(); + wxASSERT(simState); + + long alliance; + stream >> alliance; + if ((alliance < 0) || (alliance > 255)) + { + fprintf(stderr, "Error - HandleSensorUpdate - Alliance out of range (%d)\n", + alliance); + return; + } + fprintf(stdout, "<< Received sensor update msg, time %.1f, alliance %d\n", + simState->GetTime(), alliance); + + tcSensorMap* sensorMap = simState->GetSensorMap(); + tcAllianceSensorMap* allianceSensorMap = sensorMap->GetOrCreateMap(alliance); + + if (allianceSensorMap) + { + *allianceSensorMap << stream; + } + else + { + fprintf(stderr, "Error - HandleSensorUpdate - NULL alliance sensor map\n"); + } + } + /** * Handle UPDATE update message (client only) Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcMultiplayerInterface.cpp 2 May 2004 16:22:45 -0000 1.13 --- tcMultiplayerInterface.cpp 8 May 2004 21:25:26 -0000 1.14 *************** *** 587,590 **** --- 587,591 ---- * This must be called regularly to perform network functions. * (avoids need for multithreadeding) + * Need to clean this up to better isolate server vs. client processing */ void tcMultiplayerInterface::Update() *************** *** 601,604 **** --- 602,610 ---- UpdateObjects(); + if (IsServer()) + { + UpdateSensorMaps(); + } + /* update time when paused only. This is redundant ** with obj state update which also has time info, but is *************** *** 919,922 **** --- 925,995 ---- } + /** + * Send sensor map update for player at connIdx + */ + void tcMultiplayerInterface::UpdateSensorMap(unsigned connIdx) + { + tcUpdateStream stream; + tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::SENSOR_UPDATE, stream); + + int connId = GetConnectionId(connIdx); + tcPlayerStatus& pstatus = GetPlayerStatus(connId); + int alliance = pstatus.alliance; + + tcUpdateMessageHandler::AddSensorUpdateHeader(alliance, stream); + size_t initialStreamSize = stream.size(); + + tcSimState* simState = tcSimState::Get(); + wxASSERT(simState); + + tcSensorMap* sensorMap = simState->GetSensorMap(); + wxASSERT(sensorMap); + + tcAllianceSensorMap* allianceSensorMap = sensorMap->GetMap(alliance); + + if (allianceSensorMap) + { + *allianceSensorMap >> stream; + if (stream.size() > initialStreamSize) + { + SendUpdateMessage(connId, stream); + fprintf(stdout, ">> sensormap update msg sent, connId (%d) size (%d)\n", + connId, stream.size()); + } + } + else + { + fprintf(stderr, "Error - tcMultiplayerInterface::UpdateSensorMap - " + "NULL allianceSensorMap\n"); + } + + } + + /** + * Periodically send sensor updates to clients + */ + void tcMultiplayerInterface::UpdateSensorMaps() + { + wxASSERT(IsServer()); + + static double lastUpdate = -1; + + tcSimState* simState = tcSimState::Get(); + wxASSERT(simState); + + double t = simState->GetTime(); + + if (t < lastUpdate + 0.5) return; + + lastUpdate = t; + + unsigned nConnections = GetNumConnections(); + + for (unsigned n=0;n<nConnections;n++) + { + UpdateSensorMap(n); + } + + } /** |