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:54:57 +0000
committerStijn Buys <ingar@osirion.org>2007-10-21 23:54:57 +0000
commitf8e9eab39a5e96d478762d06e27ec38f80128435 (patch)
treebf55c75dbedb1212f3effa23aa6df94932edf22d /src/client
parent621f4ad1d509665e19738525c80e104b80fb7b26 (diff)
namespace and class cleanups
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile.am5
-rw-r--r--src/client/camera.cc29
-rw-r--r--src/client/camera.h40
-rw-r--r--src/client/input.cc17
-rw-r--r--src/client/input.h11
-rw-r--r--src/client/main.cc59
-rw-r--r--src/client/video.cc26
-rw-r--r--src/client/video.h20
-rw-r--r--src/client/view.cc8
-rw-r--r--src/client/view.h12
10 files changed, 92 insertions, 135 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 40bafa1..37bafcf 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -3,8 +3,9 @@ METASOURCES = AUTO
bin_PROGRAMS = osirion
osirion_LDADD = $(top_builddir)/src/game/libgame.la \
$(top_builddir)/src/gl/libosiriongl.la -lSDL
-osirion_SOURCES = camera.cc camera.h input.cc input.h main.cc video.cc video.h \
- view.cc view.h shipdrawer.cc shipdrawer.h stardrawer.cc stardrawer.h
+osirion_SOURCES = camera.cc camera.h client.cc client.h input.cc input.h \
+ main.cc shipdrawer.cc shipdrawer.h stardrawer.cc stardrawer.h video.cc video.h \
+ view.cc view.h
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 87e00fc..6a6da0c 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -14,19 +14,26 @@ using namespace common;
namespace client
{
-
-Camera::Mode Camera::mode = Camera::Track;
-const float Camera::track_pitch = -15.0f; // default tracking pitch
-const float Camera::offset_inc = 5.0f; // default offset increment
+Camera::Camera()
+{
+ pitch_track = -15.0f;
+ offset_inc = 5.0f;
+
+ yaw = 0;
+ yaw_target = 0;
-float Camera::yaw = 0; // current yaw, angle in XZ plane, positive is looking left
-float Camera::yaw_target = 0; // target yaw
+ pitch = pitch_track * 2;
+ pitch_target = pitch_track;
-float Camera::pitch = -45.0f; // current pitch, angle in XY, positive is looking up
-float Camera::pitch_target = Camera::track_pitch; // target pitch
+ distance = 0.4f;
-float Camera::distance = 0.4f; // distance from the eye to the target
+ mode = Track;
+}
+
+Camera::~Camera()
+{
+}
void Camera::draw(float elapsed)
{
@@ -95,7 +102,7 @@ void Camera::nextmode() {
mode = Track;
yaw_target = game::ship.yaw;
yaw = yaw_target;
- pitch_target = track_pitch;
+ pitch_target = pitch_track;
pitch = pitch_target;
break;
case Track:
@@ -103,7 +110,7 @@ void Camera::nextmode() {
mode = Free;
yaw_target = game::ship.yaw;
yaw = yaw_target;
- pitch_target = track_pitch;
+ pitch_target = pitch_track;
pitch = pitch_target;
break;
default:
diff --git a/src/client/camera.h b/src/client/camera.h
index 2e20c1b..7e189b3 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -18,47 +18,49 @@ for the camera eye location. The camera always looks at (0,0,0)
class Camera
{
public:
+ Camera();
+ ~Camera();
+
/// enum indicating the camera mode
enum Mode {Free, Track};
/// draw the OpenGL camera transformation
- static void draw(float elapsed);
+ void draw(float elapsed);
/// rotate the camera left
- static void rotate_left();
+ void rotate_left();
/// rotate the camera right
- static void rotate_right();
+ void rotate_right();
/// rotate the camera up
- static void rotate_up();
+ void rotate_up();
/// rotate the camera down
- static void rotate_down();
+ void rotate_down();
/// switch to next camera mode
- static void nextmode();
+ void nextmode();
/// camera target
/** The location the camera is looking at */
- static gl::Vector3f target;
+ gl::Vector3f target;
/// target yaw, angle in XZ plane, positive is looking left
- static float yaw_target;
+ float yaw_target;
/// target pitch, angle in XZ plane, positive is looking left
- static float pitch_target;
+ float pitch_target;
/// distance from the camera to the target
- static float distance;
+ float distance;
+ /// current camera mode
+ Mode mode;
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;
+ float yaw ;
/// current pitch, angle in XY, positive is looking up
- static float pitch;
-
- static Mode mode;
+ float pitch;
+ /// default tracking pitch
+ float pitch_track;
+ /// default offset increment
+ float offset_inc;
};
} // namespace client
diff --git a/src/client/input.cc b/src/client/input.cc
index b231270..fc70b37 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -5,12 +5,9 @@
*/
//project headers
-#include "input.h"
-#include "view.h"
-#include "camera.h"
-
-#include "common/functions.h"
+#include "client.h"
#include "game/game.h"
+#include "common/functions.h"
namespace client {
@@ -30,19 +27,19 @@ void Input::handle_keydown(SDL_keysym* keysym)
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();
diff --git a/src/client/input.h b/src/client/input.h
index 6027d58..fa5486d 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -14,19 +14,16 @@ class Input
{
public:
/// initialize the input subsystem
- static void init();
+ void init();
/// shutdown the input subsystem
- static void shutdown();
-
- /// exit the application
- static void quit(int exit_code);
+ void shutdown();
/// process input events
- static void process();
+ void process();
protected:
/// handle keydown events
- static void handle_keydown(SDL_keysym* keysym);
+ void handle_keydown(SDL_keysym* keysym);
};
} // namespace Client
diff --git a/src/client/main.cc b/src/client/main.cc
index 76f7277..e8486ca 100644
--- a/src/client/main.cc
+++ b/src/client/main.cc
@@ -3,63 +3,10 @@
the terms and conditions of the GNU General Public License version 2
*/
-// SDL headers
-#include <SDL/SDL.h>
-
-// C++ headers
-#include <iostream>
-
-// project headers
-#include "osirion.h"
-#include "game/game.h"
-
-#include "input.h"
-#include "video.h"
-
-void quit(int status)
-{
- SDL_Quit();
- exit(status);
-}
+#include "client.h"
int main( int argc, char *argv[] )
{
- std::cout << "Project::OSiRiON " << OSIRION_VERSION << std::endl;
-
- // Initialize the video subsystem
- client::Video::init();
- if (!client::Video::initialized) {
- quit(1);
- }
-
- // initialize input
- client::Input::init();
-
- // initialize game
- game::init();
-
- Uint32 startup = SDL_GetTicks();
- while(game::initialized) {
- Uint32 chrono = SDL_GetTicks();
-
- // overflow protection ~49 days
- if (chrono < startup) {
- startup = chrono;
- }
-
- // update the game chronometers
- float elapsed = (float) ( chrono - startup) / 1000.0f;
- game::update(elapsed);
-
- // update the video chronometers and draw
- client::Video::draw(elapsed);
- startup = chrono;
-
- // process input
- client::Input::process();
- }
-
- client::Video::shutdown();
-
- quit(0);
+ client::init();
+ client::run();
}
diff --git a/src/client/video.cc b/src/client/video.cc
index a676d10..1dc596e 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -4,8 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "video.h"
-#include "view.h"
+#include "client.h"
#include "gl/osiriongl.h"
#include <SDL/SDL.h>
@@ -13,10 +12,17 @@
namespace client {
-int Video::width = 0;
-int Video::height = 0;
-bool Video::initialized = false;
-float Video::ratio = 1;
+Video::Video()
+{
+ width = 0;
+ height = 0;
+ initialized = false;
+ ratio = 1;
+}
+
+Video::~Video()
+{
+}
void Video::reset()
{
@@ -43,7 +49,7 @@ void Video::reset()
// Setup our viewport.
gl::viewport(0, 0, width, height );
- View::reset();
+ view.reset();
}
void Video::init()
@@ -87,7 +93,7 @@ void Video::init()
gl::init();
initialized = true;
- View::init();
+ view.init();
reset();
return;
@@ -95,12 +101,12 @@ void Video::init()
void Video::draw(float elapsed)
{
- View::draw(elapsed);
+ view.draw(elapsed);
}
void Video::shutdown()
{
- client::View::shutdown();
+ view.shutdown();
gl::shutdown();
initialized = false;
diff --git a/src/client/video.h b/src/client/video.h
index 145cc24..4c07652 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -10,24 +10,26 @@ namespace client {
class Video
{
public:
+ Video();
+ ~Video();
+
/// initialize the video subsystem
- static void init();
+ void init();
/// shutdown the video subsystem
- static void shutdown();
+ void shutdown();
/// Update the screen state and redraw
- static void draw(float elapsed);
+ void draw(float elapsed);
/// reset and clear the viewport
- static void reset();
+ void reset();
/// Width of the SDL window in pixels
- static int width;
+ int width;
/// Height of the SDL window in pixels
- static int height;
+ int height;
/// True if the video subsystem is initialized
- static bool initialized;
+ bool initialized;
/// width/height ratio
- static float ratio;
-
+ float ratio;
};
} // namespace client
diff --git a/src/client/view.cc b/src/client/view.cc
index af9037b..c9a7b8a 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -4,9 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "view.h"
-#include "video.h"
-#include "camera.h"
+#include "client.h"
#include "shipdrawer.h"
#include "stardrawer.h"
#include "gl/osiriongl.h"
@@ -53,7 +51,7 @@ void View::reset() {
//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
@@ -144,7 +142,7 @@ void View::draw(float elapsed)
gl::loadidentity();
// Camera transformation
- Camera::draw(elapsed);
+ camera.draw(elapsed);
// draw the world
draw_world(elapsed);
diff --git a/src/client/view.h b/src/client/view.h
index 377cc9b..0087ae5 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -13,21 +13,21 @@ class View
{
public:
/// intialize the view
- static void init();
+ void init();
/// shutdown the view
- static void shutdown();
+ void shutdown();
/// Update the chronometer and draw the game view
- static void draw(float elapsed);
+ void draw(float elapsed);
/// Reset the projection matrix
- static void reset();
+ void reset();
protected:
/// draw the world
- static void draw_world(float elapsed);
+ void draw_world(float elapsed);
/// draw the background
- static void draw_background(float elapsed);
+ void draw_background(float elapsed);
};
} // namespace client