Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-04 18:42:05 +0000
committerStijn Buys <ingar@osirion.org>2008-02-04 18:42:05 +0000
commit151a2ac2434f4b4c23c107d9c21e4a18dd1a3c68 (patch)
tree18154b52b44327de28d82ff187f25c8369ddc5d9 /src
parent09fb43f3d36847977ac202c10c5a11f34af03a43 (diff)
converted client:: singleton classes to namespaces
Diffstat (limited to 'src')
-rw-r--r--src/client/application.cc30
-rw-r--r--src/client/camera.cc50
-rw-r--r--src/client/camera.h50
-rw-r--r--src/client/client.cc9
-rw-r--r--src/client/client.h18
-rw-r--r--src/client/console.cc14
-rw-r--r--src/client/input.cc33
-rw-r--r--src/client/input.h30
-rw-r--r--src/client/video.cc69
-rw-r--r--src/client/video.h36
-rw-r--r--src/client/view.cc51
-rw-r--r--src/client/view.h36
-rw-r--r--src/core/applicationinterface.cc10
-rw-r--r--src/core/commandbuffer.cc2
-rw-r--r--src/core/func.cc26
-rw-r--r--src/core/func.h23
-rw-r--r--src/render/tga.cc2
17 files changed, 246 insertions, 243 deletions
diff --git a/src/client/application.cc b/src/client/application.cc
index 7a88155..c8eaab4 100644
--- a/src/client/application.cc
+++ b/src/client/application.cc
@@ -31,26 +31,25 @@ void Application::quit(int status)
void Application::init()
{
+ con_print << "Initializing client..." << std::endl;
// initialize core
core::ApplicationInterface::init();
- con_print << "Initializing client..." << std::endl;
-
// Initialize the video subsystem
- video.init();
- if (!video.initialized) {
+ if (!client::video::init())
quit(1);
- }
// initialize input
- input.init();
+ input::init();
// register our engine functions
- core::func_register("con_toggle", func_con_toggle);
+ core::func::add("con_toggle", func_con_toggle);
}
void Application::run()
{
+ con_print << "Running client..." << std::endl;
+
Uint32 chrono = SDL_GetTicks();
while (true) {
@@ -61,19 +60,19 @@ void Application::run()
chrono = current;
}
- // update the core chronometer
+ // run a core frame
float seconds = ((float)(current - chrono)) / 1000.0f;
frame(seconds);
- // update the video chronometers and draw
- video.frame(seconds);
+ // run a video frame
+ video::frame(seconds);
if (seconds > 0)
current_fps = floorf(1/seconds);
else
current_fps = 9999;
// process input
- input.frame();
+ input::frame(seconds);
// update the main loop chronometer
chrono = current;
@@ -83,13 +82,13 @@ void Application::run()
void Application::shutdown()
{
- con_debug << "Shutting down client..." << std::endl;
+ con_print << "Shutting down client..." << std::endl;
console.flush();
- input.shutdown();
+ input::shutdown();
console.flush();
- video.shutdown();
+ video::shutdown();
console.flush();
core::ApplicationInterface::shutdown();
@@ -98,4 +97,5 @@ void Application::shutdown()
quit(0);
}
-}
+} // namespace client
+
diff --git a/src/client/camera.cc b/src/client/camera.cc
index a7c3349..a0d3ea0 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -15,7 +15,36 @@ using namespace render;
namespace client
{
-Camera::Camera()
+namespace camera
+{
+
+// public variables
+
+// camera target
+math::Vector3f target;
+// target yaw, angle in XZ plane, positive is looking left
+float yaw_target;
+// target pitch, angle in XZ plane, positive is looking left
+float pitch_target;
+// distance from the camera to the target
+float distance;
+// current camera mode
+Mode mode;
+
+// private variables
+
+// current yaw, angle in XZ plane, positive is looking left
+float yaw_current;
+// current pitch, angle in XY, positive is looking up
+float pitch_current;
+// default pitch in mode::Track
+float pitch_track;
+// default pitch in mode::Overview
+float pitch_overview;
+// default offset increment
+float offset_inc;
+
+void init()
{
pitch_overview = -60.0f;
pitch_track = -15.0f;
@@ -32,11 +61,11 @@ Camera::Camera()
mode = Track;
}
-Camera::~Camera()
+void shutdown()
{
}
-void Camera::draw(float elapsed)
+void draw(float elapsed)
{
if (mode == Track) {
yaw_target = game.ship.yaw();
@@ -71,21 +100,21 @@ void Camera::draw(float elapsed)
}
}
-void Camera::rotate_right()
+void rotate_right()
{
if (mode == Free || mode == Overview) {
yaw_target = degrees360f( yaw_target + offset_inc);
}
}
-void Camera::rotate_left()
+void rotate_left()
{
if (mode == Free || mode == Overview) {
yaw_target = degrees360f( yaw_target - offset_inc);
}
}
-void Camera::rotate_up()
+void rotate_up()
{
if (mode == Free) {
pitch_target = pitch_target - offset_inc;
@@ -93,7 +122,7 @@ void Camera::rotate_up()
}
}
-void Camera::rotate_down()
+void rotate_down()
{
if (mode == Free) {
pitch_target = pitch_target + offset_inc;
@@ -101,7 +130,7 @@ void Camera::rotate_down()
}
}
-void Camera::nextmode() {
+void nextmode() {
switch(mode) {
case Overview:
// switch camera to Track mode
@@ -134,4 +163,7 @@ void Camera::nextmode() {
}
}
-} //namespace camera
+} // namespace camera
+
+} // namespace client
+
diff --git a/src/client/camera.h b/src/client/camera.h
index 1a25689..dd1ecc3 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -12,59 +12,51 @@
namespace client {
/// camera functions
-/** The functions in this class perform the transformations
+/** The functions in the camera namespace perform the transformations
* for the camera eye location. The camera always looks at (0,0,0)
*/
-class Camera
+namespace camera
{
-public:
- Camera();
- ~Camera();
-
/// enum indicating the camera mode
enum Mode {Free, Track, Overview};
+ /// initialize the camera
+ extern void init();
+
+ /// shutdown the camera
+ extern void shutdown();
+
/// draw the OpenGL camera transformation
- void draw(float elapsed);
+ extern void draw(float elapsed);
/// rotate the camera left
- void rotate_left();
+ extern void rotate_left();
/// rotate the camera right
- void rotate_right();
+ extern void rotate_right();
/// rotate the camera up
- void rotate_up();
+ extern void rotate_up();
/// rotate the camera down
- void rotate_down();
+ extern void rotate_down();
/// switch to next camera mode
- void nextmode();
+ extern void nextmode();
/// camera target
/** The location the camera is looking at */
- math::Vector3f target;
+ extern math::Vector3f target;
/// target yaw, angle in XZ plane, positive is looking left
- float yaw_target;
+ extern float yaw_target;
/// target pitch, angle in XZ plane, positive is looking left
- float pitch_target;
+ extern float pitch_target;
/// distance from the camera to the target
- float distance;
+ extern float distance;
/// current camera mode
- Mode mode;
+ extern Mode mode;
-protected:
- /// current yaw, angle in XZ plane, positive is looking left
- float yaw_current;
- /// current pitch, angle in XY, positive is looking up
- float pitch_current;
- /// default pitch in mode::Track
- float pitch_track;
- /// default pitch in mode::Overview
- float pitch_overview;
- /// default offset increment
- float offset_inc;
-};
+} // namespace camera
} // namespace client
#endif // __INCLUDED_CLIENT_CAMERA_H__
+
diff --git a/src/client/client.cc b/src/client/client.cc
index e78f73d..1d29c23 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -13,15 +13,12 @@
#include "game/game.h"
-namespace client {
+namespace client
+{
// public instances
Application application;
-Camera camera;
-View view;
-Video video;
-Input input;
-Console console;
+Console console;
game::Game game;
} // namespace client
diff --git a/src/client/client.h b/src/client/client.h
index 66a7700..3b8b78e 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -26,25 +26,13 @@
*/
namespace client {
-/// global Application instance;
+/// global client Application instance;
extern Application application;
-/// global Video instance
-extern Video video;
-
-/// global Input instance
-extern Input input;
-
-/// global View instance
-extern View view;
-
-/// global Camera instance
-extern Camera camera;
-
-/// global server Console instance
+/// global client Console instance
extern Console console;
-/// global Game instance
+/// global client Game instance
extern game::Game game;
/// current fps
diff --git a/src/client/console.cc b/src/client/console.cc
index dfc1d08..f435e9a 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -54,7 +54,7 @@ void Console::draw()
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);
+ 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
@@ -62,15 +62,15 @@ void Console::draw()
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::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();
// 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;
+ float y = video::height*con_height-2*CHARHEIGHT-8;
while (y > 0 && rit < console.text.rend()) {
std::string line(*rit);
@@ -91,12 +91,12 @@ void Console::draw()
// 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_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 4, input);
// 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);
+ draw_text(CHARWIDTH*(input.size()+1), video::height*con_height - CHARHEIGHT - 4 , cursor);
}
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/client/input.cc b/src/client/input.cc
index c46c66f..08fa9ca 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -7,33 +7,36 @@
//project headers
#include "client/client.h"
-namespace client {
+namespace client
+{
+
+namespace input
+{
-void Input::init()
+void init()
{
- con_debug << "Initializing input..." << std::endl;
+ con_print << "Initializing input..." << std::endl;
//condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl;
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
}
-void Input::shutdown()
+void shutdown()
{
- con_debug << "Shutting down input..." << std::endl;
+ con_print << "Shutting down input..." << std::endl;
}
/*
see
http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html
*/
-
// handle key_release events for the game world
-void Input::handle_keyreleased(SDL_keysym* keysym)
+void handle_keyreleased(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_SPACE:
- camera.nextmode();
+ camera::nextmode();
break;
default:
break;
@@ -41,20 +44,20 @@ void Input::handle_keyreleased(SDL_keysym* keysym)
}
// handle pressed keys for the game world
-void Input::handle_keypressed(SDL_keysym* keysym)
+void handle_keypressed(SDL_keysym* keysym)
{
switch( keysym->sym ) {
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.set_thrust(game.ship.thrust() + 0.08f);
@@ -74,7 +77,7 @@ void Input::handle_keypressed(SDL_keysym* keysym)
}
-void Input::frame()
+void frame(float seconds)
{
SDL_Event event;
@@ -114,5 +117,7 @@ void Input::frame()
}
+} // namespace input
+
} // namespace client
diff --git a/src/client/input.h b/src/client/input.h
index 6067522..2fc3580 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -1,6 +1,6 @@
/* input.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
+ 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_INPUT_H__
@@ -10,24 +10,18 @@
namespace client {
-class Input
-{
-public:
- /// initialize the input subsystem
- void init();
- /// shutdown the input subsystem
- void shutdown();
+namespace input {
- /// handle one frame of input events
- void frame();
+/// initialize the input subsystem
+extern void init();
+/// shutdown the input subsystem
+extern void shutdown();
+/// handle one frame of input events
+extern void frame(float seconds);
-protected:
- /// handle key release events
- void handle_keyreleased(SDL_keysym* keysym);
- /// handle key pressed events
- void handle_keypressed(SDL_keysym* keysym);
-};
+} // namespace input
-} // namespace Client
+} // namespace client
#endif // __INCLUDED_INPUT_H__
+
diff --git a/src/client/video.cc b/src/client/video.cc
index bfff445..47e9dde 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -14,51 +14,43 @@ using namespace render;
namespace client {
-Video::Video()
-{
- width = 0;
- height = 0;
- initialized = false;
- ratio = 1;
-}
-
-Video::~Video()
-{
-}
-
-void Video::reset()
-{
- ratio = (float) width / (float) height;
+namespace video {
+const int defaultwidth = 1024;
+const int defaultheight = 768;
+int width = 0;
+int height = 0;
+float aspect = 1;
- // Set the clear color
- gl::clearcolor( 0, 0, 0, 0 );
+void reset()
+{
+ // recalculate the video aspect
+ aspect = (float) width / (float) height;
- // Setup our viewport.
+ // settup our viewport.
gl::viewport(0, 0, width, height );
- view.reset();
+ // reset the view
+ view::reset();
}
-void Video::init()
+bool init()
{
- if (initialized) {
- return;
- }
+ con_print << "Initializing video..." << std::endl;
int bpp = 0;
int flags = 0;
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl;
- return;
+ return false;
}
const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo();
if( !sdl_videoinfo) {
std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
- return;
+ return false;
}
width = 1024;
@@ -76,33 +68,40 @@ void Video::init()
if(!SDL_SetVideoMode(width, height, bpp, flags )) {
std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
- return;
+ return false;
}
+ aspect = (float) width / (float) height;
+ con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
+
render::init();
+ view::init();
- initialized = true;
- view.init();
+ video::reset();
- reset();
- return;
+ return true;
}
-void Video::frame(float seconds)
+void frame(float seconds)
{
- view.frame(seconds);
+ // render a client frame
+ view::frame(seconds);
SDL_GL_SwapBuffers();
}
-void Video::shutdown()
+void shutdown()
{
- view.shutdown();
+ con_print << "Shutting down video..." << std::endl;
+
+ view::shutdown();
render::shutdown();
- initialized = false;
width = 0;
height = 0;
}
+} // namespace video
+
} // namespace client
+
diff --git a/src/client/video.h b/src/client/video.h
index edf7823..314bdbe 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -7,30 +7,26 @@
namespace client {
-class Video
+/// the client video subsystem
+namespace video
{
-public:
- Video();
- ~Video();
-
- /// initialize the video subsystem
- void init();
- /// shutdown the video subsystem
- void shutdown();
+ /// initialize the client video subsystem
+ extern bool init();
+ /// shutdown the client video subsystem
+ extern void shutdown();
/// draw the next client video frame
- void frame(float seconds);
+ extern void frame(float seconds);
/// reset and clear the viewport
- void reset();
-
- /// Width of the SDL window in pixels
- int width;
- /// Height of the SDL window in pixels
- int height;
- /// True if the video subsystem is initialized
- bool initialized;
+ extern void reset();
+
+ /// width of the SDL window in pixels
+ extern int width;
+ /// height of the SDL window in pixels
+ extern int height;
/// width/height ratio
- float ratio;
-};
+ extern float aspect;
+
+} // namespace video
} // namespace client
diff --git a/src/client/view.cc b/src/client/view.cc
index 811a7f7..87afd38 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -22,32 +22,40 @@ using namespace render;
namespace client
{
+namespace view
+{
+
ShipDrawer *shipdrawer = 0;
StarDrawer *stardrawer = 0;
game::Ship *target = 0; // the view's target
-void View::init()
+void init()
{
- // draw scene
if (!shipdrawer) {
stardrawer = new StarDrawer(&game.star);
shipdrawer = new ShipDrawer(&game.ship);
target = &game.ship;
}
+ camera::init();
}
-void View::shutdown()
+void shutdown()
{
+ camera::shutdown();
+
delete stardrawer;
stardrawer = 0;
delete shipdrawer;
shipdrawer = 0;
}
-void View::reset()
+void reset()
{
+ // set clear color
+ gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f);
+
// shading model: Gouraud (smooth).
gl::shademodel(GL_SMOOTH);
@@ -66,7 +74,7 @@ void View::reset()
}
-void View::draw_world(float elapsed)
+void draw_world(float elapsed)
{
// draw the world
gl::push();
@@ -83,7 +91,7 @@ void View::draw_world(float elapsed)
}
-void View::draw_background(float elapsed)
+void draw_background(float elapsed)
{
using namespace gl;
@@ -129,7 +137,7 @@ void View::draw_background(float elapsed)
end();
}
-void View::draw_loader()
+void draw_loader()
{
gl::enable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga
@@ -141,19 +149,19 @@ void View::draw_loader()
gl::vertex(0,0, 0);
glTexCoord2f(1.0f, 0.0f);
- gl::vertex(video.width,0,0);
+ gl::vertex(video::width,0,0);
glTexCoord2f(1.0f, 1.0f);
- gl::vertex(video.width,video.height,0);
+ gl::vertex(video::width,video::height,0);
glTexCoord2f(0.0f, 1.0f);
- gl::vertex(0,video.height,0);
+ gl::vertex(0,video::height,0);
gl::end();
gl::disable(GL_TEXTURE_2D);
}
-void View::draw_status()
+void draw_status()
{
using namespace std;
@@ -185,12 +193,12 @@ void View::draw_status()
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);
+ draw_text(video::width-(version.size()+1)*CHARWIDTH, 4, version);
gl::disable(GL_TEXTURE_2D);
}
-void View::frame(float seconds)
+void frame(float seconds)
{
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -203,18 +211,13 @@ void View::frame(float seconds)
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::frustum(-frustumsize*video::aspect, frustumsize*video::aspect, -frustumsize, frustumsize, 1.0f, 1024.0f);
- gl::matrixmode(GL_MODELVIEW);
+ gl::matrixmode(GL_MODELVIEW); // map world to screen coordinates
gl::loadidentity();
gl::rotate(90.0f, 0, 1.0, 0);
- // Camera transformation
- camera.draw(seconds);
+ camera::draw(seconds); // draw the current camera transformation
gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
gl::enable(GL_CULL_FACE); // enable culling
@@ -232,7 +235,7 @@ void View::frame(float seconds)
// 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);
+ glOrtho(0, video::width, video::height, 0, -1000.0f, 1000.0f);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -252,5 +255,7 @@ void View::frame(float seconds)
gl::disable(GL_BLEND);
}
-} // namespace view
+} //namespace view
+
+} // namespace client
diff --git a/src/client/view.h b/src/client/view.h
index 06d139d..6220147 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -1,4 +1,4 @@
-/* view.h
+/* client/view.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,12 +6,12 @@
#ifndef __INCLUDED_CLIENT_VIEW_H__
#define __INCLUDED_CLIENT_VIEW_H__
-namespace client {
+namespace client
+{
-/// Draws the user interface
-class View
+/// functions to draw the client view
+namespace view
{
-public:
/// intialize the view
void init();
@@ -24,31 +24,7 @@ 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);
-
- /// draw the background
- void draw_background(float elapsed);
-
- /// draw the loader screen
- void draw_loader();
-
- /// draw the status bar
- void draw_status();
-};
+} // namespace view
} // namespace client
diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc
index 561bf94..6add2e0 100644
--- a/src/core/applicationinterface.cc
+++ b/src/core/applicationinterface.cc
@@ -110,12 +110,12 @@ void ApplicationInterface::init()
filesystem::init();
// register our functions
- func_register("print", func_print);
- func_register("help", func_help);
- func_register("quit", func_quit);
+ func::add("print", func_print);
+ func::add("help", func_help);
+ func::add("quit", func_quit);
- func_register("connect", func_connect);
- func_register("disconnect", func_disconnect);
+ func::add("connect", func_connect);
+ func::add("disconnect", func_disconnect);
if (game())
game()->connected = false;
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 292013b..7ba1e08 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -25,7 +25,7 @@ void exec(const char *text)
cmdstream >> cmdname;
- Func f = func_find(cmdname);
+ Func f = func::find(cmdname);
if (f) {
f(cmdstream);
diff --git a/src/core/func.cc b/src/core/func.cc
index b89e556..bcc6f50 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -6,25 +6,37 @@
#include "core/func.h"
#include <map>
+#include <string>
namespace core
{
-std::map<std::string, Func> functionmap;
+namespace func
+{
+
+std::map<std::string, Func> registry;
-void func_register(const char * functionname, Func functionptr)
+void add(const char * functionname, Func functionptr)
{
- functionmap[std::string(functionname)] = functionptr;
+ registry[std::string(functionname)] = functionptr;
}
-void func_unregister(std:: string functionname)
+void remove(const char *functionname)
{
- functionmap.erase(std::string(functionname));
+ registry.erase(std::string(functionname));
}
-Func func_find(std::string functionname)
+void remove(const std::string &functionname)
{
- return functionmap[functionname];
+ registry.erase(functionname);
}
+Func find(const std::string &functionname)
+{
+ return registry[functionname];
+}
+
+} // namespace func
+
} // namespace core
+
diff --git a/src/core/func.h b/src/core/func.h
index 901490e..b3d446f 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -1,5 +1,5 @@
/*
- core/core.h
+ core/funct.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
@@ -10,19 +10,26 @@
#include <sstream>
namespace core {
- /// function pointer type
- typedef void (* Func)(std::stringstream &args);
- /// register a function pointer
- void func_register(const char *functionname, Func functionptr);
+/// function pointer type
+typedef void (* Func)(std::stringstream &args);
- /// unregister a function pointer
- void func_unregister(std:: string functionname);
+/// the function registry
+namespace func
+{
+ /// add a function to the registry
+ void add(const char *functionname, Func functionptr);
+
+ /// remove a function from the registry
+ void remove(const char *functionname);
+ void remove(const std::string &functionname);
/// find a fuction pointer
/** Returns 0 if the function pointer could not be found
*/
- Func func_find(std::string functionname);
+ Func find(const std::string &functionname);
+}
+
}
#endif // __INCLUDED_CORE_FUNC_H__
diff --git a/src/render/tga.cc b/src/render/tga.cc
index 317e2ac..b863d9b 100644
--- a/src/render/tga.cc
+++ b/src/render/tga.cc
@@ -65,7 +65,7 @@ TGA::image *TGA::load(const char *filename)
GLubyte length = 0;
GLubyte imgType = 0;
GLubyte bits = 0;
- GLushort channels = 0;
+ GLushort channels = 0;
GLushort stride = 0;
pFile = fopen(filename, "rb");