Changeset 1739
- Timestamp:
- Sep 8, 2008, 1:36:32 AM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1735 r1739 61 61 isSynched_=false; 62 62 gameStateFailure_=false; 63 isServer_ = false; 63 64 } 64 65 … … 72 73 isSynched_=false; 73 74 gameStateFailure_=false; 75 isServer_ = false; 74 76 } 75 77 … … 83 85 isSynched_=false; 84 86 gameStateFailure_=false; 87 isServer_ = false; 85 88 } 86 89 … … 151 154 if(client_connection.isConnected() && isSynched_){ 152 155 COUT(4) << "popping partial gamestate: " << std::endl; 153 /*packet::Gamestate *gs = gamestate.getGamestate();156 packet::Gamestate *gs = gamestate.getGamestate(); 154 157 if(gs){ 155 158 COUT(4) << "client tick: sending gs " << gs << std::endl; … … 157 160 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 158 161 // gs gets automatically deleted by enet callback 159 } */162 } 160 163 } 161 164 ENetEvent *event; … … 168 171 } 169 172 int gameStateID = gamestate.processGamestates(); 170 /*if(gameStateID==GAMESTATEID_INITIAL)173 if(gameStateID==GAMESTATEID_INITIAL) 171 174 if(gameStateFailure_){ 172 packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0);173 if(!ack .send())175 packet::Acknowledgement *ack = new packet::Acknowledgement(GAMESTATEID_INITIAL, 0); 176 if(!ack->send()) 174 177 COUT(3) << "could not (negatively) ack gamestate" << std::endl; 175 178 else … … 183 186 isSynched_=true; 184 187 gameStateFailure_=false; 185 packet::Acknowledgement ack(gameStateID, 0);186 if(!ack .send())188 packet::Acknowledgement *ack = new packet::Acknowledgement(gameStateID, 0); 189 if(!ack->send()) 187 190 COUT(3) << "could not ack gamestate" << std::endl; 188 } */// otherwise we had no gamestate to load191 }// otherwise we had no gamestate to load 189 192 gamestate.cleanup(); 190 193 return; -
code/branches/network/src/network/GamestateClient.cc
r1735 r1739 73 73 return 0; 74 74 int id = GAMESTATEID_INITIAL; 75 bool b = saveShipCache(); 76 if(processGamestate(tempGamestate_)){ 77 if(b) 78 loadShipCache(); 79 id = tempGamestate_->getID(); 80 } 75 //bool b = saveShipCache(); 76 packet::Gamestate *processed = processGamestate(tempGamestate_); 77 assert(processed); 78 //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs 79 tempGamestate_=0; 80 gamestateMap_[processed->getID()]=processed; 81 last_diff_ = processed->getBaseID(); 82 last_gamestate_ = processed->getID(); 83 //if(b) 84 //loadShipCache(); 85 id = processed->getID(); 81 86 cleanup(); 82 87 return id; … … 151 156 } 152 157 153 bool GamestateClient::processGamestate(packet::Gamestate *gs){ 154 assert(gs->decompressData()); 155 if(gs->isDiffed()) 156 assert(gs->undiff(gamestateMap_[gs->getBaseID()])); 157 return gs->spreadData(); 158 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 159 if(gs->isCompressed()) 160 assert(gs->decompressData()); 161 if(gs->isDiffed()){ 162 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; 163 assert(base); 164 packet::Gamestate *undiffed = gs->undiff(base); 165 delete gs; 166 gs=undiffed; 167 COUT(3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl; 168 } 169 if(gs->spreadData()) 170 return gs; 171 else 172 return NULL; 158 173 } 159 174 -
code/branches/network/src/network/GamestateClient.h
r1735 r1739 66 66 void cleanup(); 67 67 private: 68 boolprocessGamestate(packet::Gamestate *gs);68 packet::Gamestate *processGamestate(packet::Gamestate *gs); 69 69 void removeObject(orxonox::Iterator<Synchronisable> &it); 70 70 void printGamestateMap(); -
code/branches/network/src/network/GamestateManager.cc
r1735 r1739 194 194 if(client->getGamestateID()>=0) 195 195 gamestateUsed[client->getGamestateID()]--; 196 ClientInformation::removeClient(client->getID());197 196 } 198 197 199 198 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 200 assert(gs->decompressData()); 199 if(gs->isCompressed()) 200 assert(gs->decompressData()); 201 201 assert(!gs->isDiffed()); 202 202 return gs->spreadData(); -
code/branches/network/src/network/Host.cc
r1735 r1739 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008 24 * Co-authors: 25 * ... 26 * 27 */ 28 1 29 #include <assert.h> 2 30 -
code/branches/network/src/network/Host.h
r1735 r1739 54 54 ~Host(); 55 55 static Host *instance_; 56 bool isServer_; 56 57 57 58 public: … … 64 65 static void setClientID(unsigned int id){ instance_->clientID_ = id; } 65 66 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 67 static bool isServer(){ return instance_->isServer_; } 66 68 private: 67 69 unsigned int clientID_; -
code/branches/network/src/network/Server.cc
r1735 r1739 53 53 #include "packet/Packet.h" 54 54 #include "packet/Welcome.h" 55 #include <util/Convert.h> 55 56 56 57 namespace network … … 67 68 connection = new ConnectionManager(); 68 69 gamestates_ = new GamestateManager(); 70 isServer_ = true; 69 71 } 70 72 … … 73 75 connection = new ConnectionManager(port); 74 76 gamestates_ = new GamestateManager(); 77 isServer_ = true; 75 78 } 76 79 … … 84 87 connection = new ConnectionManager(port, bindAddress); 85 88 gamestates_ = new GamestateManager(); 89 isServer_ = true; 86 90 } 87 91 … … 95 99 connection = new ConnectionManager(port, bindAddress); 96 100 gamestates_ = new GamestateManager(); 101 isServer_ = true; 97 102 } 98 103 … … 348 353 no->setTransDamp(75); 349 354 no->setRotDamp(1.0); 350 no->setCamera( "cam_"+client->getID());355 no->setCamera(std::string("cam_") + convertToString(client->getID())); 351 356 no->create(); 352 357 no->setBacksync(true); … … 364 369 if(!client) 365 370 return false; 371 gamestates_->removeClient(client); 366 372 while(it){ 367 373 if(it->objectID!=client->getShipID()){ -
code/branches/network/src/network/packet/Acknowledgement.cc
r1735 r1739 45 45 data_=new unsigned char[ getSize() ]; 46 46 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement; 47 *(unsigned int *) &data_[ _ACKID ]= id;47 *(unsigned int *)(data_ + _ACKID ) = id; 48 48 clientID_=clientID; 49 49 } -
code/branches/network/src/network/packet/Gamestate.cc
r1735 r1739 120 120 bool Gamestate::spreadData(int mode) 121 121 { 122 assert(data_ && !HEADER->compressed && !HEADER->diffed); 122 assert(data_); 123 assert(!HEADER->compressed); 124 assert(!HEADER->diffed); 123 125 unsigned int size, objectID, classID; 124 126 unsigned char *mem=data_+sizeof(GamestateHeader); … … 141 143 //fabricate the new synchronisable 142 144 if(!Synchronisable::fabricate(mem, mode)) 143 /*return false*/;145 return false; 144 146 it=orxonox::ObjectList<Synchronisable>::end(); 145 147 } … … 276 278 *GAMESTATE_HEADER(ndata) = *HEADER; 277 279 GAMESTATE_HEADER(ndata)->diffed = true; 280 GAMESTATE_HEADER(ndata)->base_id = base->getID(); 278 281 Gamestate *g = new Gamestate(ndata, 0); 282 g->flags_=flags_; 283 g->packetDirection_ = packetDirection_; 284 g->clientID_ = clientID_; 279 285 return g; 280 286 } … … 310 316 GAMESTATE_HEADER(ndata)->diffed = false; 311 317 Gamestate *g = new Gamestate(ndata, 0); 318 g->flags_=flags_; 319 g->packetDirection_ = packetDirection_; 320 g->clientID_ = clientID_; 321 assert(!g->isDiffed()); 322 assert(!g->isCompressed()); 312 323 return g; 313 324 } … … 341 352 } 342 353 354 bool Gamestate::isCompressed(){ 355 return HEADER->compressed; 356 } 357 343 358 int Gamestate::getBaseID(){ 344 359 return HEADER->base_id; -
code/branches/network/src/network/packet/Gamestate.h
r1735 r1739 64 64 int getID(); 65 65 bool isDiffed(); 66 bool isCompressed(); 66 67 int getBaseID(); 67 68 Gamestate *diff(Gamestate *base); -
code/branches/network/src/network/packet/Packet.cc
r1735 r1739 113 113 packetMap_[enetPacket_] = this; 114 114 } 115 /*switch( *(ENUM::Type *)(data_ + _PACKETID) ) 115 #ifndef NDEBUG 116 switch( *(ENUM::Type *)(data_ + _PACKETID) ) 116 117 { 117 118 case ENUM::Acknowledgement: … … 120 121 case ENUM::Gamestate: 121 122 case ENUM::Welcome: 122 COUT(3) << "welcome" << std::endl; 123 p = new Welcome( data, clientID ); 123 break; 124 124 default: 125 125 assert(0); //TODO: repair this 126 126 break; 127 }*/ 127 } 128 #endif 128 129 network::Host::addPacket( enetPacket_, clientID_); 129 130 enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet -
code/branches/network/src/network/packet/Packet.h
r1735 r1739 78 78 enet_uint32 flags_; 79 79 int clientID_; 80 ENUM::Direction packetDirection_; 80 81 unsigned char *data_; 81 82 private: 82 83 static std::map<ENetPacket *, Packet *> packetMap_; 83 84 ENetPacket *enetPacket_; 84 ENUM::Direction packetDirection_;85 85 }; 86 86
Note: See TracChangeset
for help on using the changeset viewer.