From 6d682d915eb92b08f2a92906a07d77f0749f0b6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sat, 24 Jul 2004 11:50:09 +0000 Subject: [PATCH] SuperTux lib became a bit more independend of SupeTux. SVN-Revision: 1619 --- lib/app/globals.cpp | 5 ++++- lib/app/globals.h | 5 ++++- lib/app/setup.cpp | 45 ++++++++++++++++++++++++--------------------- lib/app/setup.h | 7 ++++--- src/misc.cpp | 4 ++-- src/misc.h | 7 ++++++- src/supertux.cpp | 6 ++++-- 7 files changed, 48 insertions(+), 31 deletions(-) diff --git a/lib/app/globals.cpp b/lib/app/globals.cpp index de09e4b9a..cced05621 100644 --- a/lib/app/globals.cpp +++ b/lib/app/globals.cpp @@ -24,7 +24,10 @@ namespace SuperTux { /** The datadir prefix prepended when loading game data file */ std::string datadir; - +std::string package_symbol_name; +std::string package_name; +std::string package_version; + JoystickKeymap::JoystickKeymap() { a_button = 0; diff --git a/lib/app/globals.h b/lib/app/globals.h index 24950179b..0fb80b7d9 100644 --- a/lib/app/globals.h +++ b/lib/app/globals.h @@ -34,6 +34,9 @@ namespace SuperTux { extern std::string datadir; + extern std::string package_symbol_name; + extern std::string package_name; + extern std::string package_version; struct JoystickKeymap { @@ -77,7 +80,7 @@ namespace SuperTux /* 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; diff --git a/lib/app/setup.cpp b/lib/app/setup.cpp index 2daf4d962..50c88b645 100644 --- a/lib/app/setup.cpp +++ b/lib/app/setup.cpp @@ -60,11 +60,6 @@ using namespace SuperTux; #define DATA_PREFIX "./data/" #endif -/* Screen proprities: */ -/* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */ -#define SCREEN_W 800 -#define SCREEN_H 600 - /* Local function prototypes: */ void seticon(void); @@ -297,6 +292,13 @@ void SuperTux::free_strings(char **strings, int num) free(strings[i]); } +void SuperTux::st_info_setup(const std::string& _package_name, const std::string& _package_symbol_name, const std::string& _package_version) +{ +package_name = _package_name; +package_symbol_name = _package_symbol_name; +package_version = _package_version; +} + /* --- SETUP --- */ /* Set SuperTux configuration and save directories */ void SuperTux::st_directory_setup(void) @@ -310,10 +312,11 @@ void SuperTux::st_directory_setup(void) else home = "."; + std::string st_dir_tmp = "/." + package_symbol_name; st_dir = (char *) malloc(sizeof(char) * (strlen(home) + - strlen("/.supertux") + 1)); + strlen(st_dir_tmp.c_str()) + 1)); strcpy(st_dir, home); - strcat(st_dir, "/.supertux"); + strcat(st_dir,st_dir_tmp.c_str()); /* Remove .supertux config-file from old SuperTux versions */ if(faccessible(st_dir)) @@ -352,7 +355,7 @@ void SuperTux::st_directory_setup(void) datadir = exedir + "../data"; // SuperTux run from source dir if (access(datadir.c_str(), F_OK) != 0) { - datadir = exedir + "../share/supertux"; // SuperTux run from PATH + datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH if (access(datadir.c_str(), F_OK) != 0) { // If all fails, fall back to compiled path datadir = DATA_PREFIX; @@ -431,7 +434,7 @@ void SuperTux::st_general_free(void) } -void SuperTux::st_video_setup(void) +void SuperTux::st_video_setup(unsigned int screen_w, unsigned int screen_h) { /* Init SDL Video: */ if (SDL_Init(SDL_INIT_VIDEO) < 0) @@ -445,21 +448,21 @@ void SuperTux::st_video_setup(void) /* Open display: */ if(use_gl) - st_video_setup_gl(); + st_video_setup_gl(screen_w, screen_h); else - st_video_setup_sdl(); + st_video_setup_sdl(screen_w, screen_h); Surface::reload_all(); /* Set window manager stuff: */ - SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux"); + SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str()); } -void SuperTux::st_video_setup_sdl(void) +void SuperTux::st_video_setup_sdl(unsigned int screen_w, unsigned int screen_h) { if (use_fullscreen) { - screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */ + screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */ if (screen == NULL) { fprintf(stderr, @@ -472,7 +475,7 @@ void SuperTux::st_video_setup_sdl(void) } else { - screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_HWSURFACE | SDL_DOUBLEBUF ); + screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF ); if (screen == NULL) { @@ -485,7 +488,7 @@ void SuperTux::st_video_setup_sdl(void) } } -void SuperTux::st_video_setup_gl(void) +void SuperTux::st_video_setup_gl(unsigned int screen_w, unsigned int screen_h) { #ifndef NOOPENGL @@ -497,7 +500,7 @@ void SuperTux::st_video_setup_gl(void) if (use_fullscreen) { - screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */ + screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */ if (screen == NULL) { fprintf(stderr, @@ -510,7 +513,7 @@ void SuperTux::st_video_setup_gl(void) } else { - screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_OPENGL); + screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL); if (screen == NULL) { @@ -687,13 +690,13 @@ void seticon(void) /* Load icon into a surface: */ - icon = IMG_Load((datadir + "/images/supertux.xpm").c_str()); + icon = IMG_Load((datadir + "/images/" + package_symbol_name + ".xpm").c_str()); if (icon == NULL) { fprintf(stderr, "\nError: I could not load the icon image: %s%s\n" "The Simple DirectMedia error that occured was:\n" - "%s\n\n", datadir.c_str(), "/images/supertux.xpm", SDL_GetError()); + "%s\n\n", datadir.c_str(), ("/images/" + package_symbol_name + ".xpm").c_str(), SDL_GetError()); exit(1); } @@ -809,7 +812,7 @@ void SuperTux::parseargs(int argc, char * argv[]) else if (strcmp(argv[i], "--version") == 0) { /* Show version: */ - printf("SuperTux " VERSION "\n"); + printf((package_name + package_version + "\n").c_str() ); exit(0); } else if (strcmp(argv[i], "--disable-sound") == 0) diff --git a/lib/app/setup.h b/lib/app/setup.h index 3447f05f7..86fcfbe18 100644 --- a/lib/app/setup.h +++ b/lib/app/setup.h @@ -37,12 +37,13 @@ FILE * opendata(const char * filename, const char * mode); string_list_type dsubdirs(const char *rel_path, const char* expected_file); string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str); void free_strings(char **strings, int num); +void st_info_setup(const std::string& _package_name, const std::string& _package_symbol_name, const std::string& _package_version); void st_directory_setup(void); void st_general_setup(void); void st_general_free(); -void st_video_setup_sdl(void); -void st_video_setup_gl(void); -void st_video_setup(void); +void st_video_setup_sdl(unsigned int screen_w, unsigned int screen_h); +void st_video_setup_gl(unsigned int screen_w, unsigned int screen_h); +void st_video_setup(unsigned int screen_w, unsigned int screen_h); void st_audio_setup(void); void st_joystick_setup(void); void st_shutdown(void); diff --git a/src/misc.cpp b/src/misc.cpp index 1da2624ae..6ff02567f 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -46,7 +46,7 @@ void process_options_menu(void) if(use_gl != options_menu->isToggled(MNID_OPENGL)) { use_gl = !use_gl; - st_video_setup(); + st_video_setup(screen->w,screen->h); } #else options_menu->get_item_by_id(MNID_OPENGL).toggled = false; @@ -56,7 +56,7 @@ void process_options_menu(void) if(use_fullscreen != options_menu->isToggled(MNID_FULLSCREEN)) { use_fullscreen = !use_fullscreen; - st_video_setup(); + st_video_setup(screen->w,screen->h); } break; case MNID_SOUND: diff --git a/src/misc.h b/src/misc.h index 0fba8c792..c95cb9151 100644 --- a/src/misc.h +++ b/src/misc.h @@ -43,7 +43,12 @@ enum OptionsMenuIDs { MNID_MUSIC, MNID_SHOWFPS }; - + +/* Screen proprities: */ +/* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */ +#define SCREEN_W 800 +#define SCREEN_H 600 + /* Handle changes made to global settings in the options menu. */ void process_options_menu(void); diff --git a/src/supertux.cpp b/src/supertux.cpp index 3181f3204..01f15f820 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -51,12 +51,14 @@ int main(int argc, char * argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); bind_textdomain_codeset(PACKAGE, "ISO-8859-1"); - + + st_info_setup(PACKAGE_NAME,PACKAGE,PACKAGE_VERSION); + st_directory_setup(); parseargs(argc, argv); st_audio_setup(); - st_video_setup(); + st_video_setup(SCREEN_W,SCREEN_H); st_joystick_setup(); st_general_setup(); st_menu(); -- 2.11.0