Changeset 2965
- Timestamp:
- May 11, 2009, 1:42:10 PM (16 years ago)
- Location:
- code/branches/netp2/src/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp2/src/network/Client.cc
r2948 r2965 140 140 */ 141 141 void Client::tick(float time){ 142 // COUT(3) << "."; 143 if(client_connection.isConnected() && isSynched_){ 144 COUT(4) << "popping partial gamestate: " << std::endl; 145 packet::Gamestate *gs = gamestate.getGamestate(); 146 if(gs){ 147 COUT(4) << "client tick: sending gs " << gs << std::endl; 148 if( !gs->send() ) 149 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 142 //this steers our network frequency 143 timeSinceLastUpdate_+=time; 144 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 145 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 146 // COUT(3) << "."; 147 if(client_connection.isConnected() && isSynched_){ 148 COUT(4) << "popping partial gamestate: " << std::endl; 149 packet::Gamestate *gs = gamestate.getGamestate(); 150 if(gs){ 151 COUT(4) << "client tick: sending gs " << gs << std::endl; 152 if( !gs->send() ) 153 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 150 154 // gs gets automatically deleted by enet callback 155 } 156 FunctionCallManager::sendCalls(); 151 157 } 152 FunctionCallManager::sendCalls(); 158 ENetEvent *event; 159 // stop if the packet queue is empty 160 while(!(client_connection.queueEmpty())){ 161 event = client_connection.getEvent(); 162 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 163 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 164 // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler 165 bool b = packet->process(); 166 assert(b); 167 } 168 if(gamestate.processGamestates()) 169 { 170 if(!isSynched_) 171 isSynched_=true; 172 } 173 gamestate.cleanup(); 153 174 } 154 ENetEvent *event; 155 // stop if the packet queue is empty 156 while(!(client_connection.queueEmpty())){ 157 event = client_connection.getEvent(); 158 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 159 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 160 // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler 161 bool b = packet->process(); 162 assert(b); 163 } 164 if(gamestate.processGamestates()) 165 { 166 if(!isSynched_) 167 isSynched_=true; 168 } 169 gamestate.cleanup(); 175 170 176 return; 171 177 } -
code/branches/netp2/src/network/Client.h
r2773 r2965 88 88 89 89 bool gameStateFailure_; 90 float timeSinceLastUpdate_; 90 91 }; 91 92 -
code/branches/netp2/src/network/ClientConnection.cc
r2836 r2965 58 58 59 59 ClientConnection::ClientConnection(int port, const std::string& address) { 60 quit =false;60 quit_=false; 61 61 server=NULL; 62 62 serverAddress = new ENetAddress(); … … 67 67 68 68 ClientConnection::ClientConnection(int port, const char *address) { 69 quit =false;69 quit_=false; 70 70 server=NULL; 71 71 serverAddress = new ENetAddress(); … … 107 107 108 108 bool ClientConnection::closeConnection() { 109 quit =true;109 quit_=true; 110 110 //network_threads.join_all(); 111 111 receiverThread_->join(); … … 151 151 COUT(2) << "ClientConnection: could not create client host" << std::endl; 152 152 // add some error handling here ========================== 153 quit =true;153 quit_=true; 154 154 } 155 155 //connect to the server 156 156 if(!establishConnection()){ 157 157 COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl; 158 quit =true;158 quit_=true; 159 159 return; 160 160 } 161 161 event = new ENetEvent; 162 162 //main loop 163 while(!quit ){163 while(!quit_){ 164 164 //std::cout << "connection loop" << std::endl; 165 165 { … … 167 167 if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){ 168 168 // we should never reach this point 169 assert(0); 170 quit=true; 171 continue; 169 // assert(0); 170 printf("ClientConnection: ENet returned with an error!\n"); 171 quit_=true; 172 break; 172 173 // add some error handling here ======================== 173 174 } … … 185 186 break; 186 187 case ENET_EVENT_TYPE_DISCONNECT: 187 quit=true; 188 quit_=true; 189 printf("Received disconnect Packet from Server!\n"); 188 190 // server closed the connection 189 191 return; … … 235 237 } 236 238 // handshake 237 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit ){239 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){ 238 240 if( event.type == ENET_EVENT_TYPE_CONNECT ){ 239 241 established=true; -
code/branches/netp2/src/network/ClientConnection.h
r2836 r2965 54 54 const int NETWORK_CLIENT_MAX_CONNECTIONS = 5; 55 55 const int NETWORK_CLIENT_WAIT_TIME = 10; 56 const int NETWORK_CLIENT_CONNECT_TIMEOUT = 10000; // miliseconds56 const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds 57 57 const int NETWORK_CLIENT_CHANNELS = 2; 58 58 … … 76 76 //bool sendPackets(ENetEvent *event); 77 77 bool waitEstablished(int milisec); 78 bool isConnected(){return established;} 78 inline bool isConnected(){return established;} 79 inline bool checkConnection(){ return !quit_ && isConnected(); } 79 80 private: 80 81 ClientConnection(const ClientConnection& copy); // not used … … 90 91 ENetAddress *serverAddress; 91 92 // quit-variable (communication with threads) 92 bool quit ;93 bool quit_; 93 94 bool established; 94 95 // clientlist -
code/branches/netp2/src/network/ConnectionManager.cc
r2953 r2965 71 71 assert(instance_==0); 72 72 instance_=this; 73 quit =false;73 quit_=false; 74 74 bindAddress = new ENetAddress(); 75 75 bindAddress->host = ENET_HOST_ANY; … … 80 80 assert(instance_==0); 81 81 instance_=this; 82 quit =false;82 quit_=false; 83 83 bindAddress = new ENetAddress(); 84 84 bindAddress->host = ENET_HOST_ANY; … … 89 89 assert(instance_==0); 90 90 instance_=this; 91 quit =false;91 quit_=false; 92 92 bindAddress = new ENetAddress(); 93 93 enet_address_set_host (bindAddress, address.c_str()); … … 98 98 assert(instance_==0); 99 99 instance_=this; 100 quit =false;100 quit_=false; 101 101 bindAddress = new ENetAddress(); 102 102 enet_address_set_host (bindAddress, address); … … 105 105 106 106 ConnectionManager::~ConnectionManager(){ 107 if(!quit )107 if(!quit_) 108 108 quitListener(); 109 109 instance_=0; … … 129 129 130 130 bool ConnectionManager::quitListener() { 131 quit =true;131 quit_=true; 132 132 receiverThread_->join(); 133 133 return true; … … 185 185 if(server==NULL){ 186 186 // add some error handling here ========================== 187 quit =true;187 quit_=true; 188 188 return; 189 189 } 190 190 191 191 event = new ENetEvent; 192 while(!quit )192 while(!quit_) 193 193 { 194 194 { //mutex scope … … 196 196 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 197 197 // we should never reach this point 198 quit=true; 198 printf("ConnectionManager: ENet returned with an error\n"); 199 quit_=true; 199 200 continue; 200 201 printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh"); -
code/branches/netp2/src/network/ConnectionManager.h
r2836 r2965 81 81 void disconnectClient(ClientInformation *client); 82 82 void syncClassid(unsigned int clientID); 83 bool checkReceiverThread(){ return !quit_; } 83 84 84 85 private: … … 95 96 ENetAddress *bindAddress; 96 97 97 bool quit ; // quit-variable (communication with threads)98 bool quit_; // quit-variable (communication with threads) 98 99 99 100 boost::thread *receiverThread_; -
code/branches/netp2/src/network/Host.h
r2171 r2965 35 35 36 36 namespace orxonox { 37 38 const int CLIENTID_SERVER = 0; 39 const unsigned int NETWORK_FREQUENCY = 25; 40 const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY; 37 41 38 42 /** -
code/branches/netp2/src/network/Server.h
r2662 r2965 51 51 namespace orxonox 52 52 { 53 const int CLIENTID_SERVER = 0;54 const unsigned int NETWORK_FREQUENCY = 25;55 const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;56 53 57 54 /**
Note: See TracChangeset
for help on using the changeset viewer.