Changeset 7671 in orxonox.OLD for branches/network/src/lib/network/message_manager.cc
- Timestamp:
- May 18, 2006, 10:48:17 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/message_manager.cc
r7631 r7671 20 20 using namespace std; 21 21 22 MessageManager* MessageManager::singletonRef = NULL; 23 22 24 23 25 /** … … 35 37 MessageManager::~MessageManager () 36 38 { 39 for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ ) 40 { 41 for ( std::list<NetworkMessage>::iterator it2 = it->second.messages.begin(); it2 != it->second.messages.end(); it2++ ) 42 { 43 if ( it2->data ) 44 { 45 delete it2->data; 46 it2->data = NULL; 47 } 48 } 49 50 it->second.messages.clear(); 51 it->second.toAck.clear(); 52 } 53 54 messageQueue.clear(); 37 55 } 38 56 … … 40 58 * get the diff to last acked state of userId 41 59 * 42 * each synchrinizeable defines its own stack of states received and sent over the network. The stack contains 43 * a per user entry for the last sent/received state This function returns a delta compressed state of the 44 * synchronizeable. This state will be transmitted over the network to the other participants 60 * this class does not use the normal SynchronizeableVars for zynchronisation. instead 61 * it defines its own protocol 45 62 * 46 63 * @param userId user to create diff for … … 54 71 int MessageManager::getStateDiff( int userId, byte * data, int maxLength, int stateId, int fromStateId, int priorityTH ) 55 72 { 73 int i = 0; 74 int n; 75 76 n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength ); 77 i += n; 78 assert( n == INTSIZE ); 79 80 for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++) 81 { 82 n = Converter::intToByteArray( *it, data + i, maxLength ); 83 i += n; 84 assert( n == INTSIZE ); 85 } 86 87 messageQueue[userId].toAck.clear(); 88 89 n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength ); 90 i += n; 91 assert( n == INTSIZE ); 92 93 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 94 { 95 n = Converter::intToByteArray( it->length, data + i, maxLength ); 96 i += n; 97 assert( n == INTSIZE ); 98 99 n = Converter::intToByteArray( it->number, data + i, maxLength ); 100 i += n; 101 assert( n == INTSIZE ); 102 103 n = Converter::intToByteArray( it->messageId, data + i, maxLength ); 104 i += n; 105 assert( n == INTSIZE ); 106 107 assert( i + it->length <= maxLength ); 108 memcpy( data + i, it->data, it->length ); 109 i += it->length; 110 } 111 112 return i; 56 113 } 57 114 … … 68 125 int MessageManager::setStateDiff( int userId, byte * data, int length, int stateId, int fromStateId ) 69 126 { 127 int i = 0; 128 int n; 129 130 int nAcks; 131 132 n = Converter::byteArrayToInt( data + i, &nAcks ); 133 assert( n == INTSIZE ); 134 i += n; 135 136 std::list<int> acks; 137 138 int number; 139 140 for ( int j = 0; j < nAcks; j++ ) 141 { 142 n = Converter::byteArrayToInt( data + i, &number ); 143 assert( n == INTSIZE ); 144 i += n; 145 146 acks.push_back( number ); 147 } 148 149 int nMessages; 150 151 n = Converter::byteArrayToInt( data + i, &nMessages ); 152 assert( n == INTSIZE ); 153 i += n; 154 155 for ( int j = 0; j < nMessages; j++ ) 156 { 157 } 70 158 } 71 159 … … 77 165 { 78 166 } 167 168 /** 169 * registers function to handle messages with id messageId. someData is passed to callbackfuntion 170 * @param messageId message id to handle 171 * @param cb function pointer to callback function 172 * @param someData this pointer is passed to callback function without modification 173 * @return true on success 174 */ 175 bool MessageManager::registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData ) 176 { 177 } 178 179 /** 180 * initializes buffers for user 181 * @param userId userId 182 */ 183 void MessageManager::initUser( int userId ) 184 { 185 }
Note: See TracChangeset
for help on using the changeset viewer.