From edaacb3651cf0560314dd008d7243be4b3b2f8c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Wed, 21 Jul 2004 16:51:53 +0000 Subject: [PATCH] The SuperTux library features a SuperTux namespace now. + minor Bugfixes and cleanups SVN-Revision: 1611 --- lib/app/globals.cpp | 4 + lib/app/globals.h | 103 +++++++------- lib/app/setup.cpp | 50 +++---- lib/app/setup.h | 4 + lib/audio/musicref.cpp | 2 + lib/audio/musicref.h | 41 +++--- lib/audio/sound_manager.cpp | 2 + lib/audio/sound_manager.h | 115 ++++++++-------- lib/gui/button.h | 2 +- lib/gui/menu.cpp | 26 ++-- lib/gui/menu.h | 301 ++++++++++++++++++++--------------------- lib/gui/mousecursor.cpp | 2 + lib/gui/mousecursor.h | 102 +++++++------- lib/math/physic.cpp | 2 + lib/math/physic.h | 115 ++++++++-------- lib/math/vector.cpp | 2 + lib/math/vector.h | 147 ++++++++++---------- lib/special/base.h | 32 +++-- lib/special/game_object.cpp | 2 + lib/special/game_object.h | 86 ++++++------ lib/special/moving_object.cpp | 2 + lib/special/moving_object.h | 57 ++++---- lib/special/sprite.cpp | 2 + lib/special/sprite.h | 108 +++++++++------ lib/special/sprite_manager.cpp | 2 + lib/special/sprite_manager.h | 35 +++-- lib/special/stringlist.cpp | 16 ++- lib/special/stringlist.h | 29 ++-- lib/special/timer.cpp | 14 +- lib/special/timer.h | 119 ++++++++-------- lib/utils/configfile.cpp | 4 +- lib/utils/configfile.h | 3 + lib/utils/exceptions.h | 37 ++--- lib/utils/lispreader.cpp | 60 ++++---- lib/utils/lispreader.h | 4 + lib/utils/lispwriter.cpp | 2 + lib/utils/lispwriter.h | 63 +++++---- lib/video/drawing_context.cpp | 2 + lib/video/drawing_context.h | 262 ++++++++++++++++++----------------- lib/video/font.cpp | 4 +- lib/video/font.h | 85 ++++++------ lib/video/screen.cpp | 18 +-- lib/video/screen.h | 65 +++++---- lib/video/surface.cpp | 4 +- lib/video/surface.h | 263 ++++++++++++++++++----------------- src/badguy.h | 2 + src/camera.cpp | 2 + src/camera.h | 6 + src/collision.h | 2 + src/door.cpp | 2 + src/door.h | 3 +- src/gameloop.h | 6 +- src/gameobjs.h | 2 + src/high_scores.cpp | 3 + src/interactive_object.h | 2 + src/intro.cpp | 2 + src/level.h | 5 + src/level_subset.cpp | 2 + src/level_subset.h | 4 + src/misc.cpp | 11 ++ src/particlesystem.h | 5 + src/player.h | 4 + src/resources.cpp | 11 ++ src/resources.h | 16 +++ src/sector.h | 8 +- src/serializable.h | 4 + src/tile.h | 5 +- src/tilemap.h | 7 +- 68 files changed, 1388 insertions(+), 1126 deletions(-) diff --git a/lib/app/globals.cpp b/lib/app/globals.cpp index 035f7b52d..56f0fbf66 100644 --- a/lib/app/globals.cpp +++ b/lib/app/globals.cpp @@ -20,6 +20,8 @@ #include "app/globals.h" +namespace SuperTux { + /** The datadir prefix prepended when loading game data file */ std::string datadir; @@ -122,3 +124,5 @@ int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_del return 0; } + +} //namespace SuperTux diff --git a/lib/app/globals.h b/lib/app/globals.h index ca6528975..73c600b6c 100644 --- a/lib/app/globals.h +++ b/lib/app/globals.h @@ -30,54 +30,59 @@ #include "gui/menu.h" #include "gui/mousecursor.h" -extern std::string datadir; - -struct JoystickKeymap -{ - int a_button; - int b_button; - int start_button; - - int x_axis; - int y_axis; - - int dead_zone; - - JoystickKeymap(); -}; - -extern JoystickKeymap joystick_keymap; - -extern SDL_Surface* screen; -extern Font* gold_text; -extern Font* white_text; -extern Font* blue_text; -extern Font* gray_text; -extern Font* white_small_text; -extern Font* white_big_text; -extern Font* yellow_nums; - -extern MouseCursor * mouse_cursor; - -extern bool use_gl; -extern bool use_joystick; -extern bool use_fullscreen; -extern bool debug_mode; -extern bool show_fps; - -/** The number of the joystick that will be use in the game */ -extern int joystick_num; -extern char* level_startup_file; -extern bool launch_leveleditor_mode; -extern bool launch_worldmap_mode; - -/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ -extern char* st_dir; -extern char* st_save_dir; - -extern float game_speed; -extern SDL_Joystick * js; - -int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); +namespace SuperTux + { + + extern std::string datadir; + + struct JoystickKeymap + { + int a_button; + int b_button; + int start_button; + + int x_axis; + int y_axis; + + int dead_zone; + + JoystickKeymap(); + }; + + extern JoystickKeymap joystick_keymap; + + extern SDL_Surface* screen; + extern Font* gold_text; + extern Font* white_text; + extern Font* blue_text; + extern Font* gray_text; + extern Font* white_small_text; + extern Font* white_big_text; + extern Font* yellow_nums; + + extern MouseCursor * mouse_cursor; + + extern bool use_gl; + extern bool use_joystick; + extern bool use_fullscreen; + extern bool debug_mode; + extern bool show_fps; + + /** The number of the joystick that will be use in the game */ + extern int joystick_num; + extern char* level_startup_file; + extern bool launch_leveleditor_mode; + extern bool launch_worldmap_mode; + + /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ + extern char* st_dir; + extern char* st_save_dir; + + extern float game_speed; + extern SDL_Joystick * js; + + int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); + +} //namespace SuperTux #endif /* SUPERTUX_GLOBALS_H */ diff --git a/lib/app/setup.cpp b/lib/app/setup.cpp index 9218404c1..c51b0ce03 100644 --- a/lib/app/setup.cpp +++ b/lib/app/setup.cpp @@ -51,6 +51,7 @@ #include "audio/sound_manager.h" #include "app/gettext.h" +using namespace SuperTux; #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) @@ -70,7 +71,7 @@ void seticon(void); void usage(char * prog, int ret); /* Does the given file exist and is it accessible? */ -int faccessible(const char *filename) +int SuperTux::faccessible(const char *filename) { struct stat filestat; if (stat(filename, &filestat) == -1) @@ -87,7 +88,7 @@ int faccessible(const char *filename) } /* Can we write to this location? */ -int fwriteable(const char *filename) +int SuperTux::fwriteable(const char *filename) { FILE* fi; fi = fopen(filename, "wa"); @@ -99,7 +100,7 @@ int fwriteable(const char *filename) } /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/ -int fcreatedir(const char* relative_dir) +int SuperTux::fcreatedir(const char* relative_dir) { char path[1024]; snprintf(path, 1024, "%s/%s/", st_dir, relative_dir); @@ -121,7 +122,7 @@ int fcreatedir(const char* relative_dir) } } -FILE * opendata(const char * rel_filename, const char * mode) +FILE * SuperTux::opendata(const char * rel_filename, const char * mode) { char * filename = NULL; FILE * fi; @@ -154,7 +155,7 @@ FILE * opendata(const char * rel_filename, const char * mode) /* Get all names of sub-directories in a certain directory. */ /* Returns the number of sub-directories found. */ /* Note: The user has to free the allocated space. */ -string_list_type dsubdirs(const char *rel_path,const char* expected_file) +string_list_type SuperTux::dsubdirs(const char *rel_path,const char* expected_file) { DIR *dirStructP; struct dirent *direntp; @@ -224,7 +225,7 @@ string_list_type dsubdirs(const char *rel_path,const char* expected_file) return sdirs; } -string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str) +string_list_type SuperTux::dfiles(const char *rel_path, const char* glob, const char* exception_str) { DIR *dirStructP; struct dirent *direntp; @@ -289,7 +290,7 @@ string_list_type dfiles(const char *rel_path, const char* glob, const char* ex return sdirs; } -void free_strings(char **strings, int num) +void SuperTux::free_strings(char **strings, int num) { int i; for(i=0; i < num; ++i) @@ -298,7 +299,7 @@ void free_strings(char **strings, int num) /* --- SETUP --- */ /* Set SuperTux configuration and save directories */ -void st_directory_setup(void) +void SuperTux::st_directory_setup(void) { char *home; char str[1024]; @@ -365,7 +366,7 @@ void st_directory_setup(void) printf("Datadir: %s\n", datadir.c_str()); } -void st_general_setup(void) +void SuperTux::st_general_setup(void) { /* Seed random number generator: */ @@ -406,7 +407,7 @@ void st_general_setup(void) } -void st_general_free(void) +void SuperTux::st_general_free(void) { /* Free global images: */ @@ -428,20 +429,9 @@ void st_general_free(void) /* Free mouse-cursor */ delete mouse_cursor; - /* Free menus */ - delete main_menu; - delete game_menu; - delete options_menu; - delete options_keys_menu; - delete options_joystick_menu; - delete highscore_menu; - delete contrib_menu; - delete contrib_subset_menu; - delete save_game_menu; - delete load_game_menu; } -void st_video_setup(void) +void SuperTux::st_video_setup(void) { /* Init SDL Video: */ if (SDL_Init(SDL_INIT_VIDEO) < 0) @@ -465,7 +455,7 @@ void st_video_setup(void) SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux"); } -void st_video_setup_sdl(void) +void SuperTux::st_video_setup_sdl(void) { if (use_fullscreen) { @@ -495,7 +485,7 @@ void st_video_setup_sdl(void) } } -void st_video_setup_gl(void) +void SuperTux::st_video_setup_gl(void) { #ifndef NOOPENGL @@ -551,7 +541,7 @@ void st_video_setup_gl(void) } -void st_joystick_setup(void) +void SuperTux::st_joystick_setup(void) { /* Init Joystick: */ @@ -612,7 +602,7 @@ void st_joystick_setup(void) } } -void st_audio_setup(void) +void SuperTux::st_audio_setup(void) { /* Init SDL Audio silently even if --disable-sound : */ @@ -670,7 +660,7 @@ void st_audio_setup(void) /* --- SHUTDOWN --- */ -void st_shutdown(void) +void SuperTux::st_shutdown(void) { close_audio(); SDL_Quit(); @@ -679,7 +669,7 @@ void st_shutdown(void) /* --- ABORT! --- */ -void st_abort(const std::string& reason, const std::string& details) +void SuperTux::st_abort(const std::string& reason, const std::string& details) { fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str()); st_shutdown(); @@ -729,7 +719,7 @@ void seticon(void) /* Parse command-line arguments: */ -void parseargs(int argc, char * argv[]) +void SuperTux::parseargs(int argc, char * argv[]) { int i; @@ -913,7 +903,7 @@ void usage(char * prog, int ret) exit(ret); } -std::vector read_directory(const std::string& pathname) +std::vector SuperTux::read_directory(const std::string& pathname) { std::vector dirnames; diff --git a/lib/app/setup.h b/lib/app/setup.h index fa79017d8..53a8b17c3 100644 --- a/lib/app/setup.h +++ b/lib/app/setup.h @@ -26,6 +26,8 @@ #include "audio/sound.h" #include "special/base.h" +namespace SuperTux { + int faccessible(const char *filename); int fcreatedir(const char* relative_dir); int fwriteable(const char *filename); @@ -48,5 +50,7 @@ void st_abort(const std::string& reason, const std::string& details); void parseargs(int argc, char * argv[]); +} + #endif /*SUPERTUX_SETUP_H*/ diff --git a/lib/audio/musicref.cpp b/lib/audio/musicref.cpp index 2b5efcdf5..a2c131646 100644 --- a/lib/audio/musicref.cpp +++ b/lib/audio/musicref.cpp @@ -20,6 +20,8 @@ #include "audio/musicref.h" +using namespace SuperTux; + MusicRef::MusicRef() : music(0) { diff --git a/lib/audio/musicref.h b/lib/audio/musicref.h index b9899ed97..70a4c8aac 100644 --- a/lib/audio/musicref.h +++ b/lib/audio/musicref.h @@ -22,24 +22,29 @@ #include "audio/sound_manager.h" -/** This class holds a reference to a music file and maintains a correct - * refcount for that file. - */ -class MusicRef -{ -public: - MusicRef(); - MusicRef(const MusicRef& other); - ~MusicRef(); - - MusicRef& operator= (const MusicRef& other); - -private: - friend class SoundManager; - MusicRef(SoundManager::MusicResource* music); - - SoundManager::MusicResource* music; -}; +namespace SuperTux + { + + /** This class holds a reference to a music file and maintains a correct + * refcount for that file. + */ + class MusicRef + { + public: + MusicRef(); + MusicRef(const MusicRef& other); + ~MusicRef(); + + MusicRef& operator= (const MusicRef& other); + + private: + friend class SoundManager; + MusicRef(SoundManager::MusicResource* music); + + SoundManager::MusicResource* music; + }; + +} //namespace SuperTux #endif /*SUPERTUX_MUSICREF_H*/ diff --git a/lib/audio/sound_manager.cpp b/lib/audio/sound_manager.cpp index 1c790f1e7..c34f91f7d 100644 --- a/lib/audio/sound_manager.cpp +++ b/lib/audio/sound_manager.cpp @@ -27,6 +27,8 @@ #include "app/setup.h" #include "special/moving_object.h" +using namespace SuperTux; + SoundManager::SoundManager() : current_music(0), music_enabled(true) { diff --git a/lib/audio/sound_manager.h b/lib/audio/sound_manager.h index 70bd5fa59..7d10dbdd5 100644 --- a/lib/audio/sound_manager.h +++ b/lib/audio/sound_manager.h @@ -26,65 +26,70 @@ #include "SDL_mixer.h" #include "math/vector.h" -class MusicRef; -class MovingObject; - -/// Sound manager -/** This class handles all sounds that are played - */ -class SoundManager -{ -public: - SoundManager(); - ~SoundManager(); - - /// Play sound. - void play_sound(Mix_Chunk* sound); - /// Play sound relative to two Vectors. - void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2); - /// Play sound relative to a MovingObject and a Vector. - void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos); - - /// Load music. - /** Is used to load the music for a MusicRef. */ - MusicRef load_music(const std::string& file); - /// Test if a certain music file exists. - bool exists_music(const std::string& filename); - - /// Play music. - /** @Param loops: Defaults to -1, which means endless loops. */ - void play_music(const MusicRef& music, int loops = -1); - - /// Halt music. - void halt_music(); - - /// Enable/Disable music. - void enable_music(bool enable); - -private: - // music part - friend class MusicRef; - - /// Resource for music. - /** Contains the raw music data and - information for music reference - counting. */ - class MusicResource +namespace SuperTux { - public: - ~MusicResource(); - SoundManager* manager; - Mix_Music* music; - int refcount; - }; + class MusicRef; + class MovingObject; - void free_music(MusicResource* music); + /// Sound manager + /** This class handles all sounds that are played + */ + class SoundManager + { + public: + SoundManager(); + ~SoundManager(); - std::map musics; - MusicResource* current_music; - bool music_enabled; -}; + /// Play sound. + void play_sound(Mix_Chunk* sound); + /// Play sound relative to two Vectors. + void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2); + /// Play sound relative to a MovingObject and a Vector. + void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos); + + /// Load music. + /** Is used to load the music for a MusicRef. */ + MusicRef load_music(const std::string& file); + /// Test if a certain music file exists. + bool exists_music(const std::string& filename); + + /// Play music. + /** @param loops: Defaults to -1, which means endless loops. */ + void play_music(const MusicRef& music, int loops = -1); + + /// Halt music. + void halt_music(); + + /// Enable/Disable music. + void enable_music(bool enable); + + private: + // music part + friend class MusicRef; + + /// Resource for music. + /** Contains the raw music data and + information for music reference + counting. */ + class MusicResource + { + public: + ~MusicResource(); + + SoundManager* manager; + Mix_Music* music; + int refcount; + }; + + void free_music(MusicResource* music); + + std::map musics; + MusicResource* current_music; + bool music_enabled; + }; + +} // namespace SuperTux #endif /*SUPERTUX_SOUND_MANAGER_H*/ diff --git a/lib/gui/button.h b/lib/gui/button.h index 65d0fe350..a5fb9e6d3 100644 --- a/lib/gui/button.h +++ b/lib/gui/button.h @@ -114,7 +114,7 @@ namespace SuperTux /// Dispatch button events. Button* event(SDL_Event &event); /// Add a button to the panel. - /** @Param tag: Can be used to identify a button. */ + /** @param tag: Can be used to identify a button. */ void additem(Button* pbutton, int tag); /// Set the default size of contained buttons. void set_button_size(int w, int h); diff --git a/lib/gui/menu.cpp b/lib/gui/menu.cpp index 4dc253d55..7ec10c730 100644 --- a/lib/gui/menu.cpp +++ b/lib/gui/menu.cpp @@ -37,31 +37,23 @@ #include "audio/sound.h" #include "special/timer.h" #include "app/gettext.h" +#include "math/vector.h" + +using namespace SuperTux; #define FLICK_CURSOR_TIME 500 -Surface* checkbox; -Surface* checkbox_checked; -Surface* back; -Surface* arrow_left; -Surface* arrow_right; - -Menu* main_menu = 0; -Menu* game_menu = 0; -Menu* options_menu = 0; -Menu* options_keys_menu = 0; -Menu* options_joystick_menu = 0; -Menu* highscore_menu = 0; -Menu* load_game_menu = 0; -Menu* save_game_menu = 0; -Menu* contrib_menu = 0; -Menu* contrib_subset_menu = 0; +Surface* SuperTux::checkbox; +Surface* SuperTux::checkbox_checked; +Surface* SuperTux::back; +Surface* SuperTux::arrow_left; +Surface* SuperTux::arrow_right; std::vector Menu::last_menus; Menu* Menu::current_ = 0; /* just displays a Yes/No text that can be used to confirm stuff */ -bool confirm_dialog(Surface *background, std::string text) +bool SuperTux::confirm_dialog(Surface *background, std::string text) { //Surface* cap_screen = Surface::CaptureScreen(); diff --git a/lib/gui/menu.h b/lib/gui/menu.h index e2113d0db..a1e5c34ee 100644 --- a/lib/gui/menu.h +++ b/lib/gui/menu.h @@ -30,162 +30,161 @@ #include "special/stringlist.h" #include "gui/mousecursor.h" +namespace SuperTux + { -/* Joystick menu delay */ + /* Joystick menu delay */ #define JOYSTICK_MENU_DELAY 500 -/* IDs for menus */ - -bool confirm_dialog(Surface* background, std::string text); - -/* Kinds of menu items */ -enum MenuItemKind { - MN_ACTION, - MN_GOTO, - MN_TOGGLE, - MN_BACK, - MN_DEACTIVE, - MN_TEXTFIELD, - MN_NUMFIELD, - MN_CONTROLFIELD_KB, - MN_CONTROLFIELD_JS, - MN_STRINGSELECT, - MN_LABEL, - MN_HL, /* horizontal line */ -}; - -class Menu; - -class MenuItem -{ -public: - MenuItemKind kind; - int toggled; - char *text; - char *input; - int *int_p; // used for setting keys (can be used for more stuff...) - int id; // item id - string_list_type* list; - Menu* target_menu; - - void change_text (const char *text); - void change_input(const char *text); - - static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); - - std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol -private: - bool input_flickering; - Timer input_flickering_timer; -}; - -class Menu -{ -private: - static std::vector last_menus; - static Menu* current_; - - static void push_current(Menu* pmenu); - static void pop_current(); - -public: - /** Set the current menu, if pmenu is NULL, hide the current menu */ - static void set_current(Menu* pmenu); - - /** Return the current active menu or NULL if none is active */ - static Menu* current() { return current_; } - -private: - /* Action done on the menu */ - enum MenuAction { - MENU_ACTION_NONE = -1, - MENU_ACTION_UP, - MENU_ACTION_DOWN, - MENU_ACTION_LEFT, - MENU_ACTION_RIGHT, - MENU_ACTION_HIT, - MENU_ACTION_INPUT, - MENU_ACTION_REMOVE + /* IDs for menus */ + + bool confirm_dialog(Surface* background, std::string text); + + /* Kinds of menu items */ + enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_DEACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_CONTROLFIELD_KB, + MN_CONTROLFIELD_JS, + MN_STRINGSELECT, + MN_LABEL, + MN_HL, /* horizontal line */ }; - /** Number of the item that got 'hit' (ie. pressed) in the last - event()/action() call, -1 if none */ - int hit_item; - - // position of the menu (ie. center of the menu, not top/left) - int pos_x; - int pos_y; - - /** input event for the menu (up, down, left, right, etc.) */ - MenuAction menuaction; - - /* input implementation variables */ - int delete_character; - char mn_input_char; - Timer joystick_timer; - -public: - Timer effect; - int arrange_left; - int active_item; - - std::vector item; - - Menu(); - ~Menu(); - - void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); - - void action (); - - /** Remove all entries from the menu */ - void clear(); - - /** Return the index of the menu item that was 'hit' (ie. the user - clicked on it) in the last event() call */ - int check (); - - MenuItem& get_item(int index) { return item[index]; } - MenuItem& get_item_by_id(int id); - - int get_active_item_id(); - - bool isToggled(int id); - - void Menu::get_controlfield_key_into_input(MenuItem *item); - void Menu::get_controlfield_js_into_input(MenuItem *item); - - void draw(DrawingContext& context); - void draw_item(DrawingContext& context, - int index, int menu_width, int menu_height); - void set_pos(int x, int y, float rw = 0, float rh = 0); - - /** translate a SDL_Event into a menu_action */ - void event(SDL_Event& event); - - int get_width() const; - int get_height() const; - - bool is_toggled(int id) const; -}; - -extern Surface* checkbox; -extern Surface* checkbox_checked; -extern Surface* back; -extern Surface* arrow_left; -extern Surface* arrow_right; - -extern Menu* contrib_menu; -extern Menu* contrib_subset_menu; -extern Menu* main_menu; -extern Menu* game_menu; -extern Menu* options_menu; -extern Menu* options_keys_menu; -extern Menu* options_joystick_menu; -extern Menu* highscore_menu; -extern Menu* load_game_menu; -extern Menu* save_game_menu; + class Menu; + + class MenuItem + { + public: + MenuItemKind kind; + int toggled; + char *text; + char *input; + int *int_p; // used for setting keys (can be used for more stuff...) + int id; // item id + string_list_type* list; + Menu* target_menu; + + void change_text (const char *text); + void change_input(const char *text); + + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); + + std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol + private: + bool input_flickering; + Timer input_flickering_timer; + }; + + class Menu + { + private: + static std::vector last_menus; + static Menu* current_; + + static void push_current(Menu* pmenu); + static void pop_current(); + + public: + /** Set the current menu, if pmenu is NULL, hide the current menu */ + static void set_current(Menu* pmenu); + + /** Return the current active menu or NULL if none is active */ + static Menu* current() + { + return current_; + } + + private: + /* Action done on the menu */ + enum MenuAction { + MENU_ACTION_NONE = -1, + MENU_ACTION_UP, + MENU_ACTION_DOWN, + MENU_ACTION_LEFT, + MENU_ACTION_RIGHT, + MENU_ACTION_HIT, + MENU_ACTION_INPUT, + MENU_ACTION_REMOVE + }; + + /** Number of the item that got 'hit' (ie. pressed) in the last + event()/action() call, -1 if none */ + int hit_item; + + // position of the menu (ie. center of the menu, not top/left) + int pos_x; + int pos_y; + + /** input event for the menu (up, down, left, right, etc.) */ + MenuAction menuaction; + + /* input implementation variables */ + int delete_character; + char mn_input_char; + Timer joystick_timer; + + public: + Timer effect; + int arrange_left; + int active_item; + + std::vector item; + + Menu(); + ~Menu(); + + void additem(MenuItem* pmenu_item); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); + + void action (); + + /** Remove all entries from the menu */ + void clear(); + + /** Return the index of the menu item that was 'hit' (ie. the user + clicked on it) in the last event() call */ + int check (); + + MenuItem& get_item(int index) + { + return item[index]; + } + MenuItem& get_item_by_id(int id); + + int get_active_item_id(); + + bool isToggled(int id); + + void Menu::get_controlfield_key_into_input(MenuItem *item); + void Menu::get_controlfield_js_into_input(MenuItem *item); + + void draw(DrawingContext& context); + void draw_item(DrawingContext& context, + int index, int menu_width, int menu_height); + void set_pos(int x, int y, float rw = 0, float rh = 0); + + /** translate a SDL_Event into a menu_action */ + void event(SDL_Event& event); + + int get_width() const; + int get_height() const; + + bool is_toggled(int id) const; + }; + + extern Surface* checkbox; + extern Surface* checkbox_checked; + extern Surface* back; + extern Surface* arrow_left; + extern Surface* arrow_right; + +} //namespace SuperTux #endif /*SUPERTUX_MENU_H*/ diff --git a/lib/gui/mousecursor.cpp b/lib/gui/mousecursor.cpp index 3956c0fcf..3556fb15a 100644 --- a/lib/gui/mousecursor.cpp +++ b/lib/gui/mousecursor.cpp @@ -20,6 +20,8 @@ #include "video/drawing_context.h" #include "gui/mousecursor.h" +using namespace SuperTux; + MouseCursor* MouseCursor::current_ = 0; MouseCursor::MouseCursor(std::string cursor_file, int frames) : mid_x(0), mid_y(0) diff --git a/lib/gui/mousecursor.h b/lib/gui/mousecursor.h index 30c9ae640..0842b62c8 100644 --- a/lib/gui/mousecursor.h +++ b/lib/gui/mousecursor.h @@ -25,54 +25,62 @@ #include "special/timer.h" #include "video/surface.h" -#define MC_FRAME_PERIOD 800 // in ms +namespace SuperTux + { -#define MC_STATES_NB 3 -enum { - MC_NORMAL, - MC_CLICK, - MC_LINK, - MC_HIDE -}; + #define MC_FRAME_PERIOD 800 // in ms -/// Mouse cursor. -/** Used to create mouse cursors. - The mouse cursors can be animated - and can be used in four different states. - (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ -class MouseCursor -{ -public: - /// Constructor of MouseCursor. - /** Expects an imagefile for the cursor and the number of animation frames it contains. */ - MouseCursor(std::string cursor_file, int frames); - ~MouseCursor(); - /// Get MouseCursor state. - /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ - int state(); - /// Set MouseCursor state. - /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ - void set_state(int nstate); - /// Define the middle of a MouseCursor. - /** Useful for cross mouse cursor images in example. */ - void set_mid(int x, int y); - - /// Draw MouseCursor on screen. - void draw(DrawingContext& context); - - /// Return the current cursor. - static MouseCursor* current() { return current_; }; - /// Set current cursor. - static void set_current(MouseCursor* pcursor) { current_ = pcursor; }; - -private: - int mid_x, mid_y; - static MouseCursor* current_; - int state_before_click; - int cur_state; - int cur_frame, tot_frames; - Surface* cursor; - Timer timer; -}; + #define MC_STATES_NB 3 + + enum { + MC_NORMAL, + MC_CLICK, + MC_LINK, + MC_HIDE + }; + + /// Mouse cursor. + /** Used to create mouse cursors. + The mouse cursors can be animated + and can be used in four different states. + (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + class MouseCursor + { + public: + /// Constructor of MouseCursor. + /** Expects an imagefile for the cursor and the number of animation frames it contains. */ + MouseCursor(std::string cursor_file, int frames); + ~MouseCursor(); + /// Get MouseCursor state. + /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + int state(); + /// Set MouseCursor state. + /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + void set_state(int nstate); + /// Define the middle of a MouseCursor. + /** Useful for cross mouse cursor images in example. */ + void set_mid(int x, int y); + + /// Draw MouseCursor on screen. + void draw(DrawingContext& context); + + /// Return the current cursor. + static MouseCursor* current() + { return current_; }; + /// Set current cursor. + static void set_current(MouseCursor* pcursor) + { current_ = pcursor; }; + + private: + int mid_x, mid_y; + static MouseCursor* current_; + int state_before_click; + int cur_state; + int cur_frame, tot_frames; + Surface* cursor; + Timer timer; + }; + +} // namespace SuperTux #endif /*SUPERTUX_MOUSECURSOR_H*/ diff --git a/lib/math/physic.cpp b/lib/math/physic.cpp index 017449cf9..37d84fb1c 100644 --- a/lib/math/physic.cpp +++ b/lib/math/physic.cpp @@ -23,6 +23,8 @@ #include "math/physic.h" #include "special/timer.h" +using namespace SuperTux; + Physic::Physic() : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true) { diff --git a/lib/math/physic.h b/lib/math/physic.h index 74960746a..bae4dd3a0 100644 --- a/lib/math/physic.h +++ b/lib/math/physic.h @@ -23,60 +23,65 @@ #include "math/vector.h" -/// Physics engine. -/** This is a very simplistic physics engine handling accelerated and constant - * movement along with gravity. - */ -class Physic -{ -public: - Physic(); - ~Physic(); - - /// Resets all velocities and accelerations to 0. - void reset(); - - /// Sets velocity to a fixed value. - void set_velocity(float vx, float vy); - - void set_velocity_x(float vx); - void set_velocity_y(float vy); - - /// Velocities invertion. - void inverse_velocity_x(); - void inverse_velocity_y(); - - float get_velocity_x(); - float get_velocity_y(); - - /// Set acceleration. - /** Sets acceleration applied to the object. (Note that gravity is - * eventually added to the vertical acceleration) - */ - void set_acceleration(float ax, float ay); - - void set_acceleration_x(float ax); - void set_acceleration_y(float ay); - - float get_acceleration_x(); - float get_acceleration_y(); - - /// Enables or disables handling of gravity. - void enable_gravity(bool gravity_enabled); - - /// Applies the physical simulation to given x and y coordinates. - void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f); - - /// applies the physical simulation to given x and y coordinates. - void apply(Vector& vector, float frame_ratio, float gravity = 10.0f); - -private: - /// horizontal and vertical acceleration - float ax, ay; - /// horizontal and vertical velocity - float vx, vy; - /// should we respect gravity in out calculations? - bool gravity_enabled; -}; +namespace SuperTux + { + + /// Physics engine. + /** This is a very simplistic physics engine handling accelerated and constant + * movement along with gravity. + */ + class Physic + { + public: + Physic(); + ~Physic(); + + /// Resets all velocities and accelerations to 0. + void reset(); + + /// Sets velocity to a fixed value. + void set_velocity(float vx, float vy); + + void set_velocity_x(float vx); + void set_velocity_y(float vy); + + /// Velocities invertion. + void inverse_velocity_x(); + void inverse_velocity_y(); + + float get_velocity_x(); + float get_velocity_y(); + + /// Set acceleration. + /** Sets acceleration applied to the object. (Note that gravity is + * eventually added to the vertical acceleration) + */ + void set_acceleration(float ax, float ay); + + void set_acceleration_x(float ax); + void set_acceleration_y(float ay); + + float get_acceleration_x(); + float get_acceleration_y(); + + /// Enables or disables handling of gravity. + void enable_gravity(bool gravity_enabled); + + /// Applies the physical simulation to given x and y coordinates. + void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f); + + /// applies the physical simulation to given x and y coordinates. + void apply(Vector& vector, float frame_ratio, float gravity = 10.0f); + + private: + /// horizontal and vertical acceleration + float ax, ay; + /// horizontal and vertical velocity + float vx, vy; + /// should we respect gravity in out calculations? + bool gravity_enabled; + }; + +} //namespace SuperTux #endif /*SUPERTUX_PHYSIC_H*/ diff --git a/lib/math/vector.cpp b/lib/math/vector.cpp index 2901e3569..d3a3225e9 100644 --- a/lib/math/vector.cpp +++ b/lib/math/vector.cpp @@ -21,6 +21,8 @@ #include "math/vector.h" +using namespace SuperTux; + Vector Vector::unit() const { return *this / norm(); diff --git a/lib/math/vector.h b/lib/math/vector.h index 19b1b4373..8e8555db8 100644 --- a/lib/math/vector.h +++ b/lib/math/vector.h @@ -20,79 +20,84 @@ #ifndef SUPERTUX_VECTOR_H #define SUPERTUX_VECTOR_H -/// 2D Vector. -/** Simple two dimensional vector. */ -class Vector -{ -public: - Vector(float nx, float ny) - : x(nx), y(ny) - { } - Vector(const Vector& other) - : x(other.x), y(other.y) - { } - Vector() - : x(0), y(0) - { } - - bool operator ==(const Vector& other) const +namespace SuperTux { - return x == other.x && y == other.y; - } - const Vector& operator=(const Vector& other) - { - x = other.x; - y = other.y; - return *this; - } - - Vector operator+(const Vector& other) const - { - return Vector(x + other.x, y + other.y); - } - - Vector operator-(const Vector& other) const - { - return Vector(x - other.x, y - other.y); - } - - Vector operator*(float s) const - { - return Vector(x * s, y * s); - } - - Vector operator/(float s) const - { - return Vector(x / s, y / s); - } - - Vector operator-() const - { - return Vector(-x, -y); - } - - const Vector& operator +=(const Vector& other) - { - x += other.x; - y += other.y; - return *this; - } - - /// Scalar product of 2 vectors - float operator*(const Vector& other) const - { - return x*other.x + y*other.y; - } - - float norm() const; - Vector unit() const; - - // ... add the other operators as needed, I'm too lazy now ... - - float x, y; // leave this public, get/set methods just give me headaches - // for such simple stuff :) -}; + /// 2D Vector. + /** Simple two dimensional vector. */ + class Vector + { + public: + Vector(float nx, float ny) + : x(nx), y(ny) + { } + Vector(const Vector& other) + : x(other.x), y(other.y) + { } + Vector() + : x(0), y(0) + { } + + bool operator ==(const Vector& other) const + { + return x == other.x && y == other.y; + } + + const Vector& operator=(const Vector& other) + { + x = other.x; + y = other.y; + return *this; + } + + Vector operator+(const Vector& other) const + { + return Vector(x + other.x, y + other.y); + } + + Vector operator-(const Vector& other) const + { + return Vector(x - other.x, y - other.y); + } + + Vector operator*(float s) const + { + return Vector(x * s, y * s); + } + + Vector operator/(float s) const + { + return Vector(x / s, y / s); + } + + Vector operator-() const + { + return Vector(-x, -y); + } + + const Vector& operator +=(const Vector& other) + { + x += other.x; + y += other.y; + return *this; + } + + /// Scalar product of 2 vectors + float operator*(const Vector& other) const + { + return x*other.x + y*other.y; + } + + float norm() const; + Vector unit() const; + + // ... add the other operators as needed, I'm too lazy now ... + + float x, y; // leave this public, get/set methods just give me headaches + // for such simple stuff :) + }; + +} //namespace SuperTux #endif /*SUPERTUX_VECTOR_H*/ diff --git a/lib/special/base.h b/lib/special/base.h index 84bc12c72..7381dc1df 100644 --- a/lib/special/base.h +++ b/lib/special/base.h @@ -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 #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*/ diff --git a/lib/special/game_object.cpp b/lib/special/game_object.cpp index e1bf9b985..c8f457bca 100644 --- a/lib/special/game_object.cpp +++ b/lib/special/game_object.cpp @@ -19,6 +19,8 @@ #include "special/game_object.h" +using namespace SuperTux; + GameObject::GameObject() : wants_to_die(false) { diff --git a/lib/special/game_object.h b/lib/special/game_object.h index 8c6c3bfc4..1a4175b16 100644 --- a/lib/special/game_object.h +++ b/lib/special/game_object.h @@ -22,50 +22,58 @@ #include -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*/ diff --git a/lib/special/moving_object.cpp b/lib/special/moving_object.cpp index 92c922935..7ed991dfa 100644 --- a/lib/special/moving_object.cpp +++ b/lib/special/moving_object.cpp @@ -19,6 +19,8 @@ #include "special/moving_object.h" +using namespace SuperTux; + MovingObject::MovingObject() { base.x = base.y = base.width = base.height = 0; diff --git a/lib/special/moving_object.h b/lib/special/moving_object.h index 26c7db1c6..689f92ba1 100644 --- a/lib/special/moving_object.h +++ b/lib/special/moving_object.h @@ -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(); - - /** this function is called when the object collided with any other object +namespace SuperTux + { + + /** + * 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(); + + /** this function is called when the object collided with any other object + */ + virtual void collision(const MovingObject& other_object, + int collision_type) = 0; - Vector get_pos() const - { return Vector(base.x, base.y); } + Vector get_pos() const + { + return Vector(base.x, base.y); + } - base_type base; - base_type old_base; + base_type base; + base_type old_base; -protected: + 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*/ diff --git a/lib/special/sprite.cpp b/lib/special/sprite.cpp index 6ce6774cd..fb4d10cc0 100644 --- a/lib/special/sprite.cpp +++ b/lib/special/sprite.cpp @@ -25,6 +25,8 @@ #include "special/sprite.h" #include "video/drawing_context.h" +using namespace SuperTux; + Sprite::Sprite(lisp_object_t* cur) { init_defaults(); diff --git a/lib/special/sprite.h b/lib/special/sprite.h index 3e03ee2db..394e44b81 100644 --- a/lib/special/sprite.h +++ b/lib/special/sprite.h @@ -27,51 +27,69 @@ #include "video/surface.h" #include "math/vector.h" -class Sprite -{ - private: - std::string name; - - int x_hotspot; - int y_hotspot; - - /** Frames per second */ - float fps; - - /** Number of seconds that a frame is displayed until it is switched - to the next frame */ - float frame_delay; - - float time; - - std::vector surfaces; - - 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(); - - /** 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; - - 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 + { + + class Sprite + { + private: + std::string name; + + int x_hotspot; + int y_hotspot; + + /** Frames per second */ + float fps; + + /** Number of seconds that a frame is displayed until it is switched + to the next frame */ + float frame_delay; + + float time; + + std::vector surfaces; + + 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(); + + /** 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; + + 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*/ diff --git a/lib/special/sprite_manager.cpp b/lib/special/sprite_manager.cpp index 1c4b72e2e..65bcfe72b 100644 --- a/lib/special/sprite_manager.cpp +++ b/lib/special/sprite_manager.cpp @@ -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); diff --git a/lib/special/sprite_manager.h b/lib/special/sprite_manager.h index 9b240a04d..a2e4340e8 100644 --- a/lib/special/sprite_manager.h +++ b/lib/special/sprite_manager.h @@ -24,21 +24,26 @@ #include "special/sprite.h" -class SpriteManager -{ - private: - typedef std::map 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 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*/ diff --git a/lib/special/stringlist.cpp b/lib/special/stringlist.cpp index 1a3440c22..01ed687ae 100644 --- a/lib/special/stringlist.cpp +++ b/lib/special/stringlist.cpp @@ -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 @@ char* string_list_active(string_list_type* pstring_list) 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 @@ void string_list_add_item(string_list_type* pstring_list,const char* str) 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 @@ void string_list_copy(string_list_type* pstring_list, string_list_type pstring_l 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 @@ int string_list_find(string_list_type* pstring_list,const char* str) 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_sort(string_list_type* pstring_list) } -void string_list_free(string_list_type* pstring_list) +void SuperTux::string_list_free(string_list_type* pstring_list) { if(pstring_list != NULL) { diff --git a/lib/special/stringlist.h b/lib/special/stringlist.h index 6428813cd..436758bad 100644 --- a/lib/special/stringlist.h +++ b/lib/special/stringlist.h @@ -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*/ diff --git a/lib/special/timer.cpp b/lib/special/timer.cpp index b1a093bb1..0791f711f 100644 --- a/lib/special/timer.cpp +++ b/lib/special/timer.cpp @@ -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 @@ unsigned int st_get_ticks(void) 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 @@ return; st_pause_count = 0; } -bool st_pause_ticks_started(void) +bool SuperTux::st_pause_ticks_started(void) { if(st_pause_count == 0) return false; diff --git a/lib/special/timer.h b/lib/special/timer.h index 324c9b1c1..113ea063a 100644 --- a/lib/special/timer.h +++ b/lib/special/timer.h @@ -21,63 +21,68 @@ #ifndef SUPERTUX_TIMER_H #define SUPERTUX_TIMER_H -extern unsigned int st_pause_ticks, st_pause_count; - -/// Time a game is running. (Non-pause mode, etc.) -unsigned int st_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); - -/// 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); - - 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(); - - /// 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 + { + + extern unsigned int st_pause_ticks, st_pause_count; + + /// Time a game is running. (Non-pause mode, etc.) + unsigned int st_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); + + /// 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); + + 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(); + + /// 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*/ diff --git a/lib/utils/configfile.cpp b/lib/utils/configfile.cpp index cbef85a84..4b50531d4 100644 --- a/lib/utils/configfile.cpp +++ b/lib/utils/configfile.cpp @@ -24,13 +24,15 @@ #include "app/setup.h" #include "app/globals.h" +using namespace SuperTux; + #ifdef WIN32 const char * config_filename = "/st_config.dat"; #else const char * config_filename = "/config"; #endif -Config* config = 0; +Config* SuperTux::config = 0; static void defaults () { diff --git a/lib/utils/configfile.h b/lib/utils/configfile.h index 9ef9d319d..ad18daf79 100644 --- a/lib/utils/configfile.h +++ b/lib/utils/configfile.h @@ -22,6 +22,8 @@ #include "utils/lispreader.h" +namespace SuperTux { + class Config { public: void load (); @@ -32,6 +34,7 @@ class Config { extern Config* config; +} //namespace SuperTux #endif diff --git a/lib/utils/exceptions.h b/lib/utils/exceptions.h index 974bf0af5..fc368f7e6 100644 --- a/lib/utils/exceptions.h +++ b/lib/utils/exceptions.h @@ -24,21 +24,26 @@ #include #include -class SuperTuxException : public std::exception -{ - public: - SuperTuxException(const char* _message, const char* _file = "", const unsigned int _line = 0) - : message(_message), file(_file), line(_line) { }; - virtual ~SuperTuxException() throw() { }; - - const char* what() const throw() { return message; }; - const char* what_file() const throw() { return file; }; - const unsigned int what_line() const throw() { return line; }; - - private: - const char* message; - const char* file; - const unsigned int line; -}; +namespace SuperTux + { + + class SuperTuxException : public std::exception + { + public: + SuperTuxException(const char* _message, const char* _file = "", const unsigned int _line = 0) + : message(_message), file(_file), line(_line) { }; + virtual ~SuperTuxException() throw() { }; + + const char* what() const throw() { return message; }; + const char* what_file() const throw() { return file; }; + const unsigned int what_line() const throw() { return line; }; + + private: + const char* message; + const char* file; + const unsigned int line; + }; + +} #endif /*SUPERTUX_EXCEPTIONS_H*/ diff --git a/lib/utils/lispreader.cpp b/lib/utils/lispreader.cpp index c49d34fd9..43283fc57 100644 --- a/lib/utils/lispreader.cpp +++ b/lib/utils/lispreader.cpp @@ -31,6 +31,8 @@ #include "app/setup.h" #include "utils/lispreader.h" +using namespace SuperTux; + #define TOKEN_ERROR -1 #define TOKEN_EOF 0 #define TOKEN_OPEN_PAREN 1 @@ -285,7 +287,7 @@ lisp_object_alloc (int type) } lisp_stream_t* -lisp_stream_init_file (lisp_stream_t *stream, FILE *file) +SuperTux::lisp_stream_init_file (lisp_stream_t *stream, FILE *file) { stream->type = LISP_STREAM_FILE; stream->v.file = file; @@ -294,7 +296,7 @@ lisp_stream_init_file (lisp_stream_t *stream, FILE *file) } lisp_stream_t* -lisp_stream_init_string (lisp_stream_t *stream, char *buf) +SuperTux::lisp_stream_init_string (lisp_stream_t *stream, char *buf) { stream->type = LISP_STREAM_STRING; stream->v.string.buf = buf; @@ -304,7 +306,7 @@ lisp_stream_init_string (lisp_stream_t *stream, char *buf) } lisp_stream_t* -lisp_stream_init_any (lisp_stream_t *stream, void *data, +SuperTux::lisp_stream_init_any (lisp_stream_t *stream, void *data, int (*next_char) (void *data), void (*unget_char) (char c, void *data)) { @@ -320,7 +322,7 @@ lisp_stream_init_any (lisp_stream_t *stream, void *data, } lisp_object_t* -lisp_make_integer (int value) +SuperTux::lisp_make_integer (int value) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_INTEGER); @@ -330,7 +332,7 @@ lisp_make_integer (int value) } lisp_object_t* -lisp_make_real (float value) +SuperTux::lisp_make_real (float value) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_REAL); @@ -340,7 +342,7 @@ lisp_make_real (float value) } lisp_object_t* -lisp_make_symbol (const char *value) +SuperTux::lisp_make_symbol (const char *value) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_SYMBOL); @@ -350,7 +352,7 @@ lisp_make_symbol (const char *value) } lisp_object_t* -lisp_make_string (const char *value) +SuperTux::lisp_make_string (const char *value) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_STRING); @@ -360,7 +362,7 @@ lisp_make_string (const char *value) } lisp_object_t* -lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr) +SuperTux::lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_CONS); @@ -371,7 +373,7 @@ lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr) } lisp_object_t* -lisp_make_boolean (int value) +SuperTux::lisp_make_boolean (int value) { lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_BOOLEAN); @@ -404,7 +406,7 @@ lisp_make_pattern_var (int type, int index, lisp_object_t *sub) } lisp_object_t* -lisp_read (lisp_stream_t *in) +SuperTux::lisp_read (lisp_stream_t *in) { int token = _scan(in); lisp_object_t *obj = lisp_nil(); @@ -502,7 +504,7 @@ lisp_read (lisp_stream_t *in) } void -lisp_free (lisp_object_t *obj) +SuperTux::lisp_free (lisp_object_t *obj) { if (obj == 0) return; @@ -547,7 +549,7 @@ lisp_free (lisp_object_t *obj) } lisp_object_t* -lisp_read_from_string (const char *buf) +SuperTux::lisp_read_from_string (const char *buf) { lisp_stream_t stream; @@ -642,7 +644,7 @@ _compile_pattern (lisp_object_t **obj, int *index) } int -lisp_compile_pattern (lisp_object_t **obj, int *num_subs) +SuperTux::lisp_compile_pattern (lisp_object_t **obj, int *num_subs) { int index = 0; int result; @@ -775,7 +777,7 @@ _match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars } int -lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars, int num_subs) +SuperTux::lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars, int num_subs) { int i; @@ -787,7 +789,7 @@ lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t ** } int -lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t **vars) +SuperTux::lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t **vars) { lisp_object_t *pattern; int result; @@ -813,7 +815,7 @@ lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t } int -lisp_type (lisp_object_t *obj) +SuperTux::lisp_type (lisp_object_t *obj) { if (obj == 0) return LISP_TYPE_NIL; @@ -821,7 +823,7 @@ lisp_type (lisp_object_t *obj) } int -lisp_integer (lisp_object_t *obj) +SuperTux::lisp_integer (lisp_object_t *obj) { if (obj->type != LISP_TYPE_INTEGER) throw LispReaderException("lisp_integer()", __FILE__, __LINE__); @@ -830,7 +832,7 @@ lisp_integer (lisp_object_t *obj) } char* -lisp_symbol (lisp_object_t *obj) +SuperTux::lisp_symbol (lisp_object_t *obj) { if (obj->type != LISP_TYPE_SYMBOL) throw LispReaderException("lisp_symbol()", __FILE__, __LINE__); @@ -839,7 +841,7 @@ lisp_symbol (lisp_object_t *obj) } char* -lisp_string (lisp_object_t *obj) +SuperTux::lisp_string (lisp_object_t *obj) { if (obj->type != LISP_TYPE_STRING) throw LispReaderException("lisp_string()", __FILE__, __LINE__); @@ -848,7 +850,7 @@ lisp_string (lisp_object_t *obj) } int -lisp_boolean (lisp_object_t *obj) +SuperTux::lisp_boolean (lisp_object_t *obj) { if (obj->type != LISP_TYPE_BOOLEAN) throw LispReaderException("lisp_boolean()", __FILE__, __LINE__); @@ -857,7 +859,7 @@ lisp_boolean (lisp_object_t *obj) } float -lisp_real (lisp_object_t *obj) +SuperTux::lisp_real (lisp_object_t *obj) { if (obj->type != LISP_TYPE_REAL && obj->type != LISP_TYPE_INTEGER) throw LispReaderException("lisp_real()", __FILE__, __LINE__); @@ -868,7 +870,7 @@ lisp_real (lisp_object_t *obj) } lisp_object_t* -lisp_car (lisp_object_t *obj) +SuperTux::lisp_car (lisp_object_t *obj) { if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS) throw LispReaderException("lisp_car()", __FILE__, __LINE__); @@ -877,7 +879,7 @@ lisp_car (lisp_object_t *obj) } lisp_object_t* -lisp_cdr (lisp_object_t *obj) +SuperTux::lisp_cdr (lisp_object_t *obj) { if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS) throw LispReaderException("lisp_cdr()", __FILE__, __LINE__); @@ -886,7 +888,7 @@ lisp_cdr (lisp_object_t *obj) } lisp_object_t* -lisp_cxr (lisp_object_t *obj, const char *x) +SuperTux::lisp_cxr (lisp_object_t *obj, const char *x) { int i; @@ -902,7 +904,7 @@ lisp_cxr (lisp_object_t *obj, const char *x) } int -lisp_list_length (lisp_object_t *obj) +SuperTux::lisp_list_length (lisp_object_t *obj) { int length = 0; @@ -919,7 +921,7 @@ lisp_list_length (lisp_object_t *obj) } lisp_object_t* -lisp_list_nth_cdr (lisp_object_t *obj, int index) +SuperTux::lisp_list_nth_cdr (lisp_object_t *obj, int index) { while (index > 0) { @@ -936,7 +938,7 @@ lisp_list_nth_cdr (lisp_object_t *obj, int index) } lisp_object_t* -lisp_list_nth (lisp_object_t *obj, int index) +SuperTux::lisp_list_nth (lisp_object_t *obj, int index) { obj = lisp_list_nth_cdr(obj, index); @@ -947,7 +949,7 @@ lisp_list_nth (lisp_object_t *obj, int index) } void -lisp_dump (lisp_object_t *obj, FILE *out) +SuperTux::lisp_dump (lisp_object_t *obj, FILE *out) { if (obj == 0) { @@ -1275,7 +1277,7 @@ LispReader::get_lisp() return lst; } -lisp_object_t* lisp_read_from_file(const std::string& filename) +lisp_object_t* SuperTux::lisp_read_from_file(const std::string& filename) { FILE* in = fopen(filename.c_str(), "r"); diff --git a/lib/utils/lispreader.h b/lib/utils/lispreader.h index f0f480e52..e1a2b59e0 100644 --- a/lib/utils/lispreader.h +++ b/lib/utils/lispreader.h @@ -33,6 +33,8 @@ #include "utils/exceptions.h" +namespace SuperTux { + #define LISP_STREAM_FILE 1 #define LISP_STREAM_STRING 2 #define LISP_STREAM_ANY 3 @@ -200,5 +202,7 @@ public: lisp_object_t* get_lisp(); }; +} //namespace SuperTux + #endif /*SUPERTUX_LISPREADER_H*/ diff --git a/lib/utils/lispwriter.cpp b/lib/utils/lispwriter.cpp index 6a08cab81..02dd921a5 100644 --- a/lib/utils/lispwriter.cpp +++ b/lib/utils/lispwriter.cpp @@ -21,6 +21,8 @@ #include "utils/lispwriter.h" +using namespace SuperTux; + LispWriter::LispWriter(std::ostream& newout) : out(newout), indent_depth(0) { diff --git a/lib/utils/lispwriter.h b/lib/utils/lispwriter.h index e7f4c4c22..9b7b00221 100644 --- a/lib/utils/lispwriter.h +++ b/lib/utils/lispwriter.h @@ -24,33 +24,38 @@ #include #include -class LispWriter -{ -public: - LispWriter(std::ostream& out); - ~LispWriter(); - - void write_comment(const std::string& comment); - - void start_list(const std::string& listname); - - void write_int(const std::string& name, int value); - void write_float(const std::string& name, float value); - void write_string(const std::string& name, const std::string& value); - void write_bool(const std::string& name, bool value); - void write_int_vector(const std::string& name, const std::vector& value); - void write_int_vector(const std::string& name, const std::vector& value); - // add more write-functions when needed... - - void end_list(const std::string& listname); - -private: - void indent(); - - std::ostream& out; - int indent_depth; - std::vector lists; -}; - -#endif +namespace SuperTux + { + + class LispWriter + { + public: + LispWriter(std::ostream& out); + ~LispWriter(); + + void write_comment(const std::string& comment); + + void start_list(const std::string& listname); + + void write_int(const std::string& name, int value); + void write_float(const std::string& name, float value); + void write_string(const std::string& name, const std::string& value); + void write_bool(const std::string& name, bool value); + void write_int_vector(const std::string& name, const std::vector& value); + void write_int_vector(const std::string& name, const std::vector& value); + // add more write-functions when needed... + + void end_list(const std::string& listname); + + private: + void indent(); + + std::ostream& out; + int indent_depth; + std::vector lists; + }; + +} //namespace SuperTux + +#endif //SUPERTUX_LISPWRITER_H diff --git a/lib/video/drawing_context.cpp b/lib/video/drawing_context.cpp index 846e38c55..6a6b75369 100644 --- a/lib/video/drawing_context.cpp +++ b/lib/video/drawing_context.cpp @@ -25,6 +25,8 @@ #include "app/globals.h" #include "video/font.h" +using namespace SuperTux; + DrawingContext::DrawingContext() { transform.draw_effect = NONE_EFFECT; diff --git a/lib/video/drawing_context.h b/lib/video/drawing_context.h index b08bd6c97..b200e7bdf 100644 --- a/lib/video/drawing_context.h +++ b/lib/video/drawing_context.h @@ -26,138 +26,148 @@ #include "math/vector.h" #include "video/screen.h" +#include "video/surface.h" -class Surface; -class Font; - -// some constants for predefined layer values -enum { - LAYER_BACKGROUND0 = -300, - LAYER_BACKGROUND1 = -200, - LAYER_BACKGROUNDTILES = -100, - LAYER_TILES = 0, - LAYER_OBJECTS = 100, - LAYER_FOREGROUNDTILES = 200, - LAYER_FOREGROUND0 = 300, - LAYER_FOREGROUND1 = 400, - LAYER_GUI = 500 -}; - -/** - * This class provides functions for drawing things on screen. It also - * maintains a stack of transforms that are applied to graphics. - */ -class DrawingContext -{ -public: - DrawingContext(); - ~DrawingContext(); - - /** Adds a drawing request for a surface into the request list */ - void draw_surface(const Surface* surface, const Vector& position, int layer, - Uint32 drawing_effect = NONE_EFFECT); - /** Adds a drawing request for part of a surface */ - void draw_surface_part(const Surface* surface, const Vector& source, - const Vector& size, const Vector& dest, int layer, - Uint32 drawing_effect = NONE_EFFECT); - /** draws a text */ - void draw_text(Font* font, const std::string& text, const Vector& position, - int layer, Uint32 drawing_effect = NONE_EFFECT); - /** draws aligned text */ - void draw_text_center(Font* font, const std::string& text, - const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT); - /** draws a color gradient onto the whole screen */ - void draw_gradient(Color from, Color to, int layer); - /** fills a rectangle */ - void draw_filled_rect(const Vector& topleft, const Vector& size, - Color color, int layer); - - /** Processes all pending drawing requests and flushes the list */ - void do_drawing(); - - const Vector& get_translation() const - { return transform.translation; } - void set_translation(const Vector& newtranslation) - { transform.translation = newtranslation; } - - void push_transform(); - void pop_transform(); - - /** apply that effect in the next draws (effects are listed on surface.h) */ - void set_drawing_effect(int effect); - -private: - class Transform +namespace SuperTux { - public: - Vector translation; // only translation for now... - Vector apply(const Vector& v) const - { - return v - translation; - } - - int draw_effect; - }; - - /// the transform stack - std::vector transformstack; - /// the currently active transform - Transform transform; - - enum RequestType - { - SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT - }; - - struct SurfacePartRequest - { - const Surface* surface; - Vector source, size; - }; - - struct TextRequest - { - Font* font; - std::string text; + class Surface; + class Font; + + // some constants for predefined layer values + enum { + LAYER_BACKGROUND0 = -300, + LAYER_BACKGROUND1 = -200, + LAYER_BACKGROUNDTILES = -100, + LAYER_TILES = 0, + LAYER_OBJECTS = 100, + LAYER_FOREGROUNDTILES = 200, + LAYER_FOREGROUND0 = 300, + LAYER_FOREGROUND1 = 400, + LAYER_GUI = 500 }; - struct GradientRequest - { - Color top, bottom; - Vector size; - }; - - struct FillRectRequest - { - Color color; - Vector size; - }; - - struct DrawingRequest - { - int layer; - Uint32 drawing_effect; - - RequestType type; - Vector pos; - - void* request_data; - - bool operator<(const DrawingRequest& other) const + /** + * This class provides functions for drawing things on screen. It also + * maintains a stack of transforms that are applied to graphics. + */ + class DrawingContext { - return layer < other.layer; - } - }; - - void draw_surface_part(DrawingRequest& request); - void draw_text(DrawingRequest& request); - void draw_gradient(DrawingRequest& request); - void draw_filled_rect(DrawingRequest& request); - - typedef std::vector DrawingRequests; - DrawingRequests drawingrequests; -}; + public: + DrawingContext(); + ~DrawingContext(); + + /** Adds a drawing request for a surface into the request list */ + void draw_surface(const Surface* surface, const Vector& position, int layer, + Uint32 drawing_effect = NONE_EFFECT); + /** Adds a drawing request for part of a surface */ + void draw_surface_part(const Surface* surface, const Vector& source, + const Vector& size, const Vector& dest, int layer, + Uint32 drawing_effect = NONE_EFFECT); + /** draws a text */ + void draw_text(Font* font, const std::string& text, const Vector& position, + int layer, Uint32 drawing_effect = NONE_EFFECT); + /** draws aligned text */ + void draw_text_center(Font* font, const std::string& text, + const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT); + /** draws a color gradient onto the whole screen */ + void draw_gradient(Color from, Color to, int layer); + /** fills a rectangle */ + void draw_filled_rect(const Vector& topleft, const Vector& size, + Color color, int layer); + + /** Processes all pending drawing requests and flushes the list */ + void do_drawing(); + + const Vector& get_translation() const + { + return transform.translation; + } + void set_translation(const Vector& newtranslation) + { + transform.translation = newtranslation; + } + + void push_transform(); + void pop_transform(); + + /** apply that effect in the next draws (effects are listed on surface.h) */ + void set_drawing_effect(int effect); + + private: + class Transform + { + public: + Vector translation; // only translation for now... + + Vector apply(const Vector& v) const + { + return v - translation; + } + + int draw_effect; + }; + + /// the transform stack + std::vector transformstack; + /// the currently active transform + Transform transform; + + enum RequestType + { + SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT + }; + + struct SurfacePartRequest + { + const Surface* surface; + Vector source, size; + }; + + struct TextRequest + { + Font* font; + std::string text; + }; + + struct GradientRequest + { + Color top, bottom; + Vector size; + }; + + struct FillRectRequest + { + Color color; + Vector size; + }; + + struct DrawingRequest + { + int layer; + Uint32 drawing_effect; + + RequestType type; + Vector pos; + + void* request_data; + + bool operator<(const DrawingRequest& other) const + { + return layer < other.layer; + } + }; + + void draw_surface_part(DrawingRequest& request); + void draw_text(DrawingRequest& request); + void draw_gradient(DrawingRequest& request); + void draw_filled_rect(DrawingRequest& request); + + typedef std::vector DrawingRequests; + DrawingRequests drawingrequests; + }; + +} //namespace SuperTux #endif /*SUPERTUX_DRAWINGCONTEXT_H*/ diff --git a/lib/video/font.cpp b/lib/video/font.cpp index 831f406eb..fe9f2880c 100644 --- a/lib/video/font.cpp +++ b/lib/video/font.cpp @@ -27,6 +27,8 @@ #include "video/drawing_context.h" #include "utils/lispreader.h" +using namespace SuperTux; + Font::Font(const std::string& file, FontType ntype, int nw, int nh, int nshadowsize) : chars(0), shadow_chars(0), type(ntype), w(nw), h(nh), @@ -129,7 +131,7 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, #define SCROLL 60 #define ITEMS_SPACE 4 -void display_text_file(const std::string& file, float scroll_speed) +void SuperTux::display_text_file(const std::string& file, float scroll_speed) { std::string text; std::vector names; diff --git a/lib/video/font.h b/lib/video/font.h index 4b2617f75..f35976250 100644 --- a/lib/video/font.h +++ b/lib/video/font.h @@ -26,51 +26,56 @@ #include "video/surface.h" #include "math/vector.h" -/** Reads a text file (using LispReader, so it as to be in its formatting) - and displays it in a StarTrek fashion */ -void display_text_file(const std::string& file, float scroll_speed); +namespace SuperTux + { -/* Text type */ -class Font -{ -public: - /* Kinds of texts. */ - enum FontType { - TEXT, // images for all characters - NUM // only images for numbers - }; - - Font(const std::string& file, FontType type, int w, int h, int shadowsize=2); - ~Font(); + /** Reads a text file (using LispReader, so it as to be in its formatting) + and displays it in a StarTrek fashion */ + void display_text_file(const std::string& file, float scroll_speed); - /** returns the height of the font */ - float get_height() const; - /** returns the width of a given text. (Note that I won't add a normal - * get_width function here, as we might switch to variable width fonts in the - * future. - */ - float get_text_width(const std::string& text) const; + /* Text type */ + class Font + { + public: + /* Kinds of texts. */ + enum FontType { + TEXT, // images for all characters + NUM // only images for numbers + }; -private: - friend class DrawingContext; - - void draw(const std::string& text, const Vector& pos, - Uint32 drawing_effect = NONE_EFFECT); - void draw_chars(Surface* pchars, const std::string& text, - const Vector& position, Uint32 drawing_effect); + Font(const std::string& file, FontType type, int w, int h, int shadowsize=2); + ~Font(); - Surface* chars; - Surface* shadow_chars; - FontType type; - int w; - int h; - int shadowsize; + /** returns the height of the font */ + float get_height() const; + /** returns the width of a given text. (Note that I won't add a normal + * get_width function here, as we might switch to variable width fonts in the + * future. + */ + float get_text_width(const std::string& text) const; - /// the number of the first character that is represented in the font - int first_char; - /// the number of the last character that is represented in the font - int last_char; -}; + private: + friend class DrawingContext; + + void draw(const std::string& text, const Vector& pos, + Uint32 drawing_effect = NONE_EFFECT); + void draw_chars(Surface* pchars, const std::string& text, + const Vector& position, Uint32 drawing_effect); + + Surface* chars; + Surface* shadow_chars; + FontType type; + int w; + int h; + int shadowsize; + + /// the number of the first character that is represented in the font + int first_char; + /// the number of the last character that is represented in the font + int last_char; + }; + +} //namespace SuperTux #endif /*SUPERTUX_FONT_H*/ diff --git a/lib/video/screen.cpp b/lib/video/screen.cpp index b123cecbc..70b1d5b28 100644 --- a/lib/video/screen.cpp +++ b/lib/video/screen.cpp @@ -33,16 +33,19 @@ #include #endif -#include "app/globals.h" #include "video/screen.h" +#include "app/globals.h" #include "video/drawing_context.h" #include "special/base.h" +#include "math/vector.h" + +using namespace SuperTux; /* 'Stolen' from the SDL documentation. * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! */ -void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +void SuperTux::putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ @@ -80,7 +83,7 @@ void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) } /* Draw a single pixel on the screen. */ -void drawpixel(int x, int y, Uint32 pixel) +void SuperTux::drawpixel(int x, int y, Uint32 pixel) { /* Lock the screen for direct access to the pixels */ if ( SDL_MUSTLOCK(screen) ) @@ -105,7 +108,7 @@ void drawpixel(int x, int y, Uint32 pixel) /* --- FILL A RECT --- */ -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a) +void SuperTux::fillrect(float x, float y, float w, float h, int r, int g, int b, int a) { if(w < 0) { @@ -179,8 +182,7 @@ if(h < 0) #define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1))) #define ABS(x) ((x)>0 ? (x) : (-x)) -void -draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) +void SuperTux::draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) { #ifndef NOOPENGL if(use_gl) @@ -245,7 +247,7 @@ draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) #define LOOP_DELAY 20.0 -void fadeout(int fade_time) +void SuperTux::fadeout(int fade_time) { float alpha_inc = 256 / (fade_time / LOOP_DELAY); float alpha = 256; @@ -269,7 +271,7 @@ void fadeout(int fade_time) context.do_drawing(); } -void shrink_fade(const Vector& point, int fade_time) +void SuperTux::shrink_fade(const Vector& point, int fade_time) { float left_inc = point.x / ((float)fade_time / LOOP_DELAY); float right_inc = (screen->w - point.x) / ((float)fade_time / LOOP_DELAY); diff --git a/lib/video/screen.h b/lib/video/screen.h index 263bdae42..a1797fee3 100644 --- a/lib/video/screen.h +++ b/lib/video/screen.h @@ -25,40 +25,49 @@ #include #endif #include -class Color -{ -public: - Color() - : red(0), green(0), blue(0), alpha(255) - {} - - Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255) - : red(red_), green(green_), blue(blue_), alpha(alpha_) - {} - Color(const Color& o) - : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha) - { } +namespace SuperTux + { + + /// Color RGBA + /** Stores 8bit RGBA values. */ + class Color + { + public: + Color() + : red(0), green(0), blue(0), alpha(255) + {} - bool operator==(const Color& o) - { if(red == o.red && green == o.green && - blue == o.blue && alpha == o.alpha) - return true; - return false; } + Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255) + : red(red_), green(green_), blue(blue_), alpha(alpha_) + {} - Uint8 red, green, blue, alpha; -}; + Color(const Color& o) + : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha) + { } -#include "video/surface.h" + bool operator==(const Color& o) + { + if(red == o.red && green == o.green && + blue == o.blue && alpha == o.alpha) + return true; + return false; + } -class Vector; + Uint8 red, green, blue, alpha; + }; -void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); -void drawpixel(int x, int y, Uint32 pixel); -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255); -void draw_line(float x1, float y1, float x2, int r, int g, int b, int a = 255); -void fadeout(int fade_time); -void shrink_fade(const Vector& point, int fade_time); + class Vector; + + void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); + void drawpixel(int x, int y, Uint32 pixel); + void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255); + void draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a = 255); + + void fadeout(int fade_time); + void shrink_fade(const Vector& point, int fade_time); + +} //namespace SuperTux #endif /*SUPERTUX_SCREEN_H*/ diff --git a/lib/video/surface.cpp b/lib/video/surface.cpp index e423aa335..8550573fb 100644 --- a/lib/video/surface.cpp +++ b/lib/video/surface.cpp @@ -29,6 +29,8 @@ #include "app/globals.h" #include "app/setup.h" +using namespace SuperTux; + Surface::Surfaces Surface::surfaces; SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_) @@ -328,7 +330,7 @@ sdl_surface_from_file(const std::string& file, bool use_alpha) } SDL_Surface* -sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha) +SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha) { SDL_Surface* sdl_surface; Uint32 saved_flags; diff --git a/lib/video/surface.h b/lib/video/surface.h index aa38548b1..ea9e69496 100644 --- a/lib/video/surface.h +++ b/lib/video/surface.h @@ -30,148 +30,159 @@ #include "SDL.h" -#include "video/screen.h" #include "math/vector.h" +#include "video/screen.h" -SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha); -SDL_Surface* sdl_surface_from_nothing(); - -class SurfaceImpl; -class SurfaceSDL; -class SurfaceOpenGL; -class DrawingContext; - -/// bitset for drawing effects -enum { - /** Don't apply anything */ - NONE_EFFECT = 0x0000, - /** Draw the Surface upside down */ - VERTICAL_FLIP = 0x0001, - /** Draw the Surface with alpha equal to 128 */ - SEMI_TRANSPARENT = 0x0002 - }; - -/** This class holds all the data necessary to construct a surface */ -class SurfaceData -{ -public: - enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT }; - ConstructorType type; - SDL_Surface* surface; - std::string file; - bool use_alpha; - int x; - int y; - int w; - int h; - Color top_gradient; - Color bottom_gradient; - - SurfaceData(SDL_Surface* surf, bool use_alpha_); - SurfaceData(const std::string& file_, bool use_alpha_); - SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_); - SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_); - ~SurfaceData(); - - SurfaceSDL* create_SurfaceSDL(); - SurfaceOpenGL* create_SurfaceOpenGL(); - SurfaceImpl* create(); -}; - -/** Container class that holds a surface, necessary so that we can - switch Surface implementations (OpenGL, SDL) on the fly */ -class Surface -{ -public: - SurfaceData data; - SurfaceImpl* impl; - int w; - int h; - - typedef std::list Surfaces; - static Surfaces surfaces; -public: - static void reload_all(); - static void debug_check(); - - Surface(SDL_Surface* surf, bool use_alpha); - Surface(const std::string& file, bool use_alpha); - Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha); - Surface(Color top_gradient, Color bottom_gradient, int w_, int h_); - ~Surface(); +namespace SuperTux + { - /** Reload the surface, which is necesarry in case of a mode swich */ - void reload(); - - void resize(int widht, int height); -}; - -/** Surface implementation, all implementation have to inherit from - this class */ -class SurfaceImpl -{ -protected: - SDL_Surface* sdl_surface; - -public: - int w; - int h; - -public: - SurfaceImpl(); - virtual ~SurfaceImpl(); + SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha); + SDL_Surface* sdl_surface_from_nothing(); + + class SurfaceImpl; + class SurfaceSDL; + class SurfaceOpenGL; + class DrawingContext; - /** Return 0 on success, -2 if surface needs to be reloaded */ - virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; - virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + /// bitset for drawing effects + enum { + /** Don't apply anything */ + NONE_EFFECT = 0x0000, + /** Draw the Surface upside down */ + VERTICAL_FLIP = 0x0001, + /** Draw the Surface with alpha equal to 128 */ + SEMI_TRANSPARENT = 0x0002 + }; + + /** This class holds all the data necessary to construct a surface */ + class SurfaceData + { + public: + enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT }; + ConstructorType type; + SDL_Surface* surface; + std::string file; + bool use_alpha; + int x; + int y; + int w; + int h; + Color top_gradient; + Color bottom_gradient; + + SurfaceData(SDL_Surface* surf, bool use_alpha_); + SurfaceData(const std::string& file_, bool use_alpha_); + SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_); + SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_); + ~SurfaceData(); + + SurfaceSDL* create_SurfaceSDL(); + SurfaceOpenGL* create_SurfaceOpenGL(); + SurfaceImpl* create(); + }; + + + /// Surface + /** Container class that holds a surface, necessary so that we can + switch Surface implementations (OpenGL, SDL) on the fly */ + class Surface + { + public: + SurfaceData data; + SurfaceImpl* impl; + int w; + int h; + + typedef std::list Surfaces; + static Surfaces surfaces; + public: + static void reload_all(); + static void debug_check(); + + Surface(SDL_Surface* surf, bool use_alpha); + Surface(const std::string& file, bool use_alpha); + Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha); + Surface(Color top_gradient, Color bottom_gradient, int w_, int h_); + ~Surface(); + + /** Reload the surface, which is necesarry in case of a mode swich */ + void reload(); + + void resize(int widht, int height); + }; + + /** Surface implementation, all implementation have to inherit from + this class */ + class SurfaceImpl + { + protected: + SDL_Surface* sdl_surface; + + public: + int w; + int h; + + public: + SurfaceImpl(); + virtual ~SurfaceImpl(); + + /** Return 0 on success, -2 if surface needs to be reloaded */ + virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; #if 0 - virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; + + virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; #endif - int resize(int w_, int h_); - - SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function -}; - -class SurfaceSDL : public SurfaceImpl -{ -public: - SurfaceSDL(SDL_Surface* surf, bool use_alpha); - SurfaceSDL(const std::string& file, bool use_alpha); - SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha); - SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h); - virtual ~SurfaceSDL(); - - int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + + int resize(int w_, int h_); + + SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function + }; + + class SurfaceSDL : public SurfaceImpl + { + public: + SurfaceSDL(SDL_Surface* surf, bool use_alpha); + SurfaceSDL(const std::string& file, bool use_alpha); + SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha); + SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h); + virtual ~SurfaceSDL(); + + int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); #if 0 - int draw_stretched(float x, float y, int w, int h, Uint8 alpha); + + int draw_stretched(float x, float y, int w, int h, Uint8 alpha); #endif -}; + }; #ifndef NOOPENGL -class SurfaceOpenGL : public SurfaceImpl -{ -public: - GLuint gl_texture; + class SurfaceOpenGL : public SurfaceImpl + { + public: + GLuint gl_texture; -public: - SurfaceOpenGL(SDL_Surface* surf, bool use_alpha); - SurfaceOpenGL(const std::string& file, bool use_alpha); - SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha); - SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h); + public: + SurfaceOpenGL(SDL_Surface* surf, bool use_alpha); + SurfaceOpenGL(const std::string& file, bool use_alpha); + SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha); + SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h); - virtual ~SurfaceOpenGL(); + virtual ~SurfaceOpenGL(); - int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); #if 0 - int draw_stretched(float x, float y, int w, int h, Uint8 alpha); + + int draw_stretched(float x, float y, int w, int h, Uint8 alpha); +#endif + + private: + void create_gl(SDL_Surface * surf, GLuint * tex); + }; #endif -private: - void create_gl(SDL_Surface * surf, GLuint * tex); -}; -#endif +} //namespace SuperTux #endif /*SUPERTUX_TEXTURE_H*/ diff --git a/src/badguy.h b/src/badguy.h index 0db6b6160..6a01e5eff 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -35,6 +35,8 @@ #include "serializable.h" #include "scene.h" +using namespace SuperTux; + /* Timing constants (in ms): */ #define KICKING_TIME 200 diff --git a/src/camera.cpp b/src/camera.cpp index df856b86b..a4c5aba4f 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -29,6 +29,8 @@ #include "app/globals.h" #include "sector.h" +using namespace SuperTux; + Camera::Camera(Sector* newsector) : sector(newsector), do_backscrolling(true), scrollchange(NONE), auto_idx(0), auto_t(0) diff --git a/src/camera.h b/src/camera.h index 099e1642d..5af777eae 100644 --- a/src/camera.h +++ b/src/camera.h @@ -26,9 +26,15 @@ #include "app/defines.h" #include "math/vector.h" #include "special/game_object.h" +#include "video/drawing_context.h" #include "serializable.h" +using namespace SuperTux; + +namespace SuperTux { class LispReader; +} + class Sector; class Camera : public GameObject, public Serializable diff --git a/src/collision.h b/src/collision.h index cbbaeefa0..85b89d7bd 100644 --- a/src/collision.h +++ b/src/collision.h @@ -23,6 +23,8 @@ #include "special/base.h" +using namespace SuperTux; + class Tile; /* Collision objects */ diff --git a/src/door.cpp b/src/door.cpp index a749280be..4feec95d5 100644 --- a/src/door.cpp +++ b/src/door.cpp @@ -27,6 +27,8 @@ #include "video/drawing_context.h" #include "app/globals.h" +using namespace SuperTux; + /** data images */ Sprite* door; Surface* door_opening[DOOR_OPENING_FRAMES]; diff --git a/src/door.h b/src/door.h index 1c22907a4..50d013899 100644 --- a/src/door.h +++ b/src/door.h @@ -27,9 +27,10 @@ #include "serializable.h" #include "special/timer.h" +namespace SuperTux { class Sprite; - class LispReader; +} /** data images */ #define DOOR_OPENING_TIME 1500 diff --git a/src/gameloop.h b/src/gameloop.h index cf001209b..172c9fa05 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -26,6 +26,8 @@ #include "audio/sound.h" #include "special/base.h" +using namespace SuperTux; + /* GameLoop modes */ #define ST_GL_PLAY 0 @@ -34,7 +36,6 @@ #define ST_GL_LOAD_LEVEL_FILE 3 #define ST_GL_DEMO_GAME 4 - enum GameMenuIDs { MNID_CONTINUE, MNID_ABORTLEVEL @@ -44,7 +45,10 @@ extern int game_started; class Level; class Sector; + +namespace SuperTux { class DrawingContext; +} /** The GameSession class controlls the controll flow of a World, ie. present the menu on specifc keypresses, render and update it while diff --git a/src/gameobjs.h b/src/gameobjs.h index 23f99f351..fd89dfdc1 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -37,7 +37,9 @@ #define NO_BOUNCE 0 #define BOUNCE 1 +namespace SuperTux { class Sprite; +} struct TileId; diff --git a/src/high_scores.cpp b/src/high_scores.cpp index 73fc52899..4e1dceb3f 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -31,6 +31,9 @@ #include "video/surface.h" #include "app/setup.h" #include "utils/lispreader.h" +#include "resources.h" + +using namespace SuperTux; #ifdef WIN32 const char * highscore_filename = "/st_highscore.dat"; diff --git a/src/interactive_object.h b/src/interactive_object.h index 5f4e5bd3b..24aa86602 100644 --- a/src/interactive_object.h +++ b/src/interactive_object.h @@ -23,6 +23,8 @@ #include "special/game_object.h" #include "special/base.h" +using namespace SuperTux; + enum InteractionType { INTERACTION_TOUCH, INTERACTION_ACTIVATE // more to come diff --git a/src/intro.cpp b/src/intro.cpp index 62890b663..372b7f3eb 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -23,6 +23,8 @@ #include "video/font.h" #include "video/screen.h" +using namespace SuperTux; + void draw_intro() { display_text_file("intro.txt", 1); diff --git a/src/level.h b/src/level.h index 0068fbe1d..6f29434bc 100644 --- a/src/level.h +++ b/src/level.h @@ -24,8 +24,13 @@ #include #include +using namespace SuperTux; + class Sector; + +namespace SuperTux { class LispReader; +} class Level { diff --git a/src/level_subset.cpp b/src/level_subset.cpp index 5193c5157..fb530498c 100644 --- a/src/level_subset.cpp +++ b/src/level_subset.cpp @@ -25,6 +25,8 @@ #include "video/surface.h" #include "level_subset.h" +using namespace SuperTux; + static bool has_suffix(const std::string& data, const std::string& suffix) { if (data.length() >= suffix.length()) diff --git a/src/level_subset.h b/src/level_subset.h index d9a0fa815..b4f64f697 100644 --- a/src/level_subset.h +++ b/src/level_subset.h @@ -25,7 +25,11 @@ #include #include "utils/lispreader.h" +using namespace SuperTux; + +namespace SuperTux { class Surface; +}; /** This type holds meta-information about a level-subset. It could be extended to handle manipulation of subsets. */ diff --git a/src/misc.cpp b/src/misc.cpp index e07d46f65..1da2624ae 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -189,7 +189,18 @@ void st_menu(void) highscore_menu->additem(MN_TEXTFIELD,_("Enter your name:"),0,0); } +/* Free menus */ void st_menu_free() { delete worldmap_menu; + delete main_menu; + delete game_menu; + delete options_menu; + delete options_keys_menu; + delete options_joystick_menu; + delete highscore_menu; + delete contrib_menu; + delete contrib_subset_menu; + delete save_game_menu; + delete load_game_menu; } diff --git a/src/particlesystem.h b/src/particlesystem.h index 8ceecc439..d11c5c13d 100644 --- a/src/particlesystem.h +++ b/src/particlesystem.h @@ -26,7 +26,12 @@ #include "special/game_object.h" #include "serializable.h" +using namespace SuperTux; + +namespace SuperTux { class LispReader; +} + class DisplayManager; /** diff --git a/src/player.h b/src/player.h index 8ae05ae94..b2a40c1d1 100644 --- a/src/player.h +++ b/src/player.h @@ -32,6 +32,8 @@ #include "math/physic.h" #include "app/defines.h" +using namespace SuperTux; + class BadGuy; /* Times: */ @@ -86,7 +88,9 @@ struct player_input_type void player_input_init(player_input_type* pplayer_input); +namespace SuperTux { class Sprite; +} class Camera; extern Surface* tux_life; diff --git a/src/resources.cpp b/src/resources.cpp index aa3336e76..48eb42890 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -37,6 +37,17 @@ Surface* img_flag[2]; Surface* img_cloud[2][4]; Surface* img_distro[4]; +Menu* main_menu = 0; +Menu* game_menu = 0; +Menu* options_menu = 0; +Menu* options_keys_menu = 0; +Menu* options_joystick_menu = 0; +Menu* highscore_menu = 0; +Menu* load_game_menu = 0; +Menu* save_game_menu = 0; +Menu* contrib_menu = 0; +Menu* contrib_subset_menu = 0; + MusicRef herring_song; MusicRef level_end_song; diff --git a/src/resources.h b/src/resources.h index 18e4ecbb9..d57d57b9f 100644 --- a/src/resources.h +++ b/src/resources.h @@ -21,9 +21,14 @@ #define SUPERTUX_RESOURCES_H #include "audio/musicref.h" +#include "gui/menu.h" +using namespace SuperTux; + +namespace SuperTux { class SpriteManager; class SoundManager; +} /* Sound files: */ enum { @@ -66,6 +71,17 @@ extern MusicRef level_end_song; extern SpriteManager* sprite_manager; extern SoundManager* sound_manager; +extern Menu* contrib_menu; +extern Menu* contrib_subset_menu; +extern Menu* main_menu; +extern Menu* game_menu; +extern Menu* options_menu; +extern Menu* options_keys_menu; +extern Menu* options_joystick_menu; +extern Menu* highscore_menu; +extern Menu* load_game_menu; +extern Menu* save_game_menu; + void loadshared(); void unloadshared(); diff --git a/src/sector.h b/src/sector.h index bcfac4bc0..5d9822bfd 100644 --- a/src/sector.h +++ b/src/sector.h @@ -29,7 +29,13 @@ #include "audio/musicref.h" #include "video/drawing_context.h" +using namespace SuperTux; + +namespace SuperTux { class GameObject; +class LispReader; +} + class InteractiveObject; class Background; class Player; @@ -40,8 +46,6 @@ class TileMap; class Upgrade; class Bullet; class BadGuy; -class Vector; -class LispReader; class Tile; struct SpawnPoint diff --git a/src/serializable.h b/src/serializable.h index 9f1f69bfe..5590207e3 100644 --- a/src/serializable.h +++ b/src/serializable.h @@ -20,7 +20,11 @@ #ifndef SUPERTUX_SERIALIZABLE_H #define SUPERTUX_SERIALIZABLE_H +using namespace SuperTux; + +namespace SuperTux { class LispWriter; +} class Serializable { diff --git a/src/tile.h b/src/tile.h index 6af2fd22e..692bfe804 100644 --- a/src/tile.h +++ b/src/tile.h @@ -25,8 +25,11 @@ #include "SDL.h" #include "video/surface.h" -class Vector; +using namespace SuperTux; + +namespace SuperTux { class LispReader; +} /** Tile Class diff --git a/src/tilemap.h b/src/tilemap.h index 50a843e96..92d121dfc 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -26,9 +26,14 @@ #include "serializable.h" #include "math/vector.h" +using namespace SuperTux; + +namespace SuperTux { +class LispReader; +} + class Level; class TileManager; -class LispReader; class Tile; struct TileId -- 2.11.0