From b4973888aeaea2dde6058bc06c3f6631349e7f3c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 3 Feb 2008 01:43:03 +0000 Subject: command buffer handling engine function parsing buffered client console --- src/client/console.cc | 77 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) (limited to 'src/client/console.cc') 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 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 -- cgit v1.2.3