diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/application.cc | 8 | ||||
-rw-r--r-- | src/client/client.h | 2 | ||||
-rw-r--r-- | src/client/console.cc | 127 | ||||
-rw-r--r-- | src/client/console.h | 14 | ||||
-rw-r--r-- | src/client/input.cc | 11 | ||||
-rw-r--r-- | src/client/view.cc | 25 | ||||
-rw-r--r-- | src/client/view.h | 9 |
7 files changed, 158 insertions, 38 deletions
diff --git a/src/client/application.cc b/src/client/application.cc index d3e7f4e..5822600 100644 --- a/src/client/application.cc +++ b/src/client/application.cc @@ -17,6 +17,11 @@ namespace client { +extern "C" void func_con_toggle(std::stringstream &args) +{ + console.toggle(); +} + void Application::quit(int status) { SDL_Quit(); @@ -38,6 +43,9 @@ void Application::init() // initialize input input.init(); + + // register our engine functions + core::func_register("con_toggle", func_con_toggle); } void Application::run() diff --git a/src/client/client.h b/src/client/client.h index af3e53b..64f1aab 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -18,6 +18,8 @@ #include "core/core.h" #include "game/game.h" +#include <SDL/SDL.h> + /// client-side functions to render and control the gameworld /** The client namespace contains the necessary functions to * accept input, send it to the game and renders the result diff --git a/src/client/console.cc b/src/client/console.cc index 50093f9..a0cc7c5 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -40,31 +40,87 @@ std::ostream & Console::debugstream() void Console::draw() { using namespace render; - + + // flush console messages in the buffer flush(); float height; + bool showloader = false; if (core::game()) { - if (!core::game()->ready()) + if (!core::game()->ready()) { height = 0.6f; - else if (visible) + showloader = true; + } else if (visible) height = 0.6f; else - return; - } else + height = 0.0f; + } else { + showloader = true; height = 1.0f; + } + + if (showloader) { + // draw the loader background + gl::color(0.5f, 0.5f, 0.5f, 1.0f); + + gl::begin(gl::Quads); + gl::vertex(0,0, 0); + gl::vertex(video.width,0,0); + gl::vertex(video.width,video.height,0); + gl::vertex(0,video.height,0); + gl::end(); + } + + if (height > 0) { + // draw version below the bottom of the console + gl::color(0.0f, 1.0f, 0.0f, 1.0f); + std:: string version = std::string("The Osirion Project "); + version.append(PACKAGE_VERSION); + draw_text(video.width-CHARSIZE*(version.size()+1), video.height*height-CHARSIZE-4, version); + + // draw the transparent console background + gl::color(1, 1, 1, .5); + + gl::enable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga + + gl::begin(gl::Quads); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(0,0, 0); + + glTexCoord2f(1.0f, 0.0f); + gl::vertex(video.width,0,0); + + glTexCoord2f(1.0f, 1.0f); + gl::vertex(video.width,video.height*height,0); + + glTexCoord2f(0.0f, 1.0f); + gl::vertex(0,video.height*height,0); + + gl::end(); + + glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga + gl::enable(GL_BLEND); + + // draw the console text + gl::color(1,1,1,1); + std::deque<std::string>::reverse_iterator rit = console.text.rbegin(); + float y = video.height*height-2*CHARSIZE-8; + while (y > 0 && rit < console.text.rend()) { + draw_text(0, y, *rit); + y -= CHARSIZE; + ++rit; + } + + // draw the console input + gl::color(0.0f, 1.0f, 0.0f, 1.0f); + draw_text(0, video.height*height - CHARSIZE - 4, input); + + gl::disable(GL_TEXTURE_2D); + gl::disable(GL_BLEND); + } - // 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() @@ -72,16 +128,10 @@ 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); + while (text.size() >= MAXCONLINES) { + text.pop_front(); } - - text.append(line); - text.append("\n"); - + text.push_back(std::string(line)); std::cout << line << std::endl; } @@ -93,4 +143,33 @@ void Console::toggle() visible = !visible; } +void Console::handle_keyreleased(SDL_keysym* keysym) +{ + switch( keysym->sym ) { + case '`': + case '~': + toggle(); + return; + break; + + case SDLK_RETURN: + if (input.size()) { + core::cmd << input << std::endl; + input.clear(); + } + break; + case SDLK_BACKSPACE: + if (input.size()) { + input.erase(input.size()-1, 1); + } + break; + default: + break; + } + + if (keysym->sym >= 32 && keysym->sym <= 175) { + input += (char) keysym->sym; + } +} + } // namespace client diff --git a/src/client/console.h b/src/client/console.h index ee3b85e..7f98666 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -8,7 +8,13 @@ #define __INCLUDED_CLIENT_CONSOLE_H__ #include "sys/consoleinterface.h" + +#include <SDL/SDL.h> + #include <sstream> +#include <deque> + +#define MAXCONLINES 2048 namespace client { @@ -40,12 +46,18 @@ public: bool visible; + /// toggle handle keyboard input + void handle_keyreleased(SDL_keysym* keysym); + protected: /// console text buffer std::stringstream buffer; /// console text data - std::string text; + std::deque<std::string> text; + +private: + std::string input; }; } diff --git a/src/client/input.cc b/src/client/input.cc index d30a97e..96cd032 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -34,7 +34,8 @@ void Input::handle_keyreleased(SDL_keysym* keysym) switch( keysym->sym ) { case '`': case '~': - console.toggle(); + //console.toggle(); + core::cmd << "con_toggle" << std::endl; break; case SDLK_SPACE: camera.nextmode(); @@ -88,10 +89,14 @@ void Input::process() while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: - handle_keypressed( &event.key.keysym ); + if (!console.visible) + handle_keypressed( &event.key.keysym ); break; case SDL_KEYUP: - handle_keyreleased( &event.key.keysym ); + if (console.visible) + console.handle_keyreleased( &event.key.keysym ); + else + handle_keyreleased( &event.key.keysym ); break; case SDL_QUIT: client::application.shutdown(); diff --git a/src/client/view.cc b/src/client/view.cc index 8881ac2..3b5f785 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -12,8 +12,6 @@ #include "sys/sys.h" #include "math/mathlib.h" -#include <SDL/SDL.h> - using namespace render; namespace client @@ -49,7 +47,8 @@ void View::reset() { // Culling gl::cullface( GL_BACK ); gl::frontface(GL_CCW ); -} + +} void View::draw_world(float elapsed) @@ -135,18 +134,22 @@ void View::draw(float elapsed) { // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - + // Change to the projection matrix and set our viewing volume. gl::matrixmode( GL_PROJECTION ); gl::loadidentity(); //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 ); const float frustumsize = 0.5f; - gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f); - + x = -frustumsize * video.ratio; + width = video.ratio; + y = -frustumsize; + height = 1; - gl::matrixmode( GL_MODELVIEW ); + //gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f); + gl::frustum(x, x+width, y, y +height, 1.0f, 1024.0f); + gl::matrixmode( GL_MODELVIEW ); gl::loadidentity(); gl::rotate(90.0f, 0, 1.0, 0); @@ -159,13 +162,15 @@ void View::draw(float elapsed) // draw the semi-static background draw_background(elapsed); - // draw the console - //gl::matrixmode( GL_PROJECTION ); - //gl::loadidentity(); + // switch to ortographic projection to draw the GUI + gl::matrixmode( GL_PROJECTION ); + gl::loadidentity(); + glOrtho(0, video.width, video.height, 0, -1000.0f, 1000.0f); gl::matrixmode( GL_MODELVIEW ); gl::loadidentity(); + // draw the console console.draw(); } diff --git a/src/client/view.h b/src/client/view.h index e0a613f..92965ce 100644 --- a/src/client/view.h +++ b/src/client/view.h @@ -24,9 +24,18 @@ public: /// reset the projection matrix void reset(); + /// width of the console (in OpenGL units) float width; + + /// height of the console (in OpenGL units) float height; + /// bottom left x value + float x; + + /// bottom left y value + float y; + protected: /// draw the world void draw_world(float elapsed); |