Changeset 3126
- Timestamp:
- Jun 9, 2009, 2:53:57 PM (15 years ago)
- Location:
- code/branches/netp4/src/orxonox/gamestates
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp4/src/orxonox/gamestates/GSDedicated.cc
r3122 r3126 63 63 , inputIterator_(0) 64 64 , cleanLine_(true) 65 { 66 this->inputThread_ = new boost::thread(boost::bind(&GSDedicated::inputThread, this)); 65 , cursorX_(0) 66 , cursorY_(0) 67 { 67 68 this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH]; 68 69 // memset( this->commandLine_, 0, MAX_COMMAND_LENGTH ); 70 } 71 72 GSDedicated::~GSDedicated() 73 { 74 } 75 76 void GSDedicated::activate() 77 { 78 GameMode::setHasServer(true); 79 80 this->inputThread_ = new boost::thread(boost::bind(&GSDedicated::inputThread, this)); 81 69 82 #ifndef ORXONOX_PLATFORM_WINDOWS 70 83 this->originalTerminalSettings_ = new termios; 71 84 this->setTerminalMode(); 72 85 #endif 73 } 74 75 GSDedicated::~GSDedicated() 76 { 86 87 this->server_ = new Server(CommandLine::getValue("port")); 88 COUT(0) << "Loading scene in server mode" << std::endl; 89 90 server_->open(); 91 } 92 93 void GSDedicated::deactivate() 94 { 95 this->server_->close(); 96 delete this->server_; 97 77 98 closeThread_ = true; 78 99 #ifndef ORXONOX_PLATFORM_WINDOWS … … 83 104 #endif 84 105 //inputThread_->join(); 85 }86 87 void GSDedicated::activate()88 {89 GameMode::setHasServer(true);90 91 this->server_ = new Server(CommandLine::getValue("port"));92 COUT(0) << "Loading scene in server mode" << std::endl;93 94 server_->open();95 }96 97 void GSDedicated::deactivate()98 {99 this->server_->close();100 delete this->server_;101 106 102 107 GameMode::setHasServer(false); … … 124 129 { 125 130 unsigned char c; 131 unsigned int escapeChar=0; 126 132 while(!closeThread_) 127 133 { 128 134 c = getchar(); 129 135 { 130 boost::recursive_mutex::scoped_lock(this->inputLineMutex_);136 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 131 137 if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' ) 132 138 continue; 133 switch (c)139 if( escapeChar > 0 ) 134 140 { 135 case '\n': 136 this->cleanLine_ = true; 141 if( c == '[' ) 142 { 143 escapeChar = 2; 144 continue; 145 } 146 else if ( escapeChar == 2 ) 147 { 148 switch (c) 137 149 { 138 boost::recursive_mutex::scoped_lock(this->inputQueueMutex_); 139 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 140 this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) ); 150 case 'A': //keyup 151 152 break; 153 case 'B': //keydown 154 155 break; 156 case 'C': //keyright 157 if(cursorX_<inputIterator_) 158 ++cursorX_; 159 break; 160 case 'D': //keyleft 161 if(cursorX_>0) 162 --cursorX_; 163 break; 164 default: //not supported... 165 break; 141 166 } 142 memset( this->commandLine_, 0, inputIterator_ );143 inputIterator_ = 0;144 std::cout << endl;145 break;146 case 127: // backspace147 case '\b':167 escapeChar = 0; 168 } 169 } 170 else // not in escape sequence mode 171 { 172 switch (c) 148 173 { 149 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 150 if(inputIterator_>0) 151 --inputIterator_; 152 break; 153 } 154 case '\t': 155 { 156 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 157 COUT(0) << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl; 158 strncpy((char*)this->commandLine_, CommandExecutor::complete( std::string((const char*)this->commandLine_,inputIterator_) ).c_str(), MAX_COMMAND_LENGTH); 159 inputIterator_ = strlen((const char*)this->commandLine_); 160 break; 161 } 162 default: 163 { 164 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 165 this->commandLine_[this->inputIterator_++] = c; 166 break; 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; 167 205 } 168 206 } … … 174 212 { 175 213 #ifndef ORXONOX_PLATFORM_WINDOWS 176 // std::cout << "\033[s\033[0G"; 214 // set cursor to the begining of the line and erase the line 177 215 std::cout << "\033[0G\033[K"; 178 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 179 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 # " << std::string((const char*)this->commandLine_,inputIterator_); 180 //if ( this->cleanLine_ ) 181 // this->cleanLine_ = false; 182 //else 183 // std::cout <<"\033[u"; 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"; 184 227 std::cout.flush(); 185 228 #endif … … 227 270 #endif 228 271 } 272 273 void GSDedicated::insertCharacter( unsigned int position, char c ) 274 { 275 // std::cout << endl << (unsigned int)c << endl; 276 // check that we do not exceed MAX_COMMAND_LENGTH 277 if( inputIterator_+1 < MAX_COMMAND_LENGTH ) 278 { 279 // if cursor not at end of line then move the rest of the line 280 if( position != this->inputIterator_ ) 281 memmove( this->commandLine_+position+1, this->commandLine_+position, this->inputIterator_-position); 282 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 283 this->commandLine_[position] = c; 284 ++this->cursorX_; 285 ++this->inputIterator_; 286 } 287 } 288 void GSDedicated::deleteCharacter( unsigned int position ) 289 { 290 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 291 if ( this->inputIterator_>0 && position>0 ) 292 { 293 if ( position != this->inputIterator_ ) 294 memmove( this->commandLine_+position-1, this->commandLine_+position, this->inputIterator_-position); 295 --this->cursorX_; 296 --this->inputIterator_; 297 } 298 } 299 229 300 } -
code/branches/netp4/src/orxonox/gamestates/GSDedicated.h
r3121 r3126 61 61 static void resetTerminalMode(); 62 62 63 void insertCharacter( unsigned int position, char c ); 64 void deleteCharacter( unsigned int position ); 65 63 66 Server* server_; 64 67 float timeSinceLastUpdate_; … … 73 76 std::queue<std::string> commandQueue_; 74 77 static termios* originalTerminalSettings_; 78 79 unsigned int cursorX_; 80 unsigned int cursorY_; 75 81 }; 76 82 }
Note: See TracChangeset
for help on using the changeset viewer.