[Orxonox-commit 1251] r5969 - in code/branches/console/src: libraries/core orxonox/overlays
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Oct 20 18:47:40 CEST 2009
Author: rgrieder
Date: 2009-10-20 18:47:40 +0200 (Tue, 20 Oct 2009)
New Revision: 5969
Modified:
code/branches/console/src/libraries/core/Shell.cc
code/branches/console/src/libraries/core/Shell.h
code/branches/console/src/orxonox/overlays/InGameConsole.cc
code/branches/console/src/orxonox/overlays/InGameConsole.h
Log:
Small stuff:
- Using a reference to the Shell in InGameConsole
- Replaced the caller macro in the Shell with a template function
Modified: code/branches/console/src/libraries/core/Shell.cc
===================================================================
--- code/branches/console/src/libraries/core/Shell.cc 2009-10-20 16:46:50 UTC (rev 5968)
+++ code/branches/console/src/libraries/core/Shell.cc 2009-10-20 16:47:40 UTC (rev 5969)
@@ -35,10 +35,6 @@
#include "Core.h"
#include "ConsoleCommand.h"
-#define SHELL_UPDATE_LISTENERS(function) \
- for (std::list<ShellListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) \
- (*(it++))->function()
-
namespace orxonox
{
SetConsoleCommand(Shell, clearShell, true);
@@ -152,7 +148,7 @@
void Shell::registerListener(ShellListener* listener)
{
- this->listeners_.insert(this->listeners_.end(), listener);
+ this->listeners_.push_back(listener);
}
void Shell::unregisterListener(ShellListener* listener)
@@ -160,7 +156,7 @@
for (std::list<ShellListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
{
if ((*it) == listener)
- this->listeners_.erase(it++);
+ it = this->listeners_.erase(it);
else
++it;
}
@@ -169,7 +165,7 @@
void Shell::setCursorPosition(unsigned int cursor)
{
this->inputBuffer_->setCursorPosition(cursor);
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::setInput(const std::string& input)
@@ -198,7 +194,7 @@
this->scrollPosition_ = 0;
this->finishedLastLine_ = true;
- SHELL_UPDATE_LISTENERS(linesChanged);
+ this->updateListeners<&ShellListener::linesChanged>();
}
std::list<std::string>::const_iterator Shell::getNewestLineIterator() const
@@ -257,14 +253,14 @@
if (!this->scrollPosition_)
{
- SHELL_UPDATE_LISTENERS(lineAdded);
+ this->updateListeners<&ShellListener::lineAdded>();
}
}
else
{
(*this->lines_.begin()) += output;
this->finishedLastLine_ = newline;
- SHELL_UPDATE_LISTENERS(onlyLastLineChanged);
+ this->updateListeners<&ShellListener::onlyLastLineChanged>();
}
} while (newline);
@@ -272,8 +268,8 @@
void Shell::inputChanged()
{
- SHELL_UPDATE_LISTENERS(inputChanged);
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::inputChanged>();
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::execute()
@@ -298,46 +294,46 @@
void Shell::backspace()
{
this->inputBuffer_->removeBehindCursor();
- SHELL_UPDATE_LISTENERS(inputChanged);
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::inputChanged>();
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::deletechar()
{
this->inputBuffer_->removeAtCursor();
- SHELL_UPDATE_LISTENERS(inputChanged);
+ this->updateListeners<&ShellListener::inputChanged>();
}
void Shell::clear()
{
this->inputBuffer_->clear();
this->historyPosition_ = 0;
- SHELL_UPDATE_LISTENERS(inputChanged);
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::inputChanged>();
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::cursor_right()
{
this->inputBuffer_->increaseCursor();
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::cursor_left()
{
this->inputBuffer_->decreaseCursor();
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::cursor_end()
{
this->inputBuffer_->setCursorToEnd();
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::cursor_home()
{
this->inputBuffer_->setCursorToBegin();
- SHELL_UPDATE_LISTENERS(cursorChanged);
+ this->updateListeners<&ShellListener::cursorChanged>();
}
void Shell::history_up()
@@ -365,7 +361,7 @@
++this->scrollIterator_;
++this->scrollPosition_;
- SHELL_UPDATE_LISTENERS(linesChanged);
+ this->updateListeners<&ShellListener::linesChanged>();
}
}
@@ -376,7 +372,7 @@
--this->scrollIterator_;
--this->scrollPosition_;
- SHELL_UPDATE_LISTENERS(linesChanged);
+ this->updateListeners<&ShellListener::linesChanged>();
}
}
@@ -392,6 +388,6 @@
this->scrollPosition_ = 0;
this->scrollIterator_ = this->lines_.begin();
- SHELL_UPDATE_LISTENERS(exit);
+ this->updateListeners<&ShellListener::exit>();
}
}
Modified: code/branches/console/src/libraries/core/Shell.h
===================================================================
--- code/branches/console/src/libraries/core/Shell.h 2009-10-20 16:46:50 UTC (rev 5968)
+++ code/branches/console/src/libraries/core/Shell.h 2009-10-20 16:47:40 UTC (rev 5969)
@@ -131,6 +131,13 @@
void scroll_down();
void exit();
+ template <void (ShellListener::*F)()>
+ void updateListeners()
+ {
+ for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
+ ((*(it++))->*F)();
+ }
+
std::list<ShellListener*> listeners_;
InputBuffer* inputBuffer_;
OutputBuffer outputBuffer_;
Modified: code/branches/console/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-10-20 16:46:50 UTC (rev 5968)
+++ code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-10-20 16:47:40 UTC (rev 5969)
@@ -67,7 +67,8 @@
@brief Constructor: Creates and initializes the InGameConsole.
*/
InGameConsole::InGameConsole()
- : consoleOverlay_(0)
+ : shell_(Shell::getInstance())
+ , consoleOverlay_(0)
, consoleOverlayContainer_(0)
, consoleOverlayNoise_(0)
, consoleOverlayCursor_(0)
@@ -173,7 +174,7 @@
{
// create the corresponding input state
inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console);
- inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
+ inputState_->setKeyHandler(this->shell_.getInputBuffer());
bHidesAllInputChanged();
// create overlay and elements
@@ -251,7 +252,7 @@
// we take -1.2 because the border makes the panel bigger
this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
- Shell::getInstance().addOutputLevel(true);
+ this->shell_.addOutputLevel(true);
COUT(4) << "Info: InGameConsole initialized" << std::endl;
}
@@ -265,11 +266,11 @@
*/
void InGameConsole::linesChanged()
{
- std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
+ std::list<std::string>::const_iterator it = this->shell_.getNewestLineIterator();
int max = 0;
for (int i = 1; i < LINES; ++i)
{
- if (it != Shell::getInstance().getEndIterator())
+ if (it != this->shell_.getEndIterator())
{
++it;
max = i;
@@ -294,7 +295,7 @@
void InGameConsole::onlyLastLineChanged()
{
if (LINES > 1)
- this->print(*Shell::getInstance().getNewestLineIterator(), 1);
+ this->print(*this->shell_.getNewestLineIterator(), 1);
}
/**
@@ -313,9 +314,9 @@
void InGameConsole::inputChanged()
{
if (LINES > 0)
- this->print(Shell::getInstance().getInput(), 0);
+ this->print(this->shell_.getInput(), 0);
- if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)
+ if (this->shell_.getInput() == "" || this->shell_.getInput().size() == 0)
this->inputWindowStart_ = 0;
}
@@ -324,7 +325,7 @@
*/
void InGameConsole::cursorChanged()
{
- unsigned int pos = Shell::getInstance().getCursorPosition() - inputWindowStart_;
+ unsigned int pos = this->shell_.getCursorPosition() - inputWindowStart_;
if (pos > maxCharsPerLine_)
pos = maxCharsPerLine_;
@@ -481,10 +482,10 @@
{
if (output.size() > this->maxCharsPerLine_)
{
- if (Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
- this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();
- else if (Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
- this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
+ if (this->shell_.getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
+ this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition();
+ else if (this->shell_.getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
+ this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
}
@@ -505,7 +506,7 @@
{
this->bActive_ = true;
InputManager::getInstance().enterState("console");
- Shell::getInstance().registerListener(this);
+ this->shell_.registerListener(this);
this->windowResized(this->windowW_, this->windowH_);
this->linesChanged();
@@ -527,7 +528,7 @@
{
this->bActive_ = false;
InputManager::getInstance().leaveState("console");
- Shell::getInstance().unregisterListener(this);
+ this->shell_.unregisterListener(this);
// scroll up
this->scroll_ = -1;
Modified: code/branches/console/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/branches/console/src/orxonox/overlays/InGameConsole.h 2009-10-20 16:46:50 UTC (rev 5968)
+++ code/branches/console/src/orxonox/overlays/InGameConsole.h 2009-10-20 16:47:40 UTC (rev 5969)
@@ -80,6 +80,7 @@
void bHidesAllInputChanged();
private: // variables
+ Shell& shell_;
bool bActive_;
int windowW_;
int windowH_;
More information about the Orxonox-commit
mailing list