Changeset 1740
- Timestamp:
- Sep 8, 2008, 2:48:48 AM (16 years ago)
- Location:
- code/trunk/src/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/CMakeLists.txt
r1735 r1740 17 17 packet/Gamestate.cc 18 18 packet/Welcome.cc 19 Host.cc20 19 ) 21 20 -
code/trunk/src/network/GamestateHandler.h
r1735 r1740 43 43 virtual bool add(packet::Gamestate *gs, int clientID)=0; 44 44 virtual bool ack(int gamestateID, int clientID)=0; 45 45 46 46 static GamestateHandler *instance_; 47 48 47 48 49 49 protected: 50 50 GamestateHandler(); 51 ~GamestateHandler();52 51 virtual ~GamestateHandler(); 52 53 53 public: 54 54 static bool addGamestate(packet::Gamestate *gs, int clientID){ return instance_->add(gs, clientID); } -
code/trunk/src/network/GamestateManager.h
r1735 r1740 70 70 GamestateManager(); 71 71 ~GamestateManager(); 72 72 73 73 bool add(packet::Gamestate *gs, int clientID); 74 74 bool processGamestates(); … … 77 77 78 78 bool getSnapshot(); 79 79 80 80 bool ack(int gamestateID, int clientID); 81 81 void removeClient(ClientInformation *client); … … 83 83 void cleanup(); // "garbage handler" 84 84 bool processGamestate(packet::Gamestate *gs); 85 85 86 86 std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate* 87 87 std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate -
code/trunk/src/network/Host.h
r1735 r1740 47 47 virtual unsigned int shipID()=0; 48 48 virtual int playerID()=0; 49 50 51 49 50 51 52 52 protected: 53 53 Host(); 54 ~Host();54 virtual ~Host(); 55 55 static Host *instance_; 56 56 57 57 public: 58 58 static bool running(){return instance_!=0;} -
code/trunk/src/network/packet/Gamestate.cc
r1735 r1740 39 39 40 40 namespace packet { 41 41 42 42 43 43 #define GAMESTATE_START(data) data + sizeof(GamestateHeader) 44 44 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 45 45 #define HEADER GAMESTATE_HEADER(data_) 46 46 47 47 Gamestate::Gamestate() 48 48 { … … 64 64 assert(data_==0 /*&& bs_==0*/); 65 65 int size = calcGamestateSize(mode); 66 66 67 67 COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl; 68 68 //retval->data = (unsigned char*)malloc(size); … … 82 82 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 83 83 tempsize=it->getSize2(mode); 84 84 85 85 if(currentsize+tempsize > size){ 86 86 // start allocate additional memory … … 101 101 currentsize+=tempsize; 102 102 } 103 104 103 104 105 105 //start write gamestate header 106 106 HEADER->packetType = ENUM::Gamestate; 107 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 107 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 108 108 HEADER->normsize = currentsize; 109 109 HEADER->id = id; … … 112 112 HEADER->compressed = false; 113 113 //stop write gamestate header 114 114 115 115 COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl; 116 116 COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl; … … 125 125 // get the start of the Synchronisable list 126 126 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); 127 127 128 128 while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){ 129 129 // extract synchronisable header … … 144 144 it=orxonox::ObjectList<Synchronisable>::end(); 145 145 } 146 } else 146 } else 147 147 { 148 148 // we have our object … … 185 185 if(buffer==0) 186 186 return false; 187 187 188 188 unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)]; 189 189 unsigned char *dest = GAMESTATE_START(ndata); … … 192 192 switch ( retval ) { 193 193 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 194 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 194 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 195 195 return false; 196 196 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 224 224 bufsize = normsize; 225 225 if(bufsize==0) 226 return NULL;226 return false; 227 227 unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)]; 228 228 unsigned char *dest = ndata + sizeof(GamestateHeader); … … 236 236 case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false; 237 237 } 238 238 239 239 HEADER->compressed = false; 240 240 //copy over the header … … 245 245 data_ = ndata; 246 246 //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize); 247 247 248 248 return true; 249 249 } … … 340 340 return HEADER->diffed; 341 341 } 342 342 343 343 int Gamestate::getBaseID(){ 344 344 return HEADER->base_id;
Note: See TracChangeset
for help on using the changeset viewer.