Changeset 3214 for code/trunk/src/network/Client.cc
- Timestamp:
- Jun 23, 2009, 6:02:25 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Client.cc
r3198 r3214 39 39 // 40 40 41 #include "Client.h" 42 41 43 #include <cassert> 42 #include <enet/enet.h>43 44 44 #include " Client.h"45 #include " Host.h"45 #include "util/Debug.h" 46 #include "core/Clock.h" 46 47 #include "synchronisable/Synchronisable.h" 47 #include "core/Clock.h" 48 #include "core/CoreIncludes.h" 49 #include "packet/Packet.h" 48 #include "packet/Chat.h" 49 #include "packet/Gamestate.h" 50 50 #include "FunctionCallManager.h" 51 52 // #include "packet/Acknowledgement.h"53 51 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 { 75 setPort( port ); 76 setServerAddress( address ); 90 77 } 91 78 92 79 Client::~Client(){ 93 if (isConnected)80 if ( ClientConnection::isConnected() ) 94 81 closeConnection(); 95 82 } … … 101 88 bool Client::establishConnection(){ 102 89 Synchronisable::setClient(true); 103 isConnected=client_connection.createConnection(); 104 if(!isConnected) 105 COUT(1) << "could not create connection laber" << std::endl; 106 return isConnected; 90 return ClientConnection::establishConnection(); 107 91 } 108 92 … … 112 96 */ 113 97 bool Client::closeConnection(){ 114 isConnected=false; 115 return client_connection.closeConnection(); 98 return ClientConnection::closeConnection(); 116 99 } 117 100 118 101 bool Client::queuePacket(ENetPacket *packet, int clientID){ 119 return client_connection.addPacket(packet); 102 bool b = ClientConnection::addPacket(packet); 103 assert(b); 104 return b; 120 105 } 121 106 … … 143 128 //this steers our network frequency 144 129 timeSinceLastUpdate_+=time.getDeltaTime(); 145 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 130 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 131 { 146 132 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 147 133 // COUT(3) << "."; 148 if(client_connection.isConnected() && isSynched_){ 134 if ( isConnected() && isSynched_ ) 135 { 149 136 COUT(4) << "popping partial gamestate: " << std::endl; 150 137 packet::Gamestate *gs = gamestate.getGamestate(); … … 159 146 } 160 147 } 148 sendPackets(); // flush the enet queue 161 149 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 } 150 Connection::processQueue(); 173 151 if(gamestate.processGamestates()) 174 152 {
Note: See TracChangeset
for help on using the changeset viewer.