diff options
author | Stijn Buys <ingar@osirion.org> | 2007-10-21 23:02:47 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2007-10-21 23:02:47 +0000 |
commit | a237a2d7723b94df6cd3e91401ec28388de6f1a0 (patch) | |
tree | 7da376d276d03fced7b94a807c0952fd32bcde08 /src | |
parent | 084c6212afaa6f996091f36d0ff85ac845803a87 (diff) |
namespace cleanup
Diffstat (limited to 'src')
39 files changed, 487 insertions, 253 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__ diff --git a/src/common/color.cc b/src/common/color.cc index 85892c8..da43efc 100644 --- a/src/common/color.cc +++ b/src/common/color.cc @@ -1,15 +1,14 @@ /* - *************************************************************************** - * Copyright (C) 2002-2004 by Stijn Buys * - * stijn.buys@pandora.be * - * * - * This software is redistributed under the terms of the * - * GNU General Public License. Please read LICENSE.txt. * - *************************************************************************** + common/color.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ +// project headers #include "color.h" +namespace common { + Color::Color() { _r = _g = _b = 0.0f; _a = 1.0f; @@ -82,3 +81,4 @@ std::ostream &operator<<(std::ostream &os, const Color &c) { return os; } +} // namespace common diff --git a/src/common/color.h b/src/common/color.h index d84d1a3..e6aa9eb 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -1,11 +1,7 @@ /* - *************************************************************************** - * Copyright (C) 2004 by Stijn Buys * - * stijn.buys@pandora.be * - * * - * This software is redistributed under the terms of the * - * GNU General Public License. Please read LICENSE.txt. * - *************************************************************************** + common/color.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __COLOR_HEADER__ @@ -13,6 +9,8 @@ #include <iostream> +namespace common { + /// a class representing an RGBA color value class Color { public: @@ -47,4 +45,6 @@ std::ostream &operator<<(std::ostream &os, const Color &c); Color operator*(const float scalar, const Color& color); +} // namespace commmon + #endif // ___HEADER__ diff --git a/src/common/file.cc b/src/common/file.cc new file mode 100644 index 0000000..2ebd457 --- /dev/null +++ b/src/common/file.cc @@ -0,0 +1,70 @@ +/* + common/file.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +// project headers +#include "file.h" + +// C++ headers +#include <iostream> + +namespace common { + +std::string File::datadir = ""; +std::string File::homedir = ""; +std::string File::basedir = ""; +std::string File::moddir = ""; + +void File::open(const char * filename, ios_base::openmode mode) +{ + std::string fn; + + // if moddir is set, try the mods subdir first + if (moddir.size() > 0) { + // try homedir+moddir + fn = homedir; + fn.append(moddir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "File opened " << fn << std::endl; + return; + } + + // try datadir + moddir + fn = datadir; + fn.append(moddir); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "File opened " << fn << std::endl; + return; + } + } + + // try homedir+basedir + fn = homedir; + fn.append(basedir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + if (this->is_open()) { + std::cerr << "File opened " << fn << std::endl; + return; + } + + // try datadir+basedir + fn = datadir; + fn.append(basedir); + fn.append(filename); + std::ifstream::open(fn.c_str(), mode); + + // FIXME console + if (!this->is_open()) { + std::cerr << "File could not open " << filename << std::endl; + } else { + std::cerr << "File opened " << fn << std::endl; + } +} + +} // namespace common diff --git a/src/common/file.h b/src/common/file.h new file mode 100644 index 0000000..a377981 --- /dev/null +++ b/src/common/file.h @@ -0,0 +1,35 @@ +/* + common/file.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_FILE_H__ +#define __INCLUDED_FILE_H__ + +// C++ headers +#include <string> +#include <fstream> + +namespace common { + +/// a class to open data files +class File : public std::ifstream +{ +public: + /// open the file for reading + void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in ); + + /// location of the main data files, includes trailing / + static std::string datadir; + /// location of the personal data files, includes trailing / + static std::string homedir; + /// subdirectory with the base data files, includes trailing / + static std::string basedir; + /// subdirectory for the current mod, includes trailing / + static std::string moddir; +}; // class File + +} // namespace common + +#endif // __INCLUDED_GAME_H__ diff --git a/src/common/functions.cc b/src/common/functions.cc index 7152c91..7a01628 100644 --- a/src/common/functions.cc +++ b/src/common/functions.cc @@ -1,9 +1,14 @@ -/* functions.cc - * This file is part of the Osirion project - */ +/* + common/functions.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ +// project headers #include "functions.h" +namespace common { + float min(float a, float b) { return (a < b ? a : b); } @@ -46,3 +51,5 @@ float sgnf(float value) return 1; } + +} // namespace common diff --git a/src/common/functions.h b/src/common/functions.h index 02f25da..62cf627 100644 --- a/src/common/functions.h +++ b/src/common/functions.h @@ -1,13 +1,18 @@ -/* functions.h - This file is part of the Osirion project +/* + common/functions.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_FUNCTIONS_H__ #define __INCLUDED_FUNCTIONS_H__ +// C++ headers #include <cstdlib> #include <cmath> +namespace common { + /// return the smallest of two float values float min(float a, float b); @@ -38,5 +43,7 @@ float sgnf(float value); /// return an angle in the ]-180,180] range float degreesf(float angle); +} // namespace common + #endif // __INCLUDED_FUNCTIONS_H__ diff --git a/src/common/vector3f.cc b/src/common/vector3f.cc index 3e469b6..86bdb36 100644 --- a/src/common/vector3f.cc +++ b/src/common/vector3f.cc @@ -1,9 +1,17 @@ -/* vector3f.h - This file is part of the Osirion project +/* + common/vector3f.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ + +// project headers #include "vector3f.h" + +// C++ headers #include <cmath> +namespace common { + Vector3f::Vector3f() : x(coord[0]), y(coord[1]), z(coord[2]) { @@ -149,3 +157,5 @@ std::istream &operator>>(std::istream & is, Vector3f & vector) { Vector3f operator*(float scalar, const Vector3f& vector) { return vector * scalar; } + +} // namespace common diff --git a/src/common/vector3f.h b/src/common/vector3f.h index 53b2ce7..e943bd4 100644 --- a/src/common/vector3f.h +++ b/src/common/vector3f.h @@ -1,11 +1,20 @@ -/* vector3f.h - This file is part of the Osirion project +/* + common/vector3f.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ - #ifndef __INCLUDED_VECTOR3F_H__ - #define __INCLUDED_VECTOR3F_H__ +#ifndef __INCLUDED_VECTOR3F_H__ +#define __INCLUDED_VECTOR3F_H__ + +// project headers +#include "vector3f.h" + +// C++ headers +#include <iostream> + +namespace common { - #include <iostream> /// A point or vector in 3D-space /*! An instance of this class represents a point in 3D-space or a 3D-vector @@ -135,4 +144,6 @@ std::istream &operator>>(std::istream & is, Vector3f& vector); /// scalar*Vector3f operators Vector3f operator*(float scalar, const Vector3f& vector); +} // namespace common + #endif // __INCLUDED_VECTOR3F_H__ diff --git a/src/game/game.cc b/src/game/game.cc index e34a7b8..0ac9acc 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -1,34 +1,38 @@ -/* game.h +/* + game/game.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ - // project headers #include "ship.h" #include "star.h" -#include "file.h" + +#include "common/file.h" namespace game { +using common::File; +using common::Vector3f; + Ship ship; Star star; bool initialized = false; // TODO datadir should by set by ./configure and read from config.h // FIXME win32 -std::string datadir("./data/"); -std::string homedir("~/.osirion/"); -std::string basedir("base/"); -std::string moddir; - void init() { // load the world star.location = Vector3f(256.0f, 0.0f, 256.0f); ship.location = Vector3f(0,0,0); + // initialize game data locations // TODO create game::homedir if it doesn't exist + File::datadir = "./data/"; + File::homedir = "~/.osirion/"; + File::basedir = "base/"; + File::moddir = ""; // read game.ini File f; diff --git a/src/game/game.h b/src/game/game.h index 9f3b19a..9609884 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -1,5 +1,7 @@ -/* game.h - This file is part of the Osirion project +/* + game/game.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_GAME_H__ @@ -28,15 +30,6 @@ namespace game /// true while the game is running extern bool initialized; - - /// location of the main data files, includes trailing / - extern std::string datadir; - /// location of the personal data files, includes trailing / - extern std::string homedir; - /// subdirectory with the base data files, includes trailing / - extern std::string basedir; - /// subdirectory for the current mod, includes trailing / - extern std::string moddir; }; #endif // __INCLUDED_GAME_H__ diff --git a/src/game/player.h b/src/game/player.h index a3850a5..d2f2316 100644 --- a/src/game/player.h +++ b/src/game/player.h @@ -1,4 +1,5 @@ -/* player.h +/* + game/player.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 */ diff --git a/src/game/sector.h b/src/game/sector.h index 3f6b3e4..75e6446 100644 --- a/src/game/sector.h +++ b/src/game/sector.h @@ -1,4 +1,5 @@ -/* sector.h +/* + game/sector.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 */ diff --git a/src/game/ship.cc b/src/game/ship.cc index 84e9f41..f0c40c4 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -1,14 +1,17 @@ -/* ship.cc - This file is part of the Osirion project +/* + game/ship.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> - // project headers +#include "ship.h" #include "common/functions.h" -#include "ship.h" +// C++ headers +#include <iostream> + +namespace game { Ship::Ship() { @@ -82,3 +85,4 @@ void Ship::turn_right() yaw_offset = - max_yaw_offset; } +} // namespace game diff --git a/src/game/ship.h b/src/game/ship.h index d6a00ba..31266a4 100644 --- a/src/game/ship.h +++ b/src/game/ship.h @@ -1,5 +1,7 @@ -/* ship.h - This file is part of the Osirion project +/* + game/ship.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_SHIP_H__ @@ -8,6 +10,8 @@ // project headers #include "common/vector3f.h" +namespace game { + class Ship { public: @@ -18,7 +22,7 @@ public: void update(float elapsed); /// location of the ship in space - Vector3f location; + common::Vector3f location; /// speed vector in units/second float speed; @@ -50,5 +54,6 @@ private: float yaw_offset; }; -#endif // __INCLUDED_SHIP_H__ +} // namespace game +#endif // __INCLUDED_SHIP_H__ diff --git a/src/game/star.cc b/src/game/star.cc index 6aa82ac..924bb96 100644 --- a/src/game/star.cc +++ b/src/game/star.cc @@ -1,10 +1,9 @@ -/* star.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 -*/ + #include "star.h" +namespace game { + Star::Star() : location(0,0,0), color(1,1,1,1) @@ -15,3 +14,5 @@ Star::Star() : Star::~Star() { } + +} // namespace game diff --git a/src/game/star.h b/src/game/star.h index ef33ad5..e65a9fb 100644 --- a/src/game/star.h +++ b/src/game/star.h @@ -1,4 +1,5 @@ -/* star.h +/* + game/star.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 */ @@ -6,24 +7,28 @@ #ifndef __INCLUDED_STAR_H__ #define __INCLUDED_STAR_H__ -// C++ headers -#include <string> - // project headers #include "common/vector3f.h" #include "common/color.h" +// C++ headers +#include <string> + +namespace game { + /// A star, that shines so bright class Star { public: Star(); ~Star(); - Vector3f location; - Color color; + common::Vector3f location; + common::Color color; float radius; std::string name; }; +} // namespace game + #endif // __INCLUDED_STAR_H__ diff --git a/src/game/world.h b/src/game/world.h index 8cbc232..27909fc 100644 --- a/src/game/world.h +++ b/src/game/world.h @@ -1,4 +1,5 @@ -/* world.h +/* + game/world.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 */ @@ -12,11 +13,11 @@ namespace game { /// The game world -namespace World { +class World { /// load the intial game world into memory - void init(); + static void init(); /// unload the game world - void shutdown(); + static void shutdown(); }; } // namespace game diff --git a/src/gl/box.cc b/src/gl/box.cc index 67a8ed0..fea5d28 100644 --- a/src/gl/box.cc +++ b/src/gl/box.cc @@ -1,10 +1,11 @@ -/* box.cc - This file is part of the Osirion project +/* + gl/box.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ // project headers #include "box.h" -#include "osiriongl.h" namespace gl { diff --git a/src/gl/box.h b/src/gl/box.h index f612243..8fb4c45 100644 --- a/src/gl/box.h +++ b/src/gl/box.h @@ -1,12 +1,13 @@ -/* box.h - This file is part of the Osirion project +/* + gl/box.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_BOX_H__ #define __INCLUDED_BOX_H__ -#include "common/vector3f.h" -#include "common/color.h" +#include "osiriongl.h" namespace gl { diff --git a/src/gl/osiriongl.cc b/src/gl/osiriongl.cc index 95e12d1..08462e7 100644 --- a/src/gl/osiriongl.cc +++ b/src/gl/osiriongl.cc @@ -1,12 +1,13 @@ -/* gl.cc - * This file is part of the Osirion project - */ - -// SDL headers -#include <SDL/SDL.h> +/* + gl/osiriongl.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ #include "osiriongl.h" +#include <SDL/SDL.h> + namespace gl { diff --git a/src/gl/osiriongl.h b/src/gl/osiriongl.h index 26ff131..5a1f9f9 100644 --- a/src/gl/osiriongl.h +++ b/src/gl/osiriongl.h @@ -1,23 +1,28 @@ -/* gl.h - This file is part of the Osirion project +/* + gl/osiriongl.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_OSIRIONGL_H__ #define __INCLUDED_OSIRIONGL_H__ -// OpenGL headers -#include <GL/gl.h> - // project headers #include "common/vector3f.h" #include "common/color.h" +// OpenGL headers +#include <GL/gl.h> + /// wrapper namespace for OpenGL operations /*! The GL namespace provides a wrapper to the OpenGL library functions. * All methods take floats or Vector3f and Color as parameters. */ namespace gl { + using common::Vector3f; + using common::Color; + /// initialize the OpenGL subsystem void init(); diff --git a/src/gl/sphere.cc b/src/gl/sphere.cc index 5e4e931..bd724f5 100644 --- a/src/gl/sphere.cc +++ b/src/gl/sphere.cc @@ -1,11 +1,11 @@ -/* sphere.cc - This file is part of the Osirion project +/* + gl/sphere.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ -#include "common/functions.h" - -#include "osiriongl.h" #include "sphere.h" +#include "common/functions.h" namespace gl { diff --git a/src/gl/sphere.h b/src/gl/sphere.h index f2bbf0a..2e237c5 100644 --- a/src/gl/sphere.h +++ b/src/gl/sphere.h @@ -1,12 +1,13 @@ -/* sphere.h - This file is part of the Osirion project +/* + gl/sphere.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_SPHERE_H__ #define __INCLUDED_SPHERE_H__ -#include "common/vector3f.h" -#include "common/color.h" +#include "osiriongl.h" namespace gl { diff --git a/src/server/main.cc b/src/server/main.cc index 3ce5197..6f71468 100644 --- a/src/server/main.cc +++ b/src/server/main.cc @@ -1,4 +1,5 @@ -/* server/main.cc +/* + server/main.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 */ @@ -21,7 +22,7 @@ int main( int argc, char *argv[] ) { const float server_framerate = 1.0f / 20.0f; std::cout << "The Osirion project " << OSIRION_VERSION << std::endl; - Timer timer; + server::Timer timer; // initialize game game::init(); diff --git a/src/server/timer.cc b/src/server/timer.cc index c8e6975..dc37cb3 100644 --- a/src/server/timer.cc +++ b/src/server/timer.cc @@ -1,4 +1,5 @@ -/* server/timer.cc +/* + server/timer.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 */ @@ -6,6 +7,8 @@ #include "timer.h" #include <unistd.h> +namespace server { + Timer::Timer() { gettimeofday(&this->timer_tick, &this->timer_tz); @@ -35,3 +38,5 @@ void Timer::sleep(float seconds) { usleep((useconds_t) seconds*1000000.0f); } + +} diff --git a/src/server/timer.h b/src/server/timer.h index 63957ee..f38806c 100644 --- a/src/server/timer.h +++ b/src/server/timer.h @@ -3,6 +3,7 @@ #include <sys/time.h> +namespace server { /// a timer measures that intervals in seconds /*! A timer class measures the time elapsed @@ -36,5 +37,6 @@ private: struct timeval timer_tick; }; // class Timer +} // namespace server #endif // __INCLUDED_TIMER_H__ |