From: Patrik Gornicz Date: Sat, 2 Aug 2008 21:13:46 +0000 (-0400) Subject: created input, graphics and game namespaces X-Git-Tag: physics-premerge~170 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=commitdiff_plain;h=68b2316d5438e8ebaaa7f7fdaa8292a8a290e14d;p=libbear.git created input, graphics and game namespaces --- diff --git a/src/Entities/Ball.cpp b/src/Entities/Ball.cpp index 5bee89a..f33d426 100644 --- a/src/Entities/Ball.cpp +++ b/src/Entities/Ball.cpp @@ -21,7 +21,7 @@ Ball::~Ball() void Ball::draw() const { - glDrawCircle(radius, position, color); + graphics::drawCircle(radius, position, color); } float Ball::getRadius() const diff --git a/src/game.cpp b/src/game.cpp index 1aabda2..26fd83b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -12,6 +12,7 @@ using std::vector; #include "GameStates/Paused.h" #include "GameStates/CreatingPolygon.h" + /// ***** Private Variables ***** // The stack of active game states @@ -25,7 +26,8 @@ CreatingPolygon* creating_Polygon; /// ***** Public Methods ***** -void gameInit() + +void game::init() { running = new Running(); paused = new Paused(); @@ -43,7 +45,7 @@ void gameInit() #endif } -void gameClean() +void game::clean() { effect::clean(); @@ -54,7 +56,7 @@ void gameClean() delete running; } -void gameInput() +void game::input() { int last = active_States.size() -1; for( int i = 0; @@ -68,7 +70,7 @@ void gameInput() } } -void gameUpdate(float time_step) +void game::update(float time_step) { int last = active_States.size() -1; for( int i = 0; @@ -82,7 +84,7 @@ void gameUpdate(float time_step) } } -void gameDraw() +void game::draw() { int last = active_States.size() -1; for( int i = 0; diff --git a/src/game.h b/src/game.h index bf86897..5c8346e 100644 --- a/src/game.h +++ b/src/game.h @@ -1,12 +1,17 @@ #ifndef GAME_H #define GAME_H + /// ***** Header Methods ***** -void gameInit(); -void gameClean(); -void gameInput(); -void gameUpdate(float); -void gameDraw(); +namespace game +{ + void init(); + void clean(); + + void input(); + void update(float); + void draw(); +} #endif // GAME_H diff --git a/src/graphics/graphics.cpp b/src/graphics/graphics.cpp index 32811c3..54cda19 100644 --- a/src/graphics/graphics.cpp +++ b/src/graphics/graphics.cpp @@ -8,28 +8,29 @@ #include "../mathw.h" + /// ***** Private Method Headers ***** -void drawCircle(int); +void glDrawCircle(int); void sdlInit(); void glInit(); /// ***** Initializers/Cleaners ***** -void graphicsInit() +void graphics::init() { sdlInit(); glInit(); } -void graphicsClean() +void graphics::clean() { } /// ***** Public Methods ***** -void glDrawCircle(float radius, const Vector2& vec, const float* color) +void graphics::drawCircle(float radius, const Vector2& vec, const float* color) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -39,12 +40,12 @@ void glDrawCircle(float radius, const Vector2& vec, const float* color) if(color != NULL) glColor3fv(color); - drawCircle(32); + glDrawCircle(32); } /// ***** Private Methods ***** -void drawCircle(int pieces) +void glDrawCircle(int pieces) { glBegin(GL_POLYGON); for(int n = 0; n < pieces; n++) diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 07b317a..86fe8d9 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -3,11 +3,15 @@ #include "../Vector2.h" + /// ***** Header Methods ***** -void graphicsInit(); -void graphicsClean(); +namespace graphics +{ + void init(); + void clean(); -void glDrawCircle(float radius, const Vector2&, const float* color = 0); + void drawCircle(float radius, const Vector2&, const float* color = 0); +} #endif // GRAPHICS_H diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index cff17c9..aa21684 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -17,19 +17,19 @@ static State keyState[keySize]; /// ***** Initializers/Cleaners ***** -void inputInit() +void input::init() { for(int i=0; i< keySize; i++) keyState[i] = isR; } -void inputClean() +void input::clean() { } /// ***** Public Methods ***** -void inputUpdate() +void input::update() { SDL_Event event; @@ -55,20 +55,20 @@ void inputUpdate() } } -bool isPressed(Uint8 key) +bool input::isPressed(Uint8 key) { return keyState[key] == isP || keyState[key] == wasP; } -bool isReleased(Uint8 key) +bool input::isReleased(Uint8 key) { return keyState[key] == isR || keyState[key] == wasR; } -bool wasPressed(Uint8 key) +bool input::wasPressed(Uint8 key) { return keyState[key] == wasP; } -bool wasReleased(Uint8 key) +bool input::wasReleased(Uint8 key) { return keyState[key] == wasR; } diff --git a/src/input/inputManager.h b/src/input/inputManager.h index 8e708d9..cd1d331 100644 --- a/src/input/inputManager.h +++ b/src/input/inputManager.h @@ -3,17 +3,21 @@ #include + /// ***** Header Methods ***** -void inputInit(); -void inputClean(); +namespace input +{ + void init(); + void clean(); -void inputUpdate(); + void update(); -bool isPressed(Uint8); -bool isReleased(Uint8); + bool isPressed(Uint8); + bool isReleased(Uint8); -bool wasPressed(Uint8); -bool wasReleased(Uint8); + bool wasPressed(Uint8); + bool wasReleased(Uint8); +} #endif // INPUT_H diff --git a/src/main.cpp b/src/main.cpp index 6f5ed03..ca17fdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ void clean(); void blockUpdate(); void updateFPSCounters(); -void input(); +void handleInput(); void update(float); void draw(); @@ -67,11 +67,11 @@ void init() { installSignal(); - graphicsInit(); + graphics::init(); - gameInit(); + game::init(); - inputInit(); + input::init(); #ifdef DEBUGGING cout << "Initialization Complete" << endl; @@ -84,11 +84,11 @@ void clean() cout << "Cleaning up" << endl; #endif - inputClean(); + input::clean(); - gameClean(); + game::clean(); - graphicsClean(); + graphics::clean(); } /// ***** Private Methods ***** @@ -127,7 +127,7 @@ void blockUpdate() // run the updates for (int i = 1; i <= iupdate_sum; i++) { - input(); + handleInput(); update(time_step*i / 1000); } // remove the updates that where run from the sum @@ -155,13 +155,13 @@ void updateFPSCounters() } } -void input() +void handleInput() { - inputUpdate(); + input::update(); - gameInput(); + game::input(); - if(wasReleased(SDLK_ESCAPE)) + if(input::wasReleased(SDLK_ESCAPE)) is_Running = false; } @@ -169,14 +169,14 @@ void update(float time_step) { update_Count++; - gameUpdate(time_step); + game::update(time_step); } void draw() { draw_Count++; - gameDraw(); + game::draw(); SDL_GL_SwapBuffers();