Changeset 3121 for code/branches/netp4/src/orxonox/gamestates
- Timestamp:
- Jun 8, 2009, 9:17:40 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
r3119 r3121 43 43 #include <boost/bind.hpp> 44 44 45 #ifndef ORXONOX_PLATFORM_WINDOWS 46 #include <termios.h> 47 #endif 48 45 49 46 50 namespace orxonox … … 49 53 50 54 AddGameState(GSDedicated, "dedicated"); 55 56 termios* GSDedicated::originalTerminalSettings_; 51 57 52 58 GSDedicated::GSDedicated(const std::string& name) … … 61 67 this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH]; 62 68 // memset( this->commandLine_, 0, MAX_COMMAND_LENGTH ); 69 #ifndef ORXONOX_PLATFORM_WINDOWS 70 this->originalTerminalSettings_ = new termios; 71 this->setTerminalMode(); 72 #endif 63 73 } 64 74 … … 69 79 std::cout << "\033[0G\033[K"; 70 80 std::cout.flush(); 81 resetTerminalMode(); 82 delete this->originalTerminalSettings_; 71 83 #endif 72 84 //inputThread_->join(); … … 116 128 c = getchar(); 117 129 { 118 //boost::recursive_mutex::scoped_lock(this->inputLineMutex_);130 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 119 131 if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' ) 120 132 continue; … … 125 137 boost::recursive_mutex::scoped_lock(this->inputQueueMutex_); 126 138 this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) ); 139 memset( this->commandLine_, 0, inputIterator_ ); 127 140 inputIterator_ = 0; 128 141 } 142 else if( c == 0x8 ) // Backspace 143 { 144 boost::recursive_mutex::scoped_lock(this->inputQueueMutex_); 145 commandLine_[inputIterator_--]=0; 146 } 129 147 } 130 148 } … … 134 152 { 135 153 #ifndef ORXONOX_PLATFORM_WINDOWS 136 std::cout << "\033[s\033[0G"; 137 // boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 138 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 # "; 139 if ( this->cleanLine_ ) 140 this->cleanLine_ = false; 141 else 142 std::cout <<"\033[u"; 154 // std::cout << "\033[s\033[0G"; 155 std::cout << "\033[0G\033[K"; 156 boost::recursive_mutex::scoped_lock(this->inputLineMutex_); 157 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 # " << this->commandLine_; 158 //if ( this->cleanLine_ ) 159 // this->cleanLine_ = false; 160 //else 161 // std::cout <<"\033[u"; 143 162 std::cout.flush(); 144 163 #endif … … 164 183 } 165 184 } 185 186 void GSDedicated::setTerminalMode() 187 { 188 termios new_settings; 189 190 tcgetattr(0,this->originalTerminalSettings_); 191 new_settings = *this->originalTerminalSettings_; 192 new_settings.c_lflag &= (~ICANON); 193 new_settings.c_cc[VTIME] = 0; 194 new_settings.c_cc[VMIN] = 1; 195 tcsetattr(0,TCSANOW,&new_settings); 196 COUT(0) << endl; 197 atexit(&GSDedicated::resetTerminalMode); 198 } 199 200 void GSDedicated::resetTerminalMode() 201 { 202 #ifndef ORXONOX_PLATFORM_WINDOWS 203 tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_); 204 #endif 205 } 166 206 } -
code/branches/netp4/src/orxonox/gamestates/GSDedicated.h
r3119 r3121 39 39 #include <boost/thread/recursive_mutex.hpp> 40 40 41 struct termios; 42 41 43 namespace orxonox 42 44 { 45 43 46 class _OrxonoxExport GSDedicated : public GameState 44 47 { … … 55 58 void printLine(); 56 59 void processQueue(); 60 void setTerminalMode(); 61 static void resetTerminalMode(); 57 62 58 63 Server* server_; … … 60 65 61 66 boost::thread *inputThread_; 62 //boost::recursive_mutex inputLineMutex_;67 boost::recursive_mutex inputLineMutex_; 63 68 boost::recursive_mutex inputQueueMutex_; 64 69 bool closeThread_; … … 67 72 unsigned int inputIterator_; 68 73 std::queue<std::string> commandQueue_; 69 74 static termios* originalTerminalSettings_; 70 75 }; 71 76 }
Note: See TracChangeset
for help on using the changeset viewer.