Changeset 1245
- Timestamp:
- May 7, 2008, 4:39:42 PM (17 years ago)
- Location:
- code/branches/network3/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/Client.cc
r1233 r1245 84 84 // set server address to localhost 85 85 isConnected=false; 86 test_once=false; 86 87 } 87 88 … … 93 94 Client::Client(std::string address, int port) : client_connection(port, address){ 94 95 isConnected=false; 96 test_once=false; 95 97 } 96 98 … … 102 104 Client::Client(const char *address, int port) : client_connection(port, address){ 103 105 isConnected=false; 106 test_once=false; 104 107 } 105 108 … … 226 229 */ 227 230 void Client::tick(float time){ 231 if(client_connection.isConnected()){ 232 COUT(4) << "popping partial gamestate: " << std::endl; 233 GameStateCompressed *gs = gamestate.popPartialGameState(); 234 if(gs){ 235 COUT(4) << "client tick: sending gs " << gs << std::endl; 236 if(client_connection.addPacket(pck_gen.gstate(gs))) 237 if(!client_connection.sendPackets()) 238 COUT(3) << "Problem sending partial gamestate" << std::endl; 239 // now delete it to save memory 240 delete [] gs->data; 241 delete gs; 242 } 243 } 228 244 ENetPacket *packet; 229 245 // stop if the packet queue is empty … … 231 247 packet = client_connection.getPacket(); 232 248 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 233 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 249 if(!test_once){ 250 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 251 } 234 252 } 235 253 return; 236 254 } 237 255 238 void Client::processGamestate( GameStateCompressed *data){ 239 int id = data->id; 240 COUT(5) << "received gamestate id: " << data->id << std::endl; 241 if(gamestate.pushGameState(data)){ 242 client_connection.addPacket(pck_gen.acknowledgement(id)); 243 if(!client_connection.sendPackets()) 244 COUT(2) << "Could not send acknowledgment" << std::endl; 256 void Client::processGamestate( GameStateCompressed *data, int clientID){ 257 if(!test_once){ 258 int id = data->id; 259 COUT(5) << "received gamestate id: " << data->id << std::endl; 260 if(gamestate.pushGameState(data)){ 261 client_connection.addPacket(pck_gen.acknowledgement(id)); 262 if(!client_connection.sendPackets()) 263 COUT(2) << "Could not send acknowledgment" << std::endl; 264 } 265 // test_once=true; 245 266 } 246 267 } … … 263 284 clientID_ = w->clientID; 264 285 shipID_ = w->shipID; 265 286 return true; 266 287 } 267 288 -
code/branches/network3/src/network/Client.h
r1232 r1245 103 103 104 104 // implement data processing functions of PacketDecoder 105 void processGamestate( GameStateCompressed *data );105 void processGamestate( GameStateCompressed *data, int clientID); 106 106 void processClassid(classid *clid); 107 107 void processChat( chat *data); … … 109 109 int clientID_; // this is the id the server gave to us 110 110 int shipID_; 111 bool test_once; 111 112 }; 112 113 -
code/branches/network3/src/network/ClientConnection.h
r1168 r1245 76 76 bool sendPackets(ENetEvent *event); 77 77 bool waitEstablished(int milisec); 78 bool isConnected(){return established;} 78 79 private: 79 80 bool processData(ENetEvent *event); -
code/branches/network3/src/network/ConnectionManager.cc
r1234 r1245 165 165 enet_initialize(); 166 166 atexit(enet_deinitialize); 167 ENetEvent event;167 ENetEvent *event = new ENetEvent; 168 168 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 169 169 if(server==NULL){ … … 174 174 175 175 while(!quit){ 176 if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){176 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 177 177 // we should never reach this point 178 178 quit=true; 179 179 // add some error handling here ======================== 180 180 } 181 switch(event .type){181 switch(event->type){ 182 182 // log handling ================ 183 183 case ENET_EVENT_TYPE_CONNECT: 184 addClient( &event);184 addClient(event); 185 185 //this is a workaround to ensure thread safety 186 186 /*if(!addFakeConnectRequest(&event)) … … 191 191 //std::cout << "received data" << std::endl; 192 192 COUT(5) << "Con.Man: receive event has occured" << std::endl; 193 processData( &event);193 processData(event); 194 194 break; 195 195 case ENET_EVENT_TYPE_DISCONNECT: 196 // add some error/log handling here 197 clientDisconnect(event.peer); 196 clientDisconnect(event->peer); 198 197 break; 199 198 case ENET_EVENT_TYPE_NONE: 200 199 break; 201 200 } 201 // usleep(1000); 202 //yield(); //TODO: find apropriate 202 203 } 203 204 disconnectClients(); … … 246 247 bool ConnectionManager::clientDisconnect(ENetPeer *peer) { 247 248 COUT(4) << "removing client from list" << std::endl; 248 return head_->removeClient(peer);249 return removeClient(head_->findClient(&(peer->address))->getID()); 249 250 } 250 251 /** … … 311 312 sendWelcome(temp->getID(), temp->getShipID(), true); 312 313 return true; 314 } 315 316 bool ConnectionManager::removeClient(int clientID){ 317 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 318 while(it){ 319 if(it->objectID!=head_->findClient(clientID)->getShipID()){ 320 ++it; 321 continue; 322 } 323 orxonox::Iterator<orxonox::SpaceShip> temp=it; 324 ++it; 325 delete *temp; 326 return head_->removeClient(clientID); 327 } 328 return false; 313 329 } 314 330 … … 335 351 336 352 client->setShipID(no->objectID); 337 no->getFocus();338 353 return true; 339 354 } … … 342 357 addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID); 343 358 sendPackets(); 359 return true; 344 360 } 345 361 -
code/branches/network3/src/network/ConnectionManager.h
r1232 r1245 89 89 private: 90 90 bool clientDisconnect(ENetPeer *peer); 91 bool removeClient(int clientID); 91 92 bool processData(ENetEvent *event); 92 93 bool addClient(ENetEvent *event); -
code/branches/network3/src/network/GameStateClient.cc
r1232 r1245 166 166 167 167 GameState *GameStateClient::getPartialSnapshot(){ 168 169 GameState *reference; 170 // std::map<int, GameState*>::iterator it = --gameStateMap.end(); 171 // reference=(--gameStateMap.end())->second; 172 168 173 //std::cout << "begin getSnapshot" << std::endl; 169 174 //the size of the gamestate … … 178 183 179 184 GameState *retval=new GameState; //return value 180 retval->id=reference->id; 185 // retval->id=reference->id; 186 if(gameStateMap.size()!=0) 187 retval->id=(--gameStateMap.end())->second->id; 181 188 retval->diffed=false; 182 189 retval->complete=false; … … 190 197 size+=it->getSize(); // size of the actual data of the synchronisable 191 198 size+=3*sizeof(int); // size of datasize, classID and objectID 199 COUT(4) << "getpartialsnapshot: size: " << size << std::endl; 192 200 } 193 201 //retval->data = (unsigned char*)malloc(size); -
code/branches/network3/src/network/GameStateClient.h
r1232 r1245 70 70 void printGameStateMap(); 71 71 72 GameState *reference;73 72 int last_diff_; 74 73 std::map<int, GameState *> gameStateMap; -
code/branches/network3/src/network/GameStateManager.cc
r1233 r1245 106 106 if(gID != GAMESTATEID_INITIAL){ 107 107 // TODO something with the gamestatemap is wrong 108 GameState *client = gameStateMap.find(gID)->second; 108 GameState *client=NULL; 109 std::map<int, GameState*>::iterator it = gameStateMap.find(gID); 110 if(it!=gameStateMap.end()) 111 client = it->second; 109 112 GameState *server = reference; 110 113 //head_->findClient(clientID)->setGamestateID(id); … … 203 206 204 207 bool GameStateManager::loadPartialSnapshot(GameState *state, int clientID){ 208 if(!state) 209 return false; 205 210 unsigned char *data=state->data; 206 211 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; … … 219 224 sync.data = data; 220 225 data+=sync.length; 221 226 COUT(4) << "objectID: " << sync.objectID << " classID: " << sync.classID << std::endl; 222 227 while(it && it->objectID!=sync.objectID) 223 228 ++it; … … 226 231 if(!it){ 227 232 // the object does not exist yet 233 COUT(4) << "loadsnapshot: creating new object " << std::endl; 228 234 //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; 229 235 orxonox::Identifier* id = ID((unsigned int)sync.classID); … … 244 250 }else{ 245 251 // we have our object 252 COUT(4) << "loadpartialsnapshot: we found the appropriate object" << std::endl; 246 253 if(checkAccess(clientID, sync.objectID)){ 247 254 if(! it->updateData(sync)) … … 396 403 //std::cout << "length " << length << std::endl; 397 404 switch ( retval ) { 398 case Z_OK: COUT( 4) << "successfully decompressed" << std::endl; break;405 case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break; 399 406 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL; 400 407 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL; … … 444 451 bool GameStateManager::checkAccess(int clientID, int objectID){ 445 452 // currently we only check, wheter the object is the clients spaceship 446 return head_->findClient(objectID)->getShipID()==objectID; 453 // return head_->findClient(objectID)->getShipID()==objectID; 454 return true; // TODO: change this 447 455 } 448 456 -
code/branches/network3/src/network/PacketDecoder.cc
r1233 r1245 78 78 return true; 79 79 case GAMESTATE: 80 gstate( packet );80 gstate( packet, clientId ); 81 81 return true; 82 82 case CLASSID: … … 155 155 } 156 156 157 void PacketDecoder::gstate( ENetPacket* packet )157 void PacketDecoder::gstate( ENetPacket* packet, int clientID ) 158 158 { 159 159 GameStateCompressed* currentState = NULL; … … 190 190 //clean memory 191 191 enet_packet_destroy( packet ); 192 processGamestate(currentState );192 processGamestate(currentState, clientID); 193 193 } 194 194 … … 234 234 } 235 235 236 void PacketDecoder::processGamestate( GameStateCompressed *state )236 void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID ) 237 237 { 238 238 COUT(5) << "PacketDecoder: processing Gamestate" << std::endl; -
code/branches/network3/src/network/PacketManager.h
r1232 r1245 91 91 void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 92 92 void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 93 void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );94 void gstate( ENetPacket* packet );93 void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 94 void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); 95 95 void clid( ENetPacket *packet); 96 96 bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); … … 99 99 //process data 100 100 //two functions are note yet implemented! 101 virtual void processGamestate(GameStateCompressed *state );101 virtual void processGamestate(GameStateCompressed *state, int clientID); 102 102 virtual void processAck( ack *data, int clientID); 103 103 virtual void processClassid( classid *cid); -
code/branches/network3/src/network/Server.cc
r1232 r1245 143 143 updateGamestate(); 144 144 145 usleep(200000); // TODO remove145 // usleep(500000); // TODO remove 146 146 return; 147 147 } … … 228 228 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 229 229 connection->createClient(clientID); 230 return true; 231 } 232 233 void Server::processGamestate( GameStateCompressed *data, int clientID){ 234 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; 235 if(!gamestates->pushGameState(data, clientID)) 236 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 237 // delete[] data->data; 238 // delete data; 230 239 } 231 240 -
code/branches/network3/src/network/Server.h
r1232 r1245 74 74 void processAck( ack *data, int clientID); 75 75 bool processConnectRequest( connectRequest *con, int clientID ); 76 void processGamestate( GameStateCompressed *data, int clientID); 76 77 ConnectionManager *connection; 77 78 GameStateManager *gamestates; -
code/branches/network3/src/network/Synchronisable.cc
r1232 r1245 50 50 51 51 52 int Synchronisable::state_= 1; // detemines wheter we are server (default) or client52 int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client 53 53 54 54 /** … … 165 165 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 166 166 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 167 if( ((*i)->mode & state_) == 0 ) 167 if( ((*i)->mode & state_) == 0 ){ 168 COUT(4) << "not getting data: " << std::endl; 168 169 continue; // this variable should only be received 170 } 169 171 switch((*i)->type){ 170 172 case DATA: … … 199 201 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl; 200 202 for(i=syncList->begin(); i!=syncList->end(); i++){ 201 if( ((*i)->mode ^ state_) == 0 ) 202 continue; // this variable should only be sent 203 if( ((*i)->mode ^ state_) == 0 ){ 204 COUT(5) << "synchronisable: not updating variable " << std::endl; 205 continue; // this variable should only be updated 206 } 203 207 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 204 208 switch((*i)->type){ -
code/branches/network3/src/orxonox/objects/SpaceShip.cc
r1234 r1245 104 104 this->setRotationAxis(1, 0, 0); 105 105 this->setStatic(false); 106 /*107 this->moveForward_ = 0;108 this->rotateUp_ = 0;109 this->rotateDown_ = 0;110 this->rotateRight_ = 0;111 this->rotateLeft_ = 0;112 this->loopRight_ = 0;113 this->loopLeft_ = 0;114 this->brakeForward_ = 0;115 this->brakeRotate_ = 0;116 this->brakeLoop_ = 0;117 this->speedForward_ = 0;118 this->speedRotateUpDown_ = 0;119 this->speedRotateRightLeft_ = 0;120 this->speedLoopRightLeft_ = 0;121 this->maxSpeedForward_ = 0;122 this->maxSpeedRotateUpDown_ = 0;123 this->maxSpeedRotateRightLeft_ = 0;124 this->maxSpeedLoopRightLeft_ = 0;125 this->accelerationForward_ = 0;126 this->accelerationRotateUpDown_ = 0;127 this->accelerationRotateRightLeft_ = 0;128 this->accelerationLoopRightLeft_ = 0;129 130 this->speed = 250;131 this->loop = 100;132 this->rotate = 10;133 this->mouseX = 0;134 this->mouseY = 0;135 this->maxMouseX = 0;136 this->minMouseX = 0;137 this->moved = false;138 139 this->brakeRotate(rotate*10);140 this->brakeLoop(loop);141 */142 // this->create();143 106 144 107 … … 161 124 162 125 void SpaceShip::registerAllVariables(){ 163 registerVar( &camName_, camName_.length()+1, network::STRING); 126 registerVar( &camName_, camName_.length()+1, network::STRING, 0x1); 127 registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); 128 registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); 129 registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); 130 registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); 131 registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); 132 registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); 133 registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); 134 registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); 135 registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); 136 164 137 } 165 138 166 139 void SpaceShip::init() 167 140 { 168 COUT(4) << "================ \t\t\t\tspaceship::init" << std::endl;141 // COUT(4) << "================ \t\t\t\tspaceship::init" << std::endl; 169 142 // START CREATING THRUSTER 170 143 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 197 170 this->greenNode_->setInheritScale(false); 198 171 199 COUT(4) << "attaching red billboard" << std::endl;172 // COUT(4) << "attaching red billboard" << std::endl; 200 173 this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); 201 174 this->redNode_->setScale(0.3, 0.3, 0.3); 202 175 203 COUT(4) << "attaching green billboard" << std::endl;176 // COUT(4) << "attaching green billboard" << std::endl; 204 177 this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); 205 178 this->greenNode_->setScale(0.3, 0.3, 0.3); … … 215 188 this->chFarNode_->setInheritScale(false); 216 189 217 COUT(4) << "attaching crosshair near billboard" << std::endl;190 // COUT(4) << "attaching crosshair near billboard" << std::endl; 218 191 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 219 192 this->chNearNode_->setScale(0.2, 0.2, 0.2); 220 193 221 COUT(4) << "attaching crosshair far billboard" << std::endl;194 // COUT(4) << "attaching crosshair far billboard" << std::endl; 222 195 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 223 196 this->chFarNode_->setScale(0.4, 0.4, 0.4); 224 COUT(4) << "attaching camera" << std::endl;197 // COUT(4) << "attaching camera" << std::endl; 225 198 226 199 createCamera(); … … 237 210 void SpaceShip::loadParams(TiXmlElement* xmlElem) 238 211 { 239 COUT(4) << "using loadparams" << std::endl;212 // COUT(4) << "using loadparams" << std::endl; 240 213 Model::loadParams(xmlElem); 241 214 this->create(); … … 303 276 304 277 void SpaceShip::createCamera(){ 305 COUT(4) << "begin camera creation" << std::endl;278 // COUT(4) << "begin camera creation" << std::endl; 306 279 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 307 280 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; … … 313 286 cam->lookAt(Vector3(0,20,0)); 314 287 cam->roll(Degree(0)); 315 */ COUT(4) << "creating new camera" << std::endl;288 *//*COUT(4) << "creating new camera" << std::endl;*/ 316 289 cam_ = new Camera(this->camNode_); 317 COUT(4) << "setting target node" << std::endl;290 // COUT(4) << "setting target node" << std::endl; 318 291 cam_->setTargetNode(this->getNode()); 319 292 // this only applies to clients 320 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID) 293 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ 294 this->setBacksync(true); 321 295 CameraHandler::getInstance()->requestFocus(cam_); 296 } 322 297 // cam->setPosition(Vector3(0,-350,0)); 323 298 //cam->roll(Degree(-90)); 324 299 325 300 //this->camNode_->attachObject(cam); 326 COUT(4) << "created camera" << std::endl;301 // COUT(4) << "created camera" << std::endl; 327 302 } 328 303 … … 460 435 { 461 436 // only do this if not client TODO: remove this hack 462 if ( !network::Client::getSingleton() && InputManager::getSingleton().getMouse()->getEventCallback() != this)437 if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID ) && InputManager::getSingleton().getMouse()->getEventCallback() != this) 463 438 { 464 439 if (InputManager::getSingleton().getMouse()) … … 485 460 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 486 461 { 487 new Projectile(this); 462 Projectile *p = new Projectile(this); 463 p->setBacksync(true); 488 464 this->timeToReload_ = this->reloadTime_; 489 465 } … … 560 536 561 537 if(!network::Client::getSingleton() || network::Client::getSingleton()->getShipID() == objectID){ 538 COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl; 562 539 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 563 540 this->acceleration_.x = this->translationAcceleration_; … … 580 557 else 581 558 this->momentum_ = 0; 582 } 559 }/*else 560 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 583 561 584 562 WorldEntity::tick(dt); -
code/branches/network3/src/orxonox/objects/WorldEntity.cc
r1232 r1245 81 81 if (!this->bStatic_) 82 82 { 83 // COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl; 83 84 this->velocity_ += (dt * this->acceleration_); 84 85 this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); … … 222 223 //register acceleration 223 224 // register velocity_ 224 registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);225 registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);226 registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);225 // registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3); 226 // registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3); 227 // registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3); 227 228 } 228 229
Note: See TracChangeset
for help on using the changeset viewer.