Changeset 3202 for code/branches/netp5/src/network/Client.cc
- Timestamp:
- Jun 21, 2009, 12:27:19 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp5/src/network/Client.cc
r3198 r3202 50 50 #include "FunctionCallManager.h" 51 51 52 // #include "packet/Acknowledgement.h"53 54 52 namespace orxonox 55 53 { 56 // SetConsoleCommandShortcut(Client, chat);57 54 58 55 … … 61 58 * initializes the address and the port to default localhost:NETWORK_PORT 62 59 */ 63 Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){ 64 // set server address to localhost 65 isConnected=false; 66 isSynched_=false; 67 gameStateFailure_=false; 60 Client::Client(): 61 isSynched_(false), 62 gameStateFailure_(false) 63 { 68 64 } 69 65 … … 73 69 * @param port port of the application on the server 74 70 */ 75 Client::Client(const std::string& address, int port) : client_connection(port, address){ 76 isConnected=false; 77 isSynched_=false; 78 gameStateFailure_=false; 79 } 80 81 /** 82 * Constructor for the Client class 83 * @param address the server address 84 * @param port port of the application on the server 85 */ 86 Client::Client(const char *address, int port) : client_connection(port, address){ 87 isConnected=false; 88 isSynched_=false; 89 gameStateFailure_=false; 71 Client::Client(const std::string& address, int port): 72 isSynched_(false), 73 gameStateFailure_(false) 74 { 90 75 } 91 76 92 77 Client::~Client(){ 93 if (isConnected)78 if ( ClientConnection::isConnected() ) 94 79 closeConnection(); 95 80 } … … 101 86 bool Client::establishConnection(){ 102 87 Synchronisable::setClient(true); 103 isConnected=client_connection.createConnection(); 104 if(!isConnected) 105 COUT(1) << "could not create connection laber" << std::endl; 106 return isConnected; 88 return ClientConnection::establishConnection(); 107 89 } 108 90 … … 112 94 */ 113 95 bool Client::closeConnection(){ 114 isConnected=false; 115 return client_connection.closeConnection(); 96 return ClientConnection::closeConnection(); 116 97 } 117 98 118 99 bool Client::queuePacket(ENetPacket *packet, int clientID){ 119 return client_connection.addPacket(packet); 100 bool b = ClientConnection::addPacket(packet); 101 assert(b); 102 return b; 120 103 } 121 104 … … 143 126 //this steers our network frequency 144 127 timeSinceLastUpdate_+=time.getDeltaTime(); 145 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 128 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 129 { 146 130 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 147 131 // COUT(3) << "."; 148 if(client_connection.isConnected() && isSynched_){ 132 if ( isConnected() && isSynched_ ) 133 { 149 134 COUT(4) << "popping partial gamestate: " << std::endl; 150 135 packet::Gamestate *gs = gamestate.getGamestate(); … … 159 144 } 160 145 } 146 sendPackets(); // flush the enet queue 161 147 162 ENetEvent *event; 163 // stop if the packet queue is empty 164 while(!(client_connection.queueEmpty())){ 165 event = client_connection.getEvent(); 166 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 167 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 168 // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler 169 bool b = packet->process(); 170 assert(b); 171 delete event; 172 } 148 Connection::processQueue(); 173 149 if(gamestate.processGamestates()) 174 150 {
Note: See TracChangeset
for help on using the changeset viewer.