Changeset 1248
- Timestamp:
- May 8, 2008, 11:53:58 AM (17 years ago)
- Location:
- code/branches/network3/src/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/Client.cc
r1246 r1248 84 84 // set server address to localhost 85 85 isConnected=false; 86 test_once=false;86 isSynched_=false; 87 87 } 88 88 … … 94 94 Client::Client(std::string address, int port) : client_connection(port, address){ 95 95 isConnected=false; 96 test_once=false;96 isSynched_=false; 97 97 } 98 98 … … 104 104 Client::Client(const char *address, int port) : client_connection(port, address){ 105 105 isConnected=false; 106 test_once=false;106 isSynched_=false; 107 107 } 108 108 … … 229 229 */ 230 230 void Client::tick(float time){ 231 if(client_connection.isConnected() ){231 if(client_connection.isConnected() && isSynched_){ 232 232 COUT(4) << "popping partial gamestate: " << std::endl; 233 233 GameStateCompressed *gs = gamestate.popPartialGameState(); … … 246 246 packet = client_connection.getPacket(); 247 247 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 248 if(!test_once){ 249 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 250 } 248 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 251 249 } 252 250 if(!client_connection.sendPackets()) … … 256 254 257 255 void Client::processGamestate( GameStateCompressed *data, int clientID){ 258 if(!test_once){ 259 int id = data->id; 260 COUT(5) << "received gamestate id: " << data->id << std::endl; 261 if(gamestate.pushGameState(data)){ 262 client_connection.addPacket(pck_gen.acknowledgement(id)); 256 int id = data->id; 257 COUT(5) << "received gamestate id: " << data->id << std::endl; 258 if(gamestate.pushGameState(data)){ 259 if(!isSynched_) 260 isSynched_=true; 261 client_connection.addPacket(pck_gen.acknowledgement(id)); 263 262 // we do this at the end of a tick 264 // if(!client_connection.sendPackets()) 265 // COUT(2) << "Could not send acknowledgment" << std::endl; 266 } 267 // test_once=true; 263 if(!client_connection.sendPackets()) 264 COUT(2) << "Could not send acknowledgment" << std::endl; 268 265 } 269 266 } … … 275 272 id->setNetworkID(clid->clid); 276 273 COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl; 274 delete clid; 277 275 return; 278 276 } … … 280 278 void Client::processChat( chat *data){ 281 279 COUT(0) << "Server: " << data->message << std::endl; 280 delete[] data->message; 281 delete data; 282 282 } 283 283 … … 286 286 clientID_ = w->clientID; 287 287 shipID_ = w->shipID; 288 delete w; 288 289 return true; 289 290 } -
code/branches/network3/src/network/Client.h
r1245 r1248 101 101 GameStateClient gamestate; 102 102 bool isConnected; 103 bool isSynched_; 103 104 104 105 // implement data processing functions of PacketDecoder … … 109 110 int clientID_; // this is the id the server gave to us 110 111 int shipID_; 111 bool test_once;112 112 }; 113 113 -
code/branches/network3/src/network/GameStateManager.cc
r1246 r1248 261 261 } 262 262 263 delete[] state->data;264 delete state;265 263 return true; 266 264 } -
code/branches/network3/src/network/PacketDecoder.cc
r1245 r1248 90 90 return false; 91 91 } 92 93 // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function 92 94 93 95 //following are the decode functions for the data of the packets … … 101 103 COUT(4) << "PacketDecoder: got ack id: " << a->a << std::endl; 102 104 processAck( a, clientId ); //debug info 103 104 105 //clean memory 105 106 enet_packet_destroy( packet ); … … 121 122 //clean memory 122 123 enet_packet_destroy( packet ); 123 124 124 printMouse( mouseMove ); //debug info 125 125 } … … 132 132 //clean memory 133 133 enet_packet_destroy( packet ); 134 135 134 printKey( key ); //debug info 136 135 … … 232 231 { 233 232 printChat(data, clientId); 233 delete[] data->message; 234 delete data; 234 235 } 235 236 236 237 void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID ) 237 238 { 238 COUT( 5) << "PacketDecoder: processing Gamestate" << std::endl;239 COUT(3) << "PacketDecoder-process: processing Gamestate" << std::endl; 239 240 //printGamestate( state ); 241 delete[] state->data; 242 delete state; 240 243 } 241 244 … … 243 246 { 244 247 printClassid(cid); 248 delete cid; 245 249 return; 246 250 } … … 249 253 { 250 254 printAck(data); 255 delete data; 251 256 return; 252 257 } 253 258 254 259 bool PacketDecoder::processWelcome( welcome *w ){ 260 delete w; 255 261 return true; 256 262 } … … 258 264 bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){ 259 265 COUT(3) << "packetdecoder: processing connectRequest" << std::endl; 266 delete con; 260 267 return true; 261 268 } -
code/branches/network3/src/network/PacketGenerator.cc
r1232 r1248 58 58 59 59 ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable ); 60 60 delete ackreq; 61 61 return packet; 62 62 } … … 71 71 memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int)); 72 72 memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength); 73 return enet_packet_create(stream, dataLength+2*sizeof(int), reliable); 73 ENetPacket *packet = enet_packet_create(stream, dataLength+2*sizeof(int), reliable); 74 delete[] stream; // TODO: we could also tell enet not to copy the data, but to use the exisiting memory 75 return packet; 74 76 } 75 77 … … 84 86 85 87 ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable ); 86 88 delete mousemove; 87 89 return packet; 88 90 } … … 97 99 98 100 ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable ); 99 101 delete key; 100 102 return packet; 101 103 } … … 109 111 memcpy( &trans[1], (const void*)message, strlen( message ) + 1); 110 112 ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable ); 111 113 delete[] trans; 112 114 return packet; 113 115 } … … 136 138 COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl; 137 139 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 138 //deletedata;140 delete[] data; 139 141 return packet; 140 142 } … … 150 152 memcpy( (void *)(data+3*sizeof(int)), classname.c_str(), classname.length()+1); 151 153 ENetPacket *packet = enet_packet_create( data , 3*sizeof(int)+classname.length()+1, reliable ); 154 delete[] data; 152 155 return packet; 153 156 } … … 160 163 wc->allowed = true; 161 164 ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable); 165 delete wc; 162 166 return packet; 163 167 } … … 166 170 connectRequest *con = new connectRequest; 167 171 con->id=CONNECT; 168 return enet_packet_create( con, sizeof(connectRequest), reliable); 172 ENetPacket *packet = enet_packet_create( con, sizeof(connectRequest), reliable); 173 delete con; 174 return packet; 169 175 } 170 176 -
code/branches/network3/src/network/Server.cc
r1246 r1248 232 232 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 233 233 connection->createClient(clientID); 234 delete con; 234 235 return true; 235 236 } … … 239 240 if(!gamestates->pushGameState(data, clientID)) 240 241 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 242 delete[] data->data; 243 delete data; 241 244 } 242 245 -
code/branches/network3/src/network/Synchronisable.cc
r1245 r1248 166 166 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 167 167 if( ((*i)->mode & state_) == 0 ){ 168 COUT( 4) << "not getting data: " << std::endl;168 COUT(5) << "not getting data: " << std::endl; 169 169 continue; // this variable should only be received 170 170 }
Note: See TracChangeset
for help on using the changeset viewer.