From: Matthias Braun Date: Sun, 1 May 2005 19:02:16 +0000 (+0000) Subject: -Started to move stuff from library back to main game X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git -Started to move stuff from library back to main game -Refactored game initialisation code -Improved config loading/saving -Refactored input code into a Controller class -Simplified all these SDL_PollEvent loops through the source -Refactores Menu class (still not optimal) -General refactoring -Added missing GPL headers to files -removed scons build system for now SVN-Revision: 2379 --- diff --git a/Jamrules b/Jamrules index b07ecd4b9..5a51ca184 100644 --- a/Jamrules +++ b/Jamrules @@ -13,22 +13,28 @@ if ! $(JAMCONFIG_READ) if $(USE_STLPORT_DEBUG) { - CPPFLAGS += -I/usr/include/stlport ; - CPPFLAGS += -D_STLP_DEBUG=1 -D_STLP_DEBUG_UNINITIALIZED=1 ; - CPPFLAGS += -D_STLP_SHRED_BYTE=0xA3 ; + CXXFLAGS += -I/usr/include/stlport ; + CXXFLAGS += -D_STLP_DEBUG=1 -D_STLP_DEBUG_UNINITIALIZED=1 ; + CXXFLAGS += -D_STLP_SHRED_BYTE=0xA3 ; LIBS += -lstlport_gcc_debug ; } -COMPILER_CFLAGS += -Wall -W ; -COMPILER_CFLAGS_optimize += -O3 -g3 ; -COMPILER_C++FLAGS_optimize += -O3 -g3 ; -COMPILER_LFLAGS_optimize += -O3 -g3 ; -COMPILER_CFLAGS_debug += -DDEBUG -Werror -g3 ; -COMPILER_CXXFLAGS_debug += -DDEBUG -Werror -g3 ; -COMPILER_LFLAGS_debug += -g3 ; -COMPILER_CFLAGS_profile += -O2 -g3 -pg ; -COMPILER_CXXFLAGS_profile += -O2 -g3 -pg ; -COMPILER_LFLAGS_profile += -g3 -pg ; +switch $(VARIANT) { + case optimize : + CFLAGS += -O3 -g ; + CXXFLAGS += -O3 -g ; + LIBS += -g ; + case debug : + CFLAGS += -O0 -g3 -DDEBUG ; + CXXFLAGS += -O0 -g3 -DDEBUG ; + LIBS += -g3 ; + case profile : + CFLAGS += -O3 -g3 -pg ; + CXXFLAGS += -O3 -g3 -pg ; + LIBS += -g3 -pg ; + case * : + EXIT "Invalid variant $(VARIANT) selected" ; +} LINK = $(CXX) ; diff --git a/SConscript b/SConscript deleted file mode 100644 index 0347e234e..000000000 --- a/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -# needed so that scons -U works correctly -Default(".") - diff --git a/SConstruct b/SConstruct deleted file mode 100644 index 2f6ed8c1b..000000000 --- a/SConstruct +++ /dev/null @@ -1,191 +0,0 @@ -# -# SConstruct build file. See http://www.scons.org for details. -import os -import glob - -class ConfigHeader: - def __init__(self): - self.defines = { } - self.prefix = "" - self.postfix = "" - - def SetPrefix(self, prefix): - self.prefix = prefix - - def SetPostfix(self, postfix): - self.postfix = postfix - - def Define(self, name, value = ""): - self.defines[name] = value - - def Save(self, filename): - file = open(filename, 'w') - file.write("/* %s. Generated by SConstruct */\n" % (filename)) - file.write("\n") - file.write(self.prefix + "\n") - for key, value in self.defines.iteritems(): - file.write("#define %s \"%s\"\n" % (key, value)) - file.write(self.postfix + "\n") - file.close() - -def Glob(pattern): - path = GetBuildPath('SConscript').replace('SConscript', '') - - result = [] - for i in glob.glob(path + pattern): - result.append(i.replace(path, '')) - - return result - -def InstallData(files): - for file in files: - dir = os.path.dirname(file) - destdir = os.path.join(env.subst('$DESTDIR/$APPDATADIR'), dir) - env.Install(destdir, file) - -def InstallExec(files): - for file in files: - destfile = env.subst('$DESTDIR/$BINDIR/$PROGRAM_PREFIX') + file + \ - env.subst('$PROGRAM_POSTFIX') - env.InstallAs(destfile, file) - -# thanks to Michael P Jung -def CheckSDLConfig(context, minVersion): - context.Message('Checking for sdl-config >= %s... ' % minVersion) - from popen2 import Popen3 - p = Popen3(['sdl-config', '--version']) - ret = p.wait() - out = p.fromchild.readlines() - if ret != 0: - context.Result(False) - return False - if len(out) != 1: - # unable to parse output! - context.Result(False) - return False - # TODO validate output and catch exceptions - version = map(int, out[0].strip().split('.')) - minVersion = map(int, minVersion.split('.')) - # TODO comparing versions that way only works for pure numeric version - # numbers and fails for custom extensions. I don't care about this at - # the moment as sdl-config never used such version numbers afaik. - ret = (version >= minVersion) - context.Result(ret) - return ret - -# User configurable options -opts = Options('build_config.py') -opts.Add('CXX', 'The C++ compiler', 'g++') -opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '') -opts.Add('CPPPATH', 'Additional preprocessor paths', '') -opts.Add('CPPFLAGS', 'Additional preprocessor flags', '') -opts.Add('CPPDEFINES', 'defined constants', '') -opts.Add('LIBPATH', 'Additional library paths', '') -opts.Add('LIBS', 'Additional libraries', '') - -# installation path options -opts.Add('PREFIX', 'prefix for architecture-independent files', '/usr/local') -opts.Add('EPREFIX', 'prefix for architecture-dependent files', '$PREFIX') -opts.Add('BINDIR', 'user executables directory', '$EPREFIX/bin') -#opts.Add('SBINDIR', 'system admin executables directory', '$EPREFIX/sbin') -#opts.Add('LIBEXECDIR', 'program executables directory', '$EPREFIX/libexec') -opts.Add('DATADIR', 'read-only architecture-independent data directory', - '$PREFIX/share') -#opts.Add('SYSCONFDIR', 'read-only single-machine data directory', '$PREFIX/etc') -#opts.Add('SHAREDSTATEDIR', 'modifiable architecture-independent data directory', -# '$PREFIX/com') -#opts.Add('LOCALSTATEDIR', 'modifiable single-machine data directory', -# '$PREFIX/var') -opts.Add('LIBDIR', 'object code libraries directory', '$EPREFIX/lib') -opts.Add('INCLUDEDIR', 'C header files directory', '$PREFIX/include') -#opts.Add('OLDINCLUDEDIR', 'C header files for non-gcc directory', -# '$PREFIX/include') -#opts.Add('INFODIR', 'info documentation directory', '$PREFIX/info') -#opts.Add('MANDIR', 'man documentation directory', '$PREFIX/man') -opts.Add('DESTDIR', \ - 'destination directory for installation. It is prepended to PREFIX', '') - -# misc options -opts.Add('PROGRAM_PREFIX', 'prepend PREFIX to installed program names', '') -opts.Add('PROGRAM_SUFFIX', 'append SUFFIX to installed program names', '') -opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize', - ['optimize', 'debug', 'profile'])) - -env = Environment(options = opts) -Help(opts.GenerateHelpText(env)) - -# Package options -env['PACKAGE_NAME'] = 'SuperTux' -env['PACKAGE_VERSION'] = '0.2-cvs' -env['PACKAGE_BUGREPORT'] = 'supertux-devel@lists.berlios.de' -env['PACKAGE'] = env['PACKAGE_NAME'].lower() -env['PACKAGE_STRING'] = env['PACKAGE_NAME'] + " " + env['PACKAGE_VERSION'] - -# directories -env['APPDATADIR'] = "$DATADIR/$PACKAGE" -env['LOCALEDIR'] = "$DATADIR/locale" - - -# Create build_config.py and config.h -if not os.path.exists("build_config.py") or not os.path.exists("config.h"): - print "build_config.py or config.h don't exist - Generating new build config..." - - header = ConfigHeader() - header.Define("PACKAGE", env['PACKAGE']) - header.Define("PACKAGE_NAME", env['PACKAGE_NAME']) - header.Define("PACKAGE_VERSION", env['PACKAGE_VERSION']) - header.Define("PACKAGE_BUGREPORT", env['PACKAGE_BUGREPORT']) - header.Define("PACKAGE_STRING", env['PACKAGE_STRING']) - - conf = Configure(env, custom_tests = { - 'CheckSDLConfig' : CheckSDLConfig - }) - if not conf.CheckSDLConfig('1.2.4'): - print "Couldn't find libSDL >= 1.2.4" - Exit(1) - if not conf.CheckLib('SDL_mixer'): - print "Couldn't find SDL_mixer library!" - Exit(1) - if not conf.CheckLib('SDL_image'): - print "Couldn't find SDL_image library!" - Exit(1) - if not conf.CheckLib('GL'): - print "Couldn't find OpenGL library!" - Exit(1) - - env = conf.Finish() - - env.ParseConfig('sdl-config --cflags --libs') - env.Append(CPPDEFINES = \ - {'DATA_PREFIX':"'\"" + env.subst('$APPDATADIR') + "\"'" , - 'LOCALEDIR' :"'\"" + env.subst('$LOCALEDIR') + "\"'"}) - opts.Save("build_config.py", env) - header.Save("config.h") -else: - print "Using build_config.py" - -if env['VARIANT'] == "optimize": - env.Append(CXXFLAGS = "-O2 -g -Wall") -elif env['VARIANT'] == "debug": - env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror") - env.Append(CPPDEFINES = { "DEBUG":"1" }) -elif env['VARIANT'] == "profile": - env.Append(CXXFLAGS = "-pg -O2") - -build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT'] - -# create some install aliases (only add paths here that are really used) -env.Alias('install-data', env.subst('$DESTDIR/$APPDATADIR')) -env.Alias('install-exec', env.subst('$DESTDIR/$BINDIR')) -env.Alias('install', ['install-data', 'install-exec']) - -# append some include dirs and link libsupertux with main app -env.Append(CPPPATH = ["#", "#/src", "#/lib"]) -env.Append(LIBS = ["supertux"]) -env.Append(LIBPATH=["#" + build_dir + "/lib"]) - -env.Export(["env", "Glob", "InstallData", "InstallExec"]) -env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0) -env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0) -env.SConscript("data/SConscript", build_dir=build_dir + "/data", duplicate=0) -env.SConscript("SConscript", build_dir=build_dir, duplicate=0) diff --git a/data/SConscript b/data/SConscript deleted file mode 100644 index 31b8d6b1b..000000000 --- a/data/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -import os -Import('*') - -if 'install' in BUILD_TARGETS: - patterns = ["*.txt", "levels/*/*.stl", "levels/*/*.stwm", "levelts/*/info", - "sounds/*.wav", "music/*.mod", "music/*.ogg", - "images/*/*.jpg", "images/*/*.png", "images/*/*/*.png", - "images/*.xpm", "images/*.png", "images/*.strf", - "images/tilesets/*.stgt"] - - files = [] - for pattern in patterns: - files = files + Glob(pattern) - - InstallData(files) diff --git a/data/images/tilesets/supertux.stgt b/data/images/tilesets/supertux.stgt index acf765093..61abe0402 100644 --- a/data/images/tilesets/supertux.stgt +++ b/data/images/tilesets/supertux.stgt @@ -360,7 +360,7 @@ "coin-7.png" "coin-8.png" ) - (distro #t) + (coin #t) (anim-fps 10) ) (tile @@ -620,7 +620,7 @@ "coin3.png" "coin2.png" ) - (distro #t) + (coin #t) (anim-fps 10) ) (tile diff --git a/lib/Jamfile b/lib/Jamfile index 6f259715a..3d8038300 100644 --- a/lib/Jamfile +++ b/lib/Jamfile @@ -10,7 +10,7 @@ sources = [ Wildcard video : *.cpp *.h ] [ Wildcard lisp : *.cpp *.h ] ; -TRANSLATABLE_SOURCES += [ DoSourceGrist $(sources) ] ; +TRANSLATABLE_SOURCES += [ SearchSource $(sources) ] ; Library supertuxlib : $(sources) : noinstall ; ExternalLibs supertuxlib : SDL SDLMIXER SDLIMAGE GL ; diff --git a/lib/SConscript b/lib/SConscript deleted file mode 100644 index 0f7c963fa..000000000 --- a/lib/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('*') - -libsupertux_src = Glob("app/*.cpp") \ - + Glob("audio/*.cpp") \ - + Glob("gui/*.cpp") \ - + Glob("math/*.cpp") \ - + Glob("special/*.cpp") \ - + Glob("utils/*.cpp") \ - + Glob("video/*.cpp") \ - + Glob("lisp/*.cpp") - -lib = env.Library( - target="supertux", - source=libsupertux_src -) -Default(lib) - diff --git a/lib/app/globals.cpp b/lib/app/globals.cpp index 35ae5d0e4..53277787a 100644 --- a/lib/app/globals.cpp +++ b/lib/app/globals.cpp @@ -54,21 +54,16 @@ JoystickKeymap joystick_keymap; SDL_Surface * screen; MouseCursor * mouse_cursor; -bool use_gl; -bool use_joystick; -bool use_fullscreen; -bool debug_mode; -bool show_fps; -bool debug_grid = false; - +#if 0 int joystick_num = 0; char* level_startup_file = 0; bool launch_leveleditor_mode = false; bool launch_worldmap_mode = false; bool flip_levels_mode = false; +#endif /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ -std::string st_dir, st_save_dir; +std::string user_dir; SDL_Joystick * js; diff --git a/lib/app/globals.h b/lib/app/globals.h index edc641627..850707d73 100644 --- a/lib/app/globals.h +++ b/lib/app/globals.h @@ -38,9 +38,6 @@ namespace SuperTux class MouseCursor; extern std::string datadir; - extern std::string package_symbol_name; - extern std::string package_name; - extern std::string package_version; struct JoystickKeymap { @@ -58,32 +55,16 @@ namespace SuperTux extern JoystickKeymap joystick_keymap; - extern SDL_Surface* screen; - extern MouseCursor * mouse_cursor; #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 - extern bool use_gl; - extern bool use_joystick; - extern bool use_fullscreen; - extern int screen_width; - extern int screen_height; - extern bool debug_mode; - extern bool show_fps; - extern bool debug_grid; - /** 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; - extern bool flip_levels_mode; - - /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ - extern std::string st_dir; - extern std::string st_save_dir; + + /* SuperTux directory ($HOME/.supertux) */ + extern std::string user_dir; extern SDL_Joystick * js; diff --git a/lib/app/setup.cpp b/lib/app/setup.cpp index 9fbe18f5c..4362c17a3 100644 --- a/lib/app/setup.cpp +++ b/lib/app/setup.cpp @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - #include #include @@ -28,12 +27,6 @@ #include #include -#include "SDL.h" -#include "SDL_image.h" -#ifndef NOOPENGL -#include "SDL_opengl.h" -#endif - #include #include #include @@ -45,27 +38,13 @@ #include "globals.h" #include "setup.h" -#include "video/screen.h" -#include "video/surface.h" -#include "gui/menu.h" -#include "utils/configfile.h" -#include "audio/sound_manager.h" -#include "gettext.h" using namespace SuperTux; #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) -// on win32 we typically don't want LFS paths -#undef DATA_PREFIX -#define DATA_PREFIX "./data/" #endif -/* Local function prototypes: */ - -void seticon(void); -void usage(char * prog, int ret); - /* Does the given file exist and is it accessible? */ bool FileSystem::faccessible(const std::string& filename) { @@ -99,7 +78,7 @@ bool FileSystem::fwriteable(const std::string& filename) /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/ bool FileSystem::fcreatedir(const std::string& relative_dir) { - std::string path = st_dir + "/" + relative_dir + "/"; + std::string path = user_dir + "/" + relative_dir + "/"; if(mkdir(path.c_str(),0755) != 0) { path = datadir + "/" + relative_dir + "/"; @@ -127,7 +106,7 @@ std::set FileSystem::dsubdirs(const std::string &rel_path,const st struct dirent *direntp; std::set sdirs; std::string filename; - std::string path = st_dir + "/" + rel_path; + std::string path = user_dir + "/" + rel_path; if((dirStructP = opendir(path.c_str())) != NULL) { @@ -174,7 +153,7 @@ std::set FileSystem::dsubdirs(const std::string &rel_path,const st } else { - filename = st_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file; + filename = user_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file; if(faccessible(filename.c_str())) continue; } @@ -194,7 +173,7 @@ std::set FileSystem::dfiles(const std::string& rel_path, const std DIR *dirStructP; struct dirent *direntp; std::set sdirs; - std::string path = st_dir + "/" + rel_path; + std::string path = user_dir + "/" + rel_path; if((dirStructP = opendir(path.c_str())) != NULL) { @@ -261,618 +240,6 @@ std::string FileSystem::dirname(const std::string& filename) return filename.substr(0, p+1); } -void Setup::init(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; - - directories(); - dictionary_manager.add_directory(datadir + "/locale"); - dictionary_manager.set_charset("iso8859-1"); -} - -/* --- SETUP --- */ -/* Set SuperTux configuration and save directories */ -void Setup::directories() -{ - std::string home; - /* Get home directory (from $HOME variable)... if we can't determine it, - use the current directory ("."): */ - if (getenv("HOME") != NULL) - home = getenv("HOME"); - else - home = "."; - - st_dir = home + "/." + package_symbol_name; - - /* Remove .supertux config-file from old SuperTux versions */ - if(FileSystem::faccessible(st_dir)) { - remove(st_dir.c_str()); - } - - st_save_dir = st_dir + "/save"; - - /* Create them. In the case they exist they won't destroy anything. */ - mkdir(st_dir.c_str(), 0755); - mkdir(st_save_dir.c_str(), 0755); - - mkdir((st_dir + "/levels").c_str(), 0755); - - // try current directory as datadir - if(datadir.empty()) { - if(FileSystem::faccessible("./data/credits.txt")) - datadir = "./data/"; - } - - // User has not that a datadir, so we try some magic - if (datadir.empty()) - { -#ifndef WIN32 - // Detect datadir - char exe_file[PATH_MAX]; - if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0) - { - puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX); - datadir = DATA_PREFIX; - } - else - { - std::string exedir = std::string(dirname(exe_file)) + "/"; - - datadir = exedir + "./data/"; // SuperTux run from source dir - if (access(datadir.c_str(), F_OK) != 0) - { - datadir = exedir + "../../../../data/"; //SuperTux run from source dir (with libtool script) - - if (access(datadir.c_str(), F_OK) != 0) - { - 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; - datadir += "/"; - } - } - } - } -#else - datadir = DATA_PREFIX; - datadir += "/"; -#endif - } - printf("Datadir: %s\n", datadir.c_str()); -} - -void Setup::general(void) -{ - /* Seed random number generator: */ - - srand(SDL_GetTicks()); - - /* Set icon image: */ - - seticon(); - - /* Unicode needed for input handling: */ - - SDL_EnableUNICODE(1); - - /* Load GUI/menu images: */ - checkbox = new Surface(datadir + "/images/status/checkbox.png", true); - checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true); - back = new Surface(datadir + "/images/status/back.png", true); - arrow_left = new Surface(datadir + "/images/icons/left.png", true); - arrow_right = new Surface(datadir + "/images/icons/right.png", true); - - /* Load the mouse-cursor */ - mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1); - MouseCursor::set_current(mouse_cursor); - -} - -void Setup::general_free(void) -{ - - /* Free GUI/menu images: */ - delete checkbox; - delete checkbox_checked; - delete back; - delete arrow_left; - delete arrow_right; - - /* Free mouse-cursor */ - delete mouse_cursor; - -} - -void Setup::video(unsigned int screen_w, unsigned int screen_h) -{ - /* Init SDL Video: */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) - { - fprintf(stderr, - "\nError: I could not initialize video!\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - exit(1); - } - - /* Open display: */ - if(use_gl) - video_gl(screen_w, screen_h); - else - video_sdl(screen_w, screen_h); - - Surface::reload_all(); - - /* Set window manager stuff: */ - SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str()); -} - -void Setup::video_sdl(unsigned int screen_w, unsigned int screen_h) -{ - if (use_fullscreen) - { - screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */ - if (screen == NULL) - { - fprintf(stderr, - "\nWarning: I could not set up fullscreen video for " - "800x600 mode.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - use_fullscreen = false; - } - } - else - { - screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF ); - - if (screen == NULL) - { - fprintf(stderr, - "\nError: I could not set up video for 800x600 mode.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - exit(1); - } - } -} - -void Setup::video_gl(unsigned int screen_w, unsigned int screen_h) -{ -#ifndef NOOPENGL - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - if (use_fullscreen) - { - screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */ - if (screen == NULL) - { - fprintf(stderr, - "\nWarning: I could not set up fullscreen video for " - "640x480 mode.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - use_fullscreen = false; - } - } - else - { - screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL); - - if (screen == NULL) - { - fprintf(stderr, - "\nError: I could not set up video for 640x480 mode.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - exit(1); - } - } - - /* - * Set up OpenGL for 2D rendering. - */ - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - - glViewport(0, 0, screen->w, screen->h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, 800, 600, 0, -1.0, 1.0); - //glOrtho(0, 800SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, 0.0f); - -#endif - -} - -void Setup::joystick(void) -{ - - /* Init Joystick: */ - - use_joystick = true; - - if (SDL_Init(SDL_INIT_JOYSTICK) < 0) - { - fprintf(stderr, "Warning: I could not initialize joystick!\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - - use_joystick = false; - } - else - { - /* Open joystick: */ - if (SDL_NumJoysticks() <= 0) - { - fprintf(stderr, "Info: No joysticks were found.\n"); - - use_joystick = false; - } - else - { - js = SDL_JoystickOpen(joystick_num); - - if (js == NULL) - { - fprintf(stderr, "Warning: Could not open joystick %d.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", joystick_num, SDL_GetError()); - - use_joystick = false; - } - else - { - if (SDL_JoystickNumAxes(js) < 2) - { - fprintf(stderr, - "Warning: Joystick does not have enough axes!\n"); - - use_joystick = false; - } - else - { - if (SDL_JoystickNumButtons(js) < 2) - { - fprintf(stderr, - "Warning: " - "Joystick does not have enough buttons!\n"); - - use_joystick = false; - } - } - } - } - } -} - -void Setup::audio(void) -{ - - /* Init SDL Audio silently even if --disable-sound : */ - - if (SoundManager::get()->audio_device_available()) - { - if (SDL_Init(SDL_INIT_AUDIO) < 0) - { - /* only print out message if sound or music - was not disabled at command-line - */ - if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled()) - { - fprintf(stderr, - "\nWarning: I could not initialize audio!\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - } - /* keep the programming logic the same :-) - because in this case, use_sound & use_music' values are ignored - when there's no available audio device - */ - SoundManager::get()->enable_sound(false); - SoundManager::get()->enable_music(false); - SoundManager::get()->set_audio_device_available(false); - } - } - - - /* Open sound silently regarless the value of "use_sound": */ - - if (SoundManager::get()->audio_device_available()) - { - if (SoundManager::get()->open_audio(44100, AUDIO_S16, 2, 2048) < 0) - { - /* only print out message if sound or music - was not disabled at command-line - */ - if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled()) - { - fprintf(stderr, - "\nWarning: I could not set up audio for 44100 Hz " - "16-bit stereo.\n" - "The Simple DirectMedia error that occured was:\n" - "%s\n\n", SDL_GetError()); - } - SoundManager::get()->enable_sound(false); - SoundManager::get()->enable_music(false); - SoundManager::get()->set_audio_device_available(false); - } - } - -} - - -/* --- SHUTDOWN --- */ - -void Termination::shutdown(void) -{ - config->save(); - SoundManager::get()->close_audio(); - SDL_Quit(); -} - -/* --- ABORT! --- */ - -void Termination::abort(const std::string& reason, const std::string& details) -{ - fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str()); - shutdown(); - ::abort(); -} - -/* Set Icon (private) */ - -void seticon(void) -{ -// int masklen; -// Uint8 * mask; - SDL_Surface * icon; - - - /* Load icon into a surface: */ - - 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/" + package_symbol_name + ".xpm").c_str(), SDL_GetError()); - exit(1); - } - - - /* Create mask: */ -/* - masklen = (((icon -> w) + 7) / 8) * (icon -> h); - mask = (Uint8*) malloc(masklen * sizeof(Uint8)); - memset(mask, 0xFF, masklen); -*/ - - /* Set icon: */ - - SDL_WM_SetIcon(icon, NULL);//mask); - - - /* Free icon surface & mask: */ - -// free(mask); - SDL_FreeSurface(icon); -} - - -/* Parse command-line arguments: */ - -void Setup::parseargs(int argc, char * argv[]) -{ - int i; - - config->load(); - - /* Parse arguments: */ - - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "--fullscreen") == 0 || - strcmp(argv[i], "-f") == 0) - { - use_fullscreen = true; - } - else if (strcmp(argv[i], "--window") == 0 || - strcmp(argv[i], "-w") == 0) - { - use_fullscreen = false; - } - else if (strcmp(argv[i], "--geometry") == 0 || - strcmp(argv[i], "-g") == 0) - { - assert(i+1 < argc); - if (sscanf(argv[++i], - "%dx%d", &screen_width, &screen_height) != 2) - { - puts("Warning: Invalid geometry spec, should be \"WIDTHxHEIGHT\""); - } - } - else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0) - { - assert(i+1 < argc); - joystick_num = atoi(argv[++i]); - } - else if (strcmp(argv[i], "--joymap") == 0) - { - assert(i+1 < argc); - if (sscanf(argv[++i], - "%d:%d:%d:%d:%d", - &joystick_keymap.x_axis, - &joystick_keymap.y_axis, - &joystick_keymap.a_button, - &joystick_keymap.b_button, - &joystick_keymap.start_button) != 5) - { - puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'"); - } - else - { - std::cout << "Using new joymap:\n" - << " X-Axis: " << joystick_keymap.x_axis << "\n" - << " Y-Axis: " << joystick_keymap.y_axis << "\n" - << " A-Button: " << joystick_keymap.a_button << "\n" - << " B-Button: " << joystick_keymap.b_button << "\n" - << " Start-Button: " << joystick_keymap.start_button << std::endl; - } - } - else if (strcmp(argv[i], "--leveleditor") == 0) - { - launch_leveleditor_mode = true; - } - else if (strcmp(argv[i], "--worldmap") == 0) - { - launch_worldmap_mode = true; - } - else if (strcmp(argv[i], "--flip-levels") == 0) - { - flip_levels_mode = true; - } - else if (strcmp(argv[i], "--datadir") == 0 - || strcmp(argv[i], "-d") == 0 ) - { - assert(i+1 < argc); - datadir = argv[++i]; - } - else if (strcmp(argv[i], "--show-fps") == 0) - { - /* Use full screen: */ - show_fps = true; - } - else if (strcmp(argv[i], "--opengl") == 0 || - strcmp(argv[i], "-gl") == 0) - { -#ifndef NOOPENGL - /* Use OpengGL: */ - use_gl = true; -#endif - } - else if (strcmp(argv[i], "--sdl") == 0) - { - use_gl = false; - } - else if (strcmp(argv[i], "--usage") == 0) - { - /* Show usage: */ - usage(argv[0], 0); - } - else if (strcmp(argv[i], "--version") == 0) - { - /* Show version: */ - printf((package_name + " " + package_version + "\n").c_str() ); - exit(0); - } - else if (strcmp(argv[i], "--disable-sound") == 0) - { - /* Disable the compiled in sound feature */ - printf("Sounds disabled \n"); - SoundManager::get()->enable_sound(false); - } - else if (strcmp(argv[i], "--disable-music") == 0) - { - /* Disable the compiled in sound feature */ - printf("Music disabled \n"); - SoundManager::get()->enable_music(false); - } - else if (strcmp(argv[i], "--debug") == 0) - { - /* Enable the debug-mode */ - debug_mode = true; - - } - else if (strcmp(argv[i], "--help") == 0) - { /* Show help: */ - puts(_((" SuperTux " + package_version + "\n" - " Please see the file \"README.txt\" for more details.\n").c_str())); - printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]); - puts(_("Display Options:\n" - " -f, --fullscreen Run in fullscreen mode.\n" - " -w, --window Run in window mode.\n" - " --opengl If OpenGL support was compiled in, this will tell\n" - " SuperTux to make use of it.\n" - " --sdl Use the SDL software graphical renderer\n" - " --geometry WIDTHxHEIGHT Run SuperTux in the given resolution\n" - "\n" - "Sound Options:\n" - " --disable-sound If sound support was compiled in, this will\n" - " disable sound for this session of the game.\n" - " --disable-music Like above, but this will disable music.\n" - "\n" - "Misc Options:\n" - " -j, --joystick NUM Use joystick NUM (default: 0)\n" - " --joymap XAXIS:YAXIS:A:B:START\n" - " Define how joystick buttons and axis should be mapped\n" - " --leveleditor Opens the leveleditor in a file.\n" - " --worldmap Opens the specified worldmap file.\n" - " --flip-levels Flip levels upside-down.\n" - " -d, --datadir DIR Load Game data from DIR (default: automatic)\n" - " --debug Enables the debug mode, which is useful for developers.\n" - " --help Display a help message summarizing command-line\n" - " options, license and game controls.\n" - " --usage Display a brief message summarizing command-line options.\n" - " --version Display the version of SuperTux you're running.\n\n" - )); - exit(0); - } - else if (argv[i][0] != '-') - { - level_startup_file = argv[i]; - } - else - { - /* Unknown - complain! */ - - usage(argv[0], 1); - } - } -} - - -/* Display usage: */ - -void usage(char * prog, int ret) -{ - FILE * fi; - - - /* Determine which stream to write to: */ - - if (ret == 0) - fi = stdout; - else - fi = stderr; - - - /* Display the usage message: */ - - fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--geometry WIDTHxHEIGHT] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] [--flip-levels] FILENAME\n"), - prog); - - - /* Quit! */ - - exit(ret); -} - std::set FileSystem::read_directory(const std::string& pathname) { std::set dirnames; @@ -892,5 +259,3 @@ std::set FileSystem::read_directory(const std::string& pathname) return dirnames; } - -/* EOF */ diff --git a/lib/app/setup.h b/lib/app/setup.h index ad70bd4d8..98e947f8a 100644 --- a/lib/app/setup.h +++ b/lib/app/setup.h @@ -39,30 +39,6 @@ struct FileSystem static std::string dirname(const std::string& filename); }; -/// All you need to get an application up and running -struct Setup - { - static void init(const std::string& _package_name, const std::string& _package_symbol_name, const std::string& _package_version); - static void directories(void); - static void general(void); - static void general_free(); - static void video(unsigned int screen_w, unsigned int screen_h); - static void audio(void); - static void joystick(void); - static void parseargs(int argc, char * argv[]); - - private: - static void video_sdl(unsigned int screen_w, unsigned int screen_h); - static void video_gl(unsigned int screen_w, unsigned int screen_h); - }; - -/// Termination handling -struct Termination - { - static void shutdown(void); - static void abort(const std::string& reason, const std::string& details); - }; - } //namespace SuperTux #endif /*SUPERTUX_SETUP_H*/ diff --git a/lib/app/tinygettext.cpp b/lib/app/tinygettext.cpp index 91c29b720..dd73e8028 100644 --- a/lib/app/tinygettext.cpp +++ b/lib/app/tinygettext.cpp @@ -42,24 +42,25 @@ std::string convert(const std::string& text, iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str()); size_t in_len = text.length(); - size_t out_len = text.length()*2; + size_t out_len = text.length()*3; // FIXME: cross fingers that this is enough - char* out_orig = new char[out_len]; // FIXME: cross fingers that this is enough + char* out_orig = new char[out_len]; char* in_orig = new char[in_len+1]; strcpy(in_orig, text.c_str()); char* out = out_orig; char* in = in_orig; + size_t out_len_temp = out_len; // iconv is counting down the bytes it has + // written from this... - //std::cout << "IN: " << (int)in << " " << in_len << " " << (int)out << " " << out_len << std::endl; - int retval = iconv(cd, &in, &in_len, &out, &out_len); - //std::cout << "OUT: " << (int)in << " " << in_len << " " << (int)out << " " << out_len << std::endl; - - if (retval != 0) + size_t retval = iconv(cd, &in, &in_len, &out, &out_len_temp); + out_len -= out_len_temp; // see above + if (retval == (size_t) -1) { std::cerr << strerror(errno) << std::endl; std::cerr << "Error: conversion from " << from_charset << " to " << to_charset << " went wrong: " << retval << std::endl; + return ""; } iconv_close(cd); diff --git a/lib/audio/.cvsignore b/lib/audio/.cvsignore deleted file mode 100644 index f8d9fd474..000000000 --- a/lib/audio/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -.sconsign diff --git a/lib/audio/musicref.cpp b/lib/audio/musicref.cpp deleted file mode 100644 index a29db19ff..000000000 --- a/lib/audio/musicref.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// $Id$ -// -// SuperTux - A Jump'n Run -// Copyright (C) 2000 Bill Kendrick -// Copyright (C) 2004 Matthias Braun -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include - -#include "audio/musicref.h" - -using namespace SuperTux; - -MusicRef::MusicRef() - : music(0) -{ -} - -MusicRef::MusicRef(SoundManager::MusicResource* newmusic) - : music(newmusic) -{ - if(music) - music->refcount++; -} - -MusicRef::~MusicRef() -{ - if(music) { - music->refcount--; - if(music->refcount == 0) - music->manager->free_music(music); - } -} - -MusicRef::MusicRef(const MusicRef& other) - : music(other.music) -{ - if(music) - music->refcount++; -} - -MusicRef& -MusicRef::operator =(const MusicRef& other) -{ - SoundManager::MusicResource* oldres = music; - music = other.music; - if(music) - music->refcount++; - if(oldres) { - oldres->refcount--; - if(oldres->refcount == 0) - music->manager->free_music(music); - } - - return *this; -} - diff --git a/lib/audio/musicref.h b/lib/audio/musicref.h deleted file mode 100644 index f50538b0f..000000000 --- a/lib/audio/musicref.h +++ /dev/null @@ -1,50 +0,0 @@ -// $Id$ -// -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef SUPERTUX_MUSICREF_H -#define SUPERTUX_MUSICREF_H - -#include "sound_manager.h" - -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 deleted file mode 100644 index 2144bbae8..000000000 --- a/lib/audio/sound_manager.cpp +++ /dev/null @@ -1,256 +0,0 @@ -// $Id$ -// -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun - -#include -#include - -#include "audio/sound_manager.h" -#include "audio/musicref.h" -#include "app/globals.h" -#include "app/setup.h" -#include "special/moving_object.h" - -using namespace SuperTux; - -SoundManager* SoundManager::instance_ = 0; - -SoundManager::SoundManager() - : current_music(0), m_music_enabled(true) , m_sound_enabled(true), - audio_device(true) -{ -} - -SoundManager::~SoundManager() -{ - if(audio_device) - Mix_HaltMusic(); - - sounds.clear(); -} - -void -SoundManager::play_sound(Mix_Chunk* sound) -{ - if(!audio_device || !m_sound_enabled) - return; - - Mix_PlayChannel(-1, sound, 0); -} - -void -SoundManager::play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos) -{ - // TODO keep track of the object later and move the sound along with the - // object. - play_sound(sound, object->get_pos(), pos); -} - -void -SoundManager::play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2) -{ - if(!audio_device || !m_sound_enabled) - return; - - // TODO make sure this formula is good - float distance - = pos2.x- pos.x; - int loud = int(255.0/float(SCREEN_WIDTH*2) * fabsf(distance)); - if(loud > 255) - return; - - int chan = Mix_PlayChannel(-1, sound, 0); - if(chan < 0) - return; - Mix_SetDistance(chan, loud); - - // very bad way to do this... - if(distance > 100) - Mix_SetPanning(chan, 230, 24); - else if(distance < -100) - Mix_SetPanning(chan, 24, 230); -} - -MusicRef -SoundManager::load_music(const std::string& file) -{ - if(!audio_device) - return MusicRef(0); - - if(!exists_music(file)) - Termination::abort("Couldn't load musicfile ", file.c_str()); - - std::map::iterator i = musics.find(file); - assert(i != musics.end()); - return MusicRef(& (i->second)); -} - -bool -SoundManager::exists_music(const std::string& file) -{ - if(!audio_device) - return true; - - // song already loaded? - std::map::iterator i = musics.find(file); - if(i != musics.end()) { - return true; - } - - Mix_Music* song = Mix_LoadMUS(file.c_str()); - if(song == 0) - return false; - - // insert into music list - std::pair::iterator, bool> result = - musics.insert( - std::make_pair (file, MusicResource())); - MusicResource& resource = result.first->second; - resource.manager = this; - resource.music = song; - - return true; -} - -void -SoundManager::free_music(MusicResource* ) -{ - // TODO free music, currently we can't do this since SDL_mixer seems to have - // some bugs if you load/free alot of mod files. -} - -void -SoundManager::play_music(const MusicRef& musicref, int loops) -{ - if(!audio_device) - return; - - if(musicref.music == 0 || current_music == musicref.music) - return; - - if(current_music) - current_music->refcount--; - - current_music = musicref.music; - current_music->refcount++; - - if(m_music_enabled) - Mix_PlayMusic(current_music->music, loops); -} - -void -SoundManager::halt_music() -{ - if(!audio_device) - return; - - Mix_HaltMusic(); - - if(current_music) { - current_music->refcount--; - if(current_music->refcount == 0) - free_music(current_music); - current_music = 0; - } -} - -void -SoundManager::enable_music(bool enable) -{ - if(!audio_device) - return; - - if(enable == m_music_enabled) - return; - - m_music_enabled = enable; - if(m_music_enabled == false) { - Mix_HaltMusic(); - } else { - if(current_music) - Mix_PlayMusic(current_music->music, -1); - } -} - -void -SoundManager::enable_sound(bool enable) -{ - if(!audio_device) - return; - - m_sound_enabled = enable; -} - -SoundManager::MusicResource::~MusicResource() -{ - // don't free music buggy SDL_Mixer crashs for some mod files - // Mix_FreeMusic(music); -} - -/* --- LOAD A SOUND --- */ - -Mix_Chunk* SoundManager::load_sound(const std::string& file) -{ - if(!audio_device) - return 0; - - Mix_Chunk* snd = Mix_LoadWAV(file.c_str()); - - /*if (snd == 0) - Termination::abort("Can't load", file);*/ - - return(snd); -} - -void SoundManager::free_chunk(Mix_Chunk *chunk) -{ - Mix_FreeChunk( chunk ); -} - - -/* --- OPEN THE AUDIO DEVICE --- */ - -int SoundManager::open_audio (int frequency, Uint16 format, int channels, int chunksize) -{ - if (Mix_OpenAudio( frequency, format, channels, chunksize ) < 0) - return -1; - - // allocate 16 channels for mixing - if (Mix_AllocateChannels(8) != 8) - return -2; - - return 0; -} - - -/* --- CLOSE THE AUDIO DEVICE --- */ - -void SoundManager::close_audio( void ) -{ - if (audio_device) { - Mix_CloseAudio(); - } -} - -Mix_Chunk* SuperTux::IDToSound(int id) -{ - return SoundManager::get()->sounds[id]; -} - diff --git a/lib/audio/sound_manager.h b/lib/audio/sound_manager.h deleted file mode 100644 index 4c6e5d759..000000000 --- a/lib/audio/sound_manager.h +++ /dev/null @@ -1,169 +0,0 @@ -// $Id$ -// -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun -#include -#include - -#include "SDL_mixer.h" -#include "math/vector.h" - -namespace SuperTux - { - - class MusicRef; - class MovingObject; - - /// enum of different internal music types - enum Music_Type { - NO_MUSIC, - LEVEL_MUSIC, - HURRYUP_MUSIC, - HERRING_MUSIC - }; - - /// Sound manager - /** This class handles all sounds that are played - */ - class SoundManager - { - public: - /// 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); - - /// Load sound. - Mix_Chunk* load_sound(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); - - /// Is music enabled? - bool music_enabled() - { - return m_music_enabled; - } - - /// Enable/Disable sound. - void enable_sound(bool enable); - - /// Is sound enabled? - bool sound_enabled() - { - return m_sound_enabled; - } - - /* functions handling the sound and music */ - int open_audio(int frequency, Uint16 format, int channels, int chunksize); - void close_audio( void ); - - /// Is audio available? - bool audio_device_available() - { - return audio_device; - } - - void set_audio_device_available(bool available) - { - audio_device = available; - } - - static SoundManager* get() - { - return instance_ ? instance_ : instance_ = new SoundManager(); - } - static void destroy_instance() - { - delete instance_; - instance_ = 0; - } - - void add_sound(Mix_Chunk* sound, int id) - { - sounds[id] = sound; - } - - Mix_Chunk* get_sound(int id) - { - return sounds[id]; - } - - private: - SoundManager(); - ~SoundManager(); - - // music part - friend class MusicRef; - friend class Setup; - friend Mix_Chunk* IDToSound(int id); - - static SoundManager* instance_ ; - - void free_chunk(Mix_Chunk* chunk); - - /// 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); - - /*variables for stocking the sound and music*/ - std::map sounds; - std::map musics; - MusicResource* current_music; - bool m_music_enabled; - bool m_sound_enabled; - bool audio_device; /* != 0: available and initialized */ - }; - - Mix_Chunk* IDToSound(int id); - -} // namespace SuperTux -#endif /*SUPERTUX_SOUND_MANAGER_H*/ - diff --git a/lib/gui/.cvsignore b/lib/gui/.cvsignore deleted file mode 100644 index f8d9fd474..000000000 --- a/lib/gui/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -.sconsign diff --git a/lib/gui/button.cpp b/lib/gui/button.cpp deleted file mode 100644 index 93b226d6e..000000000 --- a/lib/gui/button.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/*************************************************************************** - button.cpp - graphical buttons - ------------------- - begin : June, 23 2004 - copyright : (C) 2004 by Ricardo Cruz - email : rick2@aeiou.pt - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#include - -#include "SDL.h" -#include - -#include "button.h" -#include "mousecursor.h" -#include "app/globals.h" -#include "video/font.h" - -using namespace SuperTux; - -Font* Button::info_font = 0; - -/* Buttons */ - -Button::Button(Surface* image_, std::string info_, SDLKey binding_) - : binding(binding_) -{ -image = image_; -size = Vector(image->w, image->h); -id = 0; -info = info_; -} - -Button::~Button() -{ -} - -void Button::draw(DrawingContext &context, bool selected) -{ -if(selected) - context.draw_filled_rect(pos, size, Color (200,240,220), LAYER_GUI); -else - context.draw_filled_rect(pos, size, Color (200,200,220), LAYER_GUI); - -Vector tanslation = -context.get_translation(); -if(state == BT_SHOW_INFO) - { - Vector offset; - if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_HEIGHT - 20) - offset = Vector(size.x, - 10); - else if(pos.x + tanslation.x < 100) - offset = Vector(size.x, 0); - else - offset = Vector(-30, -size.y/2); - context.draw_text(info_font, info, pos + offset, LEFT_ALLIGN, LAYER_GUI+2); - if(binding != 0) - context.draw_text(info_font, "(" + std::string(SDL_GetKeyName(binding)) + - ")", pos + offset + Vector(0,12), - LEFT_ALLIGN, LAYER_GUI+2); - } - -context.draw_surface_part(image, Vector(0,0), size, pos, LAYER_GUI+1); -} - -int Button::event(SDL_Event &event, int x_offset, int y_offset) -{ -state = BT_NONE; -switch(event.type) - { - case SDL_MOUSEBUTTONDOWN: - if(event.button.x > pos.x + x_offset && event.button.x < pos.x + x_offset + size.x && - event.button.y > pos.y + y_offset && event.button.y < pos.y + y_offset + size.y) - { - if(event.button.button == SDL_BUTTON_RIGHT) - state = BT_SHOW_INFO; - } - break; - case SDL_MOUSEBUTTONUP: - if(event.button.x > pos.x + x_offset && event.button.x < pos.x + x_offset + size.x && - event.button.y > pos.y + y_offset && event.button.y < pos.y + y_offset + size.y) - { - if(event.button.button == SDL_BUTTON_LEFT) - state = BT_SELECTED; - } - break; - case SDL_KEYDOWN: // key pressed - if(event.key.keysym.sym == binding) - state = BT_SELECTED; - break; - default: - break; - } -return state; -} - -/* Group of buttons */ - -ButtonGroup::ButtonGroup(Vector pos_, Vector buttons_size_, Vector buttons_box_) - : pos(pos_), buttons_size(buttons_size_), buttons_box(buttons_box_) -{ -buttons.clear(); -row = 0; -button_selected = -1; -mouse_hover = false; -mouse_left_button = false; -buttons_pair_nb = 0; -} - -ButtonGroup::~ButtonGroup() -{ -} - -void ButtonGroup::add_button(Button button, int id, bool select) -{ -button.pos.x = ((buttons.size()-buttons_pair_nb) % (int)buttons_box.x) * buttons_size.x; -button.pos.y = ((int)((buttons.size()-buttons_pair_nb) / buttons_box.x)) * buttons_size.y; -button.size = buttons_size; -button.id = id; -if(select) - button_selected = id; - -buttons.push_back(button); -} - -void ButtonGroup::add_pair_of_buttons(Button button1, int id1, Button button2, int id2) -{ -button1.pos.x = button2.pos.x = ((buttons.size()-buttons_pair_nb) % (int)buttons_box.x) * buttons_size.x; -button1.pos.y = button2.pos.y = ((int)((buttons.size()-buttons_pair_nb) / buttons_box.x)) * buttons_size.y; -button1.size.x = button2.size.x = buttons_size.x; -button1.size.y = button2.size.y = buttons_size.y / 2; -button2.pos.y += buttons_size.y / 2; -button1.id = id1; -button2.id = id2; - -buttons_pair_nb++; -buttons.push_back(button1); -buttons.push_back(button2); -} - -void ButtonGroup::draw(DrawingContext &context) -{ -context.draw_filled_rect(pos - Vector(12,4), - Vector(buttons_size.x*buttons_box.x + 16, buttons_size.y*buttons_box.y + 8), - Color (0,0,0, 128), LAYER_GUI-1); - -context.push_transform(); -context.set_translation(Vector(-pos.x, -pos.y + buttons_size.y*row)); -for(Buttons::iterator i = buttons.begin(); i != buttons.end(); ++i) - { - if(i->pos.y < row*buttons_size.y || - i->pos.y + i->size.y > (row + buttons_box.y) * buttons_size.y) - continue; - - i->draw(context, i->id == button_selected ? true : false); - } -context.pop_transform(); -} - -bool ButtonGroup::event(SDL_Event &event) -{ -bool caught_event = false; - -switch(event.type) - { - case SDL_MOUSEMOTION: - mouse_hover = false; - - if(mouse_left_button) - { - pos.x += int(event.motion.xrel * float(SCREEN_WIDTH)/screen->w); - pos.y += int(event.motion.yrel * float(SCREEN_HEIGHT)/screen->h); - caught_event = true; - } - if(event.button.x > pos.x-12 && event.button.x < pos.x+16 + buttons_box.x*buttons_size.x && - event.button.y > pos.y-4 && event.button.y < pos.y+8 + buttons_box.y*buttons_size.y) - mouse_hover = true; - break; - case SDL_MOUSEBUTTONDOWN: - if(event.button.x < pos.x-12 || event.button.x > pos.x+16 + - buttons_box.x*buttons_size.x || event.button.y < pos.y-4 || - event.button.y > pos.y+8 + buttons_box.y*buttons_size.y) - break; - - caught_event = true; - - if(event.button.button == SDL_BUTTON_WHEELUP) - { - row--; - if(row < 0) - row = 0; - } - else if(event.button.button == SDL_BUTTON_WHEELDOWN) - { - row++; - if(row > (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y + - ((int)(buttons.size()-buttons_pair_nb)%(int)buttons_box.x != 0 ? 1 : 0)) - row = (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y + - ((int)(buttons.size()-buttons_pair_nb)%(int)buttons_box.x != 0 ? 1 : 0); - } - else if(event.button.button == SDL_BUTTON_LEFT) - mouse_left_button = true; - else - caught_event = false; - break; - case SDL_MOUSEBUTTONUP: - mouse_left_button = false; - break; - default: - break; - } - -if(caught_event) - return true; - -for(Buttons::iterator i = buttons.begin(); i != buttons.end(); ++i) - { - if(i->pos.y < row*buttons_size.y || - i->pos.y + i->size.y > (row + buttons_box.y) * buttons_size.y) - continue; - - if(i->event(event, (int)pos.x, - (int)pos.y - row*(int)buttons_size.y) == BT_SELECTED) - { - button_selected = i->id; - caught_event = true; - break; - } - } - -return caught_event; -} - -int ButtonGroup::selected_id() -{ -return button_selected; -} - -void ButtonGroup::set_unselected() -{ -button_selected = -1; -} - -bool ButtonGroup::is_hover() -{ -return mouse_hover; -} diff --git a/lib/gui/button.h b/lib/gui/button.h deleted file mode 100644 index 5a78d4592..000000000 --- a/lib/gui/button.h +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************** - button.h - graphical buttons - ------------------- - begin : June, 23 2004 - copyright : (C) 2004 by Ricardo Cruz - email : rick2@aeiou.pt - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef SUPERTUX_BUTTON_H -#define SUPERTUX_BUTTON_H - -#include -#include - -#include "math/vector.h" -#include "video/drawing_context.h" - -namespace SuperTux - { -class Surface; -class ButtonGroup; - -enum { - BT_NONE, - BT_HOVER, - BT_SELECTED, - BT_SHOW_INFO - }; - -class Button -{ -public: - Button(Surface* image_, std::string info_, SDLKey binding_); - ~Button(); - - void draw(DrawingContext& context, bool selected); - int event(SDL_Event& event, int x_offset = 0, int y_offset = 0); - - static Font* info_font; - -private: - friend class ButtonGroup; - - Vector pos, size; - - Surface* image; - SDLKey binding; - - int id; - int state; - std::string info; -}; - -class ButtonGroup -{ -public: - ButtonGroup(Vector pos_, Vector size_, Vector button_box_); - ~ButtonGroup(); - - void draw(DrawingContext& context); - bool event(SDL_Event& event); - - void add_button(Button button, int id, bool select = false); - void add_pair_of_buttons(Button button1, int id1, Button button2, int id2); - - int selected_id(); - void set_unselected(); - bool is_hover(); - -private: - Vector pos, buttons_size, buttons_box; - typedef std::vector