Changeset 1098 for code/branches/network2/src
- Timestamp:
- Apr 17, 2008, 2:35:51 PM (17 years ago)
- Location:
- code/branches/network2/src
- Files:
-
- 27 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/network/CMakeLists.txt
r1070 r1098 11 11 Server.cc 12 12 Synchronisable.cc 13 dummyserver3.cc14 13 ) 15 14 … … 30 29 # build those parts only on request. 31 30 IF(NETWORK_TESTING_ENABLED) 31 ##### test for gamestate stuff ##### 32 SET( TEST_SRC_FILES 33 ConnectionManager.cc 34 GameStateManager.cc 35 PacketBuffer.cc 36 PacketDecoder.cc 37 PacketGenerator.cc 38 ClientConnection.cc 39 ClientInformation.cc 40 diffTest.cc 41 GameStateClient.cc 42 Server.cc 43 Client.cc 44 Synchronisable.cc 45 ) 46 47 ADD_EXECUTABLE(networktest ${TEST_SRC_FILES}) 48 TARGET_LINK_LIBRARIES( networktest 49 ${OGRE_LIBRARIES} 50 network 51 ${ENet_LIBRARY} 52 ${ZLIB_LIBRARY} 53 ${WINDOWS_ENET_DEPENDENCIES} 54 ) 55 ##### end test for gamestate stuff ##### 56 ENDIF(NETWORK_TESTING_ENABLED) 57 IF(BLABLA) 32 58 SET( CHATCLIENT_SRC_FILES 33 59 ClientConnection.cc … … 95 121 ${WINDOWS_ENET_DEPENDENCIES} 96 122 ) 97 ENDIF(NETWORK_TESTING_ENABLED) 123 ENDIF(BLABLA) 124 -
code/branches/network2/src/network/Client.cc
r1062 r1098 205 205 if(id!=NULL) 206 206 id->setNetworkID(clid->clid); 207 COUT(4) << " received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;207 COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl; 208 208 return; 209 209 } -
code/branches/network2/src/network/ClientConnection.cc
r1062 r1098 87 87 88 88 ENetPacket *ClientConnection::getPacket() { 89 ENetAddress address; 89 ENetAddress address; //sems that address is not needed 90 90 return getPacket(address); 91 91 } … … 162 162 case ENET_EVENT_TYPE_CONNECT: 163 163 case ENET_EVENT_TYPE_RECEIVE: 164 COUT(5) << " receiver-Thread: got new packet" << std::endl;165 processData(&event);164 COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl; 165 if ( !processData(&event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl; 166 166 break; 167 167 case ENET_EVENT_TYPE_DISCONNECT: … … 203 203 bool ClientConnection::establishConnection() { 204 204 ENetEvent event; 205 // connect to peer 205 // connect to peer (server is type ENetPeer*) 206 206 server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS); 207 207 if(server==NULL) … … 218 218 219 219 bool ClientConnection::processData(ENetEvent *event) { 220 COUT(5) << " got packet, pushing to queue" << std::endl;220 COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl; 221 221 // just add packet to the buffer 222 222 // this can be extended with some preprocessing -
code/branches/network2/src/network/ClientInformation.cc
r1062 r1098 190 190 * This function should only be applied to the head of the list 191 191 * @param clientID id to look for 192 * @return pointer to the element in the list or 0 if the search was unsuccessfull192 * @return pointer to the last element in the list or 0 if the search was unsuccessfull 193 193 */ 194 194 ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) { … … 196 196 if (temp->head) 197 197 temp=temp->next(); 198 while(temp!=0 && temp->getID()!=clientID){ 198 //bugfix: temp to temp->next(), get last elem if not found, not segflt 199 while(temp->next()!=0 && temp->getID()!=clientID){ 199 200 temp = temp->next(); 200 201 } … … 211 212 ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) { 212 213 ClientInformation *temp = this; 213 while(temp!=0){ 214 //bugfix: temp to temp->next(), get last elem if not found, not segflt 215 while(temp->next()!=0){ 214 216 if(temp->head){ 215 217 temp = temp->next(); -
code/branches/network2/src/network/ClientInformation.h
r1062 r1098 75 75 bool removeClient(int clientID); 76 76 bool removeClient(ENetPeer *peer); 77 //## add bool mask-function eventually 77 78 ClientInformation *findClient(int clientID, bool look_backwards=false); 79 //## add bool mask-function eventually 78 80 ClientInformation *findClient(ENetAddress *address, bool look_backwards=false); 79 81 -
code/branches/network2/src/network/ConnectionManager.cc
r1064 r1098 60 60 { 61 61 boost::thread_group network_threads; 62 62 63 ConnectionManager::ConnectionManager(){} 64 63 65 ConnectionManager::ConnectionManager(ClientInformation *head) { 64 66 quit=false; … … 88 90 return NULL; 89 91 } 90 92 /** 93 This function only pops the first element in PacketBuffer (first in first out) 94 used by processQueue in Server.cc 95 */ 91 96 ENetPacket *ConnectionManager::getPacket(int &clientID) { 92 97 ENetAddress address; … … 174 179 case ENET_EVENT_TYPE_CONNECT: 175 180 addClient(&event); 181 COUT(5) << "Con.Man: connection event has occured" << std::endl; 176 182 break; 177 183 case ENET_EVENT_TYPE_RECEIVE: 178 184 //std::cout << "received data" << std::endl; 185 COUT(5) << "Con.Man: receive event has occured" << std::endl; 179 186 processData(&event); 180 187 break; … … 191 198 enet_host_destroy(server); 192 199 } 193 200 201 //### added some bugfixes here, but we cannot test them because 202 //### the server crashes everytime because of some gamestates 203 //### (trying to resolve that now) 194 204 void ConnectionManager::disconnectClients() { 195 205 ENetEvent event; … … 199 209 temp = temp->next(); 200 210 } 201 temp = temp->next(); 211 //bugfix: might be the reason why server crashes when clients disconnects 212 //temp = temp->next(); 213 temp = head_->next(); 202 214 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){ 203 215 switch (event.type) 204 216 { 205 case ENET_EVENT_TYPE_NONE: 206 case ENET_EVENT_TYPE_CONNECT: 217 case ENET_EVENT_TYPE_NONE: break; 218 case ENET_EVENT_TYPE_CONNECT: break; 207 219 case ENET_EVENT_TYPE_RECEIVE: 208 220 enet_packet_destroy(event.packet); 209 221 break; 210 222 case ENET_EVENT_TYPE_DISCONNECT: 211 std::cout << "disconnecting client" << std::endl;223 COUT(4) << "disconnecting all clients" << std::endl; 212 224 delete head_->findClient(&(event.peer->address)); 225 //maybe needs bugfix: might also be a reason for the server to crash 213 226 temp = temp->next(); 214 227 break; … … 229 242 230 243 bool ConnectionManager::clientDisconnect(ENetPeer *peer) { 244 COUT(4) << "removing client from list" << std::endl; 231 245 return head_->removeClient(peer); 232 246 } 233 247 /** 248 This function adds a client that connects to the clientlist of the server 249 NOTE: if you change this, don't forget to change the test function 250 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid 251 */ 234 252 bool ConnectionManager::addClient(ENetEvent *event) { 235 253 ClientInformation *temp = head_->insertBack(new ClientInformation); 236 if(temp->prev()->head) 254 if(temp->prev()->head) { //not good if you use anything else than insertBack 255 temp->prev()->setID(0); //bugfix: not necessary but usefull 237 256 temp->setID(1); 257 } 238 258 else 239 259 temp->setID(temp->prev()->getID()+1); 240 260 temp->setPeer(event->peer); 241 std::cout << "added client id: " << temp->getID() << std::endl;261 COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl; 242 262 syncClassid(temp->getID()); 243 263 temp->setSynched(true); … … 268 288 classname = id->getName(); 269 289 network_id = id->getNetworkID(); 270 COUT(4) << " network_id: " << network_id << ", classname: " << classname << std::endl;290 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 271 291 272 292 addPacket(packet_gen.clid( (int)network_id, classname ), clientID); … … 275 295 } 276 296 sendPackets(); 297 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; 277 298 } 278 299 … … 289 310 290 311 int ConnectionManager::getObjectsClientID( int objectID ) { 291 std::map<int, int>::iterator iter = clientsShip.begin();292 while( iter != clientsShip.end()) {312 std::map<int, int>::iterator iter; 313 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) { 293 314 if( iter->second == objectID ) return iter->first; 294 315 } … … 302 323 void ConnectionManager::deleteObjectIDReg( int objectID ) { 303 324 std::map<int, int>::iterator iter = clientsShip.begin(); 304 while( iter != clientsShip.end()) {325 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) { 305 326 if( iter->second == objectID ) break; 306 327 } 307 328 clientsShip.erase( iter->first ); 308 329 } 309 330 int ConnectionManager::getNumberOfClients() { 331 return clientsShip.size(); 332 } 310 333 } -
code/branches/network2/src/network/ConnectionManager.h
r1062 r1098 84 84 bool sendPackets(ENetEvent *event); 85 85 bool sendPackets(); 86 87 //##### for testing purpose only ##### 88 ConnectionManager(); 89 std::map<int, int> testGetClientsShip() { 90 return clientsShip; 91 } 92 void testAddClientsShipID( int clientID, int objectID ) { 93 addClientsObjectID( clientID, objectID ); 94 } 95 int testGetClientsShipID( int clientID ) { 96 return getClientsShipID( clientID ); 97 } 98 int testGetObjectsClientID( int objectID ) { 99 return getObjectsClientID( objectID ); 100 } 101 void testDeleteClientsIDReg( int clientID ) { 102 deleteClientIDReg( clientID ); 103 } 104 void testDeleteObjectIDReg( int objectID ) { 105 deleteObjectIDReg( objectID ); 106 } 107 //##### for testing purpose only ##### 86 108 private: 87 109 bool clientDisconnect(ENetPeer *peer); … … 111 133 void deleteClientIDReg( int clientID ); 112 134 void deleteObjectIDReg( int objectID ); 135 int getNumberOfClients(); 113 136 }; 114 115 116 117 118 119 120 121 137 122 138 } -
code/branches/network2/src/network/GameStateClient.cc
r1062 r1098 32 32 33 33 #include "core/CoreIncludes.h" 34 #include "core/BaseObject.h" 34 35 #include "Synchronisable.h" 35 36 36 37 namespace network 37 38 { 39 struct GameStateItem{ 40 GameState *state; 41 int id; 42 }; 43 38 44 GameStateClient::GameStateClient() { 45 COUT(5) << "this: " << this << std::endl; 39 46 } 40 47 … … 44 51 bool GameStateClient::pushGameState(GameStateCompressed *compstate) { 45 52 GameState *gs; 46 if(compstate->diffed) 47 gs = decode(reference, compstate); 53 if(compstate->diffed){ 54 while(compstate->base_id > gameStateList.front()->id){ 55 // clean up old gamestates 56 free(gameStateList.front()->data); 57 // TODO: critical section 58 delete gameStateList.front(); 59 gameStateList.pop(); 60 } 61 if(compstate->base_id!=gameStateList.front()->id){ 62 COUT(4) << "pushGameState: no reference found to diff" << std::endl; 63 return false; 64 } 65 gs = decode(gameStateList.front(), compstate); 66 } 48 67 else 49 68 gs = decode(compstate); … … 95 114 96 115 if(!it){ 97 COUT( 5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;98 Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());116 COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; 117 Synchronisable *no = dynamic_cast<Synchronisable *>(ID((unsigned int) sync.classID)->fabricate()); 99 118 no->objectID=sync.objectID; 100 119 no->classID=sync.classID; 101 120 it=orxonox::ObjectList<Synchronisable>::end(); 102 121 // update data and create object/entity... 103 if( !no->updateData(sync) && !no->create() ) 104 COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl; 105 ++it; 122 if( !no->updateData(sync) ) 123 COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl; 124 if( !no->create() ) 125 COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl; 106 126 } 107 127 } else { … … 154 174 } 155 175 176 //##### ADDED FOR TESTING PURPOSE ##### 177 GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) { 178 return decompress( gc ); 179 } 180 181 GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) { 182 return undiff( g_old, g_diffed ); 183 } 184 //##### ADDED FOR TESTING PURPOSE ##### 185 156 186 GameState *GameStateClient::decompress(GameStateCompressed *a) { 187 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; 157 188 int normsize = a->normsize; 158 189 int compsize = a->compsize; … … 173 204 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL; 174 205 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL; 175 case Z_DATA_ERROR: COUT(2) << "data corrupted " << std::endl; return NULL;206 case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL; 176 207 } 177 208 … … 189 220 190 221 GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) { 191 GameState *t = decompress(x); 192 return undiff(a, t); 222 GameState *t = decode(x); 223 gameStateList.push(t); 224 //return undiff(a, t); 225 return t; 193 226 } 194 227 195 228 GameState *GameStateClient::decode(GameStateCompressed *x) { 196 GameState *t = decompress(x); 229 //GameState *t = decompress(x); 230 GameState *t = new GameState; 231 t->base_id = x->base_id; 232 t->id = x->id; 233 t->diffed = x->diffed; 234 t->data = x->data; 235 t->size = x->normsize; 236 gameStateList.push(t); 197 237 return t; 198 238 } -
code/branches/network2/src/network/GameStateClient.h
r1062 r1098 41 41 #define _GameStateClient_H__ 42 42 43 #include <queue> 44 43 45 #include "NetworkPrereqs.h" 44 46 #include "core/CorePrereqs.h" 45 #include " GameStateManager.h"47 #include "PacketTypes.h" 46 48 47 49 namespace network … … 52 54 GameStateClient(); 53 55 ~GameStateClient(); 56 //#### ADDED FOR TESTING PURPOSE #### 57 GameState* testDecompress( GameStateCompressed* gc ); 58 GameState* testUndiff( GameState* g_old, GameState* g_diffed ); 59 //#### END TESTING PURPOSE #### 54 60 bool pushGameState(GameStateCompressed *compstate); 55 61 private: … … 61 67 void removeObject(orxonox::Iterator<Synchronisable> &it); 62 68 63 GameState *reference; 69 GameState *reference; 70 std::queue<GameState *> gameStateList; 64 71 }; 65 72 -
code/branches/network2/src/network/GameStateManager.cc
r1064 r1098 60 60 61 61 void GameStateManager::update(){ 62 cleanup(); 62 63 reference = getSnapshot(id); 63 64 gameStateMap.insert(std::pair<int, GameState*>(id, reference)); … … 66 67 return; 67 68 } 69 70 71 /** 72 * this function is used to keep the memory usage low 73 * it tries to delete all the unused gamestates 74 * 75 * 76 */ 77 void GameStateManager::cleanup(){ 78 std::map<int,int>::iterator it = gameStateUsed.begin(); 79 while(it!=gameStateUsed.end()){ 80 if( (*it).second <= 0 ){ 81 free(gameStateMap[(*it).first]->data); 82 delete gameStateMap[(*it).first]; 83 gameStateMap.erase((*it).first); 84 gameStateUsed.erase(it++); 85 }else //as soon as we got a used gamestate break here because we could use newer gamestates in future 86 break; 87 } 88 } 68 89 69 90 GameStateCompressed *GameStateManager::popGameState(int clientID) { 91 //why are we searching the same client's gamestate id as we searched in 92 //Server::sendGameState? 70 93 int gID = head_->findClient(clientID)->getGamestateID(); 71 COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl; 72 if(gID!=GAMESTATEID_INITIAL){ 94 COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id << " diffed from: " << gID << " (not diffed yet)" << std::endl; 95 96 //chose wheather the next gamestate is the first or not 97 if(gID != GAMESTATEID_INITIAL){ 73 98 GameState *client = gameStateMap[gID]; 74 99 GameState *server = reference; … … 90 115 GameState *GameStateManager::getSnapshot(int id) 91 116 { 117 //std::cout << "begin getSnapshot" << std::endl; 92 118 //the size of the gamestate 93 119 int totalsize=0; … … 102 128 GameState *retval=new GameState; //return value 103 129 retval->id=id++; 104 COUT(4) << " producing gamestate with id: " << retval->id << std::endl;130 COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl; 105 131 // reserve a little memory and increase it later on 106 COUT(5) << " mallocing"<< std::endl;132 COUT(5) << "G.ST.Man: mallocing: " << memsize << std::endl; 107 133 retval->data = (unsigned char*)malloc(memsize); 108 COUT(5) << " malloced"<< std::endl;134 COUT(5) << "G.ST.Man: malloced: " << memsize << std::endl; 109 135 110 136 // offset of memory functions … … 112 138 // go through all Synchronisables 113 139 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 140 //std::cout << "begin inner loop" << std::endl; 114 141 //std::cout << "gamestatemanager: in for loop" << std::endl; 115 142 //get size of the synchronisable 116 143 tempsize=it->getSize(); 117 //COUT(5) << "size of temp gamestate: " << tempsize << std::endl;144 //COUT(5) << "size of temp gamestate: " << tempsize << std::endl; 118 145 //COUT(2) << "size of synchronisable: " << tempsize << std::endl; 119 146 // add place for data and 3 ints (length,classid,objectid) 120 147 totalsize+=tempsize+3*sizeof(int); 121 148 //std::cout << "totalsize: " << totalsize << std::endl; 149 //COUT(5) << "G.St.Man: current totalsize=" << totalsize << std::endl; 150 //COUT(5) << "G.St.Man: current it->classID=" << it->classID << " it->objectID=" << it->objectID << std::endl; 122 151 // allocate additional space 123 if(totalsize+tempsize>memsize){ 124 if(tempsize<1000){ 152 if((totalsize+tempsize) > memsize){ 153 COUT(5) << "G.St.Man: need additional memory" << std::endl; 154 if(tempsize < 1000){ 125 155 retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000); 126 156 memsize+=1000; … … 129 159 memsize+=tempsize+1000; 130 160 } 161 COUT(5) << "G.St.Man: additional space allocation finished" << std::endl; 131 162 } 132 163 133 164 // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length) 134 165 sync=it->getData((retval->data)+offset+3*sizeof(int)); 135 *(retval->data+offset)=(unsigned char)sync.length; 136 *(retval->data+offset+sizeof(int))=(unsigned char)sync.objectID; 137 *(retval->data+offset+2*sizeof(int))=(unsigned char)sync.classID; 166 memcpy(retval->data+offset, (void *)&sync.length, sizeof(int)); 167 //*(retval->data+offset)=sync.length; 168 memcpy(retval->data+offset+sizeof(int), (void *)&sync.objectID, sizeof(int)); 169 //*(retval->data+offset+sizeof(int))=sync.objectID; 170 memcpy(retval->data+offset+2*sizeof(int), (void *)&sync.classID, sizeof(int)); 171 //*(retval->data+offset+2*sizeof(int))=sync.classID; 138 172 // increase data pointer 139 173 offset+=tempsize+3*sizeof(int); 140 }141 COUT(5) << "Gamestate size: " << totalsize << std::endl;174 //std::cout << "end inner loop" << std::endl; 175 } 142 176 retval->size=totalsize; 177 //#### bugfix 178 retval->diffed = false; 179 //std::cout << "end snapShot" << std::endl; 180 COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl; 143 181 return retval; 144 182 } 145 183 184 //##### ADDED FOR TESTING PURPOSE ##### 185 GameStateCompressed* GameStateManager::testCompress( GameState* g ) { 186 return compress_( g ); 187 } 188 189 GameState* GameStateManager::testDiff( GameState* a, GameState* b ) { 190 return diff( a, b ); 191 } 192 //##### END TESTING PURPOSE ##### 193 146 194 GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) { 195 COUT(5) << "G.St.Man: this will be a DIFFED gamestate" << std::endl; 147 196 //GameState r = diff(a,b); 148 197 //r.diffed = true; 149 198 GameState *r = b; 150 199 r->diffed = false; 151 return compress_(r); 200 //return compress_(r); 201 GameStateCompressed *g = new GameStateCompressed; 202 g->base_id = b->base_id; 203 g->id = b->id; 204 g->diffed = b->diffed; 205 g->data = b->data; 206 g->normsize = b->size; 207 g->compsize = b->size; 208 return g; 152 209 } 153 210 154 211 GameStateCompressed *GameStateManager::encode(GameState *a) { 212 COUT(5) << "G.St.Man: this will be a not diffed gamestate" << std::endl; 155 213 a->diffed=false; 156 return compress_(a); 214 GameStateCompressed *g = new GameStateCompressed; 215 g->base_id = a->base_id; 216 g->id = a->id; 217 g->diffed = a->diffed; 218 g->data = a->data; 219 g->normsize = a->size; 220 g->compsize = a->size; 221 return g; 157 222 } 158 223 … … 189 254 r->size = dest_length; 190 255 r->diffed = true; 256 r->base_id = a->id; 191 257 r->data = dp; 192 258 return r; … … 194 260 195 261 GameStateCompressed *GameStateManager::compress_(GameState *a) { 196 COUT(5) << "compressing gamestate" << std::endl; 262 //COUT(4) << "G.St.Man: compressing gamestate" << std::endl; 263 264 //COUT(4) << "G.St.Man: a: id: " << a->id << " base_id: " << a->base_id << " size: " << a->size << " diffed: " << a->diffed << std::endl; 197 265 int size = a->size; 266 198 267 uLongf buffer = (uLongf)((a->size + 12)*1.01)+1; 268 //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl; 199 269 unsigned char* dest = (unsigned char*)malloc( buffer ); 270 //COUT(4) << "dest: " << dest << std::endl; 200 271 int retval; 201 272 //std::cout << "before ziped " << buffer << std::endl; 202 273 retval = compress( dest, &buffer, a->data, (uLong)size ); 274 //COUT(4) << "bloablabla aft3er compress" << std::endl; 203 275 //std::cout << "after ziped " << buffer << std::endl; 204 276 205 277 switch ( retval ) { 206 case Z_OK: COUT(5) << " successfully compressed" << std::endl; break;207 case Z_MEM_ERROR: COUT(1) << " not enough memory available in gamestate.compress" << std::endl;278 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 279 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 208 280 return NULL; 209 case Z_BUF_ERROR: COUT(2) << " not enough memory available in the buffer in gamestate.compress" << std::endl;281 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; 210 282 return NULL; 211 case Z_DATA_ERROR: COUT(2) << " decompress: data corrupted in gamestate.compress" << std::endl;283 case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; 212 284 return NULL; 213 285 } … … 221 293 compressedGamestate->data = dest; 222 294 compressedGamestate->diffed = a->diffed; 223 295 compressedGamestate->base_id = a->base_id; 296 //COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed:" << std::endl; 224 297 return compressedGamestate; 225 298 } -
code/branches/network2/src/network/GameStateManager.h
r1062 r1098 71 71 GameStateManager(ClientInformation *head); 72 72 ~GameStateManager(); 73 //#### ADDED FOR TESTING PURPOSE #### 74 GameStateCompressed* testCompress( GameState* g ); 75 GameState* testDiff( GameState* a, GameState* b ); 76 //#### END TESTING PURPOSE #### 73 77 void update(); 74 78 GameStateCompressed *popGameState(int clientID); … … 76 80 int id; 77 81 private: 82 void cleanup(); // "garbage handler" 78 83 GameState *getSnapshot(int id); 79 84 GameStateCompressed *encode(GameState *a, GameState *b); -
code/branches/network2/src/network/PacketBuffer.cc
r1062 r1098 61 61 last=first; 62 62 last->next=NULL; 63 // change this!!!!!!! 63 // change this!!!!!!! 64 64 last->packet = ev->packet; 65 last->address = ev->peer->address;65 //last->address = ev->peer->address; 66 66 } else { 67 67 //insert a new element at the bottom … … 72 72 // save the packet to the new element 73 73 last->packet = ev->packet; 74 last->address = ev->peer->address;74 //last->address = ev->peer->address; 75 75 } 76 return true; 76 // pseudo bugfix: added a return false statement for error handling 77 if ( last->packet == ev->packet ) return true; 78 return false; 77 79 } 78 80 81 //returns the first element in the list without deleting it but 82 //moving first pointer to next element 79 83 ENetPacket *PacketBuffer::pop() { 80 84 boost::mutex::scoped_lock lock(networkPacketBufferMutex); -
code/branches/network2/src/network/PacketDecoder.cc
r1064 r1098 54 54 { 55 55 int client = clientId; 56 COUT(5) << " clientId: " << client << std::endl; //control cout, not important, just debugging info56 COUT(5) << "PacketDecoder: clientId: " << client << std::endl; //control cout, not important, just debugging info 57 57 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 58 COUT(5) << "packet id: " << id << std::endl; 59 // COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl; 58 COUT(5) << "PacketDecoder: packet id: " << id << std::endl; 59 //COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl; 60 61 if ( packet == NULL ) { 62 COUT(4) << "PacketDecoder: no packets->packetbuffer queue is empty" << std::endl; 63 return false; 64 } 60 65 switch( id ) { 61 66 case ACK: … … 95 100 96 101 97 COUT(5) << " got ack id: " << a->id << std::endl;102 COUT(5) << "PacketDecoder: got ack id: " << a->id << std::endl; 98 103 processAck( a, clientId ); //debug info 99 104 … … 149 154 currentState = new GameStateCompressed; 150 155 if(currentState == NULL){ 151 COUT(3) << " could not generate new GameStateCompressed" << std::endl;156 COUT(3) << "PacketDecoder: could not generate new GameStateCompressed" << std::endl; 152 157 return; 153 158 } … … 159 164 //currentState->id = *((int *)packet->data+sizeof(int)); 160 165 memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) ); 161 COUT(5) << " decoder: received gs id: " << currentState->id << std::endl;166 COUT(5) << "PacketDecoder: received gs id: " << currentState->id << std::endl; 162 167 // std::cout << "id: " << currentState->id << std::endl; 163 168 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th … … 168 173 //size of uncompressed data 169 174 memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) ); 175 memcpy( (void*)&(currentState->base_id), (const void*)(packet->data+4*sizeof( int )), sizeof( int ) ); 170 176 //currentState->normsize = (int)*(data+3*sizeof(int)); 171 177 // std::cout << "normsize. " << currentState->normsize << std::endl; 172 178 //since the packetgenerator was changed, due to a new parameter, change this function too 173 memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+ 4*sizeof(int)), sizeof(bool));179 memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool)); 174 180 //currentState->diffed = (bool)*(data+4*sizeof(int)); 175 181 // std::cout << "diffed: " << currentState->diffed << std::endl; 176 182 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 177 183 if(currentState->compsize==0) 178 COUT(2) << " compsize is 0" << std::endl;184 COUT(2) << "PacketDecoder: compsize is 0" << std::endl; 179 185 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 180 186 if(currentState->data==NULL) 181 COUT(2) << " Gamestatepacket-decoder: memory leak" << std::endl;187 COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl; 182 188 //copy the GameStateCompressed data 183 189 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; … … 199 205 void *data = (void *)cid->message; 200 206 memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length); 201 COUT(4) << " classid: " << cid->clid << ", name: " << cid->message << std::endl;207 COUT(4) << "PacketDecoder: classid: " << cid->clid << ", name: " << cid->message << std::endl; 202 208 enet_packet_destroy( packet ); 203 209 processClassid(cid); … … 214 220 void PacketDecoder::processGamestate( GameStateCompressed *state ) 215 221 { 222 COUT(5) << "PacketDecoder: processing Gamestate" << std::endl; 223 //printGamestate( state ); 216 224 } 217 225 -
code/branches/network2/src/network/PacketGenerator.cc
r1062 r1098 52 52 ENetPacket* PacketGenerator::acknowledgement( int state, int reliable ) 53 53 { 54 COUT(4) << " generating new acknowledgement, id: " << state << std::endl;54 COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl; 55 55 ack* ackreq = new ack; 56 56 ackreq->id = ACK; … … 65 65 ENetPacket* PacketGenerator::mousem( double x, double y, int reliable ) 66 66 { 67 COUT(4) << " generating new mouse" << std::endl;67 COUT(4) << "PacketGenerator: generating new mouse" << std::endl; 68 68 mouse* mousemove = new mouse; 69 69 mousemove->id = MOUSE; … … 79 79 ENetPacket* PacketGenerator::keystrike( char press, int reliable ) 80 80 { 81 COUT(4) << " generating new keyboard" << std::endl;81 COUT(4) << "PacketGenerator: generating new keyboard" << std::endl; 82 82 keyboard* key = new keyboard; 83 83 key->id = KEYBOARD; … … 115 115 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int)); 116 116 memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int)); 117 memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool)); 118 /*(int)*(data) = gid; 119 (int)*(data+sizeof(int)) = states->id; 120 //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream 121 (int)*(data+2*sizeof(int)) = states->compsize; 122 //this is the uncompressed size of GameStateCompressed data 123 (int)*(data+3*sizeof(int)) = states->normsize; 124 //since there is a new parameter inside GameStateCompressed, change this function to create packet 125 (bool)*(data+4*sizeof(int)) = states->diffed;*/ 117 memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->base_id), sizeof(int)); 118 memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool)); 126 119 //place the GameStateCompressed data at the end of the enet datastream 127 memcpy( (void*)(data+ 4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );120 memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize ); 128 121 //create an enet packet with the generated bytestream 129 122 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); … … 135 128 { 136 129 unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1); 137 std::cout << " classid: " << classid << ", name: " << classname << std::endl;130 std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl; 138 131 *(int *)data = CLASSID; 139 132 *((int *)data+1) = classname.length()+1; -
code/branches/network2/src/network/PacketTypes.h
r1056 r1098 65 65 int size; //!< total size of data 66 66 // new ---- change functions 67 int base_id; // if gamestate is diffed this is the id of the old gamestate (base) 67 68 bool diffed; 68 69 unsigned char *data; //!< pointer to data … … 80 81 int normsize; //!< size of uncompressed data 81 82 // new ----- change functions 83 int base_id; // if gamestate is diffed this is the id of the old gamestate (base) 82 84 bool diffed; 83 85 unsigned char *data; //!< gamestate data -
code/branches/network2/src/network/Server.cc
r1062 r1098 124 124 bool Server::sendMSG(const char *msg) { 125 125 ENetPacket *packet = packet_gen.chatMessage(msg); 126 std::cout <<"adding Packets" << std::endl;126 COUT(4) <<"Server: adding Packets" << std::endl; 127 127 connection->addPacketAll(packet); 128 128 //std::cout <<"added packets" << std::endl; 129 129 if (connection->sendPackets()){ 130 std::cout << "Sucessfully" << std::endl;130 COUT(4) << "Server: Sucessfully" << std::endl; 131 131 return true; 132 132 } … … 155 155 while(!connection->queueEmpty()){ 156 156 //std::cout << "Client " << clientID << " sent: " << std::endl; 157 //clientID here is a reference to grab clientID from ClientInformation 157 158 packet = connection->getPacket(clientID); 158 elaborate(packet, clientID); 159 //if statement to catch case that packetbuffer is empty 160 if( !elaborate(packet, clientID) ) 161 COUT(4) << "Server: PacketBuffer empty" << std::endl; 159 162 } 160 163 } … … 165 168 void Server::updateGamestate() { 166 169 gamestates->update(); 170 COUT(4) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 167 171 //std::cout << "updated gamestate, sending it" << std::endl; 168 172 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 169 sendGameState(); 173 sendGameState(); 174 COUT(4) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 170 175 //std::cout << "sent gamestate" << std::endl; 171 176 } … … 175 180 */ 176 181 bool Server::sendGameState() { 177 COUT(5) << " startingsendGameState" << std::endl;182 COUT(5) << "Server: starting function sendGameState" << std::endl; 178 183 ClientInformation *temp = clients; 179 184 bool added=false; 180 while(temp !=NULL){185 while(temp != NULL){ 181 186 if(temp->head){ 182 187 temp=temp->next(); 188 //think this works without continue 183 189 continue; 184 190 } 185 191 if( !(temp->getSynched()) ){ 186 COUT(5) << " not sending gamestate" << std::endl;192 COUT(5) << "Server: not sending gamestate" << std::endl; 187 193 temp=temp->next(); 194 //think this works without continue 188 195 continue; 189 196 } 190 COUT(5) << " doing gamestate gamestate preparation" << std::endl;191 int gid = temp->getGamestateID(); 192 int cid = temp->getID(); 193 COUT(5) << " server, got acked (gamestate) ID: " << gid << std::endl;197 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 198 int gid = temp->getGamestateID(); //get gamestate id 199 int cid = temp->getID(); //get client id 200 COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl; 194 201 GameStateCompressed *gs = gamestates->popGameState(cid); 195 202 if(gs==NULL){ 196 COUT(2) << " could not generate gamestate" << std::endl;203 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 197 204 return false; 198 205 } 199 206 //std::cout << "adding gamestate" << std::endl; 200 connection->addPacket(packet_gen.gstate(gs), cid); 207 if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ) 208 COUT(4) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 201 209 //std::cout << "added gamestate" << std::endl; 202 210 added=true; 203 211 temp=temp->next(); 204 212 } 205 if(added) 213 if(added) { 214 //std::cout << "send gamestates from server.cc in sendGameState" << std::endl; 206 215 return connection->sendPackets(); 207 COUT(5) << "had no gamestates to send" << std::endl; 216 } 217 COUT(5) << "Server: had no gamestates to send" << std::endl; 208 218 return false; 209 219 } 210 220 211 221 void Server::processAck( ack *data, int clientID) { 212 COUT(5) << " processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;222 COUT(5) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl; 213 223 clients->findClient(clientID)->setGamestateID(data->a); 214 224 } -
code/branches/network2/src/network/Synchronisable.cc
r1062 r1098 57 57 datasize=0; 58 58 objectID=idCounter++; 59 syncList = new std::list<synchronisableVariable *>; 59 60 //registerAllVariables(); 60 61 } … … 71 72 void Synchronisable::registerVar(const void *var, int size, variableType t){ 72 73 // create temporary synch.Var struct 73 synchronisableVariable temp={size, var, t}; 74 synchronisableVariable *temp = new synchronisableVariable; 75 temp->size = size; 76 temp->var = var; 77 temp->type = t; 78 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 74 79 // increase datasize 75 80 datasize+=sizeof(int)+size; 76 // push temp to syncList (at the bottom) 77 syncList.push_back(temp); 81 //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl; 82 COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl; 83 syncList->push_back(temp); 78 84 } 79 85 … … 91 97 // int totalsize=0; 92 98 // //figure out size of data to be allocated 93 // for(i=syncList .begin(); i!=syncList.end(); i++){99 // for(i=syncList->begin(); i!=syncList->end(); i++){ 94 100 // // increase size (size of variable and size of size of variable ;) 95 101 // if(i->type == STRING) … … 107 113 // //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP 108 114 // int n=0; 109 // for(i=syncList .begin(); n<totalsize && i!=syncList.end(); i++){115 // for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){ 110 116 // std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int)); 111 117 // n+=sizeof(int); … … 134 140 */ 135 141 syncData Synchronisable::getData(unsigned char *mem){ 136 std::list<synchronisableVariable>::iterator i; 142 //std::cout << "inside getData" << std::endl; 143 std::list<synchronisableVariable *>::iterator i; 137 144 syncData retVal; 138 145 retVal.objectID=this->objectID; … … 141 148 retVal.data=mem; 142 149 // copy to location 143 int n=0; 144 for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){ 145 //COUT(2) << "size of variable: " << i->size << std::endl; 150 int n=0; //offset 151 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 146 152 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 147 memcpy( (void *)(retVal.data+n), (const void *)&(i->size), sizeof(int) );153 memcpy( (void *)(retVal.data+n), (const void *)&((*i)->size), sizeof(int) ); 148 154 n+=sizeof(int); 149 switch( i->type){155 switch((*i)->type){ 150 156 case DATA: 151 std::memcpy( (void *)(retVal.data+n), (const void*)( i->var), i->size);152 n+= i->size;157 std::memcpy( (void *)(retVal.data+n), (const void*)((*i)->var), (*i)->size); 158 n+=(*i)->size; 153 159 break; 154 160 case STRING: 155 std::memcpy( retVal.data+n, (const void*)( ( (std::string *) i->var)->c_str()), ( (std::string *)i->var )->length()+1);156 n+=( (std::string *) i->var)->length()+1;161 std::memcpy( retVal.data+n, (const void*)( ( (std::string *) (*i)->var)->c_str()), (*i)->size); 162 n+=(*i)->size; 157 163 break; 158 164 } … … 168 174 bool Synchronisable::updateData(syncData vars){ 169 175 unsigned char *data=vars.data; 170 std::list<synchronisableVariable>::iterator i; 171 for(i=syncList.begin(); i!=syncList.end(); i++){ 172 if((int)*data==i->size || i->type==STRING){ 173 switch(i->type){ 174 case DATA: 175 data+=sizeof(int); 176 memcpy((void*)i->var, data, i->size); 177 data+=i->size; 178 break; 179 case STRING: 180 i->size = (int)*data; 181 data+=sizeof(int); 182 *((std::string *)i->var) = std::string((const char*)data); 183 data += i->size; 184 break; 176 std::list<synchronisableVariable *>::iterator i; 177 if(syncList->empty()){ 178 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl; 179 return false; 180 } 181 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " synchronising data" << std::endl; 182 for(i=syncList->begin(); i!=syncList->end(); i++){ 183 COUT(5) << "element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 184 if(*(int *)data==(*i)->size || (*i)->type==STRING){ 185 switch((*i)->type){ 186 case DATA: 187 data+=sizeof(int); 188 memcpy((void*)(*i)->var, data, (*i)->size); 189 data+=(*i)->size; 190 break; 191 case STRING: 192 (*i)->size = *(int *)data; 193 data+=sizeof(int); 194 *((std::string *)((*i)->var)) = std::string((const char*)data); 195 data += (*i)->size; 196 break; 185 197 } 186 198 } else … … 196 208 int Synchronisable::getSize(){ 197 209 int tsize=0; 198 std::list<synchronisableVariable>::iterator i; 199 for(i=syncList.begin(); i!=syncList.end(); i++){ 200 switch(i->type){ 201 case DATA: 202 tsize+=sizeof(int); 203 tsize+=i->size; 204 break; 205 case STRING: 206 tsize+=sizeof(int); 207 tsize+=((std::string *)i->var)->length()+1; 208 break; 210 std::list<synchronisableVariable *>::iterator i; 211 for(i=syncList->begin(); i!=syncList->end(); i++){ 212 switch((*i)->type){ 213 case DATA: 214 tsize+=sizeof(int); 215 tsize+=(*i)->size; 216 break; 217 case STRING: 218 tsize+=sizeof(int); 219 (*i)->size=((std::string *)(*i)->var)->length()+1; 220 tsize+=(*i)->size; 221 break; 209 222 } 210 223 } -
code/branches/network2/src/network/Synchronisable.h
r1062 r1098 75 75 public: 76 76 77 77 virtual ~Synchronisable(); 78 78 int objectID; 79 79 int classID; … … 91 91 /* bool removeObject(Iterator<Synchronisable> it);*/ 92 92 93 std::list< SYNCVAR>syncList;93 std::list<synchronisableVariable *> *syncList; 94 94 int datasize; 95 95 }; -
code/branches/network2/src/orxonox/Orxonox.cc
r1092 r1098 305 305 hudOverlay->show(); 306 306 307 client_g->establishConnection(); 307 if( !client_g->establishConnection() ) 308 COUT(1) <<"CLIENT COULD NOT ESTABLISH CONNECTION" << std::endl; 308 309 client_g->tick(0); 309 310 -
code/branches/network2/src/orxonox/objects/Ambient.cc
r1064 r1098 57 57 RegisterObject(Ambient); 58 58 Ambient::instance_s = this; 59 registerAllVariables(); 59 60 } 60 61 … … 63 64 } 64 65 66 bool Ambient::create(){ 67 Orxonox::getSingleton()->getSceneManager()->setAmbientLight(ambientLight_); 68 return true; 69 } 70 71 void Ambient::registerAllVariables(){ 72 registerVar(&ambientLight_, sizeof(ColourValue), network::DATA); 73 74 } 75 65 76 void Ambient::loadParams(TiXmlElement* xmlElem) 66 77 { … … 83 94 { 84 95 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour); 96 ambientLight_=colour; 85 97 } 86 98 … … 96 108 97 109 XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode); 110 create(); 98 111 } 99 112 } -
code/branches/network2/src/orxonox/objects/Ambient.h
r1056 r1098 34 34 #include "util/Math.h" 35 35 #include "core/BaseObject.h" 36 #include "network/Synchronisable.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport Ambient : public BaseObject 40 class _OrxonoxExport Ambient : public BaseObject, network::Synchronisable 40 41 { 41 42 public: … … 46 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 48 void setAmbientLight(const ColourValue& colour); 49 bool create(); 50 void registerAllVariables(); 48 51 49 52 static void setAmbientLightTest(const ColourValue& colour) … … 52 55 private: 53 56 static Ambient* instance_s; 57 ColourValue ambientLight_; 54 58 55 59 }; -
code/branches/network2/src/orxonox/objects/Model.cc
r1064 r1098 82 82 83 83 bool Model::create(){ 84 WorldEntity::create(); 84 if(!WorldEntity::create()) 85 return false; 85 86 if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) 86 87 { 87 88 this->mesh_.setMesh(meshSrc_); 88 89 this->attachObject(this->mesh_.getEntity()); 89 COUT(4) << "Loader : Created model" << std::endl;90 COUT(4) << "Loader (Model.cc): Created model" << std::endl; 90 91 } 91 92 return true; … … 93 94 94 95 void Model::registerAllVariables(){ 95 WorldEntity::registerAllVariables(); 96 // WorldEntity::registerAllVariables(); 97 COUT(5) << "Model.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl; 96 98 registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); 97 99 } -
code/branches/network2/src/orxonox/objects/NPC.cc
r1056 r1098 40 40 RegisterObject(NPC); 41 41 movable_ = true; 42 registerAllVariables(); 42 43 } 43 44 … … 59 60 this->translate(location); 60 61 movable_ = movable; 62 } 63 64 void NPC::registerAllVariables(){ 65 Model::registerAllVariables(); 66 registerVar(&movable_, sizeof(movable_), network::DATA); 67 } 68 69 bool NPC::create(){ 70 Model::create(); 71 return true; 61 72 } 62 73 -
code/branches/network2/src/orxonox/objects/NPC.h
r1056 r1098 52 52 void update(); 53 53 void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable); 54 void registerAllVariables(); 55 bool create(); 54 56 55 57 private: -
code/branches/network2/src/orxonox/objects/Skybox.cc
r1064 r1098 47 47 { 48 48 RegisterObject(Skybox); 49 registerAllVariables(); 49 50 } 50 51 … … 57 58 if (xmlElem->Attribute("src")) 58 59 { 59 s td::string skyboxSrc= xmlElem->Attribute("src");60 this->setSkybox(skyboxSrc);60 skyboxSrc_ = xmlElem->Attribute("src"); 61 this->create(); 61 62 62 COUT(4) << "Loader: Set skybox: "<< skyboxSrc << std::endl << std::endl;63 COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl; 63 64 } 64 65 } … … 69 70 } 70 71 72 void Skybox::setSkyboxSrc(std::string src){ 73 skyboxSrc_ = src; 74 } 75 71 76 /** 72 77 @brief XML loading and saving. … … 80 85 81 86 XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode); 87 XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, loading); 88 create(); 82 89 } 90 91 bool Skybox::create(){ 92 this->setSkybox(skyboxSrc_); 93 return true; 94 } 95 96 void Skybox::registerAllVariables(){ 97 registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING); 98 } 99 83 100 } -
code/branches/network2/src/orxonox/objects/Skybox.h
r1056 r1098 33 33 34 34 #include "core/BaseObject.h" 35 #include "network/Synchronisable.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport Skybox : public BaseObject 39 class _OrxonoxExport Skybox : public BaseObject, public network::Synchronisable 39 40 { 40 41 public: … … 45 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 47 void setSkybox(const std::string& skyboxname); 48 49 bool create(); 50 void registerAllVariables(); 51 void setSkyboxSrc(std::string src); 47 52 48 53 private: 54 std::string skyboxSrc_; 49 55 50 56 -
code/branches/network2/src/orxonox/objects/WorldEntity.cc
r1064 r1098 72 72 } 73 73 } 74 74 75 75 76 WorldEntity::~WorldEntity() … … 162 163 */ 163 164 } 165 164 166 165 167 void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll) … … 188 190 189 191 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true); 192 193 //create(); 190 194 } 191 195
Note: See TracChangeset
for help on using the changeset viewer.