- Timestamp:
- Jul 28, 2010, 8:29:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/libraries/network/Client.cc
r6417 r7161 50 50 #include "FunctionCallManager.h" 51 51 #include "core/CoreIncludes.h" 52 #include "core/CommandLineParser.h" 52 53 #include "core/Game.h" 54 #include "core/ScopedSingletonManager.h" 53 55 54 56 namespace orxonox 55 57 { 56 58 59 ManageScopedSingleton( Client, ScopeID::Root, true ); 57 60 58 61 /** … … 61 64 */ 62 65 Client::Client(): 66 gamestate(0), 63 67 isSynched_(false), 64 68 gameStateFailure_(false), 65 69 timeSinceLastUpdate_(0) 66 70 { 67 } 68 69 /** 70 * Constructor for the Client class 71 * @param address the server address 72 * @param port port of the application on the server 73 */ 74 Client::Client(const std::string& address, int port): 75 isSynched_(false), 76 gameStateFailure_(false), 77 timeSinceLastUpdate_(0) 78 { 79 setPort( port ); 80 setServerAddress( address ); 81 } 82 83 Client::~Client(){ 71 this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") ); 72 } 73 74 Client::~Client() 75 { 84 76 if ( ClientConnection::isConnected() ) 85 77 closeConnection(); … … 90 82 * @return true/false 91 83 */ 92 bool Client::establishConnection(){ 84 bool Client::establishConnection() 85 { 93 86 Synchronisable::setClient(true); 94 return ClientConnection::establishConnection(); 87 this->gamestate = new GamestateClient(); 88 if( ClientConnection::establishConnection() ) 89 { 90 Host::setActive(true); 91 return true; 92 } 93 else 94 return false; 95 95 } 96 96 … … 99 99 * @return true/false 100 100 */ 101 bool Client::closeConnection(){ 101 bool Client::closeConnection() 102 { 103 assert(this->gamestate); 104 delete this->gamestate; 105 this->gamestate = 0; 106 Host::setActive(false); 102 107 return ClientConnection::closeConnection(); 103 108 } 104 105 bool Client::queuePacket(ENetPacket *packet, int clientID){ 109 110 void Client::setDestination(const std::string& serverAddress, unsigned int port) 111 { 112 ClientConnection::setServerAddress(serverAddress); 113 ClientConnection::setPort(port); 114 } 115 116 bool Client::queuePacket(ENetPacket *packet, int clientID) 117 { 106 118 bool b = ClientConnection::addPacket(packet); 107 119 assert(b); … … 109 121 } 110 122 111 bool Client::processChat(const std::string& message, unsigned int playerID){ 123 bool Client::processChat(const std::string& message, unsigned int playerID) 124 { 112 125 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 113 126 return true; 114 127 } 115 128 116 void Client::printRTT(){ 129 void Client::printRTT() 130 { 117 131 COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl; 118 132 } … … 123 137 * @return result(true/false) 124 138 */ 125 bool Client::chat(const std::string& message){ 139 bool Client::chat(const std::string& message) 140 { 126 141 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 127 142 return m->send(); … … 133 148 * @param time 134 149 */ 135 void Client::update(const Clock& time){ 150 void Client::update(const Clock& time) 151 { 136 152 //this steers our network frequency 137 153 timeSinceLastUpdate_+=time.getDeltaTime(); … … 143 159 { 144 160 COUT(4) << "popping partial gamestate: " << std::endl; 145 packet::Gamestate *gs = gamestate .getGamestate();161 packet::Gamestate *gs = gamestate->getGamestate(); 146 162 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 147 163 if(gs){ … … 157 173 158 174 Connection::processQueue(); 159 if(gamestate .processGamestates())175 if(gamestate->processGamestates()) 160 176 { 161 177 if(!isSynched_) 162 178 isSynched_=true; 163 179 } 164 gamestate .cleanup();180 gamestate->cleanup(); 165 181 Connection::sendPackets(); 166 182 … … 184 200 } 185 201 202 203 186 204 }
Note: See TracChangeset
for help on using the changeset viewer.