Changeset 5994 for code/branches/console/src/libraries/core
- Timestamp:
- Oct 27, 2009, 2:47:14 PM (15 years ago)
- Location:
- code/branches/console/src/libraries/core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/ConfigValueIncludes.h
r5738 r5994 47 47 @param defvalue The default-value of the variable 48 48 */ 49 #define SetConfigValueGeneric(type, varname, defvalue) \49 #define SetConfigValueGeneric(type, varname, entryname, sectionname, defvalue) \ 50 50 static orxonox::Identifier* identifier##varname = this->getIdentifier(); \ 51 51 orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \ 52 52 if (!container##varname) \ 53 53 { \ 54 container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \54 container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, sectionname, entryname, defvalue, varname); \ 55 55 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 56 56 } \ 57 57 container##varname->getValue(&varname, this) 58 58 59 #define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, defvalue)59 #define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, identifier##varname->getName(), #varname, defvalue) 60 60 61 61 -
code/branches/console/src/libraries/core/Core.cc
r5992 r5994 106 106 void setConfigValues() 107 107 { 108 #ifdef NDEBUG 109 const unsigned int defaultLevelConsole = 1; 110 const unsigned int defaultLevelLogfile = 3; 111 const unsigned int defaultLevelShell = 1; 108 #ifdef ORXONOX_RELEASE 109 const unsigned int defaultLevelLogFile = 3; 112 110 #else 113 const unsigned int defaultLevelConsole = 3; 114 const unsigned int defaultLevelLogfile = 4; 115 const unsigned int defaultLevelShell = 3; 116 #endif 117 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 118 .description("The maximal level of debug output shown in the console") 119 .callback(this, &CoreConfiguration::debugLevelChanged); 120 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 121 .description("The maximal level of debug output shown in the logfile") 122 .callback(this, &CoreConfiguration::debugLevelChanged); 123 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 124 .description("The maximal level of debug output shown in the ingame shell") 125 .callback(this, &CoreConfiguration::debugLevelChanged); 111 const unsigned int defaultLevelLogFile = 4; 112 #endif 113 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile) 114 .description("The maximum level of debug output shown in the log file"); 115 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_); 126 116 127 117 SetConfigValue(language_, Language::getInstance().defaultLanguage_) … … 131 121 .description("If true, all random actions are different each time you start the game") 132 122 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator); 133 }134 135 /**136 @brief Callback function if the debug level has changed.137 */138 void debugLevelChanged()139 {140 // softDebugLevel_ is the maximum of the 3 variables141 this->softDebugLevel_ = this->softDebugLevelConsole_;142 if (this->softDebugLevelLogfile_ > this->softDebugLevel_)143 this->softDebugLevel_ = this->softDebugLevelLogfile_;144 if (this->softDebugLevelShell_ > this->softDebugLevel_)145 this->softDebugLevel_ = this->softDebugLevelShell_;146 147 OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_);148 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_);149 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_);150 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_);151 123 } 152 124 … … 179 151 } 180 152 181 int softDebugLevel_; //!< The debug level 182 int softDebugLevelConsole_; //!< The debug level for the console 183 int softDebugLevelLogfile_; //!< The debug level for the logfile 184 int softDebugLevelShell_; //!< The debug level for the ingame shell 153 int softDebugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler) 185 154 std::string language_; //!< The language 186 155 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called … … 228 197 229 198 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used 230 OutputHandler::get OutStream().setLogPath(PathConfig::getLogPathString());199 OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString()); 231 200 232 201 // Parse additional options file now that we know its path … … 328 297 bGraphicsLoaded_ = false; 329 298 GameMode::bShowsGraphics_s = false; 330 }331 332 /**333 @brief Returns the softDebugLevel for the given device (returns a default-value if the class is right about to be created).334 @param device The device335 @return The softDebugLevel336 */337 /*static*/ int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)338 {339 switch (device)340 {341 case OutputHandler::LD_All:342 return Core::getInstance().configuration_->softDebugLevel_;343 case OutputHandler::LD_Console:344 return Core::getInstance().configuration_->softDebugLevelConsole_;345 case OutputHandler::LD_Logfile:346 return Core::getInstance().configuration_->softDebugLevelLogfile_;347 case OutputHandler::LD_Shell:348 return Core::getInstance().configuration_->softDebugLevelShell_;349 default:350 assert(0);351 return 2;352 }353 }354 355 /**356 @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value.357 @param device The device358 @param level The level359 */360 /*static*/ void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)361 {362 if (device == OutputHandler::LD_All)363 Core::getInstance().configuration_->softDebugLevel_ = level;364 else if (device == OutputHandler::LD_Console)365 Core::getInstance().configuration_->softDebugLevelConsole_ = level;366 else if (device == OutputHandler::LD_Logfile)367 Core::getInstance().configuration_->softDebugLevelLogfile_ = level;368 else if (device == OutputHandler::LD_Shell)369 Core::getInstance().configuration_->softDebugLevelShell_ = level;370 371 OutputHandler::setSoftDebugLevel(device, level);372 299 } 373 300 -
code/branches/console/src/libraries/core/Core.h
r5992 r5994 69 69 void setConfigValues(); 70 70 71 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);72 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);73 71 static const std::string& getLanguage(); 74 72 static void resetLanguage(); -
code/branches/console/src/libraries/core/GUIManager.cc
r5992 r5994 53 53 #include "util/Exception.h" 54 54 #include "util/OrxAssert.h" 55 #include "Core.h"56 55 #include "LuaState.h" 57 56 #include "PathConfig.h" … … 75 74 default: OrxAssert(false, "CEGUI log level out of range, inpect immediately!"); 76 75 } 77 OutputHandler::getOutStream( ).setOutputLevel(orxonoxLevel)76 OutputHandler::getOutStream(orxonoxLevel) 78 77 << "CEGUI: " << message << std::endl; 79 78 … … 121 120 // set the log level according to ours (translate by subtracting 1) 122 121 ceguiLogger->setLoggingLevel( 123 static_cast<LoggingLevel>( Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));122 static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1)); 124 123 this->ceguiLogger_ = ceguiLogger.release(); 125 124 -
code/branches/console/src/libraries/core/GraphicsManager.cc
r5929 r5994 408 408 orxonoxLevel = 0; 409 409 } 410 OutputHandler::getOutStream( ).setOutputLevel(orxonoxLevel)410 OutputHandler::getOutStream(orxonoxLevel) 411 411 << "Ogre: " << message << std::endl; 412 412 } -
code/branches/console/src/libraries/core/IOConsole.cc
r5986 r5994 62 62 this->originalTerminalSettings_ = new termios; 63 63 this->setTerminalMode(); 64 64 this->shell_.registerListener(this); 65 65 } 66 66 … … 234 234 } 235 235 236 #elif defined(ORXONOX_PLATFORM_WINDOWS) 237 238 IOConsole::IOConsole() 239 : shell_(Shell::getInstance()) 240 , buffer_(Shell::getInstance().getInputBuffer()) 241 { 242 this->setTerminalMode(); 243 } 244 245 IOConsole::~IOConsole() 246 { 247 } 248 249 void IOConsole::setTerminalMode() 250 { 251 } 252 253 void IOConsole::resetTerminalMode() 254 { 255 } 256 257 void IOConsole::update(const Clock& time) 258 { 259 } 260 261 void IOConsole::print(const std::string& text) 262 { 263 } 264 265 void IOConsole::printInputLine() 266 { 267 } 268 236 269 #endif /* ORXONOX_PLATFORM_UNIX */ 237 270 … … 256 289 void IOConsole::onlyLastLineChanged() 257 290 { 258 259 260 261 262 263 264 265 291 // Save cursor position and move it the beginning of the second to last line 292 std::cout << "\033[s\033[1F"; 293 // Erase the second to last line 294 std::cout << "\033[K"; 295 this->print(*(this->shell_.getNewestLineIterator())); 296 // Restore cursor 297 std::cout << "\033[u"; 298 std::cout.flush(); 266 299 } 267 300 … … 272 305 void IOConsole::lineAdded() 273 306 { 274 275 276 277 278 307 // Move curosr the beginning of the line and erase it 308 std::cout << "\033[1G\033[K"; 309 this->print(*(this->shell_.getNewestLineIterator())); 310 std::cout << std::endl; 311 this->printInputLine(); 279 312 } 280 313 … … 303 336 void IOConsole::executed() 304 337 { 305 // Move curosr the beginning of the line306 307 // Print command so the user knows what he typed338 // Move cursor the beginning of the line 339 std::cout << "\033[1G"; 340 // Print command so the user knows what he has typed 308 341 std::cout << "orxonox>" << this->shell_.getInput() << std::endl; 309 342 this->printInputLine(); 310 343 } 311 344 -
code/branches/console/src/libraries/core/LuaState.cc
r5929 r5994 182 182 void LuaState::luaLog(unsigned int level, const std::string& message) 183 183 { 184 OutputHandler::getOutStream( ).setOutputLevel(level) << message << std::endl;184 OutputHandler::getOutStream(level) << message << std::endl; 185 185 } 186 186 -
code/branches/console/src/libraries/core/Shell.cc
r5986 r5994 51 51 52 52 Shell::Shell() 53 { 54 int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell); 55 Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1); 56 53 : OutputListener("shell") 54 { 57 55 RegisterRootObject(Shell); 58 56 … … 69 67 this->configureInputBuffer(); 70 68 71 this->outputBuffer_.registerListener(this);72 OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);73 74 69 // Get a config file for the command history 75 70 this->commandHistoryConfigFileType_ = ConfigFileManager::getInstance().getNewConfigFileType(); 76 71 ConfigFileManager::getInstance().setFilename(this->commandHistoryConfigFileType_, "commandHistory.ini"); 77 72 73 // Use a stringstream object to buffer the output and get it line by line in update() 74 this->outputStream_ = &this->outputBuffer_; 75 78 76 this->setConfigValues(); 79 77 80 Core::setSoftDebugLevel(OutputHandler::LD_Shell, level); 78 // Get the previous output and add it to the Shell 79 for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin(); 80 it != OutputHandler::getInstance().getOutputVectorEnd(); ++it) 81 this->addLine(it->second, it->first); 82 83 // Register the shell as output listener 84 OutputHandler::getInstance().registerOutputListener(this); 81 85 } 82 86 83 87 Shell::~Shell() 84 88 { 85 OutputHandler::getOutStream().setOutputBuffer(0); 86 if (this->inputBuffer_) 87 this->inputBuffer_->destroy(); 89 OutputHandler::getInstance().unregisterOutputListener(this); 90 this->inputBuffer_->destroy(); 88 91 } 89 92 90 93 void Shell::setConfigValues() 91 94 { 92 SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, 100)95 SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100) 93 96 .callback(this, &Shell::commandHistoryLengthChanged); 94 SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, 0)97 SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0) 95 98 .callback(this, &Shell::commandHistoryOffsetChanged); 96 99 SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>()); 100 101 #ifdef ORXONOX_RELEASE 102 const unsigned int defaultLevel = 1; 103 #else 104 const unsigned int defaultLevel = 3; 105 #endif 106 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevelShell", "OutputHandler", defaultLevel) 107 .description("The maximal level of debug output shown in the Shell"); 108 OutputHandler::getInstance().setSoftDebugLevel("shell", this->softDebugLevel_); 97 109 } 98 110 … … 182 194 void Shell::addLine(const std::string& line, int level) 183 195 { 184 int original_level = OutputHandler::getOutStream().getOutputLevel(); 185 OutputHandler::getOutStream().setOutputLevel(level); 186 187 if (!this->finishedLastLine_) 188 this->outputBuffer_ << std::endl; 189 190 this->outputBuffer_ << line << std::endl; 191 OutputHandler::getOutStream().setOutputLevel(original_level); 196 if (level <= this->softDebugLevel_) 197 this->lines_.push_front(line); 198 this->updateListeners<&ShellListener::lineAdded>(); 192 199 } 193 200 … … 238 245 do 239 246 { 240 newline = this->outputBuffer_.getLine(&output); 247 std::getline(this->outputBuffer_, output); 248 249 bool eof = this->outputBuffer_.eof(); 250 bool fail = this->outputBuffer_.fail(); 251 if (eof) 252 this->outputBuffer_.flush(); 253 if (eof || fail) 254 this->outputBuffer_.clear(); 255 newline = (!eof && !fail); 241 256 242 257 if (!newline && output == "") … … 246 261 { 247 262 if (this->bAddOutputLevel_) 248 output.insert(0, 1, static_cast<char>(OutputHandler::get OutStream().getOutputLevel()));249 250 this->lines_. insert(this->lines_.begin(),output);263 output.insert(0, 1, static_cast<char>(OutputHandler::getInstance().getOutputLevel())); 264 265 this->lines_.push_front(output); 251 266 252 267 if (this->scrollPosition_) … … 365 380 return; 366 381 unsigned int cursorPosition = this->getCursorPosition(); 367 std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position368 for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)369 { 370 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive382 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position 383 for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++) 384 { 385 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive 371 386 { 372 387 this->historyPosition_ = newPos; 373 388 this->inputBuffer_->set(this->getFromHistory()); 374 this->setCursorPosition( cursorPosition);389 this->setCursorPosition(cursorPosition); 375 390 return; 376 391 } … … 383 398 return; 384 399 unsigned int cursorPosition = this->getCursorPosition(); 385 std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$386 for (unsigned int newPos = this->historyPosition_ -1; newPos>0; newPos--)387 { 388 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$400 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$ 401 for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--) 402 { 403 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$ 389 404 { 390 405 this->historyPosition_ = newPos; 391 406 this->inputBuffer_->set(this->getFromHistory()); 392 this->setCursorPosition( cursorPosition);407 this->setCursorPosition(cursorPosition); 393 408 return; 394 409 } -
code/branches/console/src/libraries/core/Shell.h
r5986 r5994 34 34 #include <cassert> 35 35 #include <list> 36 #include <sstream> 36 37 #include <string> 37 38 #include <vector> 38 39 39 #include "util/Output Buffer.h"40 #include "util/OutputHandler.h" 40 41 #include "input/InputBuffer.h" 41 42 #include "OrxonoxClass.h" … … 61 62 }; 62 63 63 class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public Output BufferListener64 class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputListener 64 65 { 65 66 friend class Singleton<Shell>; … … 71 72 static void history(); 72 73 73 v irtual void setConfigValues();74 void setConfigValues(); 74 75 void commandHistoryOffsetChanged(); 75 76 void commandHistoryLengthChanged(); … … 80 81 inline InputBuffer* getInputBuffer() 81 82 { return this->inputBuffer_; } 82 inline OutputBuffer& getOutputBuffer()83 { return this->outputBuffer_; }84 83 85 84 void setCursorPosition(unsigned int cursor); … … 117 116 118 117 virtual void outputChanged(); 118 119 119 void inputChanged(); 120 120 void execute(); … … 144 144 std::list<ShellListener*> listeners_; 145 145 InputBuffer* inputBuffer_; 146 OutputBufferoutputBuffer_;146 std::stringstream outputBuffer_; 147 147 bool finishedLastLine_; 148 148 std::list<std::string> lines_; … … 154 154 unsigned int historyOffset_; 155 155 bool bAddOutputLevel_; 156 int softDebugLevel_; 156 157 157 158 ConfigFileType commandHistoryConfigFileType_;
Note: See TracChangeset
for help on using the changeset viewer.