[Gcblue-commits] gcb_wx/src/network tcMessage.cpp, 1.12, 1.13 tcMultiplayerInterface.cpp, 1.36, 1.
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-11-27 00:46:42
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv3929/src/network Modified Files: tcMessage.cpp tcMultiplayerInterface.cpp tcUpdateMessageHandler.cpp Log Message: Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** tcUpdateMessageHandler.cpp 23 Mar 2006 01:11:02 -0000 1.19 --- tcUpdateMessageHandler.cpp 27 Nov 2006 00:46:39 -0000 1.20 *************** *** 30,33 **** --- 30,34 ---- #include "network/tcUpdateMessageHandler.h" #include "network/tcMultiplayerInterface.h" + #include "network/tcMessage.h" #include "tcSimState.h" #include "wxcommands.h" *************** *** 113,127 **** /** * Saves data to create obj to stream. */ ! void tcUpdateMessageHandler::AddCreate(tcGameObject* obj, tcCreateStream& stream) { ! stream << obj->mnID; ! stream << obj->mnDBKey; ! *obj >> stream; ! tcCommandStream& commandStream = stream.AsCommandStream(); ! commandStream.SetDetailLevel(tcStream::WRITE_ALL); ! *obj >> commandStream; } --- 114,147 ---- /** * Saves data to create obj to stream. + * + * @return true if create was added, false if a size limit was hit and needs to be added again */ ! bool tcUpdateMessageHandler::AddCreate(tcGameObject* obj, tcCreateStream& stream) { ! long freeSpace = (long)stream.GetMaxSize() - (long)stream.size(); ! if (freeSpace < 1) return false; ! // temporary stream for command data ! tcCommandStream tempCommand; ! tempCommand.SetDetailLevel(tcStream::WRITE_ALL); ! *obj >> tempCommand; ! freeSpace -= (long)tempCommand.size(); ! if (freeSpace < 1) return false; ! ! // temporary create stream ! tcCreateStream temp; ! temp.SetMaxSize(size_t(freeSpace)); ! temp.SetDoneFlag(true); ! ! temp << obj->mnID; ! temp << obj->mnDBKey; ! *obj >> temp; + if (temp.size() > temp.GetMaxSize()) return false; // too big, don't add + + stream << temp; + stream << tempCommand; + + return temp.GetDoneFlag(); } *************** *** 196,204 **** * Saves update data for obj to stream. Obj must be * created first for this data to be applied. * @see tcUpdateMessageHandler::AddCreate */ ! void tcUpdateMessageHandler::AddUpdate(tcGameObject* obj, tcUpdateStream& stream) { ! stream << obj->mnID; // write id /** --- 216,227 ---- * Saves update data for obj to stream. Obj must be * created first for this data to be applied. + * @return true if update was added, false if a size limit was hit and needs to be added again + * * @see tcUpdateMessageHandler::AddCreate */ ! bool tcUpdateMessageHandler::AddUpdate(tcGameObject* obj, tcUpdateStream& stream) { ! long freeSpace = (long)stream.GetMaxSize() - (long)stream.size() - sizeof(long) - sizeof(unsigned int); ! if (freeSpace < 1) return false; /** *************** *** 211,217 **** --- 234,246 ---- */ tcUpdateStream temp; + temp.SetMaxSize(size_t(freeSpace)); + temp.SetDoneFlag(true); *obj >> temp; + if (temp.size() > temp.GetMaxSize()) return false; // too big, don't add + + stream << obj->mnID; // write id + unsigned int updateSize = temp.size(); *************** *** 219,222 **** --- 248,253 ---- stream << temp; + + return temp.GetDoneFlag(); } *************** *** 257,264 **** break; default: ! fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type\n"); break; } } --- 288,299 ---- break; default: ! fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type (%d)\n", ! messageType); break; } + size_t maxSize = tcMessage::MESSAGE_SIZE - stream.size(); + stream.SetMaxSize(maxSize); + } Index: tcMessage.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMessage.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcMessage.cpp 23 Mar 2006 01:11:02 -0000 1.12 --- tcMessage.cpp 27 Nov 2006 00:46:39 -0000 1.13 *************** *** 121,126 **** if (messageSize > tcMessage::MESSAGE_SIZE) { ! std::cerr << "Error - Attempted to send oversized message, truncating." << std::endl; ! wxMessageBox("Error - Attempted to send oversized message, truncating."); messageSize = tcMessage::MESSAGE_SIZE; } --- 121,129 ---- if (messageSize > tcMessage::MESSAGE_SIZE) { ! wxString text; ! text.Printf("Error - Attempted to send oversized message (%d/%d), truncating.\n", ! messageSize, tcMessage::MESSAGE_SIZE); ! fprintf(stderr, text.c_str()); ! wxMessageBox(text); messageSize = tcMessage::MESSAGE_SIZE; } Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** tcMultiplayerInterface.cpp 24 Oct 2006 01:34:05 -0000 1.36 --- tcMultiplayerInterface.cpp 27 Nov 2006 00:46:39 -0000 1.37 *************** *** 1804,1808 **** --- 1804,1837 ---- } + unsigned int tcMultiplayerInterface::GetUpdatePeriod(const tcGameObject* obj, const std::string& playerName) const + { + bool playerControlled = obj->IsControlledBy(playerName); + const tcFlightOpsObject* flightOps = dynamic_cast<const tcFlightOpsObject*>(obj); + bool largeFlightOps = (flightOps == 0) ? false : (flightOps->CurrentAirComplementSize() > 8); + + if (!playerControlled) + { + if (!largeFlightOps) + { + return 90; + } + else + { + return 90; + } + } + else + { + if (!largeFlightOps) + { + return 25; + } + else + { + return 50; + } + } + } /** *************** *** 1841,1857 **** { unsigned int dt = t - lastUpdate; ! bool doUpdate = (dt >= 90) || ! ((dt >= 25) && (obj->IsControlledBy(playerName))); if (doUpdate) { ! tcUpdateMessageHandler::AddUpdate(obj, updateStream); pstatus.SetUpdate(obj->mnID, t); - updateCount++; } // create new message if updateCount gets too large ! if ((updateCount >= 4) || (updateStream.size() > maxMessageSize - 512)) { SendUpdateMessage(connId, updateStream); --- 1870,1922 ---- { unsigned int dt = t - lastUpdate; ! ! bool doUpdate = (dt >= GetUpdatePeriod(obj, playerName)); ! if (doUpdate) { ! bool updateAdded = tcUpdateMessageHandler::AddUpdate(obj, updateStream); ! ! if (updateAdded) ! { ! updateCount++; ! } ! else ! { ! bool updating = true; ! unsigned messageCount = 0; ! while (updating && (messageCount < 8)) ! { ! SendUpdateMessage(connId, updateStream); ! #ifdef _DEBUG ! fprintf(stdout, "Sent obj state update, time: %d\n", t); ! #endif ! updateStream.clear(); ! tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::UPDATE, ! updateStream); ! ! updating = !tcUpdateMessageHandler::AddUpdate(obj, updateStream); ! messageCount++; ! } ! ! if (messageCount >= 8) ! { ! fprintf(stderr, "tcMultiplayerInterface::UpdateNewAndExistingEntities - " ! "exceeded partial update msg limit (%s)\n", obj->mzUnit.c_str()); ! } ! else ! { ! #ifdef _DEBUG ! fprintf(stdout, " partial update msg count: %d\n", messageCount); ! #endif ! } ! updateCount = 1; ! } pstatus.SetUpdate(obj->mnID, t); } // create new message if updateCount gets too large ! if (updateCount >= 6) { SendUpdateMessage(connId, updateStream); *************** *** 1867,1879 **** else { ! tcUpdateMessageHandler::AddCreate(obj, createStream); // set time to force update at next opportunity pstatus.SetUpdate(obj->mnID, (unsigned int)(t-90)); ! createCount++; #ifdef _DEBUG fprintf(stdout, "C%d ", obj->mnID); #endif ! if ((createCount >= 8) || (createStream.size() > maxMessageSize - 1024)) { SendUpdateMessage(connId, createStream); --- 1932,1982 ---- else { ! bool createAdded = tcUpdateMessageHandler::AddCreate(obj, createStream); ! ! if (createAdded) ! { ! createCount++; ! } ! else ! { ! bool updating = true; ! unsigned messageCount = 0; ! while (updating && (messageCount < 8)) ! { ! SendUpdateMessage(connId, createStream); ! #ifdef _DEBUG ! fprintf(stdout, "Sent obj create msg, time: %d\n", t); ! #endif ! createStream.clear(); ! tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::CREATE, ! createStream); ! ! updating = !tcUpdateMessageHandler::AddCreate(obj, createStream); ! messageCount++; ! } ! ! if (messageCount >= 8) ! { ! fprintf(stderr, "tcMultiplayerInterface::UpdateNewAndExistingEntities - " ! "exceeded partial create msg limit (%s)\n", obj->mzUnit.c_str()); ! } ! else ! { ! #ifdef _DEBUG ! fprintf(stdout, " partial create msg count: %d\n", messageCount); ! #endif ! } ! ! createCount = 1; ! } ! // set time to force update at next opportunity pstatus.SetUpdate(obj->mnID, (unsigned int)(t-90)); ! #ifdef _DEBUG fprintf(stdout, "C%d ", obj->mnID); #endif ! if (createCount >= 8) { SendUpdateMessage(connId, createStream); |