diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-03 01:43:03 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-03 01:43:03 +0000 |
commit | b4973888aeaea2dde6058bc06c3f6631349e7f3c (patch) | |
tree | 010de10692b330d7634ad3090fb94d14c101f484 /src/client/console.cc | |
parent | 67f8a7a783e550cab8e6a77d997b31815ee8cd7e (diff) |
command buffer handling
engine function parsing
buffered client console
Diffstat (limited to 'src/client/console.cc')
-rw-r--r-- | src/client/console.cc | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/src/client/console.cc b/src/client/console.cc index 6a3dfaa..50093f9 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -4,24 +4,93 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "client/client.h" #include "client/console.h" +#include "core/core.h" +#include "render/render.h" + +#include <iostream> namespace client { +Console::Console() { + visible = false; +} + std::ostream & Console::messagestream() { - return (std::cout << ". "); + return (buffer << ". "); } std::ostream & Console::warningstream() { - return (std::cout << "! "); + return (buffer << "* "); +} + +std::ostream & Console::errorstream() +{ + return (buffer << "! "); } std::ostream & Console::debugstream() { - return (std::cout << "? "); + return (buffer << "? "); } -} // namespace client +void Console::draw() +{ + using namespace render; + + flush(); + + float height; + if (core::game()) { + if (!core::game()->ready()) + height = 0.6f; + else if (visible) + height = 0.6f; + else + return; + } else + height = 1.0f; + + // console background rectangle + gl::enable(GL_BLEND); + gl::begin(gl::Quads); + gl::color(1, 1, 1, .1); + gl::vertex(-0.5f*video.ratio , 0.5, -1.0f); + gl::vertex(0.5f*video.ratio ,0.5, -1.0f); + gl::vertex(0.5f*video.ratio , 0.5-height, -1.0f); + gl::vertex(-0.5f*video.ratio , 0.5-height, -1.0f); + gl::end(); + gl::disable(GL_BLEND); +} + +void Console::flush() +{ + char line[MAXCMDSIZE]; + while(this->buffer.getline(line, MAXCMDSIZE-1)) { + + while (text.size() >= 32765 - MAXCMDSIZE) { + size_t i = 0; + while (i+1 < text.size() && text[i] != '\n') + i++; + text.erase(0, i+1); + } + + text.append(line); + text.append("\n"); + + std::cout << line << std::endl; + } + + buffer.clear(); +} + +void Console::toggle() +{ + visible = !visible; +} + +} // namespace client |