[Super-tux-commit] supertux/lib/special base.h,1.2,1.3 game_object.cpp,1.1,1.2 game_object.h,1.1,1.2
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-21 16:52:04
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32238/lib/special Modified Files: base.h game_object.cpp game_object.h moving_object.cpp moving_object.h sprite.cpp sprite.h sprite_manager.cpp sprite_manager.h stringlist.cpp stringlist.h timer.cpp timer.h Log Message: The SuperTux library features a SuperTux namespace now. + minor Bugfixes and cleanups Index: moving_object.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/moving_object.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- moving_object.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ moving_object.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -19,6 +19,8 @@ #include "special/moving_object.h" +using namespace SuperTux; + MovingObject::MovingObject() { base.x = base.y = base.width = base.height = 0; Index: timer.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- timer.h 20 Jul 2004 20:05:34 -0000 1.2 +++ timer.h 21 Jul 2004 16:51:52 -0000 1.3 @@ -21,63 +21,68 @@ #ifndef SUPERTUX_TIMER_H #define SUPERTUX_TIMER_H -extern unsigned int st_pause_ticks, st_pause_count; +namespace SuperTux + { -/// Time a game is running. (Non-pause mode, etc.) -unsigned int st_get_ticks(void); + extern unsigned int st_pause_ticks, st_pause_count; -void st_pause_ticks_init(void); -void st_pause_ticks_start(void); -void st_pause_ticks_stop(void); -bool st_pause_ticks_started(void); + /// Time a game is running. (Non-pause mode, etc.) + unsigned int st_get_ticks(void); -/// Timer -/** This class can be used as stop watch - for example. It's also possible to calculate - frames per seconds and things like that with it. - It's a general timing class, but it - can esspecially be used together with st_get_ticks(). */ -class Timer -{ - public: - unsigned int period; - unsigned int time; - unsigned int (*get_ticks) (void); + void st_pause_ticks_init(void); + void st_pause_ticks_start(void); + void st_pause_ticks_stop(void); + bool st_pause_ticks_started(void); - public: - Timer(); - - /// Initialize the timer. - /** @Param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */ - void init(bool st_ticks); - - /// Start the timer with the given period (in ms). - void start(unsigned int period); - - /// Stop the timer. - void stop(); + /// Timer + /** This class can be used as stop watch + for example. It's also possible to calculate + frames per seconds and things like that with it. + It's a general timing class, but it + can esspecially be used together with st_get_ticks(). */ + class Timer + { + public: + unsigned int period; + unsigned int time; + unsigned int (*get_ticks) (void); - /// Check if the timer is started and within its period. - /** If one of these requirements isn't the case the timer - is automatically reseted. */ - int check(); - - /// Is the timer started? - int started(); + public: + Timer(); - /// Get time left until the last timing period is finished. - /** The returned value can be negative. */ - int get_left(); + /// Initialize the timer. + /** @param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */ + void init(bool st_ticks); - /// Get the gone time, since last timer start. - /** The returned value can be negative. */ - int get_gone(); - - /// Write the timer value to a file (For save games in example). - void fwrite(FILE* fi); - /// Read a timer value from a file (From save games in example). - void fread(FILE* fi); -}; + /// Start the timer with the given period (in ms). + void start(unsigned int period); + + /// Stop the timer. + void stop(); + + /// Check if the timer is started and within its period. + /** If one of these requirements isn't the case the timer + is automatically reseted. */ + int check(); + + /// Is the timer started? + int started(); + + /// Get time left until the last timing period is finished. + /** The returned value can be negative. */ + int get_left(); + + /// Get the gone time, since last timer start. + /** The returned value can be negative. */ + int get_gone(); + + /// Write the timer value to a file (For save games in example). + void fwrite(FILE* fi); + /// Read a timer value from a file (From save games in example). + void fread(FILE* fi); + }; + +} //namespace SuperTux #endif /*SUPERTUX_TIMER_H*/ Index: sprite_manager.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite_manager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite_manager.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ sprite_manager.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -22,6 +22,8 @@ #include "utils/lispreader.h" #include "special/sprite_manager.h" +using namespace SuperTux; + SpriteManager::SpriteManager(const std::string& filename) { load_resfile(filename); Index: stringlist.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/stringlist.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- stringlist.h 20 Jul 2004 17:51:37 -0000 1.1 +++ stringlist.h 21 Jul 2004 16:51:52 -0000 1.2 @@ -21,22 +21,25 @@ #ifndef SUPERTUX_STRINGLIST_H #define SUPERTUX_STRINGLIST_H -struct string_list_type -{ - int num_items; - int active_item; - char **item; -}; +namespace SuperTux + { -void string_list_init(string_list_type* pstring_list); -char* string_list_active(string_list_type* pstring_list); -void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); -int string_list_find(string_list_type* pstring_list, const char* str); -void string_list_sort(string_list_type* pstring_list); -void string_list_add_item(string_list_type* pstring_list, const char* str); -void string_list_free(string_list_type* pstring_list); + struct string_list_type + { + int num_items; + int active_item; + char **item; + }; + void string_list_init(string_list_type* pstring_list); + char* string_list_active(string_list_type* pstring_list); + void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); + int string_list_find(string_list_type* pstring_list, const char* str); + void string_list_sort(string_list_type* pstring_list); + void string_list_add_item(string_list_type* pstring_list, const char* str); + void string_list_free(string_list_type* pstring_list); +} //namespace SuperTux #endif /*SUPERTUX_STRINGLIST_H*/ Index: game_object.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/game_object.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- game_object.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ game_object.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -19,6 +19,8 @@ #include "special/game_object.h" +using namespace SuperTux; + GameObject::GameObject() : wants_to_die(false) { Index: sprite.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ sprite.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -25,6 +25,8 @@ #include "special/sprite.h" #include "video/drawing_context.h" +using namespace SuperTux; + Sprite::Sprite(lisp_object_t* cur) { init_defaults(); Index: moving_object.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/moving_object.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- moving_object.h 20 Jul 2004 17:51:37 -0000 1.1 +++ moving_object.h 21 Jul 2004 16:51:52 -0000 1.2 @@ -25,37 +25,44 @@ #include "math/vector.h" //#include "rectangle.h" -/** - * Base class for all dynamic/moving game objects. This class contains things - * for handling the bounding boxes and collision feedback. - */ -class MovingObject : public GameObject -{ -public: - MovingObject(); - virtual ~MovingObject(); +namespace SuperTux + { - /** this function is called when the object collided with any other object + /** + * Base class for all dynamic/moving game objects. This class contains things + * for handling the bounding boxes and collision feedback. */ - virtual void collision(const MovingObject& other_object, - int collision_type) = 0; + class MovingObject : public GameObject + { + public: + MovingObject(); + virtual ~MovingObject(); - Vector get_pos() const - { return Vector(base.x, base.y); } + /** this function is called when the object collided with any other object + */ + virtual void collision(const MovingObject& other_object, + int collision_type) = 0; - base_type base; - base_type old_base; + Vector get_pos() const + { + return Vector(base.x, base.y); + } -protected: + base_type base; + base_type old_base; + + protected: #if 0 // this will be used in my collision detection rewrite later - /// the current position of the object - Vector pos; - /// the position we want to move until next frame - Vector new_pos; - /// the bounding box relative to the current position - Rectangle bounding_box; + /// the current position of the object + Vector pos; + /// the position we want to move until next frame + Vector new_pos; + /// the bounding box relative to the current position + Rectangle bounding_box; #endif -}; + }; + +} //namespace SuperTux #endif /*SUPERTUX_MOVING_OBJECT_H*/ Index: base.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/base.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- base.h 20 Jul 2004 20:24:47 -0000 1.2 +++ base.h 21 Jul 2004 16:51:52 -0000 1.3 @@ -18,25 +18,29 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. -#ifndef SUPERTUX_TYPE_H -#define SUPERTUX_TYPE_H +#ifndef SUPERTUX_BASE_H +#define SUPERTUX_BASE_H #include <string> #include "SDL.h" -/// 'Base' type for game objects. -/** Mainly for layered use in game objects. - Containts upper left X and Y coordinates of an - object along with its width and height. */ -struct base_type -{ - float x; - float y; - float width; - float height; -}; +namespace SuperTux + { + + /// 'Base' type for game objects. + /** Mainly for layered use in game objects. + Containts upper left X and Y coordinates of an + object along with its width and height. */ + struct base_type + { + float x; + float y; + float width; + float height; + }; +} -#endif /*SUPERTUX_TYPE_H*/ +#endif /*SUPERTUX_BASE_H*/ Index: sprite.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite.h 20 Jul 2004 17:51:37 -0000 1.1 +++ sprite.h 21 Jul 2004 16:51:52 -0000 1.2 @@ -27,51 +27,69 @@ #include "video/surface.h" #include "math/vector.h" -class Sprite -{ - private: - std::string name; +namespace SuperTux + { - int x_hotspot; - int y_hotspot; + class Sprite + { + private: + std::string name; - /** Frames per second */ - float fps; + int x_hotspot; + int y_hotspot; - /** Number of seconds that a frame is displayed until it is switched - to the next frame */ - float frame_delay; + /** Frames per second */ + float fps; - float time; + /** Number of seconds that a frame is displayed until it is switched + to the next frame */ + float frame_delay; - std::vector<Surface*> surfaces; + float time; - void init_defaults(); - public: - /** cur has to be a pointer to data in the form of ((x-hotspot 5) - (y-hotspot 10) ...) */ - Sprite(lisp_object_t* cur); - ~Sprite(); - - void reset(); + std::vector<Surface*> surfaces; - /** Update the sprite and process to the next frame */ - void update(float delta); - void draw(DrawingContext& context, const Vector& pos, int layer, - Uint32 drawing_effect = NONE_EFFECT); - int get_current_frame() const; + void init_defaults(); + public: + /** cur has to be a pointer to data in the form of ((x-hotspot 5) + (y-hotspot 10) ...) */ + Sprite(lisp_object_t* cur); + ~Sprite(); - float get_fps() { return fps; } ; - int get_frames() { return surfaces.size(); } ; + void reset(); - std::string get_name() const { return name; } - int get_width() const; - int get_height() const; + /** Update the sprite and process to the next frame */ + void update(float delta); + void draw(DrawingContext& context, const Vector& pos, int layer, + Uint32 drawing_effect = NONE_EFFECT); + int get_current_frame() const; - Surface* get_frame(unsigned int frame) - { if(frame < surfaces.size()) return surfaces[frame]; - else return surfaces[0]; } -}; + float get_fps() + { + return fps; + } ; + int get_frames() + { + return surfaces.size(); + } ; + + std::string get_name() const + { + return name; + } + int get_width() const; + int get_height() const; + + Surface* get_frame(unsigned int frame) + { + if(frame < surfaces.size()) + return surfaces[frame]; + else + return surfaces[0]; + } + }; + +} //namespace SuperTux #endif /*SUPERTUX_SPRITE_H*/ Index: timer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- timer.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ timer.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -21,9 +21,11 @@ #include "SDL.h" #include "special/timer.h" -unsigned int st_pause_ticks, st_pause_count; +using namespace SuperTux; -unsigned int st_get_ticks(void) +unsigned int SuperTux::st_pause_ticks, SuperTux::st_pause_count; + +unsigned int SuperTux::st_get_ticks(void) { if(st_pause_count != 0) return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count; @@ -31,19 +33,19 @@ return SDL_GetTicks() - st_pause_ticks; } -void st_pause_ticks_init(void) +void SuperTux::st_pause_ticks_init(void) { st_pause_ticks = 0; st_pause_count = 0; } -void st_pause_ticks_start(void) +void SuperTux::st_pause_ticks_start(void) { if(st_pause_count == 0) st_pause_count = SDL_GetTicks(); } -void st_pause_ticks_stop(void) +void SuperTux::st_pause_ticks_stop(void) { if(st_pause_count == 0) return; @@ -52,7 +54,7 @@ st_pause_count = 0; } -bool st_pause_ticks_started(void) +bool SuperTux::st_pause_ticks_started(void) { if(st_pause_count == 0) return false; Index: game_object.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/game_object.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- game_object.h 20 Jul 2004 17:51:37 -0000 1.1 +++ game_object.h 21 Jul 2004 16:51:52 -0000 1.2 @@ -22,50 +22,58 @@ #include <string> -class DrawingContext; +namespace SuperTux + { -/** - * Base class for all game objects. This contains functions for: - * -querying the actual type of the object - * -a flag that indicates if the object wants to be removed. Objects with this - * flag will be removed at the end of each frame. This is alot safer than - * having some uncontrollable "delete this" in the code. - * -an action function that is called once per frame and allows the object to - * update it's state. - * - * Most GameObjects will also implement the DrawableObject interface so that - * they can actually be drawn on screen. - */ -class GameObject // TODO rename this once the game has been converted -{ -public: - GameObject(); - virtual ~GameObject(); + class DrawingContext; - /** This function is called once per frame and allows the object to update - * it's state. The elapsed_time is the time since the last frame and should be - * the base for all timed things. + /** + * Base class for all game objects. This contains functions for: + * -querying the actual type of the object + * -a flag that indicates if the object wants to be removed. Objects with this + * flag will be removed at the end of each frame. This is alot safer than + * having some uncontrollable "delete this" in the code. + * -an action function that is called once per frame and allows the object to + * update it's state. + * + * Most GameObjects will also implement the DrawableObject interface so that + * they can actually be drawn on screen. */ - virtual void action(float elapsed_time) = 0; + class GameObject // TODO rename this once the game has been converted + { + public: + GameObject(); + virtual ~GameObject(); - /** The GameObject should draw itself onto the provided DrawingContext if this - * function is called. - */ - virtual void draw(DrawingContext& context) = 0; + /** This function is called once per frame and allows the object to update + * it's state. The elapsed_time is the time since the last frame and should be + * the base for all timed things. + */ + virtual void action(float elapsed_time) = 0; - /** returns true if the object is not scheduled to be removed yet */ - bool is_valid() const - { return !wants_to_die; } - /** schedules this object to be removed at the end of the frame */ - void remove_me() - { wants_to_die = true; } - -private: - /** this flag indicates if the object should be removed at the end of the - * frame - */ - bool wants_to_die; -}; + /** The GameObject should draw itself onto the provided DrawingContext if this + * function is called. + */ + virtual void draw(DrawingContext& context) = 0; + /** returns true if the object is not scheduled to be removed yet */ + bool is_valid() const + { + return !wants_to_die; + } + /** schedules this object to be removed at the end of the frame */ + void remove_me() + { + wants_to_die = true; + } + + private: + /** this flag indicates if the object should be removed at the end of the + * frame + */ + bool wants_to_die; + }; + +} #endif /*SUPERTUX_GAMEOBJECT_H*/ Index: stringlist.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/stringlist.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- stringlist.cpp 20 Jul 2004 17:51:37 -0000 1.1 +++ stringlist.cpp 21 Jul 2004 16:51:52 -0000 1.2 @@ -22,14 +22,16 @@ #include "stdlib.h" #include "special/stringlist.h" -void string_list_init(string_list_type* pstring_list) +using namespace SuperTux; + +void SuperTux::string_list_init(string_list_type* pstring_list) { pstring_list->num_items = 0; pstring_list->active_item = -1; pstring_list->item = NULL; } -char* string_list_active(string_list_type* pstring_list) +char* SuperTux::string_list_active(string_list_type* pstring_list) { if(pstring_list == NULL) return ""; @@ -40,7 +42,7 @@ return ""; } -void string_list_add_item(string_list_type* pstring_list,const char* str) +void SuperTux::string_list_add_item(string_list_type* pstring_list,const char* str) { char *pnew_string; pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1)); @@ -52,7 +54,7 @@ pstring_list->active_item = 0; } -void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig) +void SuperTux::string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig) { int i; string_list_free(pstring_list); @@ -60,7 +62,7 @@ string_list_add_item(pstring_list,pstring_list_orig.item[i]); } -int string_list_find(string_list_type* pstring_list,const char* str) +int SuperTux::string_list_find(string_list_type* pstring_list,const char* str) { int i; for(i = 0; i < pstring_list->num_items; ++i) @@ -73,7 +75,7 @@ return -1; } -void string_list_sort(string_list_type* pstring_list) +void SuperTux::string_list_sort(string_list_type* pstring_list) { int i,j,y; @@ -103,7 +105,7 @@ } -void string_list_free(string_list_type* pstring_list) +void SuperTux::string_list_free(string_list_type* pstring_list) { if(pstring_list != NULL) { Index: sprite_manager.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite_manager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite_manager.h 20 Jul 2004 17:51:37 -0000 1.1 +++ sprite_manager.h 21 Jul 2004 16:51:52 -0000 1.2 @@ -24,21 +24,26 @@ #include "special/sprite.h" -class SpriteManager -{ - private: - typedef std::map<std::string, Sprite*> Sprites; - Sprites sprites; - public: - SpriteManager(const std::string& filename); - ~SpriteManager(); - - void load_resfile(const std::string& filename); - /** loads a sprite. - * WARNING: You must not delete the returned object. - */ - Sprite* load(const std::string& name); -}; +namespace SuperTux + { + + class SpriteManager + { + private: + typedef std::map<std::string, Sprite*> Sprites; + Sprites sprites; + public: + SpriteManager(const std::string& filename); + ~SpriteManager(); + + void load_resfile(const std::string& filename); + /** loads a sprite. + * WARNING: You must not delete the returned object. + */ + Sprite* load(const std::string& name); + }; + +} //namespace SuperTux #endif /*SUPERTUX_SPRITE_MANAGER_H*/ |