Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-05 00:10:02 +0000
committerStijn Buys <ingar@osirion.org>2008-02-05 00:10:02 +0000
commit95ca0e469ef856c0182bb0da411e4417391e3780 (patch)
treea07db9b9d726d175d8305dc3cc5520b8a70f7a73 /src/client/console.cc
parentcf61370df80de6dc659dbd9b803c973b300c1b4c (diff)
renamed client and server application objects
cleaned up namespaces
Diffstat (limited to 'src/client/console.cc')
-rw-r--r--src/client/console.cc117
1 files changed, 92 insertions, 25 deletions
diff --git a/src/client/console.cc b/src/client/console.cc
index f435e9a..127481a 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -4,44 +4,83 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "client/client.h"
#include "client/console.h"
+#include "client/video.h"
#include "core/core.h"
#include "render/render.h"
#include <iostream>
+#include <cmath>
namespace client {
-Console::Console() {
- console_visible = true;
-}
+namespace console {
-std::ostream & Console::messagestream()
-{
- return (buffer << ". ");
-}
+//--- private definition ------------------------------------------
-std::ostream & Console::warningstream()
+/// private client console implementation
+class Console : public sys::ConsoleInterface {
+public:
+ /// stream to send normal messages too
+ virtual std::ostream & messagestream();
+
+ /// stream to send warning messages too
+ virtual std::ostream & warningstream();
+
+ /// stream to send error messages too
+ virtual std::ostream & errorstream();
+
+ /// stream to send debug messages too
+ virtual std::ostream & debugstream();
+
+ /// console text buffer
+ std::stringstream buffer;
+};
+
+// private client console object
+Console console;
+
+// client console input
+std::string input;
+
+// console text data
+std::deque<std::string> text;
+
+// console visibility
+bool console_visible;
+
+//--- engine functions --------------------------------------------
+
+extern "C" void func_con_toggle(std::stringstream &args)
{
- return (buffer << "* ");
+ console_visible = !console_visible;
}
-std::ostream & Console::errorstream()
+//--- public ------------------------------------------------------
+
+void init()
{
- return (buffer << "! ");
+ con_print << "Initializing console..." << std::endl;
+
+ console_visible = false;
+
+ // register our engine functions
+ core::func::add("con_toggle", func_con_toggle);
}
-std::ostream & Console::debugstream()
+void shutdown()
{
- return (buffer << "? ");
+ con_print << "Shutting down console..." << std::endl;
+
+ // unregister our engine functions
+ core::func::remove("con_toggle");
}
-void Console::draw()
+void draw()
{
using namespace render;
- console.flush();
+ flush();
if(!console_visible)
return;
@@ -69,9 +108,9 @@ void Console::draw()
// draw the console text
gl::enable(GL_TEXTURE_2D);
- std::deque<std::string>::reverse_iterator rit = console.text.rbegin();
+ std::deque<std::string>::reverse_iterator rit = text.rbegin();
float y = video::height*con_height-2*CHARHEIGHT-8;
- while (y > 0 && rit < console.text.rend()) {
+ while (y > 0 && rit < text.rend()) {
std::string line(*rit);
if (line[0] == '?')
@@ -94,18 +133,17 @@ void Console::draw()
draw_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 4, input);
// draw cursor
- if ((core::time() - floorf(core::time())) < 0.5f) {
+ if ((core::time() - ::floorf(core::time())) < 0.5f) {
std::string cursor("_");
draw_text(CHARWIDTH*(input.size()+1), video::height*con_height - CHARHEIGHT - 4 , cursor);
}
gl::disable(GL_TEXTURE_2D);
}
-void Console::flush()
+void flush()
{
char line[MAXCMDSIZE];
- while(this->buffer.getline(line, MAXCMDSIZE-1)) {
-
+ while(console.buffer.getline(line, MAXCMDSIZE-1)) {
while (text.size() >= MAXCONLINES) {
text.pop_front();
}
@@ -113,15 +151,15 @@ void Console::flush()
std::cout << line << std::endl;
}
- buffer.clear();
+ console.buffer.clear();
}
-void Console::toggle()
+void toggle()
{
console_visible = !console_visible;
}
-void Console::handle_keyreleased(SDL_keysym* keysym)
+void handle_keyreleased(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_RETURN:
@@ -144,4 +182,33 @@ void Console::handle_keyreleased(SDL_keysym* keysym)
}
}
+bool visible()
+{
+ return console_visible;
+}
+
+//--- private -----------------------------------------------------
+
+std::ostream & Console::messagestream()
+{
+ return (buffer << ". ");
+}
+
+std::ostream & Console::warningstream()
+{
+ return (buffer << "* ");
+}
+
+std::ostream & Console::errorstream()
+{
+ return (buffer << "! ");
+}
+
+std::ostream & Console::debugstream()
+{
+ return (buffer << "? ");
+}
+
+} // namespace console
+
} // namespace client