- Timestamp:
- Dec 18, 2007, 5:51:47 PM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Client.cc
r601 r620 189 189 190 190 void Client::processGamestate( GameStateCompressed *data){ 191 gamestate.pushGameState( *data);191 gamestate.pushGameState(data); 192 192 client_connection.addPacket(pck_gen.acknowledgement(data->id)); 193 193 client_connection.sendPackets(); -
code/branches/FICN/src/network/ClientConnection.cc
r605 r620 148 148 while(!quit){ 149 149 //std::cout << "connection loop" << std::endl; 150 if(enet_host_service(client, &event, NETWORK_ WAIT_TIMEOUT)<0){150 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){ 151 151 // we should never reach this point 152 152 quit=true; … … 157 157 case ENET_EVENT_TYPE_CONNECT: 158 158 case ENET_EVENT_TYPE_RECEIVE: 159 std::cout << "got packet" << std::endl;159 //std::cout << "got packet" << std::endl; 160 160 processData(&event); 161 161 break; … … 180 180 ENetEvent event; 181 181 enet_peer_disconnect(server, 0); 182 while(enet_host_service(client, &event, NETWORK_ WAIT_TIMEOUT) > 0){182 while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){ 183 183 switch (event.type) 184 184 { … … 204 204 return false; 205 205 // handshake 206 if(enet_host_service(client, &event, NETWORK_ WAIT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){206 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){ 207 207 established=true; 208 208 return true; … … 213 213 214 214 bool ClientConnection::processData(ENetEvent *event){ 215 std::cout << "got packet, pushing to queue" << std::endl;215 //std::cout << "got packet, pushing to queue" << std::endl; 216 216 // just add packet to the buffer 217 217 // this can be extended with some preprocessing -
code/branches/FICN/src/network/ClientConnection.h
r605 r620 28 28 #define NETWORK_PORT 55556 29 29 #define NETWORK_CLIENT_MAX_CONNECTIONS 5 30 #define NETWORK_ WAIT_TIMEOUT 530 #define NETWORK_CLIENT_TIMEOUT 5 31 31 #define NETWORK_SEND_WAIT 5 32 32 #define NETWORK_CLIENT_CHANNELS 2 -
code/branches/FICN/src/network/ClientInformation.cc
r514 r620 190 190 ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards){ 191 191 ClientInformation *temp = this; 192 if (temp->head) 193 temp=temp->next(); 192 194 while(temp!=0 && temp->getID()!=clientID){ 193 if (temp->head)194 continue;195 195 temp = temp->next(); 196 196 } -
code/branches/FICN/src/network/ConnectionManager.cc
r514 r620 200 200 break; 201 201 case ENET_EVENT_TYPE_DISCONNECT: 202 std::cout << "disconnecting client" << std::endl; 202 203 delete head_->findClient(&(event.peer->address)); 203 204 temp = temp->next(); … … 227 228 bool ConnectionManager::addClient(ENetEvent *event){ 228 229 ClientInformation *temp = head_->insertBack(new ClientInformation); 229 temp->setID(temp->prev()->getID()+1); 230 if(temp->prev()->head) 231 temp->setID(1); 232 else 233 temp->setID(temp->prev()->getID()+1); 230 234 temp->setPeer(event->peer); 231 235 std::cout << "added client id: " << temp->prev()->getID() << std::endl; -
code/branches/FICN/src/network/GameStateClient.cc
r567 r620 39 39 } 40 40 41 bool GameStateClient::pushGameState(GameStateCompressed compstate){42 if(compstate .diffed)43 return loadSnapshot(decode(reference, compstate));41 bool GameStateClient::pushGameState(GameStateCompressed *compstate){ 42 if(compstate->diffed) 43 return loadSnapshot(decode(reference, *compstate)); 44 44 else 45 return loadSnapshot(decode( compstate));45 return loadSnapshot(decode(*compstate)); 46 46 } 47 47 … … 65 65 { 66 66 unsigned char *data=state.data; 67 std::cout << "loadSnapshot: loading gs: " << state.id << std::endl; 67 68 // get the start of the Synchronisable list 68 69 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); … … 71 72 while(data < state.data+state.size){ 72 73 // prepare the syncData struct 73 sync.length = *(int *)data;74 sync.length = (int)*data; 74 75 data+=sizeof(int); 75 sync.objectID = *(int *)data;76 sync.objectID = (int)*data; 76 77 data+=sizeof(int); 77 sync.classID = *(int *)data;78 sync.classID = (int)*data; 78 79 data+=sizeof(int); 79 80 sync.data = data; … … 150 151 151 152 switch ( retval ) { 152 case Z_OK: std::cout << "successfully compressed" << std::endl; break;153 case Z_OK: std::cout << "successfully decompressed" << std::endl; break; 153 154 case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break; 154 155 case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break; -
code/branches/FICN/src/network/GameStateClient.h
r505 r620 28 28 GameStateClient(); 29 29 ~GameStateClient(); 30 bool pushGameState(GameStateCompressed compstate);30 bool pushGameState(GameStateCompressed *compstate); 31 31 private: 32 32 bool loadSnapshot(GameState state); -
code/branches/FICN/src/network/GameStateManager.cc
r599 r620 61 61 GameStateCompressed GameStateManager::popGameState(int clientID){ 62 62 int gID = head_->findClient(clientID)->getGamestateID(); 63 std::cout << "popgamestate: sending gstate id: " << gID << std::endl; 63 64 if(gID!=GAMESTATEID_INITIAL){ 64 65 GameState *client = gameStateMap[gID]; 65 66 GameState *server = reference; 66 67 return encode(client, server); 67 } 68 GameState *server = reference; 69 return encode(server); 70 // return an undiffed gamestate and set appropriate flags 68 } else { 69 GameState *server = reference; 70 head_->findClient(clientID)->setGamestateID(id); 71 return encode(server); 72 // return an undiffed gamestate and set appropriate flags 73 } 71 74 } 72 75 … … 101 104 // go through all Synchronisables 102 105 for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){ 106 //std::cout << "gamestatemanager: in for loop" << std::endl; 103 107 //get size of the synchronisable 104 108 tempsize=it->getSize(); … … 127 131 128 132 GameStateCompressed GameStateManager::encode(GameState *a, GameState *b){ 129 GameState r = diff(a,b); 130 r.diffed = true; 133 //GameState r = diff(a,b); 134 //r.diffed = true; 135 GameState r = *b; 136 r.diffed = false; 131 137 return compress_(&r); 132 138 } … … 170 176 171 177 GameStateCompressed GameStateManager::compress_(GameState *a) { 172 COUT(2) << "compressing gamestate" << std::endl;178 //COUT(2) << "compressing gamestate" << std::endl; 173 179 int size = a->size; 174 180 uLongf buffer = (uLongf)((a->size + 12)*1.01)+1; … … 181 187 case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break; 182 188 case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break; 183 case Z_DATA_ERROR: std::cout << "d ata corrupted" << std::endl; break;189 case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break; 184 190 } 185 191 -
code/branches/FICN/src/network/PacketDecoder.cc
r531 r620 88 88 *a = *(ack*)packet->data; //press pattern of ack on new data 89 89 90 //clean memory 91 enet_packet_destroy( packet ); 92 93 printAck( a ); //debug info 90 91 processAck( a, clientId ); //debug info 92 93 //clean memory 94 enet_packet_destroy( packet ); 94 95 } 95 96 … … 143 144 unsigned char* data = (unsigned char*)packet->data; 144 145 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 145 memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 146 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 147 currentState->id = (int)*(data+sizeof(int)); 146 148 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 147 149 //position of the data stream, data+2*sizeof( int ) 148 memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) ); 150 // memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) ); 151 currentState->compsize = (int)*(data+2*sizeof(int)); 149 152 //size of uncompressed data 150 memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) ); 153 // memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) ); 154 currentState->normsize = (int)*(data+3*sizeof(int)); 151 155 //since the packetgenerator was changed, due to a new parameter, change this function too 152 memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool)); 156 // memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool)); 157 currentState->diffed = (bool)*(data+4*sizeof(int)); 153 158 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 154 159 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 160 if(currentState->data==NULL) 161 std::cout << "memory leak" << std::endl; 155 162 //copy the GameStateCompressed data 163 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; 164 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl; 156 165 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 157 166 … … 160 169 //run processGameStateCompressed 161 170 //TODO: not yet implemented! 162 //processGamestate(currentState);171 processGamestate(currentState); 163 172 } 164 173 … … 181 190 } 182 191 192 void PacketDecoder::processGamestate( GameStateCompressed *state ){ 193 194 } 195 183 196 void PacketDecoder::processClassid( classid *cid){ 184 197 printClassid(cid); … … 186 199 } 187 200 201 void PacketDecoder::processAck( ack *data, int clientID){ 202 printAck(data); 203 return; 204 } 188 205 189 206 -
code/branches/FICN/src/network/PacketGenerator.cc
r514 r620 98 98 ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable ) 99 99 { 100 int* gid = new int; 101 *gid = GAMESTATE; //first assign the correct enet id 100 int gid = GAMESTATE; //first assign the correct enet id 102 101 int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory 103 unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 104 memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id 105 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id 106 //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream 107 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int)); 102 unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 103 memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id 104 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id 105 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int)); 106 memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int)); 107 memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool)); 108 /*(int)*(data) = gid; 109 (int)*(data+sizeof(int)) = states->id; 110 //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream 111 (int)*(data+2*sizeof(int)) = states->compsize; 108 112 //this is the uncompressed size of GameStateCompressed data 109 memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));113 (int)*(data+3*sizeof(int)) = states->normsize; 110 114 //since there is a new parameter inside GameStateCompressed, change this function to create packet 111 memcpy( (void*)(data+4*sizeof(int)), (const void*)states->diffed, sizeof(bool)); 115 (bool)*(data+4*sizeof(int)) = states->diffed;*/ 112 116 //place the GameStateCompressed data at the end of the enet datastream 113 117 memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize ); 114 118 //create an enet packet with the generated bytestream 115 119 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 116 120 //delete data; 117 121 return packet; 118 122 } -
code/branches/FICN/src/network/PacketManager.h
r531 r620 66 66 //process data 67 67 //two functions are note yet implemented! 68 //virtual void processGamestate(GameState *state); 68 virtual void processGamestate(GameStateCompressed *state); 69 virtual void processAck( ack *data, int clientID); 69 70 void processClassid( classid *cid); 70 71 //virtual void processAck( ack *data); -
code/branches/FICN/src/network/Server.cc
r607 r620 144 144 std::cout << "doing gamestate" << std::endl; 145 145 int id = temp->getID(); 146 std::cout << "server, got ID: " << id << std::endl; 146 147 GameStateCompressed *gs = &(gamestates->popGameState(id)); 147 148 std::cout << "adding gamestate" << std::endl; … … 157 158 } 158 159 160 void Server::processAck( ack *data, int clientID){ 161 clients->findClient(clientID)->setGamestateID(data->id); 162 } 159 163 160 164 } -
code/branches/FICN/src/network/Server.h
r477 r620 18 18 #include "ConnectionManager.h" 19 19 #include "PacketManager.h" 20 #include "PacketTypes.h" 20 21 #include "GameStateManager.h" 21 22 #include "ClientInformation.h" … … 46 47 private: 47 48 bool sendGameState(); 49 void processAck( ack *data, int clientID); 48 50 ConnectionManager *connection; 49 51 GameStateManager *gamestates;
Note: See TracChangeset
for help on using the changeset viewer.