Changeset 1021 for code/trunk/src/network
- Timestamp:
- Apr 10, 2008, 5:03:34 PM (17 years ago)
- Location:
- code/trunk/src/network
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Client.cc
r790 r1021 184 184 while(!(client_connection.queueEmpty())){ 185 185 packet = client_connection.getPacket(); 186 //std::cout<< "tick packet size " << packet->dataLength << std::endl;186 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 187 187 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 188 188 } … … 191 191 192 192 void Client::processGamestate( GameStateCompressed *data){ 193 int id = data->id; 194 COUT(5) << "received gamestate id: " << data->id << std::endl; 193 195 gamestate.pushGameState(data); 194 std::cout << "received gamestate id: " << data->id << std::endl; 195 client_connection.addPacket(pck_gen.acknowledgement(data->id)); 196 client_connection.addPacket(pck_gen.acknowledgement(id)); 196 197 client_connection.sendPackets(); 197 198 return; … … 203 204 if(id!=NULL) 204 205 id->setNetworkID(clid->clid); 206 COUT(4) << "received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl; 205 207 return; 206 208 } 207 209 208 210 void Client::processChat( chat *data){ 209 std::cout<< "Server: " << data->message << std::endl;211 COUT(0) << "Server: " << data->message << std::endl; 210 212 } 211 213 -
code/trunk/src/network/Client.h
r790 r1021 17 17 18 18 #include "NetworkPrereqs.h" 19 20 #include "core/Tickable.h" 19 21 #include "ClientConnection.h" 20 22 #include "PacketManager.h" 21 23 #include "GameStateClient.h" 22 24 //#include "NetworkFrameListener.h" 25 23 26 24 27 … … 32 35 * 33 36 */ 34 class _NetworkExport Client : PacketDecoder {37 class _NetworkExport Client : PacketDecoder, public orxonox::Tickable{ 35 38 public: 36 39 Client(); -
code/trunk/src/network/ClientConnection.cc
r790 r1021 43 43 44 44 #include "util/Sleep.h" 45 #include "orxonox/core/Debug.h" 45 46 #include "ClientConnection.h" 46 47 … … 159 160 case ENET_EVENT_TYPE_CONNECT: 160 161 case ENET_EVENT_TYPE_RECEIVE: 161 //std::cout << "gotpacket" << std::endl;162 COUT(5) << "receiver-Thread: got new packet" << std::endl; 162 163 processData(&event); 163 164 break; … … 215 216 216 217 bool ClientConnection::processData(ENetEvent *event) { 217 //std::cout<< "got packet, pushing to queue" << std::endl;218 COUT(5) << "got packet, pushing to queue" << std::endl; 218 219 // just add packet to the buffer 219 220 // this can be extended with some preprocessing -
code/trunk/src/network/ConnectionManager.cc
r790 r1021 257 257 258 258 void ConnectionManager::syncClassid(int clientID) { 259 int i=0;259 unsigned int network_id=0; 260 260 std::string classname; 261 bool abort=false;262 261 orxonox::Identifier *id; 263 while(!abort){ 264 id = ID(i); 265 std::cout << "syncid: " << i << ", ID(id): " << id << std::endl; 266 if(id == NULL){ 267 if(i!=0) 268 abort=true; 269 else{ 270 ++i; 271 continue; 272 } 273 } 274 else{ 275 classname = id->getName(); 276 addPacket(packet_gen.clid( i, classname ),clientID); 277 } 278 ++i; 262 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin(); 263 while(it != orxonox::Factory::getFactoryEnd()){ 264 id = (*it).second; 265 if(id == NULL) 266 continue; 267 classname = id->getName(); 268 network_id = id->getNetworkID(); 269 COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl; 270 271 addPacket(packet_gen.clid( (int)network_id, classname ), clientID); 272 273 ++it; 279 274 } 280 275 sendPackets(); 281 276 } 282 277 278 279 280 void ConnectionManager::addClientsObjectID( int clientID, int objectID ) { 281 COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl; 282 clientsShip.insert( std::make_pair( clientID, objectID ) ); 283 } 284 285 int ConnectionManager::getClientsShipID( int clientID ) { 286 return clientsShip[clientID]; 287 } 288 289 int ConnectionManager::getObjectsClientID( int objectID ) { 290 std::map<int, int>::iterator iter = clientsShip.begin(); 291 while( iter != clientsShip.end() ) { 292 if( iter->second == objectID ) return iter->first; 293 } 294 return -99; 295 } 296 297 void ConnectionManager::deleteClientIDReg( int clientID ) { 298 clientsShip.erase( clientID ); 299 } 300 301 void ConnectionManager::deleteObjectIDReg( int objectID ) { 302 std::map<int, int>::iterator iter = clientsShip.begin(); 303 while( iter != clientsShip.end() ) { 304 if( iter->second == objectID ) break; 305 } 306 clientsShip.erase( iter->first ); 307 } 308 283 309 } -
code/trunk/src/network/ConnectionManager.h
r790 r1021 14 14 15 15 #include <string> 16 #include <map> 16 17 // enet library for networking support 17 18 #include <enet/enet.h> … … 73 74 bool quit; // quit-variable (communication with threads) 74 75 ClientInformation *head_; 76 77 //functions to map what object every clients uses 78 std::map<int, int> clientsShip; 79 void addClientsObjectID( int clientID, int objectID ); 80 int getClientsShipID( int clientID ); 81 int getObjectsClientID( int objectID ); 82 void deleteClientIDReg( int clientID ); 83 void deleteObjectIDReg( int objectID ); 75 84 }; 76 85 -
code/trunk/src/network/GameStateClient.cc
r871 r1021 40 40 41 41 bool GameStateClient::pushGameState(GameStateCompressed *compstate) { 42 GameState *gs; 42 43 if(compstate->diffed) 43 return loadSnapshot(decode(reference, *compstate));44 gs = decode(reference, compstate); 44 45 else 45 return loadSnapshot(decode(*compstate)); 46 gs = decode(compstate); 47 if(gs) 48 return loadSnapshot(gs); 49 COUT(4) << "could not use gamestate sent by server" << std::endl; 50 return false; 46 51 } 47 52 … … 61 66 * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot) 62 67 */ 63 bool GameStateClient::loadSnapshot(GameState state) {64 unsigned char *data=state .data;65 std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;68 bool GameStateClient::loadSnapshot(GameState *state) { 69 unsigned char *data=state->data; 70 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 66 71 // get the start of the Synchronisable list 67 72 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); 68 73 syncData sync; 69 74 // loop as long as we have some data ;) 70 while(data < state .data+state.size){75 while(data < state->data+state->size){ 71 76 // prepare the syncData struct 72 77 sync.length = (int)*data; … … 82 87 // bad luck ;) 83 88 // delete the synchronisable (obviously seems to be deleted on the server) 84 while(it && it->objectID!=sync.objectID) {89 while(it && it->objectID!=sync.objectID) 85 90 removeObject(it); 86 } 87 if(it==0){ 88 std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl; 89 Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate()); 91 92 93 if(!it){ 94 COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; 95 Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate()); 90 96 no->objectID=sync.objectID; 91 97 no->classID=sync.classID; … … 93 99 // update data and create object/entity... 94 100 if( !no->updateData(sync) && !no->create() ) 95 COUT( 0) << "We couldn't create/update the object: " << sync.objectID << std::endl;101 COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl; 96 102 ++it; 97 103 } … … 99 105 // we have our object 100 106 if(! it->updateData(sync)) 101 std::cout<< "We couldn't update objectID: " \107 COUT(1) << "We couldn't update objectID: " \ 102 108 << sync.objectID << "; classID: " << sync.classID << std::endl; 103 109 } … … 108 114 } 109 115 110 GameState GameStateClient::diff(GameState a, GameStateb) {111 unsigned char *ap = a .data, *bp = b.data;116 GameState *GameStateClient::undiff(GameState *a, GameState *b) { 117 unsigned char *ap = a->data, *bp = b->data; 112 118 int of=0; // pointers offset 113 119 int dest_length=0; 114 if(a .size>=b.size)115 dest_length=a .size;120 if(a->size>=b->size) 121 dest_length=a->size; 116 122 else 117 dest_length=b .size;123 dest_length=b->size; 118 124 unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char)); 119 while(of<a .size && of<b.size){125 while(of<a->size && of<b->size){ 120 126 *(dp+of)=*(ap+of)^*(bp+of); // do the xor 121 127 ++of; 122 128 } 123 if(a .size!=b.size){ // do we have to fill up ?129 if(a->size!=b->size){ // do we have to fill up ? 124 130 unsigned char n=0; 125 if(a .size<b.size){131 if(a->size<b->size){ 126 132 while(of<dest_length){ 127 133 *(dp+of)=n^*(bp+of); … … 137 143 // should be finished now 138 144 // FIXME: is it true or false now? (struct has changed, producing warnings) 139 GameState r = {b.id, dest_length, true, dp}; 145 GameState *r = new GameState; 146 r->id = b->id; 147 r->size = dest_length; 148 r->diffed = false; 149 r->data = dp; 140 150 return r; 141 151 } 142 152 143 GameState GameStateClient::decompress(GameStateCompresseda) {144 int normsize = a .normsize;145 int compsize = a .compsize;153 GameState *GameStateClient::decompress(GameStateCompressed *a) { 154 int normsize = a->normsize; 155 int compsize = a->compsize; 146 156 int bufsize; 147 157 if(normsize < compsize) … … 154 164 //std::cout << "gamestateclient" << std::endl; 155 165 //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl; 156 retval = uncompress( dest, &length, a .data, (uLong)compsize );166 retval = uncompress( dest, &length, a->data, (uLong)compsize ); 157 167 //std::cout << "length " << length << std::endl; 158 168 switch ( retval ) { 159 case Z_OK: std::cout<< "successfully decompressed" << std::endl; break;160 case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;161 case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;162 case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;169 case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break; 170 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL; 171 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL; 172 case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL; 163 173 } 164 174 165 GameState gamestate; 166 gamestate.id = a.id; 167 gamestate.size = normsize; 168 gamestate.data = dest; 169 gamestate.diffed = a.diffed; 175 GameState *gamestate = new GameState; 176 gamestate->id = a->id; 177 gamestate->size = normsize; 178 gamestate->data = dest; 179 gamestate->diffed = a->diffed; 180 181 delete a->data; //delete compressed data 182 delete a; //we do not need the old (struct) gamestate anymore 170 183 171 184 return gamestate; 172 185 } 173 186 174 GameState GameStateClient::decode(GameState a, GameStateCompressedx) {175 GameState t = decompress(x);176 return diff(a, t);187 GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) { 188 GameState *t = decompress(x); 189 return undiff(a, t); 177 190 } 178 191 179 GameState GameStateClient::decode(GameStateCompressedx) {180 GameState t = decompress(x);192 GameState *GameStateClient::decode(GameStateCompressed *x) { 193 GameState *t = decompress(x); 181 194 return t; 182 195 } -
code/trunk/src/network/GameStateClient.h
r790 r1021 25 25 bool pushGameState(GameStateCompressed *compstate); 26 26 private: 27 bool loadSnapshot(GameState state);28 GameState diff(GameState a, GameStateb);29 GameState decompress(GameStateCompresseda);30 GameState decode(GameState a, GameStateCompressedx);31 GameState decode(GameStateCompressedx);27 bool loadSnapshot(GameState *state); 28 GameState *undiff(GameState *a, GameState *b); 29 GameState *decompress(GameStateCompressed *a); 30 GameState *decode(GameState *a, GameStateCompressed *x); 31 GameState *decode(GameStateCompressed *x); 32 32 void removeObject(orxonox::Iterator<Synchronisable> &it); 33 33 34 GameState reference;34 GameState *reference; 35 35 }; 36 36 -
code/trunk/src/network/GameStateManager.cc
r871 r1021 43 43 44 44 #include "core/CoreIncludes.h" 45 45 46 #include "ClientInformation.h" 46 47 #include "Synchronisable.h" … … 65 66 } 66 67 67 GameStateCompressed GameStateManager::popGameState(int clientID) {68 GameStateCompressed *GameStateManager::popGameState(int clientID) { 68 69 int gID = head_->findClient(clientID)->getGamestateID(); 69 std::cout<< "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;70 COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl; 70 71 if(gID!=GAMESTATEID_INITIAL){ 71 72 GameState *client = gameStateMap[gID]; … … 100 101 GameState *retval=new GameState; //return value 101 102 retval->id=id++; 102 std::cout<< "producing gamestate with id: " << retval->id << std::endl;103 COUT(4) << "producing gamestate with id: " << retval->id << std::endl; 103 104 // reserve a little memory and increase it later on 104 //COUT(2) << "mallocing" << std::endl;105 COUT(5) << "mallocing" << std::endl; 105 106 retval->data = (unsigned char*)malloc(memsize); 106 //COUT(2) << "malloced" << std::endl;107 COUT(5) << "malloced" << std::endl; 107 108 108 109 // offset of memory functions … … 113 114 //get size of the synchronisable 114 115 tempsize=it->getSize(); 115 //std::cout<< "size of temp gamestate: " << tempsize << std::endl;116 // COUT(5) << "size of temp gamestate: " << tempsize << std::endl; 116 117 //COUT(2) << "size of synchronisable: " << tempsize << std::endl; 117 118 // add place for data and 3 ints (length,classid,objectid) … … 137 138 offset+=tempsize+3*sizeof(int); 138 139 } 140 COUT(5) << "Gamestate size: " << totalsize << std::endl; 139 141 retval->size=totalsize; 140 142 return retval; 141 143 } 142 144 143 GameStateCompressed GameStateManager::encode(GameState *a, GameState *b) {145 GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) { 144 146 //GameState r = diff(a,b); 145 147 //r.diffed = true; 146 GameState r = *b;147 r .diffed = false;148 return compress_( &r);149 } 150 151 GameStateCompressed GameStateManager::encode(GameState *a) {148 GameState *r = b; 149 r->diffed = false; 150 return compress_(r); 151 } 152 153 GameStateCompressed *GameStateManager::encode(GameState *a) { 152 154 a->diffed=false; 153 155 return compress_(a); 154 156 } 155 157 156 GameState GameStateManager::diff(GameState *a, GameState *b) {158 GameState *GameStateManager::diff(GameState *a, GameState *b) { 157 159 unsigned char *ap = a->data, *bp = b->data; 158 160 int of=0; // pointers offset … … 181 183 } 182 184 } 183 // should be finished now 184 // FIXME: is it true or false now? (struct has changed, producing warnings) 185 GameState r = {b->id, dest_length, true, dp}; 185 186 GameState *r = new GameState; 187 r->id = b->id; 188 r->size = dest_length; 189 r->diffed = true; 190 r->data = dp; 186 191 return r; 187 192 } 188 193 189 GameStateCompressed GameStateManager::compress_(GameState *a) {190 //COUT(2) << "compressing gamestate" << std::endl;194 GameStateCompressed *GameStateManager::compress_(GameState *a) { 195 COUT(5) << "compressing gamestate" << std::endl; 191 196 int size = a->size; 192 197 uLongf buffer = (uLongf)((a->size + 12)*1.01)+1; … … 198 203 199 204 switch ( retval ) { 200 case Z_OK: std::cout << "successfully compressed" << std::endl; break; 201 case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break; 202 case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break; 203 case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break; 204 } 205 206 GameStateCompressed compressedGamestate; 207 compressedGamestate.compsize = buffer; 208 //std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl; 209 compressedGamestate.normsize = size; 210 //std::cout << "compressedGamestate.normsize = size; " << size << std::endl; 211 compressedGamestate.id = a->id; 212 compressedGamestate.data = dest; 213 compressedGamestate.diffed = a->diffed; 205 case Z_OK: COUT(5) << "successfully compressed" << std::endl; break; 206 case Z_MEM_ERROR: COUT(1) << "not enough memory available in gamestate.compress" << std::endl; 207 return NULL; 208 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer in gamestate.compress" << std::endl; 209 return NULL; 210 case Z_DATA_ERROR: COUT(2) << "decompress: data corrupted in gamestate.compress" << std::endl; 211 return NULL; 212 } 213 214 GameStateCompressed *compressedGamestate = new GameStateCompressed; 215 compressedGamestate->compsize = buffer; 216 // std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl; 217 compressedGamestate->normsize = size; 218 // std::cout << "compressedGamestate.normsize = size; " << size << std::endl; 219 compressedGamestate->id = a->id; 220 compressedGamestate->data = dest; 221 compressedGamestate->diffed = a->diffed; 214 222 215 223 return compressedGamestate; -
code/trunk/src/network/GameStateManager.h
r790 r1021 43 43 ~GameStateManager(); 44 44 void update(); 45 GameStateCompressed popGameState(int clientID);45 GameStateCompressed *popGameState(int clientID); 46 46 void ackGameState(int clientID, int gamestateID); 47 47 int id; 48 48 private: 49 49 GameState *getSnapshot(int id); 50 GameStateCompressed encode(GameState *a, GameState *b);51 GameStateCompressed encode(GameState *a);52 GameState diff(GameState *a, GameState *b);53 GameStateCompressed compress_(GameState *a);50 GameStateCompressed *encode(GameState *a, GameState *b); 51 GameStateCompressed *encode(GameState *a); 52 GameState *diff(GameState *a, GameState *b); 53 GameStateCompressed *compress_(GameState *a); 54 54 bool deleteUnusedGameState(int gamestateID); 55 55 -
code/trunk/src/network/PacketDecoder.cc
r790 r1021 38 38 #include "PacketTypes.h" 39 39 #include "PacketManager.h" 40 #include "orxonox/core/Debug.h" 40 41 41 42 namespace network 42 43 { 43 using namespace std;44 44 45 45 PacketDecoder::PacketDecoder(){} … … 52 52 { 53 53 int client = clientId; 54 cout << "clientId: " << client <<endl; //control cout, not important, just debugging info54 COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info 55 55 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 56 std::cout<< "packet id: " << id << std::endl;57 std::cout<< "packet size inside packetdecoder: " << packet->dataLength << std::endl;56 COUT(5) << "packet id: " << id << std::endl; 57 // COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl; 58 58 switch( id ) { 59 59 case ACK: … … 93 93 94 94 95 std::cout<< "got ack id: " << a->id << std::endl;95 COUT(5) << "got ack id: " << a->id << std::endl; 96 96 processAck( a, clientId ); //debug info 97 97 … … 144 144 void PacketDecoder::gstate( ENetPacket* packet ) 145 145 { 146 GameStateCompressed* currentState = new GameStateCompressed; 146 GameStateCompressed* currentState = NULL; 147 currentState = new GameStateCompressed; 148 if(currentState == NULL){ 149 COUT(3) << "could not generate new GameStateCompressed" << std::endl; 150 return; 151 } 147 152 //since it's not alowed to use void* for pointer arithmetic 148 unsigned char* data = (unsigned char *)packet->data;153 unsigned char* data = (unsigned char *)(packet->data); 149 154 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 150 155 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 151 currentState->id = (int)*(data+sizeof(int)); 152 std::cout << "id: " << currentState->id << std::endl; 156 //currentState->id = *((int *)packet->data+sizeof(int)); 157 memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) ); 158 COUT(5) << "decoder: received gs id: " << currentState->id << std::endl; 159 // std::cout << "id: " << currentState->id << std::endl; 153 160 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 154 161 //position of the data stream, data+2*sizeof( int ) 155 memcpy( (void*)&(currentState->compsize), (const void*)( data+2*sizeof( int )), sizeof( int) );162 memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) ); 156 163 //currentState->compsize = (int)*(data+2*sizeof(int)); 157 std::cout << "compsize: " << currentState->compsize << std::endl;164 // std::cout << "compsize: " << currentState->compsize << std::endl; 158 165 //size of uncompressed data 159 memcpy( (void*)&(currentState->normsize), (const void*)( data+3*sizeof( int )), sizeof( int ) );166 memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) ); 160 167 //currentState->normsize = (int)*(data+3*sizeof(int)); 161 std::cout << "normsize. " << currentState->normsize << std::endl;168 // std::cout << "normsize. " << currentState->normsize << std::endl; 162 169 //since the packetgenerator was changed, due to a new parameter, change this function too 163 memcpy( (void*)&(currentState->diffed), (const void*)( data+4*sizeof(int)), sizeof(bool));170 memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool)); 164 171 //currentState->diffed = (bool)*(data+4*sizeof(int)); 165 std::cout << "diffed: " << currentState->diffed << std::endl;172 // std::cout << "diffed: " << currentState->diffed << std::endl; 166 173 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 174 if(currentState->compsize==0) 175 COUT(2) << "compsize is 0" << std::endl; 167 176 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 168 177 if(currentState->data==NULL) 169 std::cout << "memory leak" << std::endl;178 COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl; 170 179 //copy the GameStateCompressed data 171 180 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; 172 181 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl; 173 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 174 175 //clean memory 176 enet_packet_destroy( packet ); 177 //run processGameStateCompressed 178 //TODO: not yet implemented! 182 memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 183 184 //clean memory 185 enet_packet_destroy( packet ); 179 186 processGamestate(currentState); 180 187 } … … 189 196 void *data = (void *)cid->message; 190 197 memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length); 191 std::cout<< "classid: " << cid->clid << ", name: " << cid->message << std::endl;198 COUT(4) << "classid: " << cid->clid << ", name: " << cid->message << std::endl; 192 199 enet_packet_destroy( packet ); 193 200 processClassid(cid); … … 223 230 void PacketDecoder::printAck( ack* data ) 224 231 { 225 cout << "data id: " << data->id <<endl;226 cout << "data: " << data->a <<endl;232 COUT(5) << "data id: " << data->id << std::endl; 233 COUT(5) << "data: " << data->a << std::endl; 227 234 } 228 235 229 236 void PacketDecoder::printMouse( mouse* data ) 230 237 { 231 cout << "data id: " << data->id <<endl;232 cout << "data: " << data->x << " " << data->y <<endl;238 COUT(5) << "data id: " << data->id << std::endl; 239 COUT(5) << "data: " << data->x << " " << data->y << std::endl; 233 240 } 234 241 235 242 void PacketDecoder::printKey( keyboard* data ) 236 243 { 237 cout << "data id: " << data->id <<endl;238 cout << "data: " << (char)data->press <<endl;244 COUT(5) << "data id: " << data->id << std::endl; 245 COUT(5) << "data: " << (char)data->press << std::endl; 239 246 } 240 247 … … 242 249 { 243 250 if(clientId!=CLIENTID_CLIENT) 244 cout << "client: " << clientId <<endl;245 cout << "data id: " << data->id <<endl;246 cout << "data: " << data->message <<endl;251 COUT(5) << "client: " << clientId << std::endl; 252 COUT(5) << "data id: " << data->id << std::endl; 253 COUT(5) << "data: " << data->message << std::endl; 247 254 } 248 255 249 256 void PacketDecoder::printGamestate( GameStateCompressed* data ) 250 257 { 251 cout << "id of GameStateCompressed: " << data->id <<endl;252 cout << "size of GameStateCompressed: " << data->compsize <<endl;258 COUT(5) << "id of GameStateCompressed: " << data->id << std::endl; 259 COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl; 253 260 } 254 261 255 262 void PacketDecoder::printClassid( classid *cid) 256 263 { 257 cout << "id of classid: " << cid->id <<endl;258 cout << "size of classid: " << cid->length <<endl;259 cout << "ID of classid: " << cid->clid <<endl;260 cout << "data of classid: " << cid->message <<endl;264 COUT(5) << "id of classid: " << cid->id << std::endl; 265 COUT(5) << "size of classid: " << cid->length << std::endl; 266 COUT(5) << "ID of classid: " << cid->clid << std::endl; 267 COUT(5) << "data of classid: " << cid->message << std::endl; 261 268 } 262 269 -
code/trunk/src/network/PacketGenerator.cc
r790 r1021 50 50 ENetPacket* PacketGenerator::acknowledgement( int state, int reliable ) 51 51 { 52 std::cout<< "generating new acknowledgement, id: " << state << std::endl;52 COUT(4) << "generating new acknowledgement, id: " << state << std::endl; 53 53 ack* ackreq = new ack; 54 54 ackreq->id = ACK; … … 63 63 ENetPacket* PacketGenerator::mousem( double x, double y, int reliable ) 64 64 { 65 std::cout<< "generating new mouse" << std::endl;65 COUT(4) << "generating new mouse" << std::endl; 66 66 mouse* mousemove = new mouse; 67 67 mousemove->id = MOUSE; … … 77 77 ENetPacket* PacketGenerator::keystrike( char press, int reliable ) 78 78 { 79 std::cout<< "generating new keyboard" << std::endl;79 COUT(4) << "generating new keyboard" << std::endl; 80 80 keyboard* key = new keyboard; 81 81 key->id = KEYBOARD; -
code/trunk/src/network/PacketManager.h
r790 r1021 4 4 #include <string> 5 5 #include <enet/enet.h> 6 7 #include "core/CoreIncludes.h" 6 8 7 9 #include "NetworkPrereqs.h" … … 65 67 virtual void processGamestate(GameStateCompressed *state); 66 68 virtual void processAck( ack *data, int clientID); 67 v oid processClassid( classid *cid);69 virtual void processClassid( classid *cid); 68 70 //virtual void processAck( ack *data); 69 71 -
code/trunk/src/network/Server.cc
r790 r1021 18 18 #include "ClientInformation.h" 19 19 //#include "NetworkFrameListener.h" 20 #include "util/Sleep.h" 20 21 #include "Server.h" 21 22 … … 112 113 processQueue(); 113 114 updateGamestate(); 115 116 sleep(1); // TODO remove 114 117 return; 115 118 } … … 134 137 gamestates->update(); 135 138 //std::cout << "updated gamestate, sending it" << std::endl; 136 sendGameState(); 139 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 140 sendGameState(); 137 141 //std::cout << "sent gamestate" << std::endl; 138 142 } … … 142 146 */ 143 147 bool Server::sendGameState() { 144 std::cout << "starting gamestate" << std::endl;148 COUT(5) << "starting sendGameState" << std::endl; 145 149 ClientInformation *temp = clients; 146 150 bool added=false; … … 151 155 } 152 156 if( !(temp->getSynched()) ){ 153 std::cout<< "not sending gamestate" << std::endl;157 COUT(5) << "not sending gamestate" << std::endl; 154 158 temp=temp->next(); 155 159 continue; 156 160 } 157 std::cout << "doing gamestate" << std::endl;161 COUT(5) << "doing gamestate gamestate preparation" << std::endl; 158 162 int gid = temp->getGamestateID(); 159 163 int cid = temp->getID(); 160 std::cout << "server, got acked ID: " << gid << std::endl; 161 GameStateCompressed *gs = &(gamestates->popGameState(cid)); // FIXME: taking address of temporary, check if correct 164 COUT(5) << "server, got acked (gamestate) ID: " << gid << std::endl; 165 GameStateCompressed *gs = gamestates->popGameState(cid); 166 if(gs==NULL){ 167 COUT(2) << "could not generate gamestate" << std::endl; 168 return false; 169 } 162 170 //std::cout << "adding gamestate" << std::endl; 163 171 connection->addPacket(packet_gen.gstate(gs), cid); … … 168 176 if(added) 169 177 return connection->sendPackets(); 170 else171 178 COUT(5) << "had no gamestates to send" << std::endl; 179 return false; 172 180 } 173 181 174 182 void Server::processAck( ack *data, int clientID) { 183 COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl; 175 184 clients->findClient(clientID)->setGamestateID(data->a); 176 185 } -
code/trunk/src/network/Server.h
r790 r1021 16 16 #include <string> 17 17 18 #include "NetworkPrereqs.h" 19 20 #include "core/Tickable.h" 18 21 #include "PacketManager.h" 19 #include "NetworkPrereqs.h" 22 23 20 24 21 25 namespace network … … 25 29 * It implements all functions necessary for a Server 26 30 */ 27 class _NetworkExport Server : public PacketDecoder {31 class _NetworkExport Server : public PacketDecoder, public orxonox::Tickable{ 28 32 public: 29 33 Server(); -
code/trunk/src/network/Synchronisable.h
r871 r1021 56 56 int getSize(); 57 57 bool updateData(syncData vars); 58 v oid registerAllVariables();58 virtual void registerAllVariables()=0; 59 59 virtual bool create()=0; 60 60 protected: -
code/trunk/src/network/dummyclient3.cc
r790 r1021 13 13 network::PacketGenerator pck; 14 14 const int PORT = 55556; 15 std::cout<< "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;15 COUT(0) << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; 16 16 std::string str; 17 17 std::getline(std::cin, str); 18 std::cout<< "You entered: " << str << std::endl;18 COUT(3) << "You entered: " << str << std::endl; 19 19 if(str.compare("")==0) 20 20 str="127.0.0.1"; … … 22 22 Client client( str, PORT ); 23 23 if ( client.establishConnection() ) 24 std::cout<< "connection established" << std::endl;25 else std::cout<< "problems establishing connection" << std::endl;24 COUT(3) << "connection established" << std::endl; 25 else COUT(0) << "problems establishing connection" << std::endl; 26 26 char message[10000]; 27 27 char signs[] = "abcdefghijklmnopqrstuvwxy";
Note: See TracChangeset
for help on using the changeset viewer.