Changeset 912 for code/branches/network/src
- Timestamp:
- Mar 20, 2008, 4:04:52 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/GameStateClient.cc
r905 r912 40 40 41 41 bool GameStateClient::pushGameState(GameStateCompressed *compstate) { 42 GameState *gs; 42 43 if(compstate->diffed) 43 return loadSnapshot(decode(reference, compstate));44 gs = decode(reference, compstate); 44 45 else 45 return loadSnapshot(decode(compstate)); 46 gs = decode(compstate); 47 if(gs) 48 return loadSnapshot(gs); 49 COUT(4) << "could not use gamestate sent by server" << std::endl; 50 return false; 46 51 } 47 52 -
code/branches/network/src/network/PacketDecoder.cc
r891 r912 42 42 namespace network 43 43 { 44 using namespace std;45 44 46 45 PacketDecoder::PacketDecoder(){} … … 53 52 { 54 53 int client = clientId; 55 cout << "clientId: " << client <<endl; //control cout, not important, just debugging info54 COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info 56 55 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 57 56 COUT(5) << "packet id: " << id << std::endl; … … 145 144 void PacketDecoder::gstate( ENetPacket* packet ) 146 145 { 147 GameStateCompressed* currentState = new GameStateCompressed; 146 GameStateCompressed* currentState = NULL; 147 currentState = new GameStateCompressed; 148 if(currentState == NULL){ 149 COUT(3) << "could not generate new GameStateCompressed" << std::endl; 150 return; 151 } 148 152 //since it's not alowed to use void* for pointer arithmetic 149 unsigned char* data = (unsigned char *)packet->data;153 unsigned char* data = (unsigned char *)(packet->data); 150 154 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 151 155 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 152 currentState->id = (int)*( data+sizeof(int));156 currentState->id = (int)*(packet->data+sizeof(int)); 153 157 // std::cout << "id: " << currentState->id << std::endl; 154 158 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 155 159 //position of the data stream, data+2*sizeof( int ) 156 // memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );160 memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) ); 157 161 //currentState->compsize = (int)*(data+2*sizeof(int)); 158 162 // std::cout << "compsize: " << currentState->compsize << std::endl; 159 163 //size of uncompressed data 160 memcpy( (void*)&(currentState->normsize), (const void*)( data+3*sizeof( int )), sizeof( int ) );164 memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) ); 161 165 //currentState->normsize = (int)*(data+3*sizeof(int)); 162 166 // std::cout << "normsize. " << currentState->normsize << std::endl; 163 167 //since the packetgenerator was changed, due to a new parameter, change this function too 164 memcpy( (void*)&(currentState->diffed), (const void*)( data+4*sizeof(int)), sizeof(bool));168 memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool)); 165 169 //currentState->diffed = (bool)*(data+4*sizeof(int)); 166 170 // std::cout << "diffed: " << currentState->diffed << std::endl; 167 171 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 172 if(currentState->compsize==0) 173 COUT(2) << "compsize is 0" << std::endl; 168 174 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 169 175 if(currentState->data==NULL) … … 172 178 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; 173 179 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl; 174 memcpy( (void*)(currentState->data), (const void*)( data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );180 memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 175 181 176 182 //clean memory … … 222 228 void PacketDecoder::printAck( ack* data ) 223 229 { 224 COUT(5) << "data id: " << data->id << endl;225 COUT(5) << "data: " << data->a << endl;230 COUT(5) << "data id: " << data->id << std::endl; 231 COUT(5) << "data: " << data->a << std::endl; 226 232 } 227 233 228 234 void PacketDecoder::printMouse( mouse* data ) 229 235 { 230 COUT(5) << "data id: " << data->id << endl;231 COUT(5) << "data: " << data->x << " " << data->y << endl;236 COUT(5) << "data id: " << data->id << std::endl; 237 COUT(5) << "data: " << data->x << " " << data->y << std::endl; 232 238 } 233 239 234 240 void PacketDecoder::printKey( keyboard* data ) 235 241 { 236 COUT(5) << "data id: " << data->id << endl;237 COUT(5) << "data: " << (char)data->press << endl;242 COUT(5) << "data id: " << data->id << std::endl; 243 COUT(5) << "data: " << (char)data->press << std::endl; 238 244 } 239 245 … … 241 247 { 242 248 if(clientId!=CLIENTID_CLIENT) 243 COUT(5) << "client: " << clientId << endl;244 COUT(5) << "data id: " << data->id << endl;245 COUT(5) << "data: " << data->message << endl;249 COUT(5) << "client: " << clientId << std::endl; 250 COUT(5) << "data id: " << data->id << std::endl; 251 COUT(5) << "data: " << data->message << std::endl; 246 252 } 247 253 248 254 void PacketDecoder::printGamestate( GameStateCompressed* data ) 249 255 { 250 COUT(5) << "id of GameStateCompressed: " << data->id << endl;251 COUT(5) << "size of GameStateCompressed: " << data->compsize << endl;256 COUT(5) << "id of GameStateCompressed: " << data->id << std::endl; 257 COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl; 252 258 } 253 259 254 260 void PacketDecoder::printClassid( classid *cid) 255 261 { 256 COUT(5) << "id of classid: " << cid->id << endl;257 COUT(5) << "size of classid: " << cid->length << endl;258 COUT(5) << "ID of classid: " << cid->clid << endl;259 COUT(5) << "data of classid: " << cid->message << endl;262 COUT(5) << "id of classid: " << cid->id << std::endl; 263 COUT(5) << "size of classid: " << cid->length << std::endl; 264 COUT(5) << "ID of classid: " << cid->clid << std::endl; 265 COUT(5) << "data of classid: " << cid->message << std::endl; 260 266 } 261 267 -
code/branches/network/src/network/Server.cc
r907 r912 112 112 processQueue(); 113 113 updateGamestate(); 114 sleep(1); // TODO remove 114 115 return; 115 116 } … … 178 179 179 180 void Server::processAck( ack *data, int clientID) { 181 COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl; 180 182 clients->findClient(clientID)->setGamestateID(data->a); 181 183 }
Note: See TracChangeset
for help on using the changeset viewer.