Changeset 3198
- Timestamp:
- Jun 20, 2009, 4:27:38 PM (15 years ago)
- Location:
- code/trunk/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/ConfigFileManager.cc
r3196 r3198 40 40 namespace orxonox 41 41 { 42 const int CONFIG_FILE_MAX_LINELENGHT = 1024;43 42 const char* const DEFAULT_CONFIG_FILE = "default.ini"; 44 43 … … 244 243 if (file.is_open()) 245 244 { 246 247 char linearray[CONFIG_FILE_MAX_LINELENGHT];248 249 245 ConfigFileSection* newsection = 0; 250 246 251 247 while (file.good() && !file.eof()) 252 248 { 253 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 254 255 std::string line = std::string(linearray); 249 std::string line; 250 std::getline(file, line); 256 251 257 252 std::string temp = getStripped(line); -
code/trunk/src/core/ConsoleCommandCompilation.cc
r3196 r3198 73 73 74 74 // Iterate through the file and put the lines into the CommandExecutor 75 char line[1024];76 75 while (file.good() && !file.eof()) 77 76 { 78 file.getline(line, 1024); 77 std::string line; 78 std::getline(file, line); 79 79 CommandExecutor::execute(line); 80 80 } … … 144 144 145 145 std::string output = ""; 146 char line[1024];147 146 while (file.good() && !file.eof()) 148 147 { 149 file.getline(line, 1024); 148 std::string line; 149 std::getline(file, line); 150 150 output += line; 151 151 output += "\n"; -
code/trunk/src/core/Language.cc
r3196 r3198 224 224 } 225 225 226 char line[1024];227 228 226 // Iterate through the file and create the LanguageEntries 229 227 while (file.good() && !file.eof()) 230 228 { 231 file.getline(line, 1024);232 std:: string lineString = std::string(line);229 std::string lineString; 230 std::getline(file, lineString); 233 231 234 232 // Check if the line is empty … … 272 270 } 273 271 274 char line[1024];275 276 272 // Iterate through the file and create the LanguageEntries 277 273 while (file.good() && !file.eof()) 278 274 { 279 file.getline(line, 1024);280 std:: string lineString = std::string(line);275 std::string lineString; 276 std::getline(file, lineString); 281 277 282 278 // Check if the line is empty -
code/trunk/src/core/LuaBind.cc
r3196 r3198 95 95 } 96 96 97 char line[1024*32];98 97 std::string levelString = ""; 99 98 100 99 while (file.good() && !file.eof()) 101 100 { 102 file.getline(line, 1024*32); 101 std::string line; 102 std::getline(file, line); 103 103 levelString += line; 104 104 levelString += "\n"; -
code/trunk/src/network/Client.cc
r3084 r3198 169 169 bool b = packet->process(); 170 170 assert(b); 171 delete event; 171 172 } 172 173 if(gamestate.processGamestates()) -
code/trunk/src/network/ClientConnection.cc
r3084 r3198 169 169 // assert(0); 170 170 printf("ClientConnection: ENet returned with an error!\n"); 171 quit_=true;172 break;171 // quit_=true; 172 continue; 173 173 // add some error handling here ======================== 174 174 } … … 197 197 } 198 198 } 199 delete event; 199 200 // now disconnect 200 201 201 202 if(!disconnectConnection()) 203 { 204 printf("could not disconnect properly\n"); 202 205 // if disconnecting failed destroy conn. 203 206 boost::recursive_mutex::scoped_lock lock(enet_mutex_g); 204 207 enet_peer_reset(server); 208 } 209 else 210 printf("properly disconnected\n"); 205 211 return; 206 212 } … … 221 227 break; 222 228 case ENET_EVENT_TYPE_DISCONNECT: 229 printf("received disconnect confirmation from server"); 223 230 return true; 224 231 } -
code/trunk/src/network/ClientInformation.h
r2773 r3198 91 91 bool getSynched(); 92 92 93 94 93 private: 95 94 static ClientInformation *head_; -
code/trunk/src/network/ConnectionManager.cc
r3093 r3198 132 132 quit_=true; 133 133 receiverThread_->join(); 134 delete receiverThread_; 134 135 return true; 135 136 } … … 206 207 // we should never reach this point 207 208 printf("ConnectionManager: ENet returned with an error\n"); 208 quit_=true;209 printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");209 // quit_=true; 210 // printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n"); 210 211 continue; 211 212 // add some error handling here ======================== … … 218 219 // printf("===================================================================="); 219 220 case ENET_EVENT_TYPE_DISCONNECT: 221 // printf("===================================================================="); 220 222 case ENET_EVENT_TYPE_RECEIVE: 221 222 223 processData(event); 224 event = new ENetEvent; 223 225 break; 224 226 case ENET_EVENT_TYPE_NONE: 225 227 //receiverThread_->yield(); 226 msleep(1 0);228 msleep(1); 227 229 break; 228 230 } -
code/trunk/src/network/ConnectionManager.h
r3093 r3198 55 55 const int NETWORK_PORT = 55556; 56 56 const int NETWORK_MAX_CONNECTIONS = 50; 57 const int NETWORK_WAIT_TIMEOUT = 1 0;57 const int NETWORK_WAIT_TIMEOUT = 1; 58 58 const int NETWORK_DEFAULT_CHANNEL = 0; 59 59 -
code/trunk/src/network/GamestateManager.cc
r3102 r3198 63 63 GamestateManager::~GamestateManager() 64 64 { 65 if( this->reference ) 66 delete this->reference; 67 for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ ) 68 delete (*it).second; 65 69 delete trafficControl_; 66 70 } … … 133 137 // COUT(3) << "diffing" << std::endl; 134 138 // packet::Gamestate* gs1 = gs; 135 gs = gs->diff(client); 139 packet::Gamestate *diffed = gs->diff(client); 140 //packet::Gamestate *gs2 = diffed->undiff(gs); 141 // assert(*gs == *gs2); 142 gs = diffed; 136 143 // packet::Gamestate* gs2 = gs->undiff(client); 137 144 // gs = new packet::Gamestate(*gs); -
code/trunk/src/network/Server.cc
r3196 r3198 128 128 */ 129 129 void Server::close() { 130 ClientInformation *temp = ClientInformation::getBegin(); 131 ClientInformation *temp2; 132 // disconnect all connected clients 133 while( temp ) 134 { 135 temp2 = temp; 136 temp = temp->next(); 137 disconnectClient( temp2 ); 138 } 130 139 connection->quitListener(); 131 140 return; … … 198 207 switch( event->type ) { 199 208 case ENET_EVENT_TYPE_CONNECT: 200 COUT( 3) << "processing event_Type_connect" << std::endl;209 COUT(4) << "processing event_Type_connect" << std::endl; 201 210 addClient(event); 202 211 break; … … 304 313 // gs gets automatically deleted by enet callback 305 314 } 315 delete del; 306 316 return true; 307 317 } … … 381 391 if(!client) 382 392 return false; 393 else 394 disconnectClient( client ); 395 return true; 396 } 397 398 void Server::disconnectClient(int clientID){ 399 ClientInformation *client = ClientInformation::findClient(clientID); 400 if(client) 401 disconnectClient(client); 402 } 403 404 void Server::disconnectClient( ClientInformation *client){ 405 connection->disconnectClient(client); 383 406 gamestates_->removeClient(client); 384 385 407 // inform all the listeners 386 408 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); 387 409 while(listener){ 388 410 listener->clientDisconnected(client->getID()); 389 listener++; 390 } 391 392 return ClientInformation::removeClient(event->peer); 393 } 394 395 void Server::disconnectClient(int clientID){ 396 ClientInformation *client = ClientInformation::findClient(clientID); 397 if(client) 398 disconnectClient(client); 399 } 400 void Server::disconnectClient( ClientInformation *client){ 401 connection->disconnectClient(client); 402 gamestates_->removeClient(client); 411 ++listener; 412 } 413 delete client; //remove client from list 403 414 } 404 415 -
code/trunk/src/network/TrafficControl.cc
r3084 r3198 137 137 void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID) 138 138 { 139 if ( !this->bActive_ ) 140 return; 139 141 std::list<obj>::iterator itvec; // iterator to iterate through the acked objects 140 142 … … 189 191 void TrafficControl::updateClientListTemp(std::list<obj>& list) 190 192 { 191 clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list);193 clientListTemp_[currentClientID][currentGamestateID] = list; 192 194 } 193 195 … … 227 229 { 228 230 229 //now the sorting 230 231 //compare listToProcess vs clientListPerm 232 //if listToProcess contains new Objects, add them to clientListPerm 233 std::list<obj>::iterator itvec; 231 if( bActive_ ) 232 { 233 //now the sorting 234 235 //compare listToProcess vs clientListPerm 236 //if listToProcess contains new Objects, add them to clientListPerm 237 std::list<obj>::iterator itvec; 234 238 235 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];239 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 236 240 237 238 239 240 {241 for( itvec=list.begin(); itvec != list.end(); itvec++) 242 { 243 if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() ) 244 { 241 245 // we already have the object in our map 242 246 //obj bleibt in liste und permanente prio wird berechnet 243 objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;244 continue;//check next objId245 }246 else247 {247 objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS; 248 continue;//check next objId 249 } 250 else 251 { 248 252 // insert the object into clientListPerm 249 insertinClientListPerm(clientID,*itvec); 250 continue;//check next objId 251 } 252 } 253 //end compare listToProcess vs clientListPerm 254 255 if( bActive_ ) 256 { 253 insertinClientListPerm(clientID,*itvec); 254 continue;//check next objId 255 } 256 } 257 //end compare listToProcess vs clientListPerm 258 257 259 //sort copied list according to priorities 258 260 // use boost bind here because we need to pass a memberfunction to stl sort … … 275 277 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 276 278 list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 279 280 //diese Funktion updateClientList muss noch gemacht werden 281 updateClientListTemp(list); 282 //end of sorting 277 283 } 278 //diese Funktion updateClientList muss noch gemacht werden279 updateClientListTemp(list);280 //end of sorting281 284 } 282 285 -
code/trunk/src/network/packet/Acknowledgement.cc
r2710 r3198 64 64 65 65 bool Acknowledgement::process(){ 66 COUT(6) << "processing ACK with ID: " << getAckID() << endl;66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 67 67 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_); 68 68 delete this; -
code/trunk/src/network/packet/Gamestate.cc
r3196 r3198 79 79 Gamestate::~Gamestate() 80 80 { 81 if( header_ ) 82 delete header_; 81 83 } 82 84 … … 98 100 99 101 // create the header object 102 assert( header_ == 0 ); 100 103 header_ = new GamestateHeader(data_); 101 104 … … 137 140 header_->setDataSize( currentsize ); 138 141 header_->setID( id ); 142 header_->setBaseID( GAMESTATEID_INITIAL ); 139 143 header_->setDiffed( false ); 140 144 header_->setComplete( true ); … … 207 211 } 208 212 #endif 209 210 213 return true; 211 214 } … … 320 323 } 321 324 322 Gamestate *Gamestate::diff(Gamestate *base)325 /*Gamestate *Gamestate::diff(Gamestate *base) 323 326 { 324 327 assert(data_); … … 355 358 g->packetDirection_ = packetDirection_; 356 359 return g; 357 } 360 }*/ 361 362 Gamestate *Gamestate::diff(Gamestate *base) 363 { 364 assert(this && base); assert(data_ && base->data_); 365 assert(!header_->isCompressed() && !base->header_->isCompressed()); 366 assert(!header_->isDiffed()); 367 368 uint8_t *basep = GAMESTATE_START(base->data_); 369 uint8_t *gs = GAMESTATE_START(this->data_); 370 uint32_t dest_length = header_->getDataSize(); 371 372 if(dest_length==0) 373 return NULL; 374 375 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 376 uint8_t *dest = GAMESTATE_START(ndata); 377 378 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 379 #ifndef NDEBUG 380 uint8_t *dest2 = new uint8_t[dest_length]; 381 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 382 assert( memcmp( dest2, gs, dest_length) == 0 ); 383 #endif 384 385 Gamestate *g = new Gamestate(ndata, getClientID()); 386 assert(g->header_); 387 *(g->header_) = *header_; 388 g->header_->setDiffed( true ); 389 g->header_->setBaseID( base->getID() ); 390 g->flags_=flags_; 391 g->packetDirection_ = packetDirection_; 392 assert(g->isDiffed()); 393 assert(!g->isCompressed()); 394 return g; 395 } 396 397 Gamestate *Gamestate::undiff(Gamestate *base) 398 { 399 assert(this && base); assert(data_ && base->data_); 400 assert(!header_->isCompressed() && !base->header_->isCompressed()); 401 assert(header_->isDiffed()); 402 403 uint8_t *basep = GAMESTATE_START(base->data_); 404 uint8_t *gs = GAMESTATE_START(this->data_); 405 uint32_t dest_length = header_->getDataSize(); 406 407 if(dest_length==0) 408 return NULL; 409 410 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 411 uint8_t *dest = ndata + GamestateHeader::getSize(); 412 413 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 414 415 Gamestate *g = new Gamestate(ndata, getClientID()); 416 assert(g->header_); 417 *(g->header_) = *header_; 418 g->header_->setDiffed( false ); 419 g->flags_=flags_; 420 g->packetDirection_ = packetDirection_; 421 assert(!g->isDiffed()); 422 assert(!g->isCompressed()); 423 return g; 424 } 425 358 426 359 427 // Gamestate *Gamestate::diff(Gamestate *base) … … 409 477 // } 410 478 479 480 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 481 { 482 uint64_t* gd = (uint64_t*)data; 483 uint64_t* bd = (uint64_t*)basedata; 484 uint64_t* nd = (uint64_t*)newdata; 485 486 unsigned int i; 487 for( i=0; i<datalength/8; i++ ) 488 { 489 if( i<baselength/8 ) 490 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data 491 else 492 *(nd+i) = *(gd+i); // just copy over the data 493 } 494 unsigned int j; 495 // now process the rest (when datalength isn't a multiple of 4) 496 for( j = 8*(datalength/8); j<datalength; j++ ) 497 { 498 if( j<baselength ) 499 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor 500 else 501 *(newdata+j) = *(data+j); // just copy 502 } 503 assert(j==datalength); 504 } 505 411 506 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 412 507 assert(data_); … … 478 573 479 574 480 Gamestate *Gamestate::undiff(Gamestate *base)575 /*Gamestate *Gamestate::undiff(Gamestate *base) 481 576 { 482 577 assert(this && base);assert(data_); … … 514 609 assert(!g->isCompressed()); 515 610 return g; 516 } 517 611 }*/ 518 612 519 613 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) -
code/trunk/src/network/packet/Gamestate.h
r3084 r3198 124 124 // Packet functions 125 125 private: 126 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 126 127 virtual uint32_t getSize() const; 127 128 virtual inline bool process(); -
code/trunk/src/network/synchronisable/Synchronisable.cc
r3088 r3198 98 98 // delete callback function objects 99 99 if(!Identifier::isCreatingHierarchy()){ 100 // remove object from the static objectMap 101 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) 102 deletedObjects_.push(objectID); 103 // delete all Synchronisable Variables from syncList ( which are also in stringList ) 100 104 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++) 101 105 delete (*it); 102 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))103 deletedObjects_.push(objectID);106 syncList.clear(); 107 stringList.clear(); 104 108 } 105 109 std::map<uint32_t, Synchronisable*>::iterator it; … … 174 178 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 175 179 // update data and create object/entity... 180 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 181 Synchronisable::objectMap_[header.getObjectID()] = no; 176 182 bool b = no->updateData(mem, mode, true); 177 183 assert(b); … … 213 219 return it1->second; 214 220 215 ObjectList<Synchronisable>::iterator it; 216 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 217 if( it->getObjectID()==objectID ){ 218 objectMap_[objectID] = *it; 219 return *it; 220 } 221 } 221 // ObjectList<Synchronisable>::iterator it; 222 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 223 // if( it->getObjectID()==objectID ){ 224 // objectMap_[objectID] = *it; 225 // return *it; 226 // } 227 // } 228 // if the objects not in the map it should'nt exist at all anymore 222 229 return NULL; 223 230 } -
code/trunk/src/orxonox/gamestates/GSDedicated.cc
r3196 r3198 33 33 #include "core/Clock.h" 34 34 #include "core/CommandLine.h" 35 #include "core/CommandExecutor.h" 35 36 #include "core/Game.h" 36 37 #include "core/GameMode.h" 37 38 #include "network/Server.h" 38 39 40 #include <iostream> 41 #include <iomanip> 42 #include <boost/bind.hpp> 43 44 #ifndef ORXONOX_PLATFORM_WINDOWS 45 #include <termios.h> 46 #endif 47 48 39 49 namespace orxonox 40 50 { 51 const unsigned int MAX_COMMAND_LENGTH = 255; 52 41 53 AddGameState(GSDedicated, "dedicated"); 54 55 termios* GSDedicated::originalTerminalSettings_; 42 56 43 57 GSDedicated::GSDedicated(const std::string& name) … … 45 59 , server_(0) 46 60 , timeSinceLastUpdate_(0) 47 { 61 , closeThread_(false) 62 , inputIterator_(0) 63 , cleanLine_(true) 64 , cursorX_(0) 65 , cursorY_(0) 66 { 67 this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH]; 68 // memset( this->commandLine_, 0, MAX_COMMAND_LENGTH ); 48 69 } 49 70 … … 55 76 { 56 77 GameMode::setHasServer(true); 78 79 this->inputThread_ = new boost::thread(boost::bind(&GSDedicated::inputThread, this)); 80 81 #ifndef ORXONOX_PLATFORM_WINDOWS 82 this->originalTerminalSettings_ = new termios; 83 this->setTerminalMode(); 84 #endif 57 85 58 86 this->server_ = new Server(CommandLine::getValue("port")); … … 66 94 this->server_->close(); 67 95 delete this->server_; 96 97 closeThread_ = true; 98 #ifndef ORXONOX_PLATFORM_WINDOWS 99 std::cout << "\033[0G\033[K"; 100 std::cout.flush(); 101 resetTerminalMode(); 102 delete this->originalTerminalSettings_; 103 #endif 104 //inputThread_->join(); 68 105 69 106 GameMode::setHasServer(false); … … 72 109 void GSDedicated::update(const Clock& time) 73 110 { 74 // static float startTime = time.getSecondsPrecise();75 // static int nrOfTicks = 0;76 111 timeSinceLastUpdate_ += time.getDeltaTime(); 77 112 if (timeSinceLastUpdate_ >= NETWORK_PERIOD) 78 113 { 79 // ++nrOfTicks;80 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;81 114 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 82 115 server_->update(time); … … 84 117 else 85 118 { 86 usleep((int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000)); 119 usleep((unsigned int)((NETWORK_PERIOD - timeSinceLastUpdate_)*1000*1000 )); 120 usleep(NETWORK_PERIOD*1000*1000); // NOTE: this is to throttle the non-network framerate 87 121 // COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl; 88 122 } 89 } 123 processQueue(); 124 printLine(); 125 } 126 127 void GSDedicated::inputThread() 128 { 129 unsigned char c; 130 unsigned int escapeChar=0; 131 while(!closeThread_) 132 { 133 c = getchar(); 134 { 135 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 136 if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' ) 137 continue; 138 if( escapeChar > 0 ) 139 { 140 if( c == '[' ) 141 { 142 escapeChar = 2; 143 continue; 144 } 145 else if ( escapeChar == 2 ) 146 { 147 switch (c) 148 { 149 case 'A': //keyup 150 151 break; 152 case 'B': //keydown 153 154 break; 155 case 'C': //keyright 156 if(cursorX_<inputIterator_) 157 ++cursorX_; 158 break; 159 case 'D': //keyleft 160 if(cursorX_>0) 161 --cursorX_; 162 break; 163 default: //not supported... 164 // std::cout << endl << c << endl; 165 break; 166 } 167 escapeChar = 0; 168 } 169 } 170 else // not in escape sequence mode 171 { 172 switch (c) 173 { 174 case '\n': 175 this->cleanLine_ = true; 176 { 177 boost::recursive_mutex::scoped_lock(this->inputQueueMutex_); 178 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 179 this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) ); 180 } 181 memset( this->commandLine_, 0, inputIterator_ ); 182 inputIterator_ = 0; 183 this->cursorX_ = 0; 184 this->cursorY_ = 0; 185 std::cout << endl; 186 break; 187 case 127: // backspace 188 case '\b': 189 deleteCharacter( this->cursorX_ ); 190 break; 191 case '\t': 192 { 193 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 194 std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl; 195 strncpy((char*)this->commandLine_, CommandExecutor::complete( std::string((const char*)this->commandLine_,inputIterator_) ).c_str(), MAX_COMMAND_LENGTH); 196 inputIterator_ = strlen((const char*)this->commandLine_); 197 break; 198 } 199 case '\033': // 1. escape character 200 escapeChar = 1; 201 break; 202 default: 203 insertCharacter( this->cursorX_, c ); 204 break; 205 } 206 } 207 } 208 } 209 } 210 211 void GSDedicated::printLine() 212 { 213 #ifndef ORXONOX_PLATFORM_WINDOWS 214 // set cursor to the begining of the line and erase the line 215 std::cout << "\033[0G\033[K"; 216 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 217 // print status line 218 std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # "; 219 //save cursor position 220 std::cout << "\033[s"; 221 //print commandLine buffer 222 std::cout << std::string((const char*)this->commandLine_, inputIterator_); 223 //restore cursor position and move it cursorX_ to the right 224 std::cout << "\033[u"; 225 if( this->cursorX_ > 0 ) 226 std::cout << "\033[" << this->cursorX_ << "C"; 227 std::cout.flush(); 228 #endif 229 } 230 231 void GSDedicated::processQueue() 232 { 233 std::string tempstr; 234 { 235 boost::recursive_mutex::scoped_lock lock1(this->inputQueueMutex_); 236 while(true) 237 { 238 if ( !this->commandQueue_.empty() ) 239 { 240 tempstr = this->commandQueue_.front(); 241 this->commandQueue_.pop(); 242 lock1.unlock(); 243 } 244 else 245 break; 246 CommandExecutor::execute(tempstr, true); 247 } 248 } 249 } 250 251 void GSDedicated::setTerminalMode() 252 { 253 #ifndef ORXONOX_PLATFORM_WINDOWS 254 termios new_settings; 255 256 tcgetattr(0,this->originalTerminalSettings_); 257 new_settings = *this->originalTerminalSettings_; 258 new_settings.c_lflag &= ~( ICANON | ECHO ); 259 // new_settings.c_lflag |= ( ISIG | IEXTEN ); 260 new_settings.c_cc[VTIME] = 0; 261 new_settings.c_cc[VMIN] = 1; 262 tcsetattr(0,TCSANOW,&new_settings); 263 COUT(0) << endl; 264 // atexit(&GSDedicated::resetTerminalMode); 265 #endif 266 } 267 268 void GSDedicated::resetTerminalMode() 269 { 270 #ifndef ORXONOX_PLATFORM_WINDOWS 271 tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_); 272 #endif 273 } 274 275 void GSDedicated::insertCharacter( unsigned int position, char c ) 276 { 277 // std::cout << endl << (unsigned int)c << endl; 278 // check that we do not exceed MAX_COMMAND_LENGTH 279 if( inputIterator_+1 < MAX_COMMAND_LENGTH ) 280 { 281 // if cursor not at end of line then move the rest of the line 282 if( position != this->inputIterator_ ) 283 memmove( this->commandLine_+position+1, this->commandLine_+position, this->inputIterator_-position); 284 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 285 this->commandLine_[position] = c; 286 ++this->cursorX_; 287 ++this->inputIterator_; 288 } 289 } 290 void GSDedicated::deleteCharacter( unsigned int position ) 291 { 292 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 293 if ( this->inputIterator_>0 && position>0 ) 294 { 295 if ( position != this->inputIterator_ ) 296 memmove( this->commandLine_+position-1, this->commandLine_+position, this->inputIterator_-position); 297 --this->cursorX_; 298 --this->inputIterator_; 299 } 300 } 301 90 302 } -
code/trunk/src/orxonox/gamestates/GSDedicated.h
r3196 r3198 34 34 #include "core/GameState.h" 35 35 #include "network/NetworkPrereqs.h" 36 #include <queue> 37 #include <cstring> 38 #include <boost/thread/thread.hpp> 39 #include <boost/thread/mutex.hpp> 40 #include <boost/thread/recursive_mutex.hpp> 41 42 struct termios; 36 43 37 44 namespace orxonox 38 45 { 46 39 47 class _OrxonoxExport GSDedicated : public GameState 40 48 { … … 48 56 49 57 private: 50 Server* server_; 51 float timeSinceLastUpdate_; 58 void inputThread(); 59 void printLine(); 60 void processQueue(); 61 void setTerminalMode(); 62 static void resetTerminalMode(); 63 64 void insertCharacter( unsigned int position, char c ); 65 void deleteCharacter( unsigned int position ); 66 67 Server* server_; 68 float timeSinceLastUpdate_; 69 70 boost::thread *inputThread_; 71 boost::recursive_mutex inputLineMutex_; 72 boost::recursive_mutex inputQueueMutex_; 73 bool closeThread_; 74 bool cleanLine_; 75 unsigned char* commandLine_; 76 unsigned int inputIterator_; 77 std::queue<std::string> commandQueue_; 78 static termios* originalTerminalSettings_; 79 80 unsigned int cursorX_; 81 unsigned int cursorY_; 52 82 }; 53 83 } -
code/trunk/src/util/OutputBuffer.cc
r3196 r3198 36 36 namespace orxonox 37 37 { 38 const int OUTPUTBUFFER_MAX_LINE_LENGTH = 16384; //! The maximal number of lines that can be stored within the OutputBuffer.39 40 38 /** 41 39 @brief Adds a new listener to the list. … … 105 103 bool OutputBuffer::getLine(std::string* output) 106 104 { 107 char line[OUTPUTBUFFER_MAX_LINE_LENGTH]; 108 109 this->stream_.getline(line, OUTPUTBUFFER_MAX_LINE_LENGTH); 110 (*output) = std::string(line); 105 std::getline(this->stream_, *output); 111 106 112 107 bool eof = this->stream_.eof(); -
code/trunk/src/util/SignalHandler.cc
r3196 r3198 107 107 void SignalHandler::sigHandler( int sig ) 108 108 { 109 for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++ )110 {111 (*(it->cb))( it->someData );112 }113 114 109 std::string sigName = "UNKNOWN"; 115 110 … … 126 121 break; 127 122 } 123 // if the signalhandler has already been destroyed then don't do anything 124 if( SignalHandler::singletonRef_s == 0 ) 125 { 126 COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl; 127 exit(EXIT_FAILURE); 128 } 129 130 for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++ ) 131 { 132 (*(it->cb))( it->someData ); 133 } 134 128 135 129 136 COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.