Changeset 1322
- Timestamp:
- May 19, 2008, 2:33:09 AM (17 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/InputBuffer.h
r1313 r1322 62 62 InputBuffer(); 63 63 InputBuffer(const std::string allowedChars); 64 65 inline void setKeyboard(OIS::Keyboard* keyboard) 66 { this->keyboard_ = keyboard; } 64 67 65 68 template <class T> -
code/branches/console/src/core/InputHandler.cc
r1313 r1322 39 39 #include "InputEvent.h" 40 40 #include "InputManager.h" 41 #include "CommandExecutor.h" 41 42 42 43 namespace orxonox … … 89 90 { 90 91 InputManager::getSingleton().setInputMode(IM_KEYBOARD); 92 CommandExecutor::execute("openConsole"); 91 93 } 92 94 else -
code/branches/console/src/core/InputManager.cc
r1089 r1322 105 105 // create a keyboard. If none are available the exception is caught. 106 106 keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true)); 107 COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl; 107 COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl; 108 109 if (this->handlerBuffer_) 110 this->handlerBuffer_->setKeyboard(this->keyboard_); 108 111 109 112 // create a mouse. If none are available the exception is caught. 110 113 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); 111 COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl;114 COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl; 112 115 113 116 // Set mouse region -
code/branches/console/src/core/OutputBuffer.cc
r1313 r1322 49 49 } 50 50 51 OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&)) 52 { 53 this->stream_ << manipulator; 54 this->callListeners(); 55 return *this; 56 } 57 58 OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&)) 59 { 60 this->stream_ << manipulator; 61 this->callListeners(); 62 return *this; 63 } 64 65 OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&)) 66 { 67 this->stream_ << manipulator; 68 this->callListeners(); 69 return *this; 70 } 71 51 72 bool OutputBuffer::getLine(std::string* output) 52 73 { … … 59 80 60 81 if (eof) 82 { 61 83 this->stream_.flush(); 84 this->stream_.clear(); 85 } 62 86 63 // Return true if this was a whole new line, ended by \n64 87 return (!eof); 65 88 } -
code/branches/console/src/core/OutputBuffer.h
r1313 r1322 32 32 #include <list> 33 33 #include <sstream> 34 #include <iostream> 34 35 35 36 #include "CorePrereqs.h" … … 57 58 return *this; 58 59 } 60 61 OutputBuffer& operator<<(std::ostream& (*manipulator)(std::ostream&)); 62 OutputBuffer& operator<<(std::ios& (*manipulator)(std::ios&)); 63 OutputBuffer& operator<<(std::ios_base& (*manipulator)(std::ios_base&)); 59 64 60 65 template <class T> … … 88 93 void unregisterListener(OutputBufferListener* listener); 89 94 90 inline operator std::stringstream&()91 {92 return this->stream_;93 }94 95 95 private: 96 96 void callListeners(); -
code/branches/console/src/core/OutputHandler.cc
r1313 r1322 124 124 125 125 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 126 manipulator(Shell::getInstance().getOutputBuffer());126 Shell::getInstance().getOutputBuffer() << manipulator; 127 127 128 128 return *this; … … 146 146 147 147 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 148 manipulator(Shell::getInstance().getOutputBuffer());148 Shell::getInstance().getOutputBuffer() << manipulator; 149 149 150 150 return *this; … … 168 168 169 169 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 170 manipulator(Shell::getInstance().getOutputBuffer());170 Shell::getInstance().getOutputBuffer() << manipulator; 171 171 172 172 return *this; -
code/branches/console/src/core/Shell.cc
r1317 r1322 46 46 this->historyPosition_ = 0; 47 47 this->historyOffset_ = 0; 48 this->finishedLastLine_ = true; 48 49 49 50 this->clearLines(); 50 /* 51 51 52 this->inputBuffer_.registerListener(this, &Shell::inputChanged, true); 52 53 this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false); … … 63 64 this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 64 65 this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 65 */ 66 67 this->outputBuffer_.registerListener(this); 68 66 69 this->setConfigValues(); 67 70 } … … 77 80 SetConfigValue(maxHistoryLength_, 100); 78 81 SetConfigValue(historyOffset_, 0); 79 SetConfigValueVector(commandHistory_, std::vector<std::string>(1, "")); 82 SetConfigValueVector(commandHistory_, std::vector<std::string>()); 83 84 std::cout << "gaga1: " << this->commandHistory_[this->historyOffset_] << std::endl; 80 85 81 86 if (this->historyOffset_ >= this->maxHistoryLength_) … … 88 93 ModifyConfigValue(commandHistory_, remove, index); 89 94 } 95 96 std::cout << "gaga2: " << this->commandHistory_[this->historyOffset_] << std::endl; 90 97 } 91 98 … … 120 127 void Shell::addLine(const std::string& line, unsigned int level) 121 128 { 122 if ((*this->lines_.begin()) != "") 123 { 124 orxonox::OutputHandler::getOutStream().setOutputLevel(level) << std::endl; 125 } 126 orxonox::OutputHandler::getOutStream().setOutputLevel(level) << line << std::endl; 129 int original_level = OutputHandler::getOutStream().getOutputLevel(); 130 OutputHandler::getOutStream().setOutputLevel(level); 131 132 if (!this->finishedLastLine_) 133 this->outputBuffer_ << std::endl; 134 135 this->outputBuffer_ << line << std::endl; 136 OutputHandler::getOutStream().setOutputLevel(original_level); 127 137 } 128 138 … … 130 140 { 131 141 this->lines_.clear(); 132 this->lines_.insert(this->lines_.begin(), "");133 142 this->scrollIterator_ = this->lines_.begin(); 134 143 135 144 this->scrollPosition_ = 0; 145 this->finishedLastLine_ = true; 136 146 137 147 SHELL_UPDATE_LISTENERS(linesChanged); … … 141 151 { 142 152 if (this->scrollPosition_) 143 {144 153 return this->scrollIterator_; 145 }146 154 else 147 { 148 if ((*this->lines_.begin()) == "" && this->lines_.size() > 1) 149 return (++this->lines_.begin()); 150 else 151 return this->lines_.begin(); 152 } 155 return this->lines_.begin(); 153 156 } 154 157 … … 160 163 void Shell::addToHistory(const std::string& command) 161 164 { 162 this->historyOffset_ = (this->historyOffset_ + 1) % this->maxHistoryLength_; 165 std::cout << "command: " << command << std::endl; 166 std::cout << "offset: " << this->historyOffset_ << std::endl; 163 167 ModifyConfigValue(commandHistory_, set, this->historyOffset_, command); 164 this->commandHistory_[this->historyOffset_] = command;168 // this->commandHistory_[this->historyOffset_] = command; 165 169 this->historyPosition_ = 0; 170 std::cout << "gaga3: " << this->commandHistory_[this->historyOffset_] << std::endl; 171 ModifyConfigValue(historyOffset_, set, (this->historyOffset_ + 1) % this->maxHistoryLength_); 172 std::cout << "offset new: " << this->historyOffset_ << std::endl; 166 173 } 167 174 … … 174 181 { 175 182 std::string output; 176 while (this->outputBuffer_.getLine(&output)) 177 { 178 bool newline = false; 179 if ((*this->lines_.begin()) == "") 180 newline = true; 181 182 (*this->lines_.begin()) += output; 183 184 SHELL_UPDATE_LISTENERS(onlyLastLineChanged); 185 186 this->lines_.insert(this->lines_.begin(), ""); 187 188 if (this->scrollPosition_) 189 this->scrollPosition_++; 190 else 191 this->scrollIterator_ = this->lines_.begin(); 192 193 if (newline) 183 bool newline; 184 do 185 { 186 newline = this->outputBuffer_.getLine(&output); 187 188 if (!newline && output == "") 189 break; 190 191 if (this->finishedLastLine_) 194 192 { 193 this->lines_.insert(this->lines_.begin(), output); 194 195 if (this->scrollPosition_) 196 this->scrollPosition_++; 197 else 198 this->scrollIterator_ = this->lines_.begin(); 199 200 this->finishedLastLine_ = newline; 195 201 SHELL_UPDATE_LISTENERS(lineAdded); 196 202 } 197 } 198 199 (*this->lines_.begin()) += output; 200 SHELL_UPDATE_LISTENERS(onlyLastLineChanged); 203 else 204 { 205 (*this->lines_.begin()) += output; 206 this->finishedLastLine_ = newline; 207 SHELL_UPDATE_LISTENERS(onlyLastLineChanged); 208 } 209 210 } while (newline); 201 211 } 202 212 … … 209 219 void Shell::execute() 210 220 { 211 if (CommandExecutor::execute(this->inputBuffer_.get())) 212 this->addLine(this->inputBuffer_.get(), 0); 213 else 221 // this->addToHistory(this->inputBuffer_.get()); 222 this->addLine(this->inputBuffer_.get(), 0); 223 224 if (!CommandExecutor::execute(this->inputBuffer_.get())) 214 225 this->addLine("Error: Can't execute \"" + this->inputBuffer_.get() + "\".", 1); 215 226 … … 282 293 if (this->historyPosition_ > 0) 283 294 { 284 this->historyPosition_ ++;295 this->historyPosition_--; 285 296 this->inputBuffer_.set(this->getFromHistory()); 286 297 } -
code/branches/console/src/core/Shell.h
r1317 r1322 118 118 InputBuffer inputBuffer_; 119 119 OutputBuffer outputBuffer_; 120 bool finishedLastLine_; 120 121 std::list<std::string> lines_; 121 122 std::list<std::string>::const_iterator scrollIterator_; -
code/branches/console/src/orxonox/console/InGameConsole.cc
r1317 r1322 42 42 #include "core/ConfigValueIncludes.h" 43 43 #include "core/ConsoleCommand.h" 44 #include "core/InputManager.h" 44 45 #include "GraphicsEngine.h" 45 46 … … 48 49 namespace orxonox 49 50 { 51 ConsoleCommand(InGameConsole, openConsole, AccessLevel::None, true); 52 ConsoleCommand(InGameConsole, closeConsole, AccessLevel::None, true); 53 50 54 using namespace Ogre; 51 55 52 56 float InGameConsole::REL_WIDTH = 0.8; 53 57 float InGameConsole::REL_HEIGHT = 0.4; 54 float InGameConsole::BLINK = 0. 25;58 float InGameConsole::BLINK = 0.5; 55 59 56 60 /** … … 63 67 this->active_ = false; 64 68 this->cursor_ = 0.0; 69 this->cursorSymbol_ = '|'; 65 70 66 71 this->init(); 67 72 this->setConfigValues(); 73 74 Shell::getInstance().registerListener(this); 68 75 } 69 76 … … 95 102 SetConfigValue(REL_WIDTH, 0.8); 96 103 SetConfigValue(REL_HEIGHT, 0.4); 97 SetConfigValue(BLINK, 0. 25);104 SetConfigValue(BLINK, 0.5); 98 105 } 99 106 … … 104 111 { 105 112 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 106 for (int i = 1; i < LINES && it != Shell::getInstance().getEndIterator(); i++) 107 { 108 this->consoleOverlayTextAreas_[i]->setCaption(*it); 109 ++it; 113 for (int i = 1; i < LINES; i++) 114 { 115 if (it != Shell::getInstance().getEndIterator()) 116 { 117 this->print(*it, i); 118 ++it; 119 } 120 else 121 { 122 this->print("", i); 123 } 110 124 } 111 125 } … … 117 131 { 118 132 if (LINES > 1) 119 this-> consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator());133 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 120 134 } 121 135 … … 125 139 void InGameConsole::lineAdded() 126 140 { 127 for (int i = LINES - 1; i > 1; i--) 128 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 129 130 if (LINES > 1) 131 this->consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator()); 141 this->linesChanged(); 132 142 } 133 143 … … 138 148 { 139 149 if (LINES > 0) 140 this-> consoleOverlayTextAreas_[0]->setCaption(Shell::getInstance().getInput());150 this->print(Shell::getInstance().getInput(), 0); 141 151 } 142 152 … … 147 157 { 148 158 std::string input = Shell::getInstance().getInput(); 149 input.insert(Shell::getInstance().getCursorPosition(), 1, '|');159 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 150 160 if (LINES > 0) 151 this-> consoleOverlayTextAreas_[0]->setCaption(input);161 this->print(input, 0); 152 162 } 153 163 … … 158 168 { 159 169 this->deactivate(); 160 CommandExecutor::execute("set InputMode 2");170 InputManager::getSingleton().setInputMode(IM_INGAME); 161 171 } 162 172 … … 266 276 if (this->cursor_ >= 2 * InGameConsole::BLINK) 267 277 this->cursor_ = 0; 268 // print(convert2UTF(this->ib_->get())); 278 279 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 280 { 281 this->cursorSymbol_ = ' '; 282 this->cursorChanged(); 283 } 284 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 285 { 286 this->cursorSymbol_ = '|'; 287 this->cursorChanged(); 288 } 269 289 270 290 // this creates a flickering effect … … 296 316 void InGameConsole::activate() 297 317 { 318 this->linesChanged(); 319 298 320 this->consoleOverlay_->show(); 299 321 // just in case window size has changed... … … 334 356 @param s String to be printed 335 357 */ 336 void InGameConsole::print(Ogre::UTFString s) 337 { 338 if (this->cursor_ > InGameConsole::BLINK) 339 this->consoleOverlayTextAreas_[0]->setCaption(">" + s); 340 else 341 this->consoleOverlayTextAreas_[0]->setCaption(">" + s + "_"); 342 } 343 344 /** 345 @brief Shifts all lines up and clears the bottom line. 346 */ 347 void InGameConsole::newline() 348 { 349 Ogre::UTFString line; 350 for (int i = LINES - 1; i >= 1; i--) 351 { 352 line = this->consoleOverlayTextAreas_[i - 1]->getCaption(); 353 // don't copy the cursor... 354 int l = line.length(); 355 if (!line.empty() && line.substr(l-1) == "_") 356 line.erase(l-1); 357 this->consoleOverlayTextAreas_[i]->setCaption(line); 358 } 359 this->consoleOverlayTextAreas_[0]->setCaption(">"); 358 void InGameConsole::print(const std::string& text, int index) 359 { 360 if (LINES > index) 361 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(text)); 360 362 } 361 363 -
code/branches/console/src/orxonox/console/InGameConsole.h
r1317 r1322 71 71 void init(); 72 72 void resize(); 73 void print(Ogre::UTFString s); 74 void newline(); 73 void print(const std::string& text, int index); 75 74 static Ogre::UTFString convert2UTF(std::string s); 76 75 … … 84 83 float scrollTimer_; 85 84 float cursor_; 85 char cursorSymbol_; 86 86 bool active_; 87 87 Ogre::OverlayManager* om_;
Note: See TracChangeset
for help on using the changeset viewer.