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>2007-10-21 23:02:47 +0000
committerStijn Buys <ingar@osirion.org>2007-10-21 23:02:47 +0000
commita237a2d7723b94df6cd3e91401ec28388de6f1a0 (patch)
tree7da376d276d03fced7b94a807c0952fd32bcde08 /src/client
parent084c6212afaa6f996091f36d0ff85ac845803a87 (diff)
namespace cleanup
Diffstat (limited to 'src/client')
-rw-r--r--src/client/camera.cc52
-rw-r--r--src/client/camera.h56
-rw-r--r--src/client/input.cc37
-rw-r--r--src/client/input.h20
-rw-r--r--src/client/main.cc12
-rw-r--r--src/client/shipdrawer.cc22
-rw-r--r--src/client/shipdrawer.h11
-rw-r--r--src/client/stardrawer.cc6
-rw-r--r--src/client/stardrawer.h8
-rw-r--r--src/client/video.cc43
-rw-r--r--src/client/video.h23
-rw-r--r--src/client/view.cc51
-rw-r--r--src/client/view.h25
13 files changed, 214 insertions, 152 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 42d686a..87e00fc 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -1,30 +1,34 @@
-/* client/camera.cc
+/*
+ client/camera.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
*/
-#include "common/functions.h"
-#include "game/game.h"
+#include "camera.h"
+
#include "gl/osiriongl.h"
+#include "game/game.h"
+#include "common/functions.h"
-namespace camera
-{
-enum Mode {Free, Track};
-Mode mode = Track;
+using namespace common;
-const float track_pitch = -15.0f; // default tracking pitch
-const float offset_inc = 5.0f; // default offset increment
+namespace client
+{
+
+Camera::Mode Camera::mode = Camera::Track;
-float yaw = 0; // current yaw, angle in XZ plane, positive is looking left
-float yaw_target = 0; // target yaw
+const float Camera::track_pitch = -15.0f; // default tracking pitch
+const float Camera::offset_inc = 5.0f; // default offset increment
-float pitch = -45.0f; // current pitch, angle in XY, positive is looking up
-float pitch_target = track_pitch; // target pitch
+float Camera::yaw = 0; // current yaw, angle in XZ plane, positive is looking left
+float Camera::yaw_target = 0; // target yaw
-float distance = 0.4f; // distance from the eye to the target
+float Camera::pitch = -45.0f; // current pitch, angle in XY, positive is looking up
+float Camera::pitch_target = Camera::track_pitch; // target pitch
+float Camera::distance = 0.4f; // distance from the eye to the target
-void draw(float elapsed)
+void Camera::draw(float elapsed)
{
if (mode == Track) {
yaw_target = game::ship.yaw;
@@ -54,37 +58,37 @@ void draw(float elapsed)
}
}
-void rotate_right()
+void Camera::rotate_right()
{
if (mode == Free ) {
yaw_target = degreesf( yaw_target + offset_inc);
}
}
-void rotate_left()
+void Camera::rotate_left()
{
if (mode == Free ) {
yaw_target = degreesf( yaw_target - offset_inc);
}
}
-void rotate_up()
+void Camera::rotate_up()
{
if (mode == Free ) {
- pitch_target = pitch_target + offset_inc;
- if (pitch_target > 90.0f) pitch_target = 90.0f;
+ pitch_target = pitch_target - offset_inc;
+ if (pitch_target < -90.0f) pitch_target = -90.0f;
}
}
-void rotate_down()
+void Camera::rotate_down()
{
if (mode == Free ) {
- pitch_target = pitch_target - offset_inc;
- if (pitch_target < -90.0f) pitch_target = -90.0f;
+ pitch_target = pitch_target + offset_inc;
+ if (pitch_target > 90.0f) pitch_target = 90.0f;
}
}
-void nextmode() {
+void Camera::nextmode() {
switch(mode) {
case Free:
// switch camera to Track mode
diff --git a/src/client/camera.h b/src/client/camera.h
index 63c7aa5..2e20c1b 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -1,44 +1,66 @@
-/* camera.h
- This file is part of the Osirion project
+/*
+ client/camera.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CAMERA_H__
#define __INCLUDED_CAMERA_H__
-#include "common/vector3f.h"
+#include "gl/osiriongl.h"
+
+namespace client {
/// camera functions
/** The functions in this namespace performs the transformations
for the camera eye location. The camera always looks at (0,0,0)
*/
-namespace camera
+class Camera
{
+public:
+ /// enum indicating the camera mode
+ enum Mode {Free, Track};
+
/// draw the OpenGL camera transformation
- void draw(float elapsed);
+ static void draw(float elapsed);
/// rotate the camera left
- void rotate_left();
+ static void rotate_left();
/// rotate the camera right
- void rotate_right();
+ static void rotate_right();
/// rotate the camera up
- void rotate_up();
+ static void rotate_up();
/// rotate the camera down
- void rotate_down();
+ static void rotate_down();
/// switch to next camera mode
- void nextmode();
+ static void nextmode();
/// camera target
/** The location the camera is looking at */
- extern Vector3f target;
+ static gl::Vector3f target;
- /// horizontal viewing angle x/z plane
- extern float horiz_angle;
- /// vertical viewing angle z/y plane
- extern float vert_angle;
+ /// target yaw, angle in XZ plane, positive is looking left
+ static float yaw_target;
+ /// target pitch, angle in XZ plane, positive is looking left
+ static float pitch_target;
/// distance from the camera to the target
- /** The distance in game units from the eye of the camera to the target */
- extern float distance;
+ static float distance;
+
+protected:
+ /// default tracking pitch
+ static const float track_pitch;
+ /// default offset increment
+ static const float offset_inc;
+
+ /// current yaw, angle in XZ plane, positive is looking left
+ static float yaw;
+ /// current pitch, angle in XY, positive is looking up
+ static float pitch;
+
+ static Mode mode;
};
+
+} // namespace client
#endif // __INCLUDED_CAMERA_H__
diff --git a/src/client/input.cc b/src/client/input.cc
index 8af7414..b231270 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -1,50 +1,48 @@
-/* input.cc
+/*
+ input.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
*/
-// SDL headers
-#include <SDL/SDL.h>
-
//project headers
-#include "common/functions.h"
-#include "game/game.h"
-
+#include "input.h"
#include "view.h"
#include "camera.h"
-namespace input
-{
+#include "common/functions.h"
+#include "game/game.h"
-void init()
+namespace client {
+
+void Input::init()
{
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
}
-void shutdown()
+void Input::shutdown()
{
}
-void handle_keydown(SDL_keysym* keysym)
+void Input::handle_keydown(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_ESCAPE:
game::shutdown();
break;
case SDLK_SPACE:
- camera::nextmode();
+ Camera::nextmode();
break;
case SDLK_LEFT:
- camera::rotate_left();
+ Camera::rotate_left();
break;
case SDLK_RIGHT:
- camera::rotate_right();
+ Camera::rotate_right();
break;
case SDLK_UP:
- camera::rotate_up();
+ Camera::rotate_up();
break;
case SDLK_DOWN:
- camera::rotate_down();
+ Camera::rotate_down();
break;
case SDLK_KP_PLUS:
game::ship.thrust_increase();
@@ -64,7 +62,7 @@ void handle_keydown(SDL_keysym* keysym)
}
-void process()
+void Input::process()
{
SDL_Event event;
@@ -83,4 +81,5 @@ void process()
}
-} // namespace input
+} // namespace client
+
diff --git a/src/client/input.h b/src/client/input.h
index f1e94d9..6027d58 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -6,19 +6,29 @@
#ifndef __INCLUDED_INPUT_H__
#define __INCLUDED_INPUT_H__
+#include <SDL/SDL.h>
-namespace input
+namespace client {
+
+class Input
{
+public:
/// initialize the input subsystem
- void init();
+ static void init();
/// shutdown the input subsystem
- void shutdown();
+ static void shutdown();
/// exit the application
- void quit(int exit_code);
+ static void quit(int exit_code);
/// process input events
- void process();
+ static void process();
+
+protected:
+ /// handle keydown events
+ static void handle_keydown(SDL_keysym* keysym);
};
+} // namespace Client
+
#endif // __INCLUDED_INPUT_H__
diff --git a/src/client/main.cc b/src/client/main.cc
index 696c02f..76f7277 100644
--- a/src/client/main.cc
+++ b/src/client/main.cc
@@ -27,13 +27,13 @@ int main( int argc, char *argv[] )
std::cout << "Project::OSiRiON " << OSIRION_VERSION << std::endl;
// Initialize the video subsystem
- video::init();
- if (!video::initialized) {
+ client::Video::init();
+ if (!client::Video::initialized) {
quit(1);
}
// initialize input
- input::init();
+ client::Input::init();
// initialize game
game::init();
@@ -52,14 +52,14 @@ int main( int argc, char *argv[] )
game::update(elapsed);
// update the video chronometers and draw
- video::draw(elapsed);
+ client::Video::draw(elapsed);
startup = chrono;
// process input
- input::process();
+ client::Input::process();
}
- video::shutdown();
+ client::Video::shutdown();
quit(0);
}
diff --git a/src/client/shipdrawer.cc b/src/client/shipdrawer.cc
index d889178..de8dee0 100644
--- a/src/client/shipdrawer.cc
+++ b/src/client/shipdrawer.cc
@@ -1,15 +1,18 @@
-/* shipdrawer.cc
+/*
+ shipdrawer.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
*/
-#include <iostream>
-
-// project headers
+#include "shipdrawer.h"
#include "gl/osiriongl.h"
#include "gl/box.h"
-#include "shipdrawer.h"
+#include <iostream>
+
+namespace client {
+
+using namespace gl;
Vector3f v0(1.0f, -1.0f, -1.0f);
Vector3f v1(1.0f, 1.0f, -1.0f);
@@ -21,7 +24,7 @@ Vector3f v5(-1.0f, 1.0f, -1.0f);
Vector3f v6(-1.0f, 1.0f, 1.0f);
Vector3f v7(-1.0f, -1.0f, 1.0f);
-ShipDrawer::ShipDrawer(Ship *s)
+ShipDrawer::ShipDrawer(game::Ship *s)
{
angle = 0;
ship = s;
@@ -33,17 +36,14 @@ ShipDrawer::~ShipDrawer()
void ShipDrawer::draw(float elapsed)
{
- using namespace gl;
-
gl::push();
rotate(ship->yaw, 0.0f, 1.0f, 0.0f );
-
Vector3f tl(0.25, 0.125, 0.125);
Vector3f br(-0.25, -0.125, -0.125);
- Box box(tl, br);
+ gl::Box box(tl, br);
box.draw();
tl = Vector3f(0, 0.07, 0.25);
@@ -106,3 +106,5 @@ void ShipDrawer::draw(float elapsed)
gl::pop();
}
+
+} // namespace client
diff --git a/src/client/shipdrawer.h b/src/client/shipdrawer.h
index 8860585..73db28d 100644
--- a/src/client/shipdrawer.h
+++ b/src/client/shipdrawer.h
@@ -1,4 +1,5 @@
-/* shipdrawer.h
+/*
+ shipdrawer.h
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
@@ -9,18 +10,22 @@
// project headers
#include "game/ship.h"
+namespace client {
+
class ShipDrawer
{
public:
- ShipDrawer(Ship *s);
+ ShipDrawer(game::Ship *s);
~ShipDrawer();
/// update the model state
void draw(float elapsed);
private:
- Ship *ship;
+ game::Ship *ship;
float angle;
};
+} // namespace client
+
#endif // __INCLUDED_SHIPDRAWER_H__
diff --git a/src/client/stardrawer.cc b/src/client/stardrawer.cc
index 6bdf34c..d5a0f9f 100644
--- a/src/client/stardrawer.cc
+++ b/src/client/stardrawer.cc
@@ -6,7 +6,9 @@
#include "gl/osiriongl.h"
#include "stardrawer.h"
-StarDrawer::StarDrawer(Star *s) {
+namespace client {
+
+StarDrawer::StarDrawer(game::Star *s) {
star = s;
sphere.radius = s->radius;
@@ -20,3 +22,5 @@ void StarDrawer::draw(float elapsed)
gl::color(star->color);
sphere.draw();
}
+
+} // namespace client
diff --git a/src/client/stardrawer.h b/src/client/stardrawer.h
index 7656414..354da6a 100644
--- a/src/client/stardrawer.h
+++ b/src/client/stardrawer.h
@@ -9,18 +9,22 @@
#include "gl/sphere.h"
#include "game/star.h"
+namespace client {
+
/// Class to draw stars
class StarDrawer
{
public:
- StarDrawer(Star *s);
+ StarDrawer(game::Star *s);
~StarDrawer();
void draw(float elapsed);
private:
- Star *star;
+ game::Star *star;
gl::Sphere sphere;
};
+} // namespace client
+
#endif // __INCLUDED_STARDRAWER_H__
diff --git a/src/client/video.cc b/src/client/video.cc
index 2697585..a676d10 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -1,27 +1,24 @@
-/* video.cc
+/*
+ video.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
*/
-// SDL headers
-#include <SDL/SDL.h>
+#include "video.h"
+#include "view.h"
+#include "gl/osiriongl.h"
-// C++ headers
+#include <SDL/SDL.h>
#include <iostream>
-// project headers
-#include "gl/osiriongl.h"
-#include "view.h"
+namespace client {
+int Video::width = 0;
+int Video::height = 0;
+bool Video::initialized = false;
+float Video::ratio = 1;
-namespace video
-{
-int width = 0;
-int height = 0;
-bool initialized = false;
-float ratio = 1;
-
-void reset()
+void Video::reset()
{
ratio = (float) width / (float) height;
@@ -46,10 +43,10 @@ void reset()
// Setup our viewport.
gl::viewport(0, 0, width, height );
- view::reset();
+ View::reset();
}
-void init()
+void Video::init()
{
if (initialized) {
return;
@@ -90,20 +87,20 @@ void init()
gl::init();
initialized = true;
- view::init();
+ View::init();
reset();
return;
}
-void draw(float elapsed)
+void Video::draw(float elapsed)
{
- view::draw(elapsed);
+ View::draw(elapsed);
}
-void shutdown()
+void Video::shutdown()
{
- view::shutdown();
+ client::View::shutdown();
gl::shutdown();
initialized = false;
@@ -111,4 +108,4 @@ void shutdown()
height = 0;
}
-} // namespace video
+} // namespace client
diff --git a/src/client/video.h b/src/client/video.h
index 3b126f1..145cc24 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -5,26 +5,31 @@
#ifndef __INCLUDED_VIDEO_H__
#define __INCLUDED_VIDEO_H__
+namespace client {
-namespace video
+class Video
{
+public:
/// initialize the video subsystem
- void init();
+ static void init();
/// shutdown the video subsystem
- void shutdown();
+ static void shutdown();
/// Update the screen state and redraw
- void draw(float elapsed);
+ static void draw(float elapsed);
/// reset and clear the viewport
- void reset();
+ static void reset();
/// Width of the SDL window in pixels
- extern int width;
+ static int width;
/// Height of the SDL window in pixels
- extern int height;
+ static int height;
/// True if the video subsystem is initialized
- extern bool initialized;
+ static bool initialized;
/// width/height ratio
- extern float ratio;
+ static float ratio;
+
};
+} // namespace client
+
#endif // __INCLUDED_VIDEO_H__
diff --git a/src/client/view.cc b/src/client/view.cc
index d9b5f42..af9037b 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -1,35 +1,34 @@
-/* view.cc
+/*
+ view.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
*/
-// C++ headers
-#include <iostream>
-
-// SDL headers
-#include <SDL/SDL.h>
-
-// project headers
-#include "osirion.h"
-#include "common/functions.h"
-
-#include "game/game.h"
-#include "gl/osiriongl.h"
-
+#include "view.h"
#include "video.h"
#include "camera.h"
#include "shipdrawer.h"
#include "stardrawer.h"
+#include "gl/osiriongl.h"
+#include "game/game.h"
+#include "common/functions.h"
+#include "osirion.h"
-namespace view
+#include <SDL/SDL.h>
+
+#include <iostream>
+
+namespace client
{
+using namespace common;
+
ShipDrawer *shipdrawer = 0;
StarDrawer *stardrawer = 0;
-Ship *target =0; // the view's target
+game::Ship *target =0; // the view's target
-void init() {
+void View::init() {
// draw scene
if (!shipdrawer) {
stardrawer = new StarDrawer(&game::star);
@@ -39,7 +38,7 @@ void init() {
}
-void shutdown()
+void View::shutdown()
{
delete stardrawer;
stardrawer = 0;
@@ -47,14 +46,14 @@ void shutdown()
shipdrawer = 0;
}
-void reset() {
+void View::reset() {
// 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);
+ gl::frustum( -frustumsize * Video::ratio, frustumsize * Video::ratio, -frustumsize, frustumsize, 1.0f, 1024.0f);
/*
map world coordinates to GL coordinates
@@ -65,7 +64,7 @@ void reset() {
gl::rotate(90.0f, 0, 1.0, 0);
}
-void draw_background()
+void View::draw_background(float elapsed)
{
using namespace gl;
@@ -116,7 +115,7 @@ void draw_background()
gl::disable(GL_BLEND);
}
-void draw_world(float elapsed)
+void View::draw_world(float elapsed)
{
// draw the world
gl::push();
@@ -135,7 +134,7 @@ void draw_world(float elapsed)
}
-void draw(float elapsed)
+void View::draw(float elapsed)
{
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -145,15 +144,15 @@ void draw(float elapsed)
gl::loadidentity();
// Camera transformation
- camera::draw(elapsed);
+ Camera::draw(elapsed);
// draw the world
draw_world(elapsed);
// draw the semi-static background
- draw_background();
+ draw_background(elapsed);
- SDL_GL_SwapBuffers( );
+ SDL_GL_SwapBuffers();
}
} // namespace view
diff --git a/src/client/view.h b/src/client/view.h
index de73ab9..377cc9b 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -6,19 +6,30 @@
#ifndef __INCLUDED_VIEW_H__
#define __INCLUDED_VIEW_H__
-#include "common/vector3f.h"
+namespace client {
-/// Draws the view of the map
-namespace view
+/// Draws the userinterface
+class View
{
- void init();
- void shutdown();
+public:
+ /// intialize the view
+ static void init();
+ /// shutdown the view
+ static void shutdown();
/// Update the chronometer and draw the game view
- void draw(float elapsed);
+ static void draw(float elapsed);
/// Reset the projection matrix
- void reset();
+ static void reset();
+
+protected:
+ /// draw the world
+ static void draw_world(float elapsed);
+ /// draw the background
+ static void draw_background(float elapsed);
};
+} // namespace client
+
#endif // __INCLUDED_VIEW_H__