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-04 00:54:30 +0000
committerStijn Buys <ingar@osirion.org>2008-02-04 00:54:30 +0000
commit840f9b8678f607aecc15d47bc77248c4ac8b8574 (patch)
treef90688ca7afabb8e4123e1a811dd168a86717a3c /src/client
parent43b994017a560a2fa97894ebfe121375d6614b6f (diff)
tweaked console
client status with timer and fps core connect/disconnect
Diffstat (limited to 'src/client')
-rw-r--r--src/client/application.cc60
-rw-r--r--src/client/application.h3
-rw-r--r--src/client/client.h3
-rw-r--r--src/client/console.cc134
-rw-r--r--src/client/console.h7
-rw-r--r--src/client/input.cc35
-rw-r--r--src/client/input.h4
-rw-r--r--src/client/video.cc5
-rw-r--r--src/client/video.h4
-rw-r--r--src/client/view.cc158
-rw-r--r--src/client/view.h10
11 files changed, 248 insertions, 175 deletions
diff --git a/src/client/application.cc b/src/client/application.cc
index 5822600..b7505a1 100644
--- a/src/client/application.cc
+++ b/src/client/application.cc
@@ -1,7 +1,7 @@
/*
client/application.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
// project headers
@@ -15,7 +15,8 @@
// C++ headers
#include <cmath>
-namespace client {
+namespace client
+{
extern "C" void func_con_toggle(std::stringstream &args)
{
@@ -33,16 +34,16 @@ void Application::init()
// initialize core
core::ApplicationInterface::init();
- con_debug << "Initializing client..." << std::endl;
+ con_print << "Initializing client..." << std::endl;
// Initialize the video subsystem
video.init();
if (!video.initialized) {
- quit(1);
- }
+ quit(1);
+ }
- // initialize input
- input.init();
+ // initialize input
+ input.init();
// register our engine functions
core::func_register("con_toggle", func_con_toggle);
@@ -52,41 +53,46 @@ void Application::run()
{
Uint32 chrono = SDL_GetTicks();
- while(true) {
- Uint32 current = SDL_GetTicks();
-
- // overflow protection ~49 days
- if (current < chrono) {
- chrono = current;
- }
+ while (true) {
+ Uint32 current = SDL_GetTicks();
- // update the game chronometers
- float elapsed = (float) ( current - chrono) / 1000.0f;
- chrono = current;
+ // overflow protection ~49 days
+ if (current < chrono) {
+ chrono = current;
+ }
- core::ApplicationInterface::frame(elapsed);
+ // update the core chronometer
+ float seconds = ((float)(current - chrono)) / 1000.0f;
+ frame(seconds);
+
+ // update the video chronometers and draw
+ video.frame(seconds);
+ if (seconds > 0)
+ current_fps = floorf(1/seconds);
+ else
+ current_fps = 9999;
- // update the video chronometers and draw
- video.draw(elapsed);
+ // process input
+ input.frame();
- // process input
- input.process();
- }
+ // update the main loop chronometer
+ chrono = current;
+ }
}
-void Application::shutdown()
+void Application::shutdown()
{
con_debug << "Shutting down client..." << std::endl;
console.flush();
input.shutdown();
console.flush();
-
+
video.shutdown();
console.flush();
- core::ApplicationInterface::shutdown();
+ core::ApplicationInterface::shutdown();
console.flush();
quit(0);
diff --git a/src/client/application.h b/src/client/application.h
index 40da1da..62eccd6 100644
--- a/src/client/application.h
+++ b/src/client/application.h
@@ -25,6 +25,9 @@ public:
/// quit the client Application
virtual void quit(int status);
+
+ /// current fps
+ float current_fps;
};
}
diff --git a/src/client/client.h b/src/client/client.h
index 64f1aab..66a7700 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -47,6 +47,9 @@ extern Console console;
/// global Game instance
extern game::Game game;
+/// current fps
+inline float fps() { return (application.current_fps); }
+
} // namespace client
#endif // __INCLUDED_CLIENT_H__
diff --git a/src/client/console.cc b/src/client/console.cc
index a0cc7c5..dfc1d08 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -14,7 +14,7 @@
namespace client {
Console::Console() {
- visible = false;
+ console_visible = true;
}
std::ostream & Console::messagestream()
@@ -40,87 +40,65 @@ 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()) {
- height = 0.6f;
- showloader = true;
- } else if (visible)
- height = 0.6f;
- else
- height = 0.0f;
- } else {
- showloader = true;
- height = 1.0f;
- }
+
+ console.flush();
+ if(!console_visible)
+ return;
- if (showloader) {
- // draw the loader background
- gl::color(0.5f, 0.5f, 0.5f, 1.0f);
+ float con_height = 0.70f;
- 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();
- }
+ glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga
+
+ // draw version below the bottom of the console
+ gl::enable(GL_TEXTURE_2D);
+ gl::color(0.0f, 1.0f, 0.0f, 0.5f);
+ std:: string version = std::string("The Osirion Project ");
+ version.append(VERSION);
+ draw_text(video.width-CHARWIDTH*(version.size()+1), video.height*con_height-CHARHEIGHT-4, version);
+ gl::disable(GL_TEXTURE_2D);
+
+ // draw the transparent console background
+ gl::color(1.0f, 1.0f, 1.0f, 0.01f);
+
+ gl::begin(gl::Quads);
+ gl::vertex(0.0f, 0.0f, 0.0f);
+ gl::vertex(video.width, 0.0f,0.0f);
+ gl::vertex(video.width,video.height*con_height,0.0f);
+ gl::vertex(0,video.height*con_height,0.0f);
+ 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);
+ // draw the console text
+ gl::enable(GL_TEXTURE_2D);
+ std::deque<std::string>::reverse_iterator rit = console.text.rbegin();
+ float y = video.height*con_height-2*CHARHEIGHT-8;
+ while (y > 0 && rit < console.text.rend()) {
+ std::string line(*rit);
- gl::enable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga
+ if (line[0] == '?')
+ gl::color(0.7f,0.7f,0.7f, 1.0f);
+ else if (line[0] == '*')
+ gl::color(1.0f,1.0f,0.0f, 1.0f);
+ else if (line[0] == '!')
+ gl::color(1.0f,0.0f,0.0f, 1.0f);
+ else
+ gl::color(1.0f,1.0f,1.0f, 1.0f);
+ line.erase(0,2);
- 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();
+ draw_text(CHARWIDTH, y, line);
+ y -= CHARHEIGHT;
+ ++rit;
+ }
- 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(CHARWIDTH, video.height*con_height - CHARHEIGHT - 4, input);
- // 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);
+ // draw cursor
+ 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()
@@ -140,18 +118,12 @@ void Console::flush()
void Console::toggle()
{
- visible = !visible;
+ console_visible = !console_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;
diff --git a/src/client/console.h b/src/client/console.h
index 7f98666..c0d485f 100644
--- a/src/client/console.h
+++ b/src/client/console.h
@@ -44,7 +44,8 @@ public:
/// toggle the console on or off
void toggle();
- bool visible;
+ /// true of the console is visible
+ inline bool visible() { return console_visible; }
/// toggle handle keyboard input
void handle_keyreleased(SDL_keysym* keysym);
@@ -54,13 +55,13 @@ protected:
std::stringstream buffer;
/// console text data
- std::deque<std::string> text;
+ std::deque<std::string> text;
private:
std::string input;
+ bool console_visible;
};
}
#endif // __INCLUDED_CLIENT_CONSOLE_H__
-
diff --git a/src/client/input.cc b/src/client/input.cc
index 96cd032..c46c66f 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -28,15 +28,10 @@ see
http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html
*/
-// handle key_release events
+// handle key_release events for the game world
void Input::handle_keyreleased(SDL_keysym* keysym)
{
switch( keysym->sym ) {
- case '`':
- case '~':
- //console.toggle();
- core::cmd << "con_toggle" << std::endl;
- break;
case SDLK_SPACE:
camera.nextmode();
break;
@@ -45,13 +40,10 @@ void Input::handle_keyreleased(SDL_keysym* keysym)
}
}
-// handle pressed keys
+// handle pressed keys for the game world
void Input::handle_keypressed(SDL_keysym* keysym)
{
switch( keysym->sym ) {
- case SDLK_ESCAPE:
- client::application.shutdown();
- break;
case SDLK_LEFT:
camera.rotate_left();
break;
@@ -82,22 +74,37 @@ void Input::handle_keypressed(SDL_keysym* keysym)
}
-void Input::process()
+void Input::frame()
{
SDL_Event event;
while( SDL_PollEvent( &event ) ) {
+
switch( event.type ) {
case SDL_KEYDOWN:
- if (!console.visible)
+ /*
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ client::application.shutdown();
+ }
+ */
+ if (core::connected() && !console.visible()) {
+ // send key events to the game world
handle_keypressed( &event.key.keysym );
+ }
break;
+
case SDL_KEYUP:
- if (console.visible)
+ if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') {
+ console.toggle();
+ } else if (console.visible()) {
+ // send key events to the console
console.handle_keyreleased( &event.key.keysym );
- else
+ } else if (core::connected()) {
+ // send key events to the game world
handle_keyreleased( &event.key.keysym );
+ }
break;
+
case SDL_QUIT:
client::application.shutdown();
break;
diff --git a/src/client/input.h b/src/client/input.h
index 23ddd5d..6067522 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -18,8 +18,8 @@ public:
/// shutdown the input subsystem
void shutdown();
- /// process input events
- void process();
+ /// handle one frame of input events
+ void frame();
protected:
/// handle key release events
diff --git a/src/client/video.cc b/src/client/video.cc
index 4018834..bfff445 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -88,10 +88,9 @@ void Video::init()
return;
}
-void Video::draw(float elapsed)
+void Video::frame(float seconds)
{
- if (core::game() && core::game()->ready())
- view.draw(elapsed);
+ view.frame(seconds);
SDL_GL_SwapBuffers();
}
diff --git a/src/client/video.h b/src/client/video.h
index 6da89f3..edf7823 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -17,8 +17,8 @@ public:
void init();
/// shutdown the video subsystem
void shutdown();
- /// Update the screen state and redraw
- void draw(float elapsed);
+ /// draw the next client video frame
+ void frame(float seconds);
/// reset and clear the viewport
void reset();
diff --git a/src/client/view.cc b/src/client/view.cc
index 3b5f785..1dd0df6 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -12,6 +12,11 @@
#include "sys/sys.h"
#include "math/mathlib.h"
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+
using namespace render;
namespace client
@@ -41,25 +46,26 @@ void View::shutdown()
}
void View::reset() {
- // Our shading model--Gouraud (smooth).
+ // shading model: Gouraud (smooth).
gl::shademodel(GL_SMOOTH);
- // Culling
+ // culling
gl::cullface( GL_BACK );
gl::frontface(GL_CCW );
+ // alpha-blending
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ gl::disable(GL_BLEND);
+
+ // depth
+ gl::depthmask(GL_TRUE);
+ gl::disable(GL_DEPTH_TEST);
+ gl::disable( GL_CULL_FACE );
}
void View::draw_world(float elapsed)
{
-
- gl::enable( GL_CULL_FACE );
-
- // Depth buffer writing
- gl::depthmask(GL_TRUE);
- gl::enable(GL_DEPTH_TEST);
-
// draw the world
gl::push();
@@ -73,17 +79,11 @@ void View::draw_world(float elapsed)
stardrawer->draw(elapsed);
gl::pop();
- gl::disable( GL_CULL_FACE );
-
}
void View::draw_background(float elapsed)
{
using namespace gl;
-
- // enable Alpha blending
- gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- gl::enable(GL_BLEND);
// galactic axis
begin(Lines);
@@ -125,42 +125,107 @@ void View::draw_background(float elapsed)
vertex(gridsize-dx, y, i-dz);
}
end();
-
- gl::disable(GL_BLEND);
- gl::disable(GL_DEPTH_TEST);
}
-void View::draw(float elapsed)
+void View::draw_loader()
{
- // Clear the color and depth buffers.
- gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ gl::enable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga
+ gl::color(1.0f, 1.0f, 1.0f, 1.0f);
+
+ 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);
- // Change to the projection matrix and set our viewing volume.
- gl::matrixmode( GL_PROJECTION );
- gl::loadidentity();
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(video.width,video.height,0);
- //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 );
- const float frustumsize = 0.5f;
- x = -frustumsize * video.ratio;
- width = video.ratio;
- y = -frustumsize;
- height = 1;
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(0,video.height,0);
+ gl::end();
- //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::disable(GL_TEXTURE_2D);
+}
- gl::matrixmode( GL_MODELVIEW );
- gl::loadidentity();
- gl::rotate(90.0f, 0, 1.0, 0);
+void View::draw_status()
+{
+ using namespace std;
+
+ if (console.visible())
+ return;
+
+ glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga
+ gl::enable(GL_TEXTURE_2D);
+
+ // print the status in the upper left corner
+ gl::color(1.0f, 1.0f, 1.0f, 1.0f);
+ std::stringstream status;
- // Camera transformation
- camera.draw(elapsed);
+ int hours = (int) sys::time() / 3600;
+ int minutes = (int) (sys::time() - 3600*hours) / 60;
+ int seconds = (int) (sys::time() - 3600*hours - 60 *minutes);
+ status << " clock " << setfill('0') << setw(2) << hours << ":"
+ << setfill('0') << setw(2) << minutes << ":"
+ << setfill('0') << setw(2) << seconds;
+
+ minutes = (int) floorf(core::time() / 60.0f);
+ seconds = (int) floorf(core::time() - (float) minutes* 60.0f);
+
+ status << " time " << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds;
+ status << " fps " << setw(4) << client::fps();
+ draw_text(0, 4, status);
+
+ // print the version number in the upper right corner
+ gl::color(0.0f, 1.0f, 0.0f, 1.0f);
+ std::string version("ver. ");
+ version.append(VERSION);
+ draw_text(video.width-(version.size()+1)*CHARWIDTH, 4, version);
+
+ gl::disable(GL_TEXTURE_2D);
+}
- // draw the world
- draw_world(elapsed);
+void View::frame(float seconds)
+{
+ // Clear the color and depth buffers.
+ gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ if (core::connected()) {
+ // draw the game world
+
+ // Change to the projection matrix and set our viewing volume.
+ gl::matrixmode( GL_PROJECTION );
+ gl::loadidentity();
+
+ const float frustumsize = 0.5f;
+ x = -frustumsize * video.ratio;
+ width = video.ratio;
+ y = -frustumsize;
+ height = 1;
+ 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);
- // draw the semi-static background
- draw_background(elapsed);
+ // Camera transformation
+ camera.draw(seconds);
+
+ gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
+ gl::enable(GL_CULL_FACE); // enable culling
+
+ draw_world(seconds); // draw the world
+
+ gl::disable(GL_CULL_FACE); // disable culling
+ gl::enable(GL_BLEND); // enable alpha blending
+
+ draw_background(seconds); // draw the spacegrid
+
+ gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
+ }
// switch to ortographic projection to draw the GUI
gl::matrixmode( GL_PROJECTION );
@@ -169,9 +234,20 @@ void View::draw(float elapsed)
gl::matrixmode( GL_MODELVIEW );
gl::loadidentity();
+
+ if (!core::connected()) {
+ // draw the loader bitmap
+ draw_loader();
+ gl::enable(GL_BLEND); // enable alpha blending
+ }
// draw the console
console.draw();
+
+ // draw the status line
+ draw_status();
+
+ gl::disable(GL_BLEND);
}
} // namespace view
diff --git a/src/client/view.h b/src/client/view.h
index 92965ce..06d139d 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -18,8 +18,8 @@ public:
/// shutdown the view
void shutdown();
- /// update the chronometer and draw the game view
- void draw(float elapsed);
+ /// draw the next frame
+ void frame(float seconds);
/// reset the projection matrix
void reset();
@@ -42,6 +42,12 @@ protected:
/// draw the background
void draw_background(float elapsed);
+
+ /// draw the loader screen
+ void draw_loader();
+
+ /// draw the status bar
+ void draw_status();
};
} // namespace client