diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ac085e --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.o +cabrio + +.bzr +.bzrignore +.pc + +debian/cabrio.debhelper.log +debian/cabrio.substvars +debian/cabrio +debian/files \ No newline at end of file diff --git a/Makefile b/Makefile index 63e628f..5bda4fa 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,26 @@ CC=gcc BIN_DIR=/usr/bin DATA_DIR=/usr/share/cabrio -CFLAGS=-g -Wall -DDATA_DIR=\"$(DATA_DIR)\" -LDFLAGS=-lGL -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL_mixer -lGLU -lxml2 \ - -lavutil -lavformat -lavcodec -lswscale +OPTIMIZE=-O3 -ffast-math +ifeq ($(DEBUG), 1) + OPTIMIZE=-O0 +endif +CFLAGS+=-g -Wall $(OPTIMIZE) -DDATA_DIR=\"$(DATA_DIR)\" +LDFLAGS+=-lGL -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -lSDL2_mixer -lGLU -lxml2 INCLUDES=-I./include -I/usr/include/libxml2 +# Works with libav 9.18 and 10.7 (buggy with this, weird behavior) +ifneq (,$(BUNDLED_LIBAV)) + LIBAV_PATH=libav + LDFLAGS+=-L./$(LIBAV_PATH)/linux/lib -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread + INCLUDES+=-I./$(LIBAV_PATH)/linux/include + ifeq (,$(wildcard ./$(LIBAV_PATH)/linux/lib/libavformat.a)) + TMP:=$(shell cp -f ./build_libav_linux.sh ./$(LIBAV_PATH)/ && cd $(LIBAV_PATH)/ && ./build_libav_linux.sh) + endif +else + LDFLAGS+=-lavutil -lavformat -lavcodec -lswscale +endif + INSTALL=/usr/bin/install -c cabrio: main.o ogl.o sdl_wrapper.o config.o bg.o menu.o game_sel.o \ @@ -23,6 +38,8 @@ install: cabrio $(INSTALL) -m 644 -t $(DATA_DIR)/pixmaps data/pixmaps/* $(INSTALL) -m 644 -t $(DATA_DIR)/sounds data/sounds/* $(INSTALL) -m 755 -d $(DATA_DIR)/themes + $(INSTALL) -m 755 -d $(DATA_DIR)/themes/lmc + $(INSTALL) -m 644 -t $(DATA_DIR)/themes/lmc data/themes/lmc/* $(INSTALL) -m 755 -d $(DATA_DIR)/themes/carousel $(INSTALL) -m 644 -t $(DATA_DIR)/themes/carousel data/themes/carousel/* $(INSTALL) -m 755 -d $(DATA_DIR)/themes/ice @@ -31,6 +48,7 @@ install: cabrio $(INSTALL) -m 644 -t $(DATA_DIR)/themes/industrial data/themes/industrial/* $(INSTALL) -m 755 -d $(DATA_DIR)/themes/wood $(INSTALL) -m 644 -t $(DATA_DIR)/themes/wood data/themes/wood/* + $(INSTALL) -m 644 -t $(DATA_DIR)/../applications/ cabrio.desktop $(INSTALL) -m 755 -d $(BIN_DIR) $(INSTALL) -m 755 -t $(BIN_DIR) cabrio diff --git a/README b/README old mode 100644 new mode 100755 index 259c49f..956e475 --- a/README +++ b/README @@ -1,4 +1,101 @@ -Cabrio +TODO: HELP NEEDED ! +- Link a theme for each list - +- Video with some freezes and memory leaks ... - + +Version from "Livemamecab" https://github.com/fredbcode/livemamecab +Demo ISO Here http://traceroot.c.la +Ubuntu PPA here https://launchpad.net/~sergio-br2/+archive/ubuntu/cabrio (Thanks Sergio Benjamim) + +- Added tag to themes, allowing selection of background music by Pieter Hulshoff +- Fixed memory leaks in XML configuration functions by Pieter Hulshoff +- Improved handling of long game lists by Pieter Hulshoff +- Fix ffmpeg problem, should works with libavcodec53/54/55 fixed by f.dorin +- New option "video loop" for snap +- New option "video sound" for snap +- New option "theme sound" music theme onf/off +- New option "theme sound" volume (1 min -> 128 Max) +- New option direct switch to list +- New option hide buttons +- Save selection game at cabrio start +- SDL2 support by sergio-br2 + +New options: + +false/true +false/true +false/true +50 +false/true +false/true + +Option for music: + +Put your music here /usr/share/cabrio/sounds/music.mp3 +You can also use the tag placed within the tag (in a theme XML file). +A directory indication will cause a random music file to be selected from that directory. +In your theme file: + +lmc +/path/music/ + +Option for direct list: + +Example: keyboard touch "a" to directly switch to the first list and "b" for the second (max 5 lists) + + +list1 +a + + keyboard + 0 + + + +list2 +b + + keyboard + 0 + + + +Option to use full path for roms: + +You can use directory tag to indicate a rom folder, so you don't need to use +full path in the rom-image tag. But some emulators have problem with this, +because they need the full path instead Cabrio default approach: it first go +to the directory, and then executes the emulator. So you can use concat-path +tag, it will join both directory and rom-image in one string only: + + + + MAME + MAME + retroarch + Arcade + /home/your-user/Path/to/your/ROMs/ + true + + + -L + + + /usr/lib/libretro/mame_libretro.so + + + + +[...] + + After Burner II + Arcade + aburner2.zip + + +This results: + +retroarch -L /usr/lib/libretro/mame_libretro.so /home/your-user/Path/to/your/ROMs/aburner2.zip + ====== Cabrio is an emulator front-end primarily designed for use with arcade @@ -9,11 +106,11 @@ with limited controls (e.g. a joystick). Installation ------------ You will need the following libraries and their headers/development packages: - * SDL - * SDL_image - * SDL_gfx - * SDL_mixer - * SDL_ttf + * SDL2 + * SDL2_image + * SDL2_gfx + * SDL2_mixer + * SDL2_ttf * glut * libxml2 * ffmpeg @@ -24,6 +121,10 @@ can be edited in the Makefile). See http://www.cabrio-fe.org/support/compile.html for more information. +Debian/Ubuntu: + +apt-get install gcc make libc6-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libsdl2-dev libsdl2-image-dev libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libxml2-dev + Configuration ------------- @@ -46,3 +147,6 @@ Astronomy, Heidelberg). http://hubblesite.org/ Default font "FreeSans.ttf" courtesy of the GNU FreeFont project: http://www.gnu.org/software/freefont/ + +Music Theme: Happy Arcade Tune +Author: rezoner from http://opengameart.org diff --git a/build_libav_linux.sh b/build_libav_linux.sh new file mode 100755 index 0000000..e192876 --- /dev/null +++ b/build_libav_linux.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +rm -f config.h +echo "Building for Linux" + +GENERAL=" + --disable-shared \ + --enable-static" + +MODULES="\ + --disable-avresample \ + --disable-avdevice \ + --disable-filters \ + --disable-programs \ + --disable-network \ + --disable-avfilter \ + --disable-encoders \ + --disable-doc \ + --disable-avplay \ + --disable-avprobe \ + --disable-avserver" + +VIDEO_DECODERS="\ + --enable-decoder=h264 \ + --enable-decoder=h263 \ + --enable-decoder=h263p \ + --enable-decoder=mpeg2video" + +AUDIO_DECODERS="\ + --enable-decoder=aac \ + --enable-decoder=atrac3 \ + --enable-decoder=atrac3p \ + --enable-decoder=mp3 \ + --enable-decoder=pcm_s16le \ + --enable-decoder=pcm_s8" + +DEMUXERS="\ + --enable-demuxer=mov \ + --enable-demuxer=h264 \ + --enable-demuxer=mpegps \ + --enable-demuxer=mpegvideo \ + --enable-demuxer=avi \ + --enable-demuxer=mp3 \ + --enable-demuxer=aac \ + --enable-demuxer=oma \ + --enable-demuxer=pcm_s16le \ + --enable-demuxer=pcm_s8 \ + --enable-demuxer=wav" + +VIDEO_ENCODERS="\ + --enable-encoder=huffyuv \ + --enable-encoder=ffv1 \ + --enable-encoder=mjpeg" + +AUDIO_ENCODERS="\ + --enable-encoder=pcm_s16le" + +MUXERS="\ + --enable-muxer=avi" + +PARSERS="\ + --enable-parser=h264 \ + --enable-parser=mpeg4video \ + --enable-parser=mpegvideo \ + --enable-parser=aac \ + --enable-parser=mpegaudio" + + +./configure \ + --prefix=./linux \ + ${GENERAL} \ + --extra-cflags="-D__STDC_CONSTANT_MACROS -O3" \ + --enable-zlib \ + --enable-pic \ + --disable-yasm \ + --disable-everything \ + --enable-protocol=file \ + ${MODULES} \ + ${VIDEO_DECODERS} \ + ${AUDIO_DECODERS} \ + ${VIDEO_ENCODERS} \ + ${AUDIO_ENCODERS} \ + ${DEMUXERS} \ + ${MUXERS} \ + ${PARSERS} + +make clean +make install diff --git a/cabrio.desktop b/cabrio.desktop new file mode 100644 index 0000000..b813a34 --- /dev/null +++ b/cabrio.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Cabrio +GenericName=Front End for Emulators +Comment=Graphical front end for video game emulators +Exec=cabrio %f +Categories=Game;Emulator; diff --git a/category.c b/category.c index 2daca20..8172f2c 100644 --- a/category.c +++ b/category.c @@ -62,6 +62,7 @@ int category_value_add( struct category *category, char *name ) { struct category_value *search = category->values; struct category_value *after = category->values; struct category_value *category_value = malloc( sizeof(struct category_value) ); + int i = 0; if( search ) { do { @@ -74,6 +75,13 @@ int category_value_add( struct category *category, char *name ) { if( category_value ) { memset( category_value, 0, sizeof(struct category_value) ); category_value->name = name; + while( i < 4) { + if (!list_choice[i]) { + list_choice[i]=name; + break; + } + i++; + } if( after ) { after = after->prev; @@ -160,7 +168,6 @@ void catgeory_dump( void ) { printf("Category: %s (%d)\n", category->name, category->value_count ); struct category_value *value = category->values; while( value ) { - printf(" Value: %s\n", value->name ); value = value->next; if( value == category->values ) break; } diff --git a/config.c b/config.c index 01bc6a0..9f395f7 100644 --- a/config.c +++ b/config.c @@ -30,6 +30,7 @@ static const char *default_submenu_texture = "\\pixmaps\\submenu_item.png"; static const char *default_back_texture = "\\pixmaps\\button_blue.png"; static const char *default_select_texture = "\\pixmaps\\button_red.png"; static const char *default_arrow_texture = "\\pixmaps\\arrow.png"; +static const char *default_music = "\\sounds\\music.mp3"; static const char *default_sounds[] = { "\\sounds\\back.wav", "\\sounds\\blip.wav", @@ -40,12 +41,13 @@ static const char *default_sounds[] = { static const char *default_dir = ".cabrio"; /* Relative to user's home */ static const char *default_theme_dir = "/themes"; static const char *default_background = "/pixmaps/default_background.jpg"; -static const char *default_font = "/fonts/FreeSans.ttf"; +static const char *default_font = "/fonts/FreeSans.ttf"; static const char *default_menu_texture = "/pixmaps/menu_item.png"; static const char *default_submenu_texture = "/pixmaps/submenu_item.png"; static const char *default_back_texture = "/pixmaps/button_blue.png"; static const char *default_select_texture = "/pixmaps/button_red.png"; static const char *default_arrow_texture = "/pixmaps/arrow.png"; +static const char *default_music = "/sounds/music.mp3"; static const char *default_sounds[] = { "/sounds/back.wav", "/sounds/blip.wav", @@ -108,60 +110,66 @@ static const char *tag_root = "cabrio-config"; static const char *tag_emulators = "emulators"; static const char *tag_emulator_executable = "executable"; static const char *tag_game_list = "game-list"; -static const char *tag_games = "games"; -static const char *tag_game = "game"; -static const char *tag_game_rom_image = "rom-image"; -static const char *tag_game_categories = "categories"; -static const char *tag_game_images = "images"; -static const char *tag_game_images_image = "image"; -static const char *tag_game_video = "video"; +static const char *tag_games = "games"; +static const char *tag_game = "game"; +static const char *tag_game_rom_image = "rom-image"; +static const char *tag_game_categories = "categories"; +static const char *tag_game_images = "images"; +static const char *tag_game_images_image = "image"; +static const char *tag_game_video = "video"; static const char *tag_iface = "interface"; static const char *tag_iface_full_screen = "full-screen"; -static const char *tag_iface_screen = "screen"; -static const char *tag_iface_screen_hflip = "flip-horizontal"; -static const char *tag_iface_screen_vflip = "flip-vertical"; -static const char *tag_iface_controls = "controls"; -static const char *tag_iface_frame_rate = "frame-rate"; -static const char *tag_iface_gfx = "graphics"; -static const char *tag_iface_gfx_quality = "quality"; -static const char *tag_iface_gfx_max_width = "max-image-width"; -static const char *tag_iface_gfx_max_height = "max-image-height"; -static const char *tag_iface_theme = "theme"; -static const char *tag_iface_labels = "labels"; -static const char *tag_iface_labels_label = "label"; -static const char *tag_iface_prune_menus = "prune-menus"; -static const char *tag_iface_lookups = "lookups"; -static const char *tag_iface_lookups_category = "category-lookup"; -static const char *tag_iface_lookups_lookup = "lookup"; -static const char *tag_themes = "themes"; -static const char *tag_themes_theme = "theme"; -static const char *tag_theme_menu = "menu"; -static const char *tag_theme_menu_item_width = "item-width"; -static const char *tag_theme_menu_item_height = "item-height"; -static const char *tag_theme_menu_items_visible = "items-visible"; -static const char *tag_theme_menu_border = "border"; -static const char *tag_theme_submenu = "submenu"; -static const char *tag_theme_submenu_item_width = "item-width"; -static const char *tag_theme_submenu_item_height = "item-height"; -static const char *tag_theme_background = "background"; -static const char *tag_theme_font = "font"; -static const char *tag_theme_font_file = "font-file"; -static const char *tag_theme_sounds = "sounds"; -static const char *tag_theme_sounds_sound = "sound"; -static const char *tag_theme_sounds_sound_file = "sound-file"; -static const char *tag_theme_snap = "snap"; -static const char *tag_theme_snap_fix_ar = "fix-aspect-ratio"; -static const char *tag_theme_snap_platform_icons = "platform-icons"; -static const char *tag_theme_hints = "hints"; -static const char *tag_theme_hints_pulse = "pulse"; -static const char *tag_theme_hints_image_back = "back-image"; -static const char *tag_theme_hints_image_select = "select-image"; -static const char *tag_theme_hints_image_arrow = "arrow-image"; -static const char *tag_theme_game_sel = "game-selector"; -static const char *tag_theme_game_sel_selected = "selected"; -static const char *tag_theme_game_sel_tile_size = "tile-size"; -static const char *tag_theme_game_sel_tiles = "tiles"; -static const char *tag_theme_game_sel_tiles_tile = "tile"; +static const char *tag_iface_video_loop = "video-loop"; +static const char *tag_iface_hide_buttons = "hide-buttons"; +static const char *tag_iface_video_sound = "video-sound"; +static const char *tag_iface_theme_sound = "theme-sound"; +static const char *tag_iface_music_volume = "music-volume"; +static const char *tag_iface_screen = "screen"; +static const char *tag_iface_screen_hflip = "flip-horizontal"; +static const char *tag_iface_screen_vflip = "flip-vertical"; +static const char *tag_iface_controls = "controls"; +static const char *tag_iface_frame_rate = "frame-rate"; +static const char *tag_iface_gfx = "graphics"; +static const char *tag_iface_gfx_quality = "quality"; +static const char *tag_iface_gfx_max_width = "max-image-width"; +static const char *tag_iface_gfx_max_height = "max-image-height"; +static const char *tag_iface_theme = "theme"; +static const char *tag_iface_labels = "labels"; +static const char *tag_iface_labels_label = "label"; +static const char *tag_iface_prune_menus = "prune-menus"; +static const char *tag_iface_lookups = "lookups"; +static const char *tag_iface_lookups_category = "category-lookup"; +static const char *tag_iface_lookups_lookup = "lookup"; +static const char *tag_themes = "themes"; +static const char *tag_themes_theme = "theme"; +static const char *tag_theme_menu = "menu"; +static const char *tag_theme_menu_item_width = "item-width"; +static const char *tag_theme_menu_item_height = "item-height"; +static const char *tag_theme_menu_items_visible = "items-visible"; +static const char *tag_theme_menu_border = "border"; +static const char *tag_theme_submenu = "submenu"; +static const char *tag_theme_submenu_item_width = "item-width"; +static const char *tag_theme_submenu_item_height = "item-height"; +static const char *tag_theme_music = "music"; +static const char *tag_theme_background = "background"; +static const char *tag_theme_font = "font"; +static const char *tag_theme_font_file = "font-file"; +static const char *tag_theme_sounds = "sounds"; +static const char *tag_theme_sounds_sound = "sound"; +static const char *tag_theme_sounds_sound_file = "sound-file"; +static const char *tag_theme_snap = "snap"; +static const char *tag_theme_snap_fix_ar = "fix-aspect-ratio"; +static const char *tag_theme_snap_platform_icons = "platform-icons"; +static const char *tag_theme_hints = "hints"; +static const char *tag_theme_hints_pulse = "pulse"; +static const char *tag_theme_hints_image_back = "back-image"; +static const char *tag_theme_hints_image_select = "select-image"; +static const char *tag_theme_hints_image_arrow = "arrow-image"; +static const char *tag_theme_game_sel = "game-selector"; +static const char *tag_theme_game_sel_selected = "selected"; +static const char *tag_theme_game_sel_tile_size = "tile-size"; +static const char *tag_theme_game_sel_tiles = "tiles"; +static const char *tag_theme_game_sel_tiles_tile = "tile"; static const char *tag_locations = "locations"; static const char *tag_locations_location = "location"; @@ -199,6 +207,7 @@ static const char *tag_position_y = "y-position"; static const char *tag_position_z = "z-position"; static const char *tag_order = "order"; static const char *tag_directory = "directory"; +static const char *tag_concat_path = "concat-path"; static const char *tag_color = "color"; static const char *tag_match = "match"; static const char *tag_category = "category"; @@ -277,7 +286,7 @@ int config_read_orientation( char *name, char *value, int *target ) { } int config_read_integer( char *name, char *value, int *target ) { - char *pos = value; + const char *pos = value; if( pos ) { while( *pos ) { if( (*pos < '0' || *pos > '9') && (*pos != '-') ) { @@ -325,9 +334,9 @@ int config_read_percentage( char *name, char *value, int *target ) { return 0; } -int config_read_rgb( char *name, char *value, struct config_rgb *rgb ) { - char *pos = value; - char hex[3]; +int config_read_rgb( const char *name, const char *value, struct config_rgb *rgb ) { + const char *pos = value; + char hex[3] = {0}; if( strlen( value ) != 6 ) { fprintf( stderr, "Warning: Element %s requires RGB value (rrggbb)\n", name ); @@ -387,10 +396,14 @@ int config_read_param( xmlNode *node, struct config_param *param ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - strncpy( param->name, (char*)xmlNodeGetContent(node), CONFIG_PARAM_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( param->name, content, CONFIG_PARAM_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_value ) == 0 ) { - strncpy( param->value, (char*)xmlNodeGetContent(node), CONFIG_PARAM_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( param->value, content, CONFIG_PARAM_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_param, node->name ); @@ -436,25 +449,42 @@ int config_read_emulator( xmlNode *node, struct config_emulator *emulator ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - strncpy( emulator->name, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( emulator->name, content, CONFIG_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_display_name ) == 0 ) { - strncpy( emulator->display_name, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( emulator->display_name, content, CONFIG_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_emulator_executable ) == 0 ) { - strncpy( emulator->executable, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( emulator->executable, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_directory ) == 0 ) { - strncpy( emulator->directory, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( emulator->directory, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_concat_path ) == 0 ) { + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &emulator->concat_path ); + free( content ); } else if( strcmp( (char*)node->name, tag_platform ) == 0 ) { - emulator->platform = config_platform( (char*)xmlNodeGetContent(node) ); + char *content = (char*)xmlNodeGetContent(node); + emulator->platform = config_platform( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_params ) == 0 ) { config_read_emulator_params( node->children, emulator ); } else if( strcmp( (char*)node->name, tag_default ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &emulator->is_default ); + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &emulator->is_default ); + free( content ); } else { fprintf( stderr, warn_skip, tag_emulator, node->name ); @@ -696,10 +726,14 @@ int config_read_image( xmlNode *node, struct config_image *image ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_type ) == 0 ) { - image->type = config_image_type( (char*)xmlNodeGetContent(node) ); + char *content = (char*)xmlNodeGetContent(node); + image->type = config_image_type( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_image_file ) == 0 ) { - strncpy( image->file_name, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( image->file_name, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_game_images_image, node->name ); @@ -739,10 +773,14 @@ int config_read_game( xmlNode *node, struct config_game *game, const char *game_ while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - strncpy( game->name, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( game->name, content, CONFIG_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_game_rom_image ) == 0 ) { - strncpy( game->rom_image, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( game->rom_image, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_game_images ) == 0 ) { config_read_game_images( node->children, game ); @@ -751,16 +789,22 @@ int config_read_game( xmlNode *node, struct config_game *game, const char *game_ config_read_game_categories( node->children, game ); } else if( strcmp( (char*)node->name, tag_platform ) == 0 ) { - game->platform = config_platform( (char*)xmlNodeGetContent(node) ); + char *content = (char*)xmlNodeGetContent(node); + game->platform = config_platform( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_params ) == 0 ) { config_read_game_params( node->children, game ); } else if( strcmp( (char*)node->name, tag_game_video ) == 0 ) { - strncpy( game->video, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( game->video, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_emulator ) == 0 ) { - strncpy( game->emulator, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( game->emulator, content, CONFIG_NAME_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_game, node->name ); @@ -871,10 +915,14 @@ int config_read_device( xmlNode *node, struct config_control *control ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_type ) == 0 ) { - control->device_type = device_id( (char*)xmlNodeGetContent(node) ); + char *content = (char*)xmlNodeGetContent(node); + control->device_type = device_id( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_id ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &control->device_id ); + char *content = (char*)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &control->device_id ); + free( content ); } else { fprintf( stderr, warn_skip, tag_device, node->name ); @@ -890,10 +938,14 @@ int config_read_control( xmlNode *node, struct config_control *control ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_type ) == 0 ) { - control->control_type = control_id( (char*)xmlNodeGetContent(node) ); + char *content = (char*)xmlNodeGetContent(node); + control->control_type = control_id( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_id ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &control->control_id ); + char *content = (char*)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &control->control_id ); + free( content ); } else { fprintf( stderr, warn_skip, tag_control, node->name ); @@ -914,9 +966,12 @@ int config_read_event( xmlNode *node ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - if(!( event = event_id( (char*)xmlNodeGetContent(node) ) )) { + char *content = (char*)xmlNodeGetContent(node); + if(!( event = event_id( content ) )) { + free( content ); return -1; } + free( content ); } else if( strcmp( (char*)node->name, tag_device ) == 0 ) { if( config_read_device( node->children, &tmp ) != 0 ) { @@ -944,6 +999,7 @@ int config_read_event( xmlNode *node ) { tmp.value = key_id( value ); if( tmp.value == 0 ) { fprintf( stderr, "Warning: Unknown key name '%s'\n", value ); + free( value ); return -1; } break; @@ -981,6 +1037,7 @@ int config_read_event( xmlNode *node ) { /* Replace exisiting control for this event */ memcpy( &config.iface.controls[event], &tmp, sizeof(struct config_control) ); + free( value ); return 0; } @@ -1003,46 +1060,72 @@ int config_read_menu( xmlNode *node, struct config_menu *menu ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_image_file ) == 0 ) { - strncpy( menu->texture, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( menu->texture, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_menu_item_width ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->item_width ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->item_width ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_menu_item_height ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->item_height ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->item_height ); + free( content ); } else if( strcmp( (char*)node->name, tag_font_scale ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->font_scale ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->font_scale ); + free( content ); } else if( strcmp( (char*)node->name, tag_zoom ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->zoom ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->zoom ); + free( content ); } else if( strcmp( (char*)node->name, tag_transparency ) == 0 ) { - config_read_percentage( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->transparency ); + char *content = (char*)xmlNodeGetContent(node); + config_read_percentage( (char*)node->name, content, &menu->transparency ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset1 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->offset1 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->offset1 ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset2 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->offset2 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &menu->offset2 ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_menu_items_visible ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->max_visible ); + char *content = (char*)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &menu->max_visible ); + free( content ); } else if( strcmp( (char*)node->name, tag_spacing ) == 0 ) { - if( strcasecmp( (char*)xmlNodeGetContent(node), config_auto ) == 0 ) + char *content = (char*)xmlNodeGetContent(node); + if( strcasecmp( content, config_auto ) == 0 ) menu->spacing = -1; else - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->spacing ); + config_read_float( (char*)node->name, content, &menu->spacing ); + free( content ); } else if( strcmp( (char*)node->name, tag_orientation ) == 0 ) { - config_read_orientation( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->orientation ); + char *content = (char*)xmlNodeGetContent(node); + config_read_orientation( (char*)node->name, content, &menu->orientation ); + free( content ); } else if( strcmp( (char*)node->name, tag_auto_hide ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->auto_hide ); + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &menu->auto_hide ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_menu_border ) == 0 ) { - config_read_percentage( (char*)node->name, (char*)xmlNodeGetContent(node), &menu->border ); + char *content = (char*)xmlNodeGetContent(node); + config_read_percentage( (char*)node->name, content, &menu->border ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_menu, node->name ); @@ -1057,22 +1140,34 @@ int config_read_submenu( xmlNode *node, struct config_submenu *submenu ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_image_file ) == 0 ) { - strncpy( submenu->texture, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char*)xmlNodeGetContent(node); + strncpy( submenu->texture, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_submenu_item_width ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &submenu->item_width ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &submenu->item_width ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_submenu_item_height ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &submenu->item_height ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &submenu->item_height ); + free( content ); } else if( strcmp( (char*)node->name, tag_font_scale ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &submenu->font_scale ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &submenu->font_scale ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset1 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &submenu->offset1 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &submenu->offset1 ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset2 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &submenu->offset2 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &submenu->offset2 ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_submenu, node->name ); @@ -1087,31 +1182,49 @@ int config_read_snap( xmlNode *node, struct config_snap *snap ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_offset1 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->offset1 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->offset1 ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset2 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->offset2 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->offset2 ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_x ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->angle_x ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->angle_x ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_y ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->angle_y ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->angle_y ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_z ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->angle_z ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->angle_z ); + free( content ); } else if( strcmp( (char*)node->name, tag_size ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->size ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &snap->size ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_snap_fix_ar ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->fix_aspect_ratio ); + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &snap->fix_aspect_ratio ); + free( content ); } else if( strcmp( (char*)node->name, tag_auto_hide ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->auto_hide ); + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &snap->auto_hide ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_snap_platform_icons ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &snap->platform_icons ); + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &snap->platform_icons ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_snap, node->name ); @@ -1126,28 +1239,44 @@ int config_read_hints( xmlNode *node, struct config_hints *hints ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_offset1 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &hints->offset1 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &hints->offset1 ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset2 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &hints->offset2 ); + char *content = (char*)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &hints->offset2 ); + free( content ); } else if( strcmp( (char*)node->name, tag_size ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &hints->size ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &hints->size ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_hints_pulse ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &hints->pulse ); + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &hints->pulse ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_hints_image_back ) == 0 ) { - strncpy( hints->image_back, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( hints->image_back, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_hints_image_select ) == 0 ) { - strncpy( hints->image_select, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( hints->image_select, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_hints_image_arrow ) == 0 ) { - strncpy( hints->image_arrow, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( hints->image_arrow, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_spacing ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &hints->spacing ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &hints->spacing ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_hints, node->name ); @@ -1162,32 +1291,49 @@ int config_read_game_selector_tile( xmlNode *node, struct config_game_sel_tile * while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_order ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->order ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &tile->order ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_x ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->angle[0] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->angle[0] ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_y ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->angle[1] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->angle[1] ); + free( content ); } else if( strcmp( (char*)node->name, tag_angle_z ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->angle[2] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->angle[2] ); + free( content ); } else if( strcmp( (char*)node->name, tag_position_x ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->pos[0] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->pos[0] ); + free( content ); } else if( strcmp( (char*)node->name, tag_position_y ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->pos[1] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->pos[1] ); + free( content ); } else if( strcmp( (char*)node->name, tag_position_z ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->pos[2] ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &tile->pos[2] ); + free( content ); } else if( strcmp( (char*)node->name, tag_transparency ) == 0 ) { - config_read_percentage( (char*)node->name, (char*)xmlNodeGetContent(node), &tile->transparency ); + char *content = (char *)xmlNodeGetContent(node); + config_read_percentage( (char*)node->name, content, &tile->transparency ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_game_sel_tiles_tile, node->name ); } + } node = node->next; } @@ -1214,7 +1360,7 @@ int config_read_game_selector_tiles( xmlNode *node, struct config_game_sel *game fprintf( stderr, warn_skip, tag_theme_game_sel_tiles, node->name ); } } - node = node->next; + node = node->next; } return 0; } @@ -1223,25 +1369,39 @@ int config_read_game_selector( xmlNode *node, struct config_game_sel *game_sel ) while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_offset1 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->offset1 ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &game_sel->offset1 ); + free( content ); } else if( strcmp( (char*)node->name, tag_offset2 ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->offset2 ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &game_sel->offset2 ); + free( content ); } else if( strcmp( (char*)node->name, tag_x_size ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->size_x ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &game_sel->size_x ); + free( content ); } else if( strcmp( (char*)node->name, tag_y_size ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->size_y ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &game_sel->size_y ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_game_sel_tile_size ) == 0 ) { - config_read_float( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->tile_size ); + char *content = (char *)xmlNodeGetContent(node); + config_read_float( (char*)node->name, content, &game_sel->tile_size ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_game_sel_selected ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->selected ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &game_sel->selected ); + free( content ); } else if( strcmp( (char*)node->name, tag_orientation ) == 0 ) { - config_read_orientation( (char*)node->name, (char*)xmlNodeGetContent(node), &game_sel->orientation ); + char *content = (char *)xmlNodeGetContent(node); + config_read_orientation( (char*)node->name, content, &game_sel->orientation ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_game_sel_tiles ) == 0 ) { game_sel->tiles = NULL; @@ -1250,6 +1410,7 @@ int config_read_game_selector( xmlNode *node, struct config_game_sel *game_sel ) else { fprintf( stderr, warn_skip, tag_theme_game_sel, node->name ); } + } node = node->next; } @@ -1260,13 +1421,19 @@ int config_read_graphics( xmlNode *node ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_iface_gfx_quality ) == 0 ) { - config_read_lmh( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.gfx_quality ); + char *content = (char *)xmlNodeGetContent(node); + config_read_lmh( (char*)node->name, content, &config.iface.gfx_quality ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_gfx_max_width ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.gfx_max_width ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.gfx_max_width ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_gfx_max_height ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.gfx_max_height ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.gfx_max_height ); + free( content ); } else { fprintf( stderr, warn_skip, tag_iface_gfx, node->name ); @@ -1281,13 +1448,19 @@ int config_read_font( xmlNode *node, struct config_theme *theme ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_theme_font_file ) == 0 ) { - strncpy( theme->font_file, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->font_file, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_size ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &theme->font_size ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &theme->font_size ); + free( content ); } else if( strcmp( (char*)node->name, tag_color ) == 0 ) { - config_read_rgb( (char*)node->name, (char*)xmlNodeGetContent(node), &theme->font_rgb ); + char *content = (char *)xmlNodeGetContent(node); + config_read_rgb( (char*)node->name, content, &theme->font_rgb ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_font, node->name ); @@ -1321,7 +1494,9 @@ int config_read_sound( xmlNode *node, struct config_theme *theme ) { /* Already got it */ } else if( strcmp( (char*)node->name, tag_theme_sounds_sound_file ) == 0 ) { - strncpy( theme->sounds[id], (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->sounds[id], content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_sounds_sound, node->name ); @@ -1356,13 +1531,19 @@ int config_read_theme_background( xmlNode *node, struct config_theme *theme ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_image_file ) == 0 ) { - strncpy( theme->background_image, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->background_image, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_rotation ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &theme->background_rotation ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &theme->background_rotation ); + free( content ); } else if( strcmp( (char*)node->name, tag_transparency ) == 0 ) { - config_read_percentage( (char*)node->name, (char*)xmlNodeGetContent(node), &theme->background_transparency ); + char *content = (char *)xmlNodeGetContent(node); + config_read_percentage( (char*)node->name, content, &theme->background_transparency ); + free( content ); } else { fprintf( stderr, warn_skip, tag_theme_background, node->name ); @@ -1377,19 +1558,29 @@ int config_read_interface_screen( xmlNode *node ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_width ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.screen_width ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.screen_width ); + free( content ); } else if( strcmp( (char*)node->name, tag_height ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.screen_height ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.screen_height ); + free( content ); } else if( strcmp( (char*)node->name, tag_rotation ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.screen_rotation ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.screen_rotation ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_screen_hflip ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.screen_hflip ); + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.screen_hflip ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_screen_vflip ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.screen_vflip ); + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.screen_vflip ); + free( content ); } else { fprintf( stderr, warn_skip, tag_iface_screen, node->name ); @@ -1483,10 +1674,14 @@ int config_read_lookup( xmlNode *node, struct config_lookup *lookup ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_match ) == 0 ) { - strncpy( lookup->match, (char*)xmlNodeGetContent(node), CONFIG_LABEL_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( lookup->match, content, CONFIG_LABEL_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_value ) == 0 ) { - strncpy( lookup->value, (char*)xmlNodeGetContent(node), CONFIG_LABEL_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( lookup->value, content, CONFIG_LABEL_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_iface_lookups_lookup, node->name ); @@ -1504,7 +1699,9 @@ int config_read_category_lookup( xmlNode *node ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_category ) == 0 ) { - category = config_category( (char*)xmlNodeGetContent(node) ); + char *content = (char *)xmlNodeGetContent(node); + category = config_category( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_lookups_lookup ) == 0 ) { /* Ignore for now */ @@ -1570,13 +1767,42 @@ int config_read_interface( xmlNode *node ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_iface_full_screen ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.full_screen ); - } + char *content = (char*)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.full_screen ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_iface_video_loop ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.video_loop ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_iface_hide_buttons ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.hide_buttons ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_iface_video_sound ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.video_sound ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_iface_music_volume ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.music_volume ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_iface_theme_sound ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.theme_sound ); + free( content ); + } else if( strcmp( (char*)node->name, tag_iface_screen ) == 0 ) { config_read_interface_screen( node->children ); } else if( strcmp( (char*)node->name, tag_iface_frame_rate ) == 0 ) { - config_read_integer( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.frame_rate ); + char *content = (char *)xmlNodeGetContent(node); + config_read_integer( (char*)node->name, content, &config.iface.frame_rate ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_controls ) == 0 ) { config_read_controls( node->children ); @@ -1585,13 +1811,17 @@ int config_read_interface( xmlNode *node ) { config_read_graphics( node->children ); } else if( strcmp( (char*)node->name, tag_iface_theme ) == 0 ) { - strncpy( config.iface.theme_name, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( config.iface.theme_name, content, CONFIG_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_labels ) == 0 ) { config_read_interface_labels( node->children ); } else if( strcmp( (char*)node->name, tag_iface_prune_menus ) == 0 ) { - config_read_boolean( (char*)node->name, (char*)xmlNodeGetContent(node), &config.iface.prune_menus ); + char *content = (char *)xmlNodeGetContent(node); + config_read_boolean( (char*)node->name, content, &config.iface.prune_menus ); + free( content ); } else if( strcmp( (char*)node->name, tag_iface_lookups ) == 0 ) { config_read_interface_lookups( node->children ); @@ -1636,8 +1866,15 @@ int config_read_theme( xmlNode *node, struct config_theme *theme ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - strncpy( theme->name, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); - } + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->name, content, CONFIG_NAME_LENGTH ); + free( content ); + } + else if( strcmp( (char*)node->name, tag_theme_music ) == 0 ) { + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->music, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); + } else if( strcmp( (char*)node->name, tag_theme_background ) == 0 ) { config_read_theme_background( node->children, theme ); } @@ -1666,6 +1903,7 @@ int config_read_theme( xmlNode *node, struct config_theme *theme ) { fprintf( stderr, warn_skip, tag_themes_theme, node->name ); } } + node = node->next; } return 0; @@ -1675,7 +1913,9 @@ int config_read_interface_theme( xmlNode *node, struct config_theme *theme ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_name ) == 0 ) { - strncpy( theme->name, (char*)xmlNodeGetContent(node), CONFIG_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( theme->name, content, CONFIG_NAME_LENGTH ); + free( content ); } else if( strcmp( (char*)node->name, tag_theme_background ) == 0 ) { config_read_theme_background( node->children, theme ); @@ -1704,6 +1944,21 @@ int config_read_interface_theme( xmlNode *node, struct config_theme *theme ) { else if( strcmp( (char*)node->name, tag_iface_full_screen ) == 0 ) { /* Ignore */ } + else if( strcmp( (char*)node->name, tag_iface_video_loop ) == 0 ) { + /* Ignore */ + } + else if( strcmp( (char*)node->name, tag_iface_hide_buttons ) == 0 ) { + /* Ignore */ + } + else if( strcmp( (char*)node->name, tag_iface_music_volume ) == 0 ) { + /* Ignore */ + } + else if( strcmp( (char*)node->name, tag_iface_theme_sound ) == 0 ) { + /* Ignore */ + } + else if( strcmp( (char*)node->name, tag_iface_video_sound ) == 0 ) { + /* Ignore */ + } else if( strcmp( (char*)node->name, tag_iface_screen ) == 0 ) { /* Ignore */ } @@ -1805,10 +2060,14 @@ int config_read_location( xmlNode *node, struct config_location *location ) { while( node ) { if( node->type == XML_ELEMENT_NODE ) { if( strcmp( (char*)node->name, tag_type ) == 0 ) { - location->type = config_location_type( (char*)xmlNodeGetContent(node) ); + char *content = (char *)xmlNodeGetContent(node); + location->type = config_location_type( content ); + free( content ); } else if( strcmp( (char*)node->name, tag_directory ) == 0 ) { - strncpy( location->directory, (char*)xmlNodeGetContent(node), CONFIG_FILE_NAME_LENGTH ); + char *content = (char *)xmlNodeGetContent(node); + strncpy( location->directory, content, CONFIG_FILE_NAME_LENGTH ); + free( content ); } else { fprintf( stderr, warn_skip, tag_locations_location, node->name ); @@ -1958,6 +2217,11 @@ int config_write_interface( xmlNodePtr root ) { int i; xmlNodePtr interface = xmlNewNode( NULL, (xmlChar*)tag_iface ); xmlNewChild( interface, NULL, (xmlChar*)tag_iface_full_screen, config_write_boolean( config.iface.full_screen ) ); + xmlNewChild( interface, NULL, (xmlChar*)tag_iface_video_loop, config_write_boolean( config.iface.video_loop ) ); + xmlNewChild( interface, NULL, (xmlChar*)tag_iface_hide_buttons, config_write_boolean( config.iface.hide_buttons ) ); + xmlNewChild( interface, NULL, (xmlChar*)tag_iface_music_volume, config_write_boolean( config.iface.music_volume ) ); + xmlNewChild( interface, NULL, (xmlChar*)tag_iface_video_sound, config_write_boolean( config.iface.video_sound ) ); + xmlNewChild( interface, NULL, (xmlChar*)tag_iface_theme_sound, config_write_boolean( config.iface.theme_sound ) ); xmlNodePtr screen = xmlNewNode( NULL, (xmlChar*)tag_iface_screen ); xmlNewChild( screen, NULL, (xmlChar*)tag_width, config_write_numeric( config.iface.screen_width ) ); @@ -2146,7 +2410,7 @@ int config_new( void ) { else { int i; struct config_param *prev_param = NULL; - struct config_category *platform_catgeory; +// struct config_category *platform_category = NULL; const int num_params = 4; const char *params[] = { "-nowindow", "-skip_gameinfo", "-switchres", "-joystick" }; const char *keys[] = { @@ -2156,8 +2420,13 @@ int config_new( void ) { "left", /* EVENT_LEFT */ "right", /* EVENT_RIGHT */ "return", /* EVENT_SELECT */ - "backspace", /* EVENT_BACK */ - "escape" /* EVENT_QUIT */ + "backspace", /* EVENT_BACK */ + "escape", /* EVENT_QUIT */ + "list1", /* EVENT_CALL LIST1 */ + "list2", /* EVENT_CALL LIST2 */ + "list3", /* EVENT_CALL LIST3 */ + "list4", /* EVENT_CALL LIST4 */ + "list5", /* EVENT_CALL LIST5 */ }; emulator->id = 0; @@ -2182,6 +2451,9 @@ int config_new( void ) { config.platforms = NULL; config.iface.full_screen = 0; + config.iface.video_loop = 0; + config.iface.hide_buttons = 0; + config.iface.video_sound = 1 ; config.iface.screen_width = 640; config.iface.screen_height = 480; config.iface.screen_rotation = 0; @@ -2203,7 +2475,7 @@ int config_new( void ) { config.iface.prune_menus = 1; /* Ensure the game list category has id 0 - we need to track it later */ - platform_catgeory = config_category( default_label_lists ); +// platform_category = config_category( default_label_lists ); strncpy( config.iface.labels.label_all, default_label_all, CONFIG_LABEL_LENGTH ); strncpy( config.iface.labels.label_platform, default_label_platform, CONFIG_LABEL_LENGTH ); strncpy( config.iface.labels.label_back, default_label_back, CONFIG_LABEL_LENGTH ); @@ -2301,7 +2573,7 @@ int config_new( void ) { for( i = 0 ; i < NUM_SOUNDS ; i++ ) { snprintf( default_theme.sounds[i], CONFIG_FILE_NAME_LENGTH, "%s%s", DATA_DIR, (char*)default_sounds[i] ); } - + snprintf( default_theme.music, CONFIG_FILE_NAME_LENGTH, "%s%s", DATA_DIR, (char*)default_music ); config.themes = &default_theme; } return 0; @@ -2493,3 +2765,9 @@ int config_open( const char *filename ) { return created; } +void config_resolution_overwrite( int w, int h ) { + config.iface.screen_width = w; + config.iface.screen_height = h; + + return; +} diff --git a/data/sounds/music.mp3 b/data/sounds/music.mp3 new file mode 100644 index 0000000..d979b45 Binary files /dev/null and b/data/sounds/music.mp3 differ diff --git a/data/themes/lmc/arrow.png b/data/themes/lmc/arrow.png new file mode 100755 index 0000000..b642d7c Binary files /dev/null and b/data/themes/lmc/arrow.png differ diff --git a/data/themes/lmc/background.jpg b/data/themes/lmc/background.jpg new file mode 100755 index 0000000..b401e8e Binary files /dev/null and b/data/themes/lmc/background.jpg differ diff --git a/data/themes/lmc/menu-item.png b/data/themes/lmc/menu-item.png new file mode 100755 index 0000000..9c9e511 Binary files /dev/null and b/data/themes/lmc/menu-item.png differ diff --git a/data/themes/lmc/submenu-item.png b/data/themes/lmc/submenu-item.png new file mode 100755 index 0000000..2ca06eb Binary files /dev/null and b/data/themes/lmc/submenu-item.png differ diff --git a/data/themes/lmc/theme.xml b/data/themes/lmc/theme.xml new file mode 100755 index 0000000..a22b224 --- /dev/null +++ b/data/themes/lmc/theme.xml @@ -0,0 +1,144 @@ + + + + lmc + + background.jpg + 0% + 0 + + + + 30 + + + + menu-item.png + 3 + 1.1 + -1.95 + 0.7 + 10% + + + + + submenu-item.png + + + + + true + 2.05 + 0 + 0.9 + 4.5 + + + + 0.8 + 0 + 1.1 + 0 + 5 + 5 + + + + + + 5 + 0.7 + landscape + -1.0 + + + 0 + 1.5 + 4 + -0.5 + -90 + 100% + + + 1 + 1.0 + 2.6 + -0.4 + -90 + 80% + + + 2 + 0.6 + 2.3 + -0.3 + -80 + 60% + + + 3 + 0.3 + 2.0 + -0.2 + -75 + + + 4 + 0.1 + 1.7 + -0.1 + -70 + + + 5 + 0 + 0 + 1.7 + + + 6 + 0.1 + -1.7 + -0.1 + 70 + + + 7 + 0.3 + -2.0 + -0.2 + 75 + + + 8 + 0.6 + -2.3 + -0.3 + 80 + 60% + + + 9 + 1.0 + -2.6 + -0.4 + 90 + 80% + + + 10 + 1.5 + -4 + -0.5 + 90 + 100% + + + + + + + + + diff --git a/debian/cabrio.1 b/debian/cabrio.1 new file mode 100644 index 0000000..23c0542 --- /dev/null +++ b/debian/cabrio.1 @@ -0,0 +1,9 @@ +.TH "CABRIO" "1" "November 2009" "Steve Maddison" "User Commands" +.SH "NAME" +cabrio \- free open source arcade cabinet emulation front end +.SH "SYNOPSIS" +cabrio +.SH "DESCRIPTION" +Cabrio is a graphical front end for emulators, specifically designed for use in arcade cabinets. It allows you to select games via an intuitive, attractive interface which is easy to use with limited controls, such as a joystick. Cabrio is made available under the GNU General Public License Version 2, meaning anyone can freely download the source code and even contribute to development. +.PP +See http://www.cabrio-fe.org/support/ for help in configuration and usage. diff --git a/debian/cabrio.manpages b/debian/cabrio.manpages new file mode 100644 index 0000000..1bcce20 --- /dev/null +++ b/debian/cabrio.manpages @@ -0,0 +1 @@ +debian/cabrio.1 diff --git a/debian/changelog b/debian/changelog index 9286b8e..badcfee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,26 @@ +cabrio (0.8.3-3) UNRELEASED; urgency=low + + * Updated to latest Fredbcode git version + + SDL2 support. + + -- Sérgio Benjamim Sun, 22 Mar 2015 00:30:00 -0300 + +cabrio (0.8.3-2) UNRELEASED; urgency=low + + * Updated to latest Fredbcode git version (commit #246) + + Fix libavcodec54: but no video sound. + + -- Sérgio Benjamim Sun, 10 Aug 2014 22:57:00 -0300 + +cabrio (0.8.3-1) unstable; urgency=low + + * Fredbcode git version (commit #246) + * Updated some of debian standard, fixed some lintian warnings/errors + * Added a simple man page do debian package + * Cabrio using FreeSans.ttf from the system + + -- Sérgio Benjamim Fri, 06 Jun 2014 15:00:00 +0100 + cabrio (0.8.2-1) unstable; urgency=low * Fixes for Ubuntu 10 @@ -10,4 +33,3 @@ cabrio (0.8.1-1) unstable; urgency=low * Initial release -- Steve Maddison Sun, 29 Nov 2009 17:11:18 +0100 - diff --git a/debian/compat b/debian/compat index 7ed6ff8..ec63514 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -5 +9 diff --git a/debian/control b/debian/control index 57bb2cd..187dae9 100644 --- a/debian/control +++ b/debian/control @@ -1,14 +1,18 @@ Source: cabrio -Section: unknown -Priority: extra +Section: otherosfs +Priority: optional Maintainer: Steve Maddison -Build-Depends: debhelper (>= 5) -Standards-Version: 3.7.3 +Build-Depends: debhelper (>= 9), libsdl2-dev, libsdl2-image-dev, libsdl2-gfx-dev, libsdl2-mixer-dev, libsdl2-ttf-dev, libxml2-dev +# libavcodec-dev, libavutil-dev, libavformat-dev, libswscale-dev +Standards-Version: 3.9.6 +Homepage: http://www.cabrio-fe.org Package: cabrio Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: A front end for video game emulators - Cabrio is a graphical front end for video game emulators - originall designed for use on arcade cabinets, but also - usable on your regular computer. +Depends: ${shlibs:Depends}, ${misc:Depends}, fonts-freefont-ttf | ttf-freefont +Description: Front end for video game emulators + Cabrio is a graphical front end for video game emulators originally designed + for use on arcade cabinets, but also usable on your regular computer. + . + It features a simple graphical interface which is easy to use with limited + controls (e.g. a joystick). diff --git a/debian/copyright b/debian/copyright index c36ab94..6754817 100644 --- a/debian/copyright +++ b/debian/copyright @@ -3,7 +3,7 @@ Sun, 29 Nov 2009 17:11:18 +0100. It was downloaded from -Upstream Author(s): +Upstream Author: Steve Maddison @@ -13,8 +13,12 @@ Copyright: License: - GNU General Public License + Licensed under the terms of the GNU General Public License version 2 -The Debian packaging is (C) 2009, Steve Maddison and -is licensed under the GPL, see `/usr/share/common-licenses/GPL'. +The Debian packaging is: + Copyright (C) 2009 Steve Maddison + Copyright (C) 2014 Sergio Benjamim (sergio-br2) + +and is licensed under the GPL version 2, +see `/usr/share/common-licenses/GPL-2'. diff --git a/debian/dirs b/debian/dirs index 72c6090..d15e8a3 100644 --- a/debian/dirs +++ b/debian/dirs @@ -1,4 +1,5 @@ usr/bin +usr/share/applications usr/share/cabrio usr/share/cabrio/fonts usr/share/cabrio/pixmaps @@ -7,4 +8,5 @@ usr/share/cabrio/themes usr/share/cabrio/themes/carousel usr/share/cabrio/themes/ice usr/share/cabrio/themes/industrial +usr/share/cabrio/themes/lmc usr/share/cabrio/themes/wood diff --git a/debian/patches/FreeSans.ttf.patch b/debian/patches/FreeSans.ttf.patch new file mode 100644 index 0000000..2241a91 --- /dev/null +++ b/debian/patches/FreeSans.ttf.patch @@ -0,0 +1,14 @@ +Index: cabrio_sergio/config.c +=================================================================== +--- cabrio_sergio.orig/config.c 2014-08-11 00:17:02.000000000 -0300 ++++ cabrio_sergio/config.c 2014-08-11 00:20:58.035230094 -0300 +@@ -41,7 +41,8 @@ + static const char *default_dir = ".cabrio"; /* Relative to user's home */ + static const char *default_theme_dir = "/themes"; + static const char *default_background = "/pixmaps/default_background.jpg"; +-static const char *default_font = "/fonts/FreeSans.ttf"; ++//static const char *default_font = "/fonts/FreeSans.ttf"; ++static const char *default_font = "/../fonts/truetype/freefont/FreeSans.ttf"; // FreeSans.ttf is in /usr/share/fonts/truetype/freefont/FreeSans.ttf + static const char *default_menu_texture = "/pixmaps/menu_item.png"; + static const char *default_submenu_texture = "/pixmaps/submenu_item.png"; + static const char *default_back_texture = "/pixmaps/button_blue.png"; diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..32cd716 --- /dev/null +++ b/debian/patches/series @@ -0,0 +1 @@ +FreeSans.ttf.patch diff --git a/debian/rules b/debian/rules index f3fe68f..c6343fe 100755 --- a/debian/rules +++ b/debian/rules @@ -1,93 +1,20 @@ #!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 +export DEB_CXXFLAGS_MAINT_STRIP=-g -O2 +export DEB_CFLAGS_MAINT_STRIP=-g -O2 +%: + dh $@ --parallel +override_dh_auto_build: + # Build with libav 9.18, you have to download it, see https://github.com/fredbcode/cabrio/pull/13 + dh_auto_build -- BUNDLED_LIBAV=1 - -configure: configure-stamp -configure-stamp: - dh_testdir - # Add here commands to configure the package. - - touch configure-stamp - - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - $(MAKE) - #docbook-to-man debian/cabrio.sgml > cabrio.1 - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - $(MAKE) clean - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - +override_dh_auto_install: # Add here commands to install the package into debian/cabrio. - $(MAKE) DESTDIR=$(CURDIR)/debian/cabrio \ + dh_auto_install -- DESTDIR=$(CURDIR)/debian/cabrio \ BIN_DIR=$(CURDIR)/debian/cabrio/usr/bin \ DATA_DIR=$(CURDIR)/debian/cabrio/usr/share/cabrio \ install - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples -# dh_install -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip - dh_compress - dh_fixperms -# dh_perl -# dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure + #$(MAKE) -C builddir DESTDIR=$(CURDIR)/debian/cabrio install + rm $(CURDIR)/debian/cabrio/usr/share/cabrio/fonts/FreeSans.ttf diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/emulator.c b/emulator.c index 1b20bbc..f211176 100644 --- a/emulator.c +++ b/emulator.c @@ -21,7 +21,10 @@ #include "event.h" #include "snap.h" #include "platform.h" +#include +char filename[CONFIG_FILE_NAME_LENGTH]= ".cabrio/.lock"; +char save_filename[CONFIG_FILE_NAME_LENGTH]; void pause_all( void ) { sound_pause(); @@ -51,14 +54,12 @@ int resume_all( void ) { return -6; if( submenu_resume() != 0 ) return -7; - if( game_list_resume() != 0 ) - return -8; sound_resume(); if( snap_resume() != 0 ) return -9; if( game_sel_resume() != 0 ) return -10; - + return 0; } @@ -68,6 +69,7 @@ int emulator_exec( struct game *game ) { int i = 0; int count = 0; char current_dir[CONFIG_FILE_NAME_LENGTH]; + #ifdef __WIN32__ PROCESS_INFORMATION pi; STARTUPINFO si; @@ -88,7 +90,7 @@ int emulator_exec( struct game *game ) { if( param->value && *param->value && count < CONFIG_MAX_PARAMS - 2 ) params[count++] = param->value; param = param->next; - } + } param = game->params; while( param ) { if( param->name && *param->name && count < CONFIG_MAX_PARAMS - 2 ) @@ -96,32 +98,42 @@ int emulator_exec( struct game *game ) { if( param->value && *param->value && count < CONFIG_MAX_PARAMS - 2 ) params[count++] = param->value; param = param->next; - } + } } else { - fprintf(stderr, "Error: No suitable emulator found in configuration\n"); + fprintf( stderr, "Error: No suitable emulator found in configuration\n" ); return -1; } - + if( game && game->rom_path && game->rom_path[0] ) { - params[count++] = game->rom_path; + /* If true, concatenates directory and rom string */ + if ( game->emulator->concat_path ) { + char tmp[CONFIG_FILE_NAME_LENGTH]; + strcpy( tmp, (game->emulator->directory) ); + strcat( tmp, (game->rom_path) ); + params[count++] = tmp; + } + else + params[count++] = game->rom_path; } else { - fprintf(stderr, "Error: No ROM image specified for game\n"); - return -1; + fprintf( stderr, "Error: No ROM image specified for game\n" ); + return -1; } - - /* If emulator provided a directory, go to it. */ - if( game->emulator->directory[0] ) { - getcwd( current_dir, CONFIG_FILE_NAME_LENGTH-1 ); - chdir( game->emulator->directory ); + + /* If emulator provided a directory and if it didn't concatenate with rom_path, go to it. */ + if( game->emulator->directory[0] && game->emulator->concat_path == 0 ) { + if ( getcwd( current_dir, CONFIG_FILE_NAME_LENGTH-1 )) { + if (chdir( game->emulator->directory )) + printf( "Changing directory to %s\n", game->emulator->directory ); + } } - + #ifdef __unix__ /* Terminate param list */ params[count] = NULL; - printf( "Executing: %s", game->emulator->executable ); + printf( "Executing: " ); for( i = 0 ; i < count ; i++ ) { printf( " %s", params[i] ); } @@ -129,10 +141,10 @@ int emulator_exec( struct game *game ) { pid_t pid = fork(); if (pid == 0) { - if( execvp( game->emulator->executable, params ) != 0 ) { - fprintf( stderr, "Error: Couldn't execute emulator '%s': %s\n", game->emulator->executable, strerror(errno) ); + if( execvp( params[0], params ) != 0 ) { + fprintf( stderr, "Error: Couldn't execute emulator '%s': %s\n", params[0], strerror( errno ) ); exit( 1 ); - } + } } else if (pid < 0) { fprintf(stderr, "Error: failed to fork\n"); @@ -140,6 +152,7 @@ int emulator_exec( struct game *game ) { } wait( NULL ); #endif + #ifdef __WIN32__ memset( &pi, 0, sizeof(PROCESS_INFORMATION)); memset( &si, 0, sizeof(STARTUPINFO)); @@ -158,7 +171,7 @@ int emulator_exec( struct game *game ) { } } printf( "Executing: %s\n", cmdline ); - + if( CreateProcess( NULL, cmdline, 0, 0, 0, 0, 0, 0, &si, &pi ) ) { WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); @@ -172,17 +185,34 @@ int emulator_exec( struct game *game ) { } #endif - if( game->emulator->directory[0] ) - chdir( current_dir ); - + if( game->emulator->directory[0] ) { + if (chdir( current_dir )) + fprintf( stderr, "current directory.\n"); + } return 0; } int emulator_run( struct game *game ) { int ret = 0; - + struct passwd *passwd = getpwuid(getuid()); + if (music){ + Mix_HaltMusic(); + music = NULL; + } pause_all(); sdl_free(); + FILE* file = NULL; + + snprintf( save_filename, CONFIG_FILE_NAME_LENGTH, "%s/%s", passwd->pw_dir, filename ); + + file = fopen( save_filename, "w+" ); + if( file == NULL ) { + fprintf(stderr, "Can't save state: %s\n", save_filename); + } + else { + fprintf(file, "%s", game->name); + fclose( file ); + } emulator_exec( game ); @@ -199,7 +229,7 @@ int emulator_run( struct game *game ) { struct config_emulator *emulator_get_by_name( const char *name ) { struct config_emulator *e = config_get()->emulators; - + if( name && name[0] ) { while( e ) { if( strcasecmp( e->name, name ) == 0 ) @@ -207,13 +237,13 @@ struct config_emulator *emulator_get_by_name( const char *name ) { e = e->next; } } - + return e; } struct config_emulator *emulator_get_by_platform( const char *platform ) { struct config_emulator *e = config_get()->emulators; - + if( platform && platform[0] ) { while( e ) { if( e->platform && e->platform->name && strcasecmp( e->platform->name, platform ) == 0 ) @@ -221,22 +251,22 @@ struct config_emulator *emulator_get_by_platform( const char *platform ) { e = e->next; } } - + return e; } struct config_emulator *emulator_get_default( void ) { struct config_emulator *e = config_get()->emulators; - + while( e ) { if( e->is_default ) break; e = e->next; } - + if( !e ) e = config_get()->emulators; - + return e; } diff --git a/event.c b/event.c index f587094..2164cbe 100644 --- a/event.c +++ b/event.c @@ -6,34 +6,37 @@ #include "game_sel.h" #include "focus.h" #include "sdl_wrapper.h" -#include +#include #define MAX_JOYSTICKS 8 static const char *event_str[] = { "none", "up", "down", "left", "right", - "select", "back", "quit" + "select", "back", "quit", "list1", "list2", "list3", "list4", "list5" }; static const int AXIS_THRESHOLD = 8000; +static const int AXIS_THRESHOLD_PRESSED = 32000; static const int BALL_THRESHOLD = 10; static const int MOUSE_THRESHOLD = 10; static int num_joysticks = 0; +static int jbutton_already_pressed = -1; +static int jaxis_already_pressed = -1; static SDL_Joystick *joysticks[MAX_JOYSTICKS]; -static int event = EVENT_NONE; static struct event events[NUM_EVENTS]; int event_init( void ) { const struct config* config = config_get(); int i; - + SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1"); + num_joysticks = SDL_NumJoysticks(); if( num_joysticks > MAX_JOYSTICKS ) num_joysticks = MAX_JOYSTICKS; for( i = 0 ; i < num_joysticks ; i++ ) { - SDL_JoystickOpen( i ); + joysticks[i] = SDL_JoystickOpen( i ); } for( i = 1 ; i < NUM_EVENTS ; i++ ) { @@ -42,24 +45,29 @@ int event_init( void ) { events[i].control_type = config->iface.controls[i].control_type; events[i].control_id = config->iface.controls[i].control_id; events[i].value = config->iface.controls[i].value; - /* printf("%s: %s%d %s%d = %d\n", + // debug // +/* printf("%s: %s%d %s%d = %d\n", event_name(i), device_name(events[i].device_type), events[i].device_id, control_name(events[i].control_type), events[i].control_id, events[i].value - ); */ + ); +*/ } - + return 0; } void event_free( void ) { int i; - + for( i = 0 ; i < num_joysticks ; i++ ) { - SDL_JoystickClose( joysticks[i] ); + if ( SDL_JoystickGetAttached( joysticks[i] ) ) { + SDL_JoystickClose( joysticks[i] ); + joysticks[i] = NULL; + } } } @@ -71,12 +79,12 @@ int event_resume( void ) { return event_init(); } -int event_set( int id, struct event *event ) { +int event_set( int id, struct event *event_s ) { if( id < 1 || id >= NUM_EVENTS ) { fprintf( stderr, "Warning: Can't set non-existent event %d\n", id ); return -1; } - memcpy( &events[id], event, sizeof(struct event) ); + memcpy( &events[id], event_s, sizeof(struct event) ); return 0; } @@ -93,169 +101,224 @@ void event_flush( void ) { while( SDL_PollEvent( &sdl_event ) ); } -int event_poll( void ) { +int event_filter( void* data, SDL_Event* sdl_event ) { + if( sdl_event->type == SDL_TEXTINPUT ) + return 0; + return 1; +} + +void event_set_filter( void ) { + SDL_SetEventFilter( event_filter, NULL ); +} + +int event_poll( int event_num ) { SDL_Event sdl_event; int i; - if( SDL_PollEvent( &sdl_event ) ) { - event = EVENT_NONE; - if( sdl_event.type == SDL_QUIT ) { - event = EVENT_QUIT; - } + if( event_num == EVENT_NONE ) + jbutton_already_pressed = -1; + + while( SDL_PollEvent( &sdl_event ) ) { + if( sdl_event.type == SDL_QUIT ) + return EVENT_QUIT; + for( i = 1 ; i < NUM_EVENTS ; i++ ) { - if( events[i].device_type == DEV_KEYBOARD ) { - if( sdl_event.type == SDL_KEYDOWN && sdl_event.key.keysym.sym == events[i].value ) { - event = i; - } - } - else if( events[i].device_type == DEV_JOYSTICK ) { - if( sdl_event.type == SDL_JOYAXISMOTION - && sdl_event.jaxis.which == events[i].device_id - && events[i].control_type == CTRL_AXIS - && sdl_event.jaxis.axis == events[i].control_id ) { - if( sdl_event.jaxis.value < -AXIS_THRESHOLD && events[i].value < 0 ) { - event = i; - } - else if ( sdl_event.jaxis.value > AXIS_THRESHOLD && events[i].value > 0 ) { - event = i; - } - } - else if ( sdl_event.type == SDL_JOYBUTTONDOWN - && sdl_event.jbutton.which == events[i].device_id - && events[i].control_type == CTRL_BUTTON - && sdl_event.jbutton.button == events[i].value ) { - event = i; - } - else if ( sdl_event.type == SDL_JOYHATMOTION - && sdl_event.jhat.which == events[i].device_id - && events[i].control_type == CTRL_HAT - && sdl_event.jhat.hat == events[i].control_id - && sdl_hat_dir_value( sdl_event.jhat.value ) == events[i].value ) { - event = i; - } - else if ( sdl_event.type == SDL_JOYBALLMOTION - && sdl_event.jball.which == events[i].device_id - && events[i].control_type == CTRL_BALL - && sdl_event.jball.ball == events[i].control_id ) { - if( events[i].value == DIR_DOWN && sdl_event.jball.yrel > BALL_THRESHOLD ) { - event = i; - } - else if( events[i].value == DIR_UP && sdl_event.jball.yrel < -BALL_THRESHOLD ) { - event = i; - } - else if( events[i].value == DIR_LEFT && sdl_event.jball.xrel < -BALL_THRESHOLD ) { - event = i; - } - else if( events[i].value == DIR_RIGHT && sdl_event.jball.xrel > BALL_THRESHOLD ) { - event = i; - } - } - } - else if( events[i].device_type == DEV_MOUSE ) { - if( sdl_event.type == SDL_MOUSEBUTTONDOWN - && sdl_event.button.which == events[i].device_id - && events[i].control_type == CTRL_BUTTON - && sdl_event.button.button == events[i].value ) { - event = i; - } - else if ( sdl_event.type == SDL_MOUSEMOTION - && sdl_event.motion.which == events[i].device_id - && events[i].control_type == CTRL_AXIS ) { - if( events[i].value == DIR_DOWN && sdl_event.motion.yrel > MOUSE_THRESHOLD ) { - event = i; + switch( sdl_event.type ) { + case SDL_KEYDOWN: + if( events[i].device_type == DEV_KEYBOARD + && events[i].value == sdl_event.key.keysym.sym ) + return i; + + break; + + case SDL_JOYAXISMOTION: + if( events[i].device_type == DEV_JOYSTICK + && events[i].control_type == CTRL_AXIS + && events[i].device_id == sdl_event.jaxis.which + && events[i].control_id == sdl_event.jaxis.axis ) { + if( events[i].value < 0 && ( ( sdl_event.jaxis.value < -AXIS_THRESHOLD && jaxis_already_pressed == -1 ) || ( sdl_event.jaxis.value < -AXIS_THRESHOLD_PRESSED && jaxis_already_pressed > -1 ) ) ) { + jaxis_already_pressed = sdl_event.jaxis.axis; + return i; + } + else if( events[i].value > 0 && ( ( sdl_event.jaxis.value > AXIS_THRESHOLD && jaxis_already_pressed == -1 ) || ( sdl_event.jaxis.value > AXIS_THRESHOLD_PRESSED && jaxis_already_pressed > -1 ) ) ) { + jaxis_already_pressed = sdl_event.jaxis.axis; + return i; + } + else if( sdl_event.jaxis.value < AXIS_THRESHOLD && sdl_event.jaxis.value > -AXIS_THRESHOLD ) { + if( jaxis_already_pressed == sdl_event.jaxis.axis ) { + jaxis_already_pressed = -1; + return EVENT_NONE; + } + else + return event_num; + } } - else if( events[i].value == DIR_UP && sdl_event.motion.yrel < -MOUSE_THRESHOLD ) { - event = i; + break; + + case SDL_JOYBUTTONDOWN: + if( events[i].device_type == DEV_JOYSTICK + && events[i].control_type == CTRL_BUTTON + && events[i].device_id == sdl_event.jbutton.which + && events[i].value == sdl_event.jbutton.button + && jbutton_already_pressed == -1 ) { + jbutton_already_pressed = sdl_event.jbutton.button; + return i; } - else if( events[i].value == DIR_LEFT && sdl_event.motion.xrel < -MOUSE_THRESHOLD ) { - event = i; + break; + + case SDL_JOYBUTTONUP: + if( jbutton_already_pressed == sdl_event.jbutton.button ) { + jbutton_already_pressed = -1; + return EVENT_NONE; } - else if( events[i].value == DIR_RIGHT && sdl_event.motion.xrel > MOUSE_THRESHOLD ) { - event = i; + else + return event_num; + + break; + + case SDL_JOYHATMOTION: + if( events[i].device_type == DEV_JOYSTICK + && events[i].control_type == CTRL_HAT + && events[i].device_id == sdl_event.jhat.which + && events[i].control_id == sdl_event.jhat.hat + && events[i].value == sdl_hat_dir_value( sdl_event.jhat.value ) ) + return i; + + break; + + case SDL_JOYBALLMOTION: + if( events[i].device_type == DEV_JOYSTICK + && events[i].control_type == CTRL_BALL + && events[i].device_id == sdl_event.jball.which + && events[i].control_id == sdl_event.jball.ball ) { + if( events[i].value == DIR_DOWN && sdl_event.jball.yrel > BALL_THRESHOLD ) + return i; + + else if( events[i].value == DIR_UP && sdl_event.jball.yrel < -BALL_THRESHOLD ) + return i; + + else if( events[i].value == DIR_LEFT && sdl_event.jball.xrel < -BALL_THRESHOLD ) + return i; + + else if( events[i].value == DIR_RIGHT && sdl_event.jball.xrel > BALL_THRESHOLD ) + return i; + } + break; + + case SDL_MOUSEBUTTONDOWN: + if( events[i].device_type == DEV_MOUSE + && events[i].control_type == CTRL_BUTTON + && events[i].device_id == sdl_event.button.which + && events[i].value == sdl_event.button.button ) + return i; + + break; + + case SDL_MOUSEMOTION: + if( events[i].device_type == DEV_MOUSE + && events[i].control_type == CTRL_AXIS + && events[i].device_id == sdl_event.motion.which ) { + if( events[i].value == DIR_DOWN && sdl_event.motion.yrel > MOUSE_THRESHOLD ) + return i; + + else if( events[i].value == DIR_UP && sdl_event.motion.yrel < -MOUSE_THRESHOLD ) + return i; + + else if( events[i].value == DIR_LEFT && sdl_event.motion.xrel < -MOUSE_THRESHOLD ) + return i; + + else if( events[i].value == DIR_RIGHT && sdl_event.motion.xrel > MOUSE_THRESHOLD ) + return i; } - } + break; + + // Quick return in the case of events not covered above, like SDL_KEYUP + default: + return EVENT_NONE; + } } } - return event; + // Returns the last event happened if there is no new event in the queue + return event_num; } -int event_probe( int timeout, struct event *event ) { +int event_probe( int timeout, struct event *event_p ) { SDL_Event sdl_event; - - event->device_type = DEV_UNKNOWN; - event->device_id = 0; - event->control_type = CTRL_UNKNOWN; - event->control_id = 0; - + + event_p->device_type = DEV_UNKNOWN; + event_p->device_id = 0; + event_p->control_type = CTRL_UNKNOWN; + event_p->control_id = 0; + while( timeout > 0 ) { SDL_PollEvent( &sdl_event ); switch( sdl_event.type ) { case SDL_KEYDOWN: - event->device_type = DEV_KEYBOARD; - event->device_id = sdl_event.key.which; - event->value = sdl_event.key.keysym.sym; + event_p->device_type = DEV_KEYBOARD; + //event->device_id = sdl_event.key.which; + event_p->value = sdl_event.key.keysym.sym; return 1; case SDL_JOYAXISMOTION: - event->device_type = DEV_JOYSTICK; - event->device_id = sdl_event.jaxis.which; - event->control_type = CTRL_AXIS; - event->control_id = sdl_event.jaxis.axis; + event_p->device_type = DEV_JOYSTICK; + event_p->device_id = sdl_event.jaxis.which; + event_p->control_type = CTRL_AXIS; + event_p->control_id = sdl_event.jaxis.axis; if( sdl_event.jaxis.value > AXIS_THRESHOLD ) - event->value = 1; + event_p->value = 1; else if( sdl_event.jaxis.value < -AXIS_THRESHOLD ) - event->value = -1; + event_p->value = -1; else return -1; return 1; case SDL_JOYBUTTONDOWN: - event->device_type = DEV_JOYSTICK; - event->device_id = sdl_event.jbutton.which; - event->control_type = CTRL_BUTTON; - event->value = sdl_event.jbutton.button; + event_p->device_type = DEV_JOYSTICK; + event_p->device_id = sdl_event.jbutton.which; + event_p->control_type = CTRL_BUTTON; + event_p->value = sdl_event.jbutton.button; return 1; case SDL_JOYHATMOTION: - event->device_type = DEV_JOYSTICK; - event->device_id = sdl_event.jhat.which; - event->control_type = CTRL_HAT; - event->control_id = sdl_event.jhat.hat; - event->value = sdl_hat_dir_value( sdl_event.jhat.value ); + event_p->device_type = DEV_JOYSTICK; + event_p->device_id = sdl_event.jhat.which; + event_p->control_type = CTRL_HAT; + event_p->control_id = sdl_event.jhat.hat; + event_p->value = sdl_hat_dir_value( sdl_event.jhat.value ); return 1; case SDL_JOYBALLMOTION: - event->device_type = DEV_JOYSTICK; - event->device_id = sdl_event.jball.which; - event->control_type = CTRL_BALL; - event->control_id = sdl_event.jball.ball; + event_p->device_type = DEV_JOYSTICK; + event_p->device_id = sdl_event.jball.which; + event_p->control_type = CTRL_BALL; + event_p->control_id = sdl_event.jball.ball; if( sdl_event.jball.xrel > BALL_THRESHOLD ) - event->value = DIR_LEFT; + event_p->value = DIR_LEFT; else if( sdl_event.jball.xrel < -BALL_THRESHOLD ) - event->value = DIR_RIGHT; + event_p->value = DIR_RIGHT; else if( sdl_event.jball.yrel > BALL_THRESHOLD ) - event->value = DIR_DOWN; + event_p->value = DIR_DOWN; else if( sdl_event.jball.yrel < -BALL_THRESHOLD ) - event->value = DIR_UP; + event_p->value = DIR_UP; else return -1; return 1; case SDL_MOUSEBUTTONDOWN: - event->device_type = DEV_MOUSE; - event->device_id = sdl_event.button.which; - event->control_type = CTRL_BUTTON; - event->value = sdl_event.button.button; + event_p->device_type = DEV_MOUSE; + event_p->device_id = sdl_event.button.which; + event_p->control_type = CTRL_BUTTON; + event_p->value = sdl_event.button.button; return 1; case SDL_MOUSEMOTION: - event->device_type = DEV_MOUSE; - event->device_id = sdl_event.motion.which; - event->control_type = CTRL_AXIS; + event_p->device_type = DEV_MOUSE; + event_p->device_id = sdl_event.motion.which; + event_p->control_type = CTRL_AXIS; if( sdl_event.motion.xrel > MOUSE_THRESHOLD ) - event->value = DIR_LEFT; + event_p->value = DIR_LEFT; else if( sdl_event.motion.xrel < -MOUSE_THRESHOLD ) - event->value = DIR_RIGHT; + event_p->value = DIR_RIGHT; else if( sdl_event.motion.yrel > MOUSE_THRESHOLD ) - event->value = DIR_DOWN; + event_p->value = DIR_DOWN; else if( sdl_event.motion.yrel < -MOUSE_THRESHOLD ) - event->value = DIR_UP; + event_p->value = DIR_UP; else return -1; return 1; @@ -299,10 +362,9 @@ int event_id( char *name ) { return EVENT_NONE; } -const char *event_name( int event ) { - if( event < 0 || event > NUM_EVENTS ) +const char *event_name( int event_n ) { + if( event_n < 0 || event_n > NUM_EVENTS ) return NULL; else - return event_str[event]; + return event_str[event_n]; } - diff --git a/font.c b/font.c index 00ca157..c1a2ace 100644 --- a/font.c +++ b/font.c @@ -1,4 +1,4 @@ -#include +#include #include #include "config.h" #include "font.h" diff --git a/frame.c b/frame.c index 19d84a7..6af6474 100644 --- a/frame.c +++ b/frame.c @@ -1,4 +1,4 @@ -#include +#include #include "frame.h" #include "video.h" diff --git a/game.c b/game.c index 9fc0ee5..aab8663 100644 --- a/game.c +++ b/game.c @@ -10,6 +10,11 @@ #include "emulator.h" #include "location.h" #include "lookup.h" +#include +#include + +char lfilename[CONFIG_FILE_NAME_LENGTH]= ".cabrio/.lock"; +char lsave_filename[CONFIG_FILE_NAME_LENGTH]; struct game *game_start = NULL; struct game *game_filter_start = NULL; @@ -23,6 +28,108 @@ struct game *game_first( void ) { return game_filter_start; } + +// This function expects list_start to point to the start of the list +struct game *game_list_sort_nr_games( struct game *list_start, int nr_games ) +{ + + // 1 game list + if ( nr_games == 1 ) + return list_start; + + //Define left list + struct game *left = list_start; + + // Define right list + struct game *right = list_start; + int i; + for ( i = 1; i <= nr_games/2; i++ ) // Find the start of the 2nd half + right = right->all_next; + right->all_prev->all_next = NULL; // Disconnect the left list + right->all_prev = NULL; // Disconnect the right list + + // Sort the lists + left = game_list_sort_nr_games( left, nr_games/2 ); + right = game_list_sort_nr_games( right, nr_games-nr_games/2 ); + + // Merge the sorted lists + struct game *result; + + // Determine the start of the merged list + if ( strcasecmp( left->name, right->name ) < 0 ) // left < right + { + result = left; + left = left->all_next; + } + else + { + result = right; + right = right->all_next; + } + + // Merge the rest of the sorted lists + struct game *loop_game = result; + while ( left != NULL || right != NULL ) + { + if ( right == NULL || (left != NULL && (strcasecmp( left->name, right->name ) < 0)) ) + { + loop_game->all_next = left; + left->all_prev = loop_game; + loop_game = loop_game->all_next; + left = left->all_next; + } + else + { + loop_game->all_next = right; + right->all_prev = loop_game; + loop_game = loop_game->all_next; + right = right->all_next; + } + } + + // Return the sorted list + return result; + +} + + +struct game *game_list_sort( struct game *list_start ) +{ + + struct game *loop_game; + int nr_games = 0; + + // Check for empty list + if ( list_start == NULL ) + return NULL; + + // Disconnect the start and end of the list + list_start->all_prev->all_next = NULL; + list_start->all_prev = NULL; + + // Count number of games in the list + for ( loop_game = list_start; loop_game != NULL; loop_game = loop_game->all_next ) + { + nr_games++; + } + + // Sort the list + struct game *result_game = game_list_sort_nr_games( list_start, nr_games ); + + // Reconnect the start and end of the list + loop_game = result_game; + while ( loop_game->all_next ) + loop_game = loop_game->all_next; + loop_game->all_next = result_game; + result_game->all_prev = loop_game; + + // Return the sorted list + return result_game; + +} + + + void game_add( struct game *game, struct game *after ) { if( after == NULL ) { game->all_prev = game; @@ -158,7 +265,7 @@ int game_add_category( struct game *game, char *name, char *value ) { int game_list_create( void ) { struct game *game = NULL; - struct game *prev = NULL; + struct game *last = NULL; struct config_game *config_game = config_get()->games; if( !config_game ) @@ -247,6 +354,7 @@ int game_list_create( void ) { } } else { + free( image ); fprintf( stderr, "Warning: Couldn't allocate game image object for '%s'\n", game->name ); } } @@ -294,24 +402,15 @@ int game_list_create( void ) { } while( category != category_first() ); } - /* insert into list (sort by name) */ - prev = game_start; - if( game_start ) { - prev = game_start->all_prev; - while( strcasecmp( prev->name, game->name ) > 0 ) { - prev = prev->all_prev; - if( prev == game_start->all_prev ) break; - } - } - game_add( game, prev ); - if( !game_start || strcasecmp( game->name, game_start->name ) < 0 ) { - game_start = game; - } - game->next = game->all_next; - game->prev = game->all_prev; + /* insert into list */ + game_add( game, last ); + if ( !game_start ) + game_start = game; + last = game; } config_game = config_game->next; } + game_start = game_list_sort( game_start ); game_list_unfilter(); /* if( game_start ) { @@ -332,8 +431,7 @@ int game_list_create( void ) { g = g->all_next; if( g == game_start ) break; } - }*/ - + } */ return 0; } @@ -341,7 +439,6 @@ int game_list_filter_category( char *name, char *value ) { int count = 0; struct game *game = game_start; struct game_category *category = NULL; - game_filter_start = NULL; if( game && game->categories ) { do { @@ -404,6 +501,21 @@ int game_list_filter_platform( struct platform *platform ) { int game_list_unfilter( void ) { int count = 0; struct game* game = game_start; + struct game* lockgame = game_start; + FILE* file = NULL; + struct passwd *passwd = getpwuid(getuid()); + char lock[CONFIG_FILE_NAME_LENGTH]; + snprintf( lsave_filename, CONFIG_FILE_NAME_LENGTH, "%s/%s", passwd->pw_dir, lfilename ); + + file = fopen( lsave_filename, "r" ); + if( file == NULL ) { + fprintf(stderr, "Can'load state: %s\n", lsave_filename); + } + else { + if (fgets(lock,CONFIG_FILE_NAME_LENGTH, file)) + fclose( file ); + } + if( game ) { do { @@ -411,10 +523,16 @@ int game_list_unfilter( void ) { game->prev = game->all_prev; game = game->all_next; count++; + if (strncmp(game->name,lock, strlen(game->name)) == 0){ + lockgame = game; + } } while ( game != game_start ); - } + } game_filter_start = game_start; + if (lockgame) { + game_filter_start = lockgame; + } return count; } diff --git a/game_sel.c b/game_sel.c index 5f2318c..53ac362 100644 --- a/game_sel.c +++ b/game_sel.c @@ -12,6 +12,8 @@ #include "submenu.h" #include "snap.h" #include "media.h" +#include "category.h" +#include "game.h" static const GLfloat IMAGE_SCALE = 0.005; static const int MAX_STEPS = 25; @@ -351,6 +353,44 @@ int game_sel_event( int event ) { sound_play( SOUND_BACK ); focus_set( FOCUS_SUBMENU ); break; + case EVENT_LIST1: + snap_clear(); + sound_play( SOUND_SELECT ); + game_list_filter_category( "Lists" , list_choice[0]); + game_sel_got_focus(); + break; + + case EVENT_LIST2: + snap_clear(); + sound_play( SOUND_SELECT ); + sound_play( SOUND_SELECT ); + game_list_filter_category( "Lists" , list_choice[1]); + game_sel_got_focus(); + break; + + case EVENT_LIST3: + snap_clear(); + sound_play( SOUND_SELECT ); + sound_play( SOUND_SELECT ); + game_list_filter_category( "Lists" , list_choice[2]); + game_sel_got_focus(); + break; + + case EVENT_LIST4: + snap_clear(); + sound_play( SOUND_SELECT ); + sound_play( SOUND_SELECT ); + game_list_filter_category( "Lists" , list_choice[3]); + game_sel_got_focus(); + break; + + case EVENT_LIST5: + snap_clear(); + sound_play( SOUND_SELECT ); + sound_play( SOUND_SELECT ); + game_list_filter_category( "Lists" , list_choice[4]); + game_sel_got_focus(); + break; default: break; } @@ -371,7 +411,7 @@ int game_sel_got_focus( void ) { else { sound_play( SOUND_NO ); focus_set( FOCUS_SUBMENU ); - } + } return 0; } diff --git a/hint.c b/hint.c index 096b9c3..494b082 100644 --- a/hint.c +++ b/hint.c @@ -8,7 +8,7 @@ #define ORIENT_LEFT 0 #define ORIENT_RIGHT 1 -static const GLfloat ARROW_SIZE = 1.0; +//static const GLfloat ARROW_SIZE = 1.0; static const GLfloat BUTTON_SIZE = 0.75; static const GLfloat ALPHA_MIN = 0.5; static const GLfloat ALPHA_STEP_SIZE = 0.02; @@ -173,6 +173,7 @@ int hint_draw( void ) { break; default: break; + } return 0; diff --git a/include/category.h b/include/category.h index 718e677..0e95495 100644 --- a/include/category.h +++ b/include/category.h @@ -27,6 +27,6 @@ struct category *category_first( void ); struct category *category_get( const char *name ); struct category_value *category_get_value( struct category *category, const char *name ); int category_value_add_unknown( struct category *category ); - +char *list_choice[5]; #endif diff --git a/include/config.h b/include/config.h index 0443b0c..d183186 100644 --- a/include/config.h +++ b/include/config.h @@ -50,6 +50,7 @@ struct config_emulator { char display_name[CONFIG_NAME_LENGTH]; char executable[CONFIG_FILE_NAME_LENGTH]; char directory[CONFIG_FILE_NAME_LENGTH]; + int concat_path; int is_default; struct config_param *params; struct config_platform *platform; @@ -187,6 +188,7 @@ struct config_theme { int background_transparency; char sounds[NUM_SOUNDS][CONFIG_FILE_NAME_LENGTH]; char font_file[CONFIG_FILE_NAME_LENGTH]; + char music[CONFIG_FILE_NAME_LENGTH]; int font_size; struct config_rgb font_rgb; struct config_menu menu; @@ -206,6 +208,11 @@ struct config_labels { struct config_iface { int full_screen; + int video_loop; + int hide_buttons; + int music_volume; + int video_sound; + int theme_sound; int screen_width; int screen_height; int screen_rotation; @@ -252,5 +259,7 @@ int config_write( void ); int config_update( void ); struct config_image_type *config_image_type( char *name ); +void config_resolution_overwrite( int w, int h ); + #endif diff --git a/include/event.h b/include/event.h index f61c79d..2dba020 100644 --- a/include/event.h +++ b/include/event.h @@ -12,6 +12,11 @@ enum event_t { EVENT_SELECT, EVENT_BACK, EVENT_QUIT, + EVENT_LIST1, + EVENT_LIST2, + EVENT_LIST3, + EVENT_LIST4, + EVENT_LIST5, NUM_EVENTS }; @@ -32,7 +37,8 @@ int event_set( int id, struct event *event ); struct event *event_get( int id ); void event_flush( void ); -int event_poll( void ); +void event_set_filter( void ); +int event_poll( int event_num ); int event_probe( int timeout, struct event *event ); int event_process( int e ); int event_id( char *name ); diff --git a/include/focus.h b/include/focus.h index d8a4d75..8f09575 100644 --- a/include/focus.h +++ b/include/focus.h @@ -4,7 +4,7 @@ enum focus_t { FOCUS_MENU, FOCUS_SUBMENU, - FOCUS_GAMESEL + FOCUS_GAMESEL, }; int focus_has( void ); diff --git a/include/frame.h b/include/frame.h index 1aa0663..e17033b 100644 --- a/include/frame.h +++ b/include/frame.h @@ -1,7 +1,7 @@ #ifndef _FRAME_H_ #define _FRAME_H_ 1 -#include +#include #include "video.h" struct frame_list { diff --git a/include/packet.h b/include/packet.h index 9103c65..025b050 100644 --- a/include/packet.h +++ b/include/packet.h @@ -1,7 +1,7 @@ #ifndef _PACKET_H_ #define _PACKET_H_ 1 -#include +#include #include "video.h" struct packet_queue { diff --git a/include/sdl_ogl.h b/include/sdl_ogl.h index 6d6fb6c..2c3a88b 100644 --- a/include/sdl_ogl.h +++ b/include/sdl_ogl.h @@ -1,11 +1,11 @@ #ifndef _SDL_OGL_H_ #define _SDL_OGL_H_ 1 -#include +#include #ifdef __WIN32__ #define _WINCON_H 1 /* Avoid inclusion of wincon.h */ #endif -#include +#include #include "sdl_wrapper.h" #include "ogl.h" diff --git a/include/sdl_wrapper.h b/include/sdl_wrapper.h index dcd1765..42dc9ea 100644 --- a/include/sdl_wrapper.h +++ b/include/sdl_wrapper.h @@ -5,8 +5,8 @@ int sdl_init( void ); void sdl_free( void ); -void sdl_frame_delay( void ); -void sdl_clear( void ); +void sdl_frame_delay( int frame_rate ); +//void sdl_clear( void ); void sdl_swap( void ); int sdl_hat_dir_value( int direction ); diff --git a/include/sound.h b/include/sound.h index 828c785..24c4a4b 100644 --- a/include/sound.h +++ b/include/sound.h @@ -1,7 +1,7 @@ #ifndef _SOUND_H_ #define _SOUND_H_ 1 -#include +#include enum sound_t { SOUND_BACK, @@ -19,8 +19,10 @@ int sound_open_mixer( void ); void sound_close_mixer( void ); void sound_play( int s ); - +void playmusic( void ); +void stopmusic( void ); int sound_id( char *name ); const char *sound_name( int s ); +Mix_Music *music; #endif diff --git a/include/video.h b/include/video.h index 7382cf7..2304cad 100644 --- a/include/video.h +++ b/include/video.h @@ -11,5 +11,5 @@ int video_open( const char *filename ); void video_close( void ); struct texture *video_get_frame( void ); struct texture *video_texture( void ); - +extern int reader_running; #endif diff --git a/key.c b/key.c index 27f37bb..cd91684 100644 --- a/key.c +++ b/key.c @@ -1,5 +1,5 @@ #include "key.h" -#include +#include /* Big list o' key names. These are just the SDLK_* macros with their prefix chopped off. */ static const char *key_name_backspace = "backspace"; @@ -73,112 +73,16 @@ static const char *key_name_x = "x"; static const char *key_name_y = "y"; static const char *key_name_z = "z"; static const char *key_name_delete = "delete"; -static const char *key_name_world_0 = "world_0"; -static const char *key_name_world_1 = "world_1"; -static const char *key_name_world_2 = "world_2"; -static const char *key_name_world_3 = "world_3"; -static const char *key_name_world_4 = "world_4"; -static const char *key_name_world_5 = "world_5"; -static const char *key_name_world_6 = "world_6"; -static const char *key_name_world_7 = "world_7"; -static const char *key_name_world_8 = "world_8"; -static const char *key_name_world_9 = "world_9"; -static const char *key_name_world_10 = "world_10"; -static const char *key_name_world_11 = "world_11"; -static const char *key_name_world_12 = "world_12"; -static const char *key_name_world_13 = "world_13"; -static const char *key_name_world_14 = "world_14"; -static const char *key_name_world_15 = "world_15"; -static const char *key_name_world_16 = "world_16"; -static const char *key_name_world_17 = "world_17"; -static const char *key_name_world_18 = "world_18"; -static const char *key_name_world_19 = "world_19"; -static const char *key_name_world_20 = "world_20"; -static const char *key_name_world_21 = "world_21"; -static const char *key_name_world_22 = "world_22"; -static const char *key_name_world_23 = "world_23"; -static const char *key_name_world_24 = "world_24"; -static const char *key_name_world_25 = "world_25"; -static const char *key_name_world_26 = "world_26"; -static const char *key_name_world_27 = "world_27"; -static const char *key_name_world_28 = "world_28"; -static const char *key_name_world_29 = "world_29"; -static const char *key_name_world_30 = "world_30"; -static const char *key_name_world_31 = "world_31"; -static const char *key_name_world_32 = "world_32"; -static const char *key_name_world_33 = "world_33"; -static const char *key_name_world_34 = "world_34"; -static const char *key_name_world_35 = "world_35"; -static const char *key_name_world_36 = "world_36"; -static const char *key_name_world_37 = "world_37"; -static const char *key_name_world_38 = "world_38"; -static const char *key_name_world_39 = "world_39"; -static const char *key_name_world_40 = "world_40"; -static const char *key_name_world_41 = "world_41"; -static const char *key_name_world_42 = "world_42"; -static const char *key_name_world_43 = "world_43"; -static const char *key_name_world_44 = "world_44"; -static const char *key_name_world_45 = "world_45"; -static const char *key_name_world_46 = "world_46"; -static const char *key_name_world_47 = "world_47"; -static const char *key_name_world_48 = "world_48"; -static const char *key_name_world_49 = "world_49"; -static const char *key_name_world_50 = "world_50"; -static const char *key_name_world_51 = "world_51"; -static const char *key_name_world_52 = "world_52"; -static const char *key_name_world_53 = "world_53"; -static const char *key_name_world_54 = "world_54"; -static const char *key_name_world_55 = "world_55"; -static const char *key_name_world_56 = "world_56"; -static const char *key_name_world_57 = "world_57"; -static const char *key_name_world_58 = "world_58"; -static const char *key_name_world_59 = "world_59"; -static const char *key_name_world_60 = "world_60"; -static const char *key_name_world_61 = "world_61"; -static const char *key_name_world_62 = "world_62"; -static const char *key_name_world_63 = "world_63"; -static const char *key_name_world_64 = "world_64"; -static const char *key_name_world_65 = "world_65"; -static const char *key_name_world_66 = "world_66"; -static const char *key_name_world_67 = "world_67"; -static const char *key_name_world_68 = "world_68"; -static const char *key_name_world_69 = "world_69"; -static const char *key_name_world_70 = "world_70"; -static const char *key_name_world_71 = "world_71"; -static const char *key_name_world_72 = "world_72"; -static const char *key_name_world_73 = "world_73"; -static const char *key_name_world_74 = "world_74"; -static const char *key_name_world_75 = "world_75"; -static const char *key_name_world_76 = "world_76"; -static const char *key_name_world_77 = "world_77"; -static const char *key_name_world_78 = "world_78"; -static const char *key_name_world_79 = "world_79"; -static const char *key_name_world_80 = "world_80"; -static const char *key_name_world_81 = "world_81"; -static const char *key_name_world_82 = "world_82"; -static const char *key_name_world_83 = "world_83"; -static const char *key_name_world_84 = "world_84"; -static const char *key_name_world_85 = "world_85"; -static const char *key_name_world_86 = "world_86"; -static const char *key_name_world_87 = "world_87"; -static const char *key_name_world_88 = "world_88"; -static const char *key_name_world_89 = "world_89"; -static const char *key_name_world_90 = "world_90"; -static const char *key_name_world_91 = "world_91"; -static const char *key_name_world_92 = "world_92"; -static const char *key_name_world_93 = "world_93"; -static const char *key_name_world_94 = "world_94"; -static const char *key_name_world_95 = "world_95"; -static const char *key_name_kp0 = "kp0"; -static const char *key_name_kp1 = "kp1"; -static const char *key_name_kp2 = "kp2"; -static const char *key_name_kp3 = "kp3"; -static const char *key_name_kp4 = "kp4"; -static const char *key_name_kp5 = "kp5"; -static const char *key_name_kp6 = "kp6"; -static const char *key_name_kp7 = "kp7"; -static const char *key_name_kp8 = "kp8"; -static const char *key_name_kp9 = "kp9"; +static const char *key_name_kp_0 = "kp_0"; +static const char *key_name_kp_1 = "kp_1"; +static const char *key_name_kp_2 = "kp_2"; +static const char *key_name_kp_3 = "kp_3"; +static const char *key_name_kp_4 = "kp_4"; +static const char *key_name_kp_5 = "kp_5"; +static const char *key_name_kp_6 = "kp_6"; +static const char *key_name_kp_7 = "kp_7"; +static const char *key_name_kp_8 = "kp_8"; +static const char *key_name_kp_9 = "kp_9"; static const char *key_name_kp_period = "kp_period"; static const char *key_name_kp_divide = "kp_divide"; static const char *key_name_kp_multiply = "kp_multiply"; @@ -210,28 +114,21 @@ static const char *key_name_f12 = "f12"; static const char *key_name_f13 = "f13"; static const char *key_name_f14 = "f14"; static const char *key_name_f15 = "f15"; -static const char *key_name_numlock = "numlock"; +static const char *key_name_numlockclear = "numlockclear"; static const char *key_name_capslock = "capslock"; -static const char *key_name_scrollock = "scrollock"; +static const char *key_name_scrolllock = "scrolllock"; static const char *key_name_rshift = "rshift"; static const char *key_name_lshift = "lshift"; static const char *key_name_rctrl = "rctrl"; static const char *key_name_lctrl = "lctrl"; static const char *key_name_ralt = "ralt"; static const char *key_name_lalt = "lalt"; -static const char *key_name_rmeta = "rmeta"; -static const char *key_name_lmeta = "lmeta"; -static const char *key_name_lsuper = "lsuper"; -static const char *key_name_rsuper = "rsuper"; static const char *key_name_mode = "mode"; -static const char *key_name_compose = "compose"; static const char *key_name_help = "help"; -static const char *key_name_print = "print"; +static const char *key_name_printscreen = "printscreen"; static const char *key_name_sysreq = "sysreq"; -static const char *key_name_break = "break"; static const char *key_name_menu = "menu"; static const char *key_name_power = "power"; -static const char *key_name_euro = "euro"; static const char *key_name_undo = "undo"; int key_id( char *name ) { @@ -310,112 +207,16 @@ int key_id( char *name ) { else if( strcasecmp( name, key_name_y ) == 0 )return SDLK_y; else if( strcasecmp( name, key_name_z ) == 0 )return SDLK_z; else if( strcasecmp( name, key_name_delete ) == 0 )return SDLK_DELETE; - else if( strcasecmp( name, key_name_world_0 ) == 0 )return SDLK_WORLD_0; - else if( strcasecmp( name, key_name_world_1 ) == 0 )return SDLK_WORLD_1; - else if( strcasecmp( name, key_name_world_2 ) == 0 )return SDLK_WORLD_2; - else if( strcasecmp( name, key_name_world_3 ) == 0 )return SDLK_WORLD_3; - else if( strcasecmp( name, key_name_world_4 ) == 0 )return SDLK_WORLD_4; - else if( strcasecmp( name, key_name_world_5 ) == 0 )return SDLK_WORLD_5; - else if( strcasecmp( name, key_name_world_6 ) == 0 )return SDLK_WORLD_6; - else if( strcasecmp( name, key_name_world_7 ) == 0 )return SDLK_WORLD_7; - else if( strcasecmp( name, key_name_world_8 ) == 0 )return SDLK_WORLD_8; - else if( strcasecmp( name, key_name_world_9 ) == 0 )return SDLK_WORLD_9; - else if( strcasecmp( name, key_name_world_10 ) == 0 )return SDLK_WORLD_10; - else if( strcasecmp( name, key_name_world_11 ) == 0 )return SDLK_WORLD_11; - else if( strcasecmp( name, key_name_world_12 ) == 0 )return SDLK_WORLD_12; - else if( strcasecmp( name, key_name_world_13 ) == 0 )return SDLK_WORLD_13; - else if( strcasecmp( name, key_name_world_14 ) == 0 )return SDLK_WORLD_14; - else if( strcasecmp( name, key_name_world_15 ) == 0 )return SDLK_WORLD_15; - else if( strcasecmp( name, key_name_world_16 ) == 0 )return SDLK_WORLD_16; - else if( strcasecmp( name, key_name_world_17 ) == 0 )return SDLK_WORLD_17; - else if( strcasecmp( name, key_name_world_18 ) == 0 )return SDLK_WORLD_18; - else if( strcasecmp( name, key_name_world_19 ) == 0 )return SDLK_WORLD_19; - else if( strcasecmp( name, key_name_world_20 ) == 0 )return SDLK_WORLD_20; - else if( strcasecmp( name, key_name_world_21 ) == 0 )return SDLK_WORLD_21; - else if( strcasecmp( name, key_name_world_22 ) == 0 )return SDLK_WORLD_22; - else if( strcasecmp( name, key_name_world_23 ) == 0 )return SDLK_WORLD_23; - else if( strcasecmp( name, key_name_world_24 ) == 0 )return SDLK_WORLD_24; - else if( strcasecmp( name, key_name_world_25 ) == 0 )return SDLK_WORLD_25; - else if( strcasecmp( name, key_name_world_26 ) == 0 )return SDLK_WORLD_26; - else if( strcasecmp( name, key_name_world_27 ) == 0 )return SDLK_WORLD_27; - else if( strcasecmp( name, key_name_world_28 ) == 0 )return SDLK_WORLD_28; - else if( strcasecmp( name, key_name_world_29 ) == 0 )return SDLK_WORLD_29; - else if( strcasecmp( name, key_name_world_30 ) == 0 )return SDLK_WORLD_30; - else if( strcasecmp( name, key_name_world_31 ) == 0 )return SDLK_WORLD_31; - else if( strcasecmp( name, key_name_world_32 ) == 0 )return SDLK_WORLD_32; - else if( strcasecmp( name, key_name_world_33 ) == 0 )return SDLK_WORLD_33; - else if( strcasecmp( name, key_name_world_34 ) == 0 )return SDLK_WORLD_34; - else if( strcasecmp( name, key_name_world_35 ) == 0 )return SDLK_WORLD_35; - else if( strcasecmp( name, key_name_world_36 ) == 0 )return SDLK_WORLD_36; - else if( strcasecmp( name, key_name_world_37 ) == 0 )return SDLK_WORLD_37; - else if( strcasecmp( name, key_name_world_38 ) == 0 )return SDLK_WORLD_38; - else if( strcasecmp( name, key_name_world_39 ) == 0 )return SDLK_WORLD_39; - else if( strcasecmp( name, key_name_world_40 ) == 0 )return SDLK_WORLD_40; - else if( strcasecmp( name, key_name_world_41 ) == 0 )return SDLK_WORLD_41; - else if( strcasecmp( name, key_name_world_42 ) == 0 )return SDLK_WORLD_42; - else if( strcasecmp( name, key_name_world_43 ) == 0 )return SDLK_WORLD_43; - else if( strcasecmp( name, key_name_world_44 ) == 0 )return SDLK_WORLD_44; - else if( strcasecmp( name, key_name_world_45 ) == 0 )return SDLK_WORLD_45; - else if( strcasecmp( name, key_name_world_46 ) == 0 )return SDLK_WORLD_46; - else if( strcasecmp( name, key_name_world_47 ) == 0 )return SDLK_WORLD_47; - else if( strcasecmp( name, key_name_world_48 ) == 0 )return SDLK_WORLD_48; - else if( strcasecmp( name, key_name_world_49 ) == 0 )return SDLK_WORLD_49; - else if( strcasecmp( name, key_name_world_50 ) == 0 )return SDLK_WORLD_50; - else if( strcasecmp( name, key_name_world_51 ) == 0 )return SDLK_WORLD_51; - else if( strcasecmp( name, key_name_world_52 ) == 0 )return SDLK_WORLD_52; - else if( strcasecmp( name, key_name_world_53 ) == 0 )return SDLK_WORLD_53; - else if( strcasecmp( name, key_name_world_54 ) == 0 )return SDLK_WORLD_54; - else if( strcasecmp( name, key_name_world_55 ) == 0 )return SDLK_WORLD_55; - else if( strcasecmp( name, key_name_world_56 ) == 0 )return SDLK_WORLD_56; - else if( strcasecmp( name, key_name_world_57 ) == 0 )return SDLK_WORLD_57; - else if( strcasecmp( name, key_name_world_58 ) == 0 )return SDLK_WORLD_58; - else if( strcasecmp( name, key_name_world_59 ) == 0 )return SDLK_WORLD_59; - else if( strcasecmp( name, key_name_world_60 ) == 0 )return SDLK_WORLD_60; - else if( strcasecmp( name, key_name_world_61 ) == 0 )return SDLK_WORLD_61; - else if( strcasecmp( name, key_name_world_62 ) == 0 )return SDLK_WORLD_62; - else if( strcasecmp( name, key_name_world_63 ) == 0 )return SDLK_WORLD_63; - else if( strcasecmp( name, key_name_world_64 ) == 0 )return SDLK_WORLD_64; - else if( strcasecmp( name, key_name_world_65 ) == 0 )return SDLK_WORLD_65; - else if( strcasecmp( name, key_name_world_66 ) == 0 )return SDLK_WORLD_66; - else if( strcasecmp( name, key_name_world_67 ) == 0 )return SDLK_WORLD_67; - else if( strcasecmp( name, key_name_world_68 ) == 0 )return SDLK_WORLD_68; - else if( strcasecmp( name, key_name_world_69 ) == 0 )return SDLK_WORLD_69; - else if( strcasecmp( name, key_name_world_70 ) == 0 )return SDLK_WORLD_70; - else if( strcasecmp( name, key_name_world_71 ) == 0 )return SDLK_WORLD_71; - else if( strcasecmp( name, key_name_world_72 ) == 0 )return SDLK_WORLD_72; - else if( strcasecmp( name, key_name_world_73 ) == 0 )return SDLK_WORLD_73; - else if( strcasecmp( name, key_name_world_74 ) == 0 )return SDLK_WORLD_74; - else if( strcasecmp( name, key_name_world_75 ) == 0 )return SDLK_WORLD_75; - else if( strcasecmp( name, key_name_world_76 ) == 0 )return SDLK_WORLD_76; - else if( strcasecmp( name, key_name_world_77 ) == 0 )return SDLK_WORLD_77; - else if( strcasecmp( name, key_name_world_78 ) == 0 )return SDLK_WORLD_78; - else if( strcasecmp( name, key_name_world_79 ) == 0 )return SDLK_WORLD_79; - else if( strcasecmp( name, key_name_world_80 ) == 0 )return SDLK_WORLD_80; - else if( strcasecmp( name, key_name_world_81 ) == 0 )return SDLK_WORLD_81; - else if( strcasecmp( name, key_name_world_82 ) == 0 )return SDLK_WORLD_82; - else if( strcasecmp( name, key_name_world_83 ) == 0 )return SDLK_WORLD_83; - else if( strcasecmp( name, key_name_world_84 ) == 0 )return SDLK_WORLD_84; - else if( strcasecmp( name, key_name_world_85 ) == 0 )return SDLK_WORLD_85; - else if( strcasecmp( name, key_name_world_86 ) == 0 )return SDLK_WORLD_86; - else if( strcasecmp( name, key_name_world_87 ) == 0 )return SDLK_WORLD_87; - else if( strcasecmp( name, key_name_world_88 ) == 0 )return SDLK_WORLD_88; - else if( strcasecmp( name, key_name_world_89 ) == 0 )return SDLK_WORLD_89; - else if( strcasecmp( name, key_name_world_90 ) == 0 )return SDLK_WORLD_90; - else if( strcasecmp( name, key_name_world_91 ) == 0 )return SDLK_WORLD_91; - else if( strcasecmp( name, key_name_world_92 ) == 0 )return SDLK_WORLD_92; - else if( strcasecmp( name, key_name_world_93 ) == 0 )return SDLK_WORLD_93; - else if( strcasecmp( name, key_name_world_94 ) == 0 )return SDLK_WORLD_94; - else if( strcasecmp( name, key_name_world_95 ) == 0 )return SDLK_WORLD_95; - else if( strcasecmp( name, key_name_kp0 ) == 0 )return SDLK_KP0; - else if( strcasecmp( name, key_name_kp1 ) == 0 )return SDLK_KP1; - else if( strcasecmp( name, key_name_kp2 ) == 0 )return SDLK_KP2; - else if( strcasecmp( name, key_name_kp3 ) == 0 )return SDLK_KP3; - else if( strcasecmp( name, key_name_kp4 ) == 0 )return SDLK_KP4; - else if( strcasecmp( name, key_name_kp5 ) == 0 )return SDLK_KP5; - else if( strcasecmp( name, key_name_kp6 ) == 0 )return SDLK_KP6; - else if( strcasecmp( name, key_name_kp7 ) == 0 )return SDLK_KP7; - else if( strcasecmp( name, key_name_kp8 ) == 0 )return SDLK_KP8; - else if( strcasecmp( name, key_name_kp9 ) == 0 )return SDLK_KP9; + else if( strcasecmp( name, key_name_kp_0 ) == 0 )return SDLK_KP_0; + else if( strcasecmp( name, key_name_kp_1 ) == 0 )return SDLK_KP_1; + else if( strcasecmp( name, key_name_kp_2 ) == 0 )return SDLK_KP_2; + else if( strcasecmp( name, key_name_kp_3 ) == 0 )return SDLK_KP_3; + else if( strcasecmp( name, key_name_kp_4 ) == 0 )return SDLK_KP_4; + else if( strcasecmp( name, key_name_kp_5 ) == 0 )return SDLK_KP_5; + else if( strcasecmp( name, key_name_kp_6 ) == 0 )return SDLK_KP_6; + else if( strcasecmp( name, key_name_kp_7 ) == 0 )return SDLK_KP_7; + else if( strcasecmp( name, key_name_kp_8 ) == 0 )return SDLK_KP_8; + else if( strcasecmp( name, key_name_kp_9 ) == 0 )return SDLK_KP_9; else if( strcasecmp( name, key_name_kp_period ) == 0 )return SDLK_KP_PERIOD; else if( strcasecmp( name, key_name_kp_divide ) == 0 )return SDLK_KP_DIVIDE; else if( strcasecmp( name, key_name_kp_multiply ) == 0 )return SDLK_KP_MULTIPLY; @@ -447,28 +248,21 @@ int key_id( char *name ) { else if( strcasecmp( name, key_name_f13 ) == 0 )return SDLK_F13; else if( strcasecmp( name, key_name_f14 ) == 0 )return SDLK_F14; else if( strcasecmp( name, key_name_f15 ) == 0 )return SDLK_F15; - else if( strcasecmp( name, key_name_numlock ) == 0 )return SDLK_NUMLOCK; + else if( strcasecmp( name, key_name_numlockclear ) == 0 )return SDLK_NUMLOCKCLEAR; else if( strcasecmp( name, key_name_capslock ) == 0 )return SDLK_CAPSLOCK; - else if( strcasecmp( name, key_name_scrollock ) == 0 )return SDLK_SCROLLOCK; + else if( strcasecmp( name, key_name_scrolllock ) == 0 )return SDLK_SCROLLLOCK; else if( strcasecmp( name, key_name_rshift ) == 0 )return SDLK_RSHIFT; else if( strcasecmp( name, key_name_lshift ) == 0 )return SDLK_LSHIFT; else if( strcasecmp( name, key_name_rctrl ) == 0 )return SDLK_RCTRL; else if( strcasecmp( name, key_name_lctrl ) == 0 )return SDLK_LCTRL; else if( strcasecmp( name, key_name_ralt ) == 0 )return SDLK_RALT; else if( strcasecmp( name, key_name_lalt ) == 0 )return SDLK_LALT; - else if( strcasecmp( name, key_name_rmeta ) == 0 )return SDLK_RMETA; - else if( strcasecmp( name, key_name_lmeta ) == 0 )return SDLK_LMETA; - else if( strcasecmp( name, key_name_lsuper ) == 0 )return SDLK_LSUPER; - else if( strcasecmp( name, key_name_rsuper ) == 0 )return SDLK_RSUPER; else if( strcasecmp( name, key_name_mode ) == 0 )return SDLK_MODE; - else if( strcasecmp( name, key_name_compose ) == 0 )return SDLK_COMPOSE; else if( strcasecmp( name, key_name_help ) == 0 )return SDLK_HELP; - else if( strcasecmp( name, key_name_print ) == 0 )return SDLK_PRINT; + else if( strcasecmp( name, key_name_printscreen ) == 0 )return SDLK_PRINTSCREEN; else if( strcasecmp( name, key_name_sysreq ) == 0 )return SDLK_SYSREQ; - else if( strcasecmp( name, key_name_break ) == 0 )return SDLK_BREAK; else if( strcasecmp( name, key_name_menu ) == 0 )return SDLK_MENU; else if( strcasecmp( name, key_name_power ) == 0 )return SDLK_POWER; - else if( strcasecmp( name, key_name_euro ) == 0 )return SDLK_EURO; else if( strcasecmp( name, key_name_undo ) == 0 )return SDLK_UNDO; return 0; } @@ -546,112 +340,16 @@ const char *key_name( int key ) { case SDLK_y: return key_name_y; case SDLK_z: return key_name_z; case SDLK_DELETE: return key_name_delete; - case SDLK_WORLD_0: return key_name_world_0; - case SDLK_WORLD_1: return key_name_world_1; - case SDLK_WORLD_2: return key_name_world_2; - case SDLK_WORLD_3: return key_name_world_3; - case SDLK_WORLD_4: return key_name_world_4; - case SDLK_WORLD_5: return key_name_world_5; - case SDLK_WORLD_6: return key_name_world_6; - case SDLK_WORLD_7: return key_name_world_7; - case SDLK_WORLD_8: return key_name_world_8; - case SDLK_WORLD_9: return key_name_world_9; - case SDLK_WORLD_10: return key_name_world_10; - case SDLK_WORLD_11: return key_name_world_11; - case SDLK_WORLD_12: return key_name_world_12; - case SDLK_WORLD_13: return key_name_world_13; - case SDLK_WORLD_14: return key_name_world_14; - case SDLK_WORLD_15: return key_name_world_15; - case SDLK_WORLD_16: return key_name_world_16; - case SDLK_WORLD_17: return key_name_world_17; - case SDLK_WORLD_18: return key_name_world_18; - case SDLK_WORLD_19: return key_name_world_19; - case SDLK_WORLD_20: return key_name_world_20; - case SDLK_WORLD_21: return key_name_world_21; - case SDLK_WORLD_22: return key_name_world_22; - case SDLK_WORLD_23: return key_name_world_23; - case SDLK_WORLD_24: return key_name_world_24; - case SDLK_WORLD_25: return key_name_world_25; - case SDLK_WORLD_26: return key_name_world_26; - case SDLK_WORLD_27: return key_name_world_27; - case SDLK_WORLD_28: return key_name_world_28; - case SDLK_WORLD_29: return key_name_world_29; - case SDLK_WORLD_30: return key_name_world_30; - case SDLK_WORLD_31: return key_name_world_31; - case SDLK_WORLD_32: return key_name_world_32; - case SDLK_WORLD_33: return key_name_world_33; - case SDLK_WORLD_34: return key_name_world_34; - case SDLK_WORLD_35: return key_name_world_35; - case SDLK_WORLD_36: return key_name_world_36; - case SDLK_WORLD_37: return key_name_world_37; - case SDLK_WORLD_38: return key_name_world_38; - case SDLK_WORLD_39: return key_name_world_39; - case SDLK_WORLD_40: return key_name_world_40; - case SDLK_WORLD_41: return key_name_world_41; - case SDLK_WORLD_42: return key_name_world_42; - case SDLK_WORLD_43: return key_name_world_43; - case SDLK_WORLD_44: return key_name_world_44; - case SDLK_WORLD_45: return key_name_world_45; - case SDLK_WORLD_46: return key_name_world_46; - case SDLK_WORLD_47: return key_name_world_47; - case SDLK_WORLD_48: return key_name_world_48; - case SDLK_WORLD_49: return key_name_world_49; - case SDLK_WORLD_50: return key_name_world_50; - case SDLK_WORLD_51: return key_name_world_51; - case SDLK_WORLD_52: return key_name_world_52; - case SDLK_WORLD_53: return key_name_world_53; - case SDLK_WORLD_54: return key_name_world_54; - case SDLK_WORLD_55: return key_name_world_55; - case SDLK_WORLD_56: return key_name_world_56; - case SDLK_WORLD_57: return key_name_world_57; - case SDLK_WORLD_58: return key_name_world_58; - case SDLK_WORLD_59: return key_name_world_59; - case SDLK_WORLD_60: return key_name_world_60; - case SDLK_WORLD_61: return key_name_world_61; - case SDLK_WORLD_62: return key_name_world_62; - case SDLK_WORLD_63: return key_name_world_63; - case SDLK_WORLD_64: return key_name_world_64; - case SDLK_WORLD_65: return key_name_world_65; - case SDLK_WORLD_66: return key_name_world_66; - case SDLK_WORLD_67: return key_name_world_67; - case SDLK_WORLD_68: return key_name_world_68; - case SDLK_WORLD_69: return key_name_world_69; - case SDLK_WORLD_70: return key_name_world_70; - case SDLK_WORLD_71: return key_name_world_71; - case SDLK_WORLD_72: return key_name_world_72; - case SDLK_WORLD_73: return key_name_world_73; - case SDLK_WORLD_74: return key_name_world_74; - case SDLK_WORLD_75: return key_name_world_75; - case SDLK_WORLD_76: return key_name_world_76; - case SDLK_WORLD_77: return key_name_world_77; - case SDLK_WORLD_78: return key_name_world_78; - case SDLK_WORLD_79: return key_name_world_79; - case SDLK_WORLD_80: return key_name_world_80; - case SDLK_WORLD_81: return key_name_world_81; - case SDLK_WORLD_82: return key_name_world_82; - case SDLK_WORLD_83: return key_name_world_83; - case SDLK_WORLD_84: return key_name_world_84; - case SDLK_WORLD_85: return key_name_world_85; - case SDLK_WORLD_86: return key_name_world_86; - case SDLK_WORLD_87: return key_name_world_87; - case SDLK_WORLD_88: return key_name_world_88; - case SDLK_WORLD_89: return key_name_world_89; - case SDLK_WORLD_90: return key_name_world_90; - case SDLK_WORLD_91: return key_name_world_91; - case SDLK_WORLD_92: return key_name_world_92; - case SDLK_WORLD_93: return key_name_world_93; - case SDLK_WORLD_94: return key_name_world_94; - case SDLK_WORLD_95: return key_name_world_95; - case SDLK_KP0: return key_name_kp0; - case SDLK_KP1: return key_name_kp1; - case SDLK_KP2: return key_name_kp2; - case SDLK_KP3: return key_name_kp3; - case SDLK_KP4: return key_name_kp4; - case SDLK_KP5: return key_name_kp5; - case SDLK_KP6: return key_name_kp6; - case SDLK_KP7: return key_name_kp7; - case SDLK_KP8: return key_name_kp8; - case SDLK_KP9: return key_name_kp9; + case SDLK_KP_0: return key_name_kp_0; + case SDLK_KP_1: return key_name_kp_1; + case SDLK_KP_2: return key_name_kp_2; + case SDLK_KP_3: return key_name_kp_3; + case SDLK_KP_4: return key_name_kp_4; + case SDLK_KP_5: return key_name_kp_5; + case SDLK_KP_6: return key_name_kp_6; + case SDLK_KP_7: return key_name_kp_7; + case SDLK_KP_8: return key_name_kp_8; + case SDLK_KP_9: return key_name_kp_9; case SDLK_KP_PERIOD: return key_name_kp_period; case SDLK_KP_DIVIDE: return key_name_kp_divide; case SDLK_KP_MULTIPLY: return key_name_kp_multiply; @@ -683,28 +381,21 @@ const char *key_name( int key ) { case SDLK_F13: return key_name_f13; case SDLK_F14: return key_name_f14; case SDLK_F15: return key_name_f15; - case SDLK_NUMLOCK: return key_name_numlock; + case SDLK_NUMLOCKCLEAR: return key_name_numlockclear; case SDLK_CAPSLOCK: return key_name_capslock; - case SDLK_SCROLLOCK: return key_name_scrollock; + case SDLK_SCROLLLOCK: return key_name_scrolllock; case SDLK_RSHIFT: return key_name_rshift; case SDLK_LSHIFT: return key_name_lshift; case SDLK_RCTRL: return key_name_rctrl; case SDLK_LCTRL: return key_name_lctrl; case SDLK_RALT: return key_name_ralt; case SDLK_LALT: return key_name_lalt; - case SDLK_RMETA: return key_name_rmeta; - case SDLK_LMETA: return key_name_lmeta; - case SDLK_LSUPER: return key_name_lsuper; - case SDLK_RSUPER: return key_name_rsuper; case SDLK_MODE: return key_name_mode; - case SDLK_COMPOSE: return key_name_compose; case SDLK_HELP: return key_name_help; - case SDLK_PRINT: return key_name_print; + case SDLK_PRINTSCREEN: return key_name_printscreen; case SDLK_SYSREQ: return key_name_sysreq; - case SDLK_BREAK: return key_name_break; case SDLK_MENU: return key_name_menu; case SDLK_POWER: return key_name_power; - case SDLK_EURO: return key_name_euro; case SDLK_UNDO: return key_name_undo; } return NULL; diff --git a/location.c b/location.c index b406d90..fad0cf9 100644 --- a/location.c +++ b/location.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "location.h" #include "config.h" @@ -172,8 +173,7 @@ int location_get_match( const char *type, const char *filename, char *path ) { struct location *location = location_get_first( type ); char search[CONFIG_FILE_NAME_LENGTH]; char *pos = NULL; - DIR *dir = NULL; - struct dirent *dentry; + char check_path[CONFIG_FILE_NAME_LENGTH]; int found = 0; if( type && filename ) { @@ -194,19 +194,55 @@ int location_get_match( const char *type, const char *filename, char *path ) { strcat( search, "." ); while( location && !found ) { - if( (dir = opendir( location->directory )) ) { - while( (dentry = readdir( dir )) ) { #ifdef __WIN32__ - if( strncasecmp( dentry->d_name, search, strlen(search) ) == 0 ) { - snprintf( path, CONFIG_FILE_NAME_LENGTH, "%s\\%s", location->directory, dentry->d_name ); + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s\\%spng", location->directory, search ); #else - if( strncasecmp( dentry->d_name, search, strlen(search) ) == 0 ) { - snprintf( path, CONFIG_FILE_NAME_LENGTH, "%s/%s", location->directory, dentry->d_name ); + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s/%spng", location->directory, search ); #endif - found++; - } - } - closedir( dir ); + if ( access( check_path, 0 ) == 0 ) + { + strcpy( path, check_path ); + found++; + } +#ifdef __WIN32__ + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s\\%sjpg", location->directory, search ); +#else + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s/%sjpg", location->directory, search ); +#endif + if ( access( check_path, 0 ) == 0 ) + { + strcpy( path, check_path ); + found++; + } +#ifdef __WIN32__ + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s\\%smp3", location->directory, search ); +#else + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s/%smp3", location->directory, search ); +#endif + if ( access( check_path, 0 ) == 0 ) + { + strcpy( path, check_path ); + found++; + } +#ifdef __WIN32__ + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s\\%sflv", location->directory, search ); +#else + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s/%sflv", location->directory, search ); +#endif + if ( access( check_path, 0 ) == 0 ) + { + strcpy( path, check_path ); + found++; + } +#ifdef __WIN32__ + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s\\%smp4", location->directory, search ); +#else + snprintf( check_path, CONFIG_FILE_NAME_LENGTH, "%s/%smp4", location->directory, search ); +#endif + if ( access( check_path, 0 ) == 0 ) + { + strcpy( path, check_path ); + found++; } location = location->next; } diff --git a/main.c b/main.c index bd646ef..8c33115 100644 --- a/main.c +++ b/main.c @@ -20,8 +20,8 @@ static int supress_wait = 0; -void supress( void ) { - supress_wait = config_get()->iface.frame_rate / 5; +void supress( int frame_rate ) { + supress_wait = frame_rate / 5; } void clean_up( void ) { @@ -47,9 +47,14 @@ void bail( void ) { } int main( int argc, char *arvg[] ) { + const struct config *config_m = config_get(); int quit = 0; int config_status = 0; - int event; + int event = EVENT_SELECT; + + + // Initialise pseudo random generator + srand( time( NULL ) ); #ifdef __WIN32__ freopen( "cabrio.out", "w", stdout ); @@ -65,7 +70,7 @@ int main( int argc, char *arvg[] ) { if( ogl_init() != 0 ) bail(); - + /* Clear the screen as soon as we can. This avoids graphics * glitches which can occur with some SDL implementations. */ ogl_clear(); @@ -113,7 +118,7 @@ int main( int argc, char *arvg[] ) { if( snap_init() != 0 ) bail(); - + if( game_list_create() != 0 ) bail(); @@ -125,42 +130,45 @@ int main( int argc, char *arvg[] ) { sound_init(); video_init(); - + event_flush(); - if( !config_get()->iface.theme.menu.auto_hide ) + if( !config_m->iface.theme.menu.auto_hide ) menu_show(); - + focus_set( FOCUS_GAMESEL ); while( !quit ) { + if( event == EVENT_SELECT ) { + event_set_filter(); + event = EVENT_NONE; + } ogl_clear(); bg_draw(); snap_draw(); - hint_draw(); + if (!config_m->iface.hide_buttons) + hint_draw(); menu_draw(); submenu_draw(); game_sel_draw(); sdl_swap(); - - if (( event = event_poll() )) { + if (Mix_PlayingMusic() != 1 && config_m->iface.theme_sound && reader_running == 0) + playmusic(); + if (( event = event_poll( event ) )) { if( supress_wait == 0 ) { if( event == EVENT_QUIT ) { quit = 1; } else { - supress(); + supress( config_m->iface.frame_rate ); event_process( event ); } } } if( supress_wait > 0 ) supress_wait--; - - sdl_frame_delay(); + sdl_frame_delay( config_m->iface.frame_rate ); } - clean_up(); return 0; } - diff --git a/packet.c b/packet.c index fe3054e..6e5ea5c 100644 --- a/packet.c +++ b/packet.c @@ -1,4 +1,4 @@ -#include +#include #include "packet.h" @@ -44,7 +44,7 @@ int packet_queue_put( struct packet_queue *q, AVPacket *p ) { int packet_queue_get( struct packet_queue *q, AVPacket *p, int block ) { AVPacketList *packet; - int ret; + int ret = 0; SDL_LockMutex( q->mutex ); diff --git a/sample_video_broken/README.txt b/sample_video_broken/README.txt new file mode 100644 index 0000000..c941236 --- /dev/null +++ b/sample_video_broken/README.txt @@ -0,0 +1,42 @@ +This version works only with libavcodec53 + +But 'avcodec_decode_audio3’ still deprecated, need review ! + +Some videos still broken + +Here sample good and sample bad + +diff /tmp/good /tmp/bad +2c2 +< Complete name : chasehq_good.mp4 +--- +> Complete name : chasehq_bad.mp4 +4,6c4,6 +< Format profile : Base Media +< Codec ID : isom +< File size : 8.61 MiB +--- +> Format profile : Base Media / Version 2 +> Codec ID : mp42 +> File size : 8.60 MiB +9c9 +< Overall bit rate : 2 295 Kbps +--- +> Overall bit rate : 2 293 Kbps +12d11 +< Writing application : Lavf54.20.4 +15c14 +< ID : 1 +--- +> ID : 2 +43c42 +< ID : 2 +--- +> ID : 1 +48,49c47,48 +< Duration : 31s 446ms +< Bit rate mode : Variable +--- +> Duration : 31s 445ms +> Bit rate mode : Constant + diff --git a/sample_video_broken/chasehq_bad.mp4 b/sample_video_broken/chasehq_bad.mp4 new file mode 100644 index 0000000..69eb500 Binary files /dev/null and b/sample_video_broken/chasehq_bad.mp4 differ diff --git a/sample_video_broken/chasehq_good.mp4 b/sample_video_broken/chasehq_good.mp4 new file mode 100644 index 0000000..de04592 Binary files /dev/null and b/sample_video_broken/chasehq_good.mp4 differ diff --git a/sdl_ogl.c b/sdl_ogl.c index 9a86831..19c6458 100644 --- a/sdl_ogl.c +++ b/sdl_ogl.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include "sdl_ogl.h" #include "config.h" @@ -11,13 +11,23 @@ unsigned int next_power_of_two( unsigned int x ) { return 1<w, surface->h, sx, sy, &dx, &dy ); if( (dx & (dx-1)) != 0 ) { if( (dx & (dx-1)) == 1 ) { - sx =- 0.001; + sx -= 0.001; } else { sx += 0.001; @@ -62,7 +72,7 @@ SDL_Surface *resize( SDL_Surface *surface ) { } if( (dy & (dy-1)) != 0 ) { if( (dy & (dy-1)) == 1 ) { - sy =- 0.001; + sy -= 0.001; } else { sy += 0.001; @@ -71,7 +81,7 @@ SDL_Surface *resize( SDL_Surface *surface ) { } while( (dx & (dx-1)) != 0 && (dy & (dy-1)) != 0 ); tmp = zoomSurface( surface, sx, sy, 0 ); - resized = SDL_DisplayFormatAlpha( tmp ); + resized = display_format_alpha( tmp ); SDL_FreeSurface( tmp ); } diff --git a/sdl_wrapper.c b/sdl_wrapper.c index ee8a212..e7d3c8d 100644 --- a/sdl_wrapper.c +++ b/sdl_wrapper.c @@ -2,44 +2,38 @@ #include "config.h" #include "sdl_wrapper.h" -#include +#include #ifdef __WIN32__ #define _WINCON_H 1 /* Avoid inclusion of wincon.h */ #endif -#include -#include -#include +#include +#include +#include static SDL_Surface *screen = NULL; -static SDL_VideoInfo saved_video; +static SDL_Window *window = NULL; +static SDL_GLContext *glcontext = NULL; -static const int SDL_SCREEN_BPP = 32; +//static const int SDL_SCREEN_BPP = 32; static const int MAX_FRAME_RATE = 100; static const char *title = "Cabrio"; static FPSmanager manager; -static int frame_rate = 0; -int sdl_init( void ) { - int mode = SDL_SWSURFACE|SDL_OPENGL; - const struct config *config = config_get(); - - if( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) { - fprintf(stderr, "Error: Unable to initialise SDL: %s\n", SDL_GetError()); - return 1; - } - SDL_ShowCursor(SDL_DISABLE); - memcpy( &saved_video, SDL_GetVideoInfo(), sizeof(SDL_VideoInfo) ); - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - if( config->iface.full_screen ) - mode |= SDL_FULLSCREEN; - screen = SDL_SetVideoMode( config->iface.screen_width, config->iface.screen_height, SDL_SCREEN_BPP, mode ); - if( screen == NULL ) { - fprintf(stderr, "Error: Unable to set video mode: %s\n", SDL_GetError()); - return 1; - } +void sdl_resolution_overwrite( void ) { + SDL_DisplayMode res; + + SDL_GetDesktopDisplayMode(0, &res); + config_resolution_overwrite( res.w, res.h ); + + // debug // +// printf( "\nDisplay resolution: %dx%d\nRefresh rate: %d Hz\n%s\n\n", res.w, res.h, res.refresh_rate, SDL_GetPixelFormatName( res.format ) ); + + return; +} + +void sdl_init_framerate ( int frame_rate ) { SDL_initFramerate( &manager ); - - frame_rate = config->iface.frame_rate; + if( frame_rate < 0 ) { frame_rate = 0; fprintf( stderr, "Warning: Negative frame rate, setting to 0 (unlimited)\n" ); @@ -51,25 +45,60 @@ int sdl_init( void ) { if( frame_rate ) { SDL_setFramerate( &manager, frame_rate ); } - SDL_WM_SetCaption( title, NULL ); + return; +} + +int sdl_init( void ) { + int mode = SDL_SWSURFACE|SDL_WINDOW_OPENGL; + const struct config *c = config_get(); + + if( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) { + fprintf(stderr, "Error: Unable to initialise SDL: %s\n", SDL_GetError()); + return 1; + } + + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); + SDL_ShowCursor(SDL_DISABLE); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + if( c->iface.full_screen ) { + mode |= SDL_WINDOW_FULLSCREEN; // maybe use SDL_WINDOW_FULLSCREEN_DESKTOP ? + sdl_resolution_overwrite(); + } + window = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c->iface.screen_width, c->iface.screen_height, mode ); + if( window == NULL ) { + fprintf(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError()); + return 1; + } + + glcontext = SDL_GL_CreateContext( window ); + + screen = SDL_GetWindowSurface( window ); + + sdl_init_framerate( c->iface.frame_rate ); + return 0; } void sdl_free( void ) { - if( config_get()->iface.full_screen ) - SDL_SetVideoMode( saved_video.current_w, saved_video.current_h, saved_video.vfmt->BitsPerPixel, SDL_FULLSCREEN ); + SDL_FreeSurface( screen ); + screen = NULL; + SDL_GL_DeleteContext( glcontext ); + glcontext = NULL; + SDL_DestroyWindow( window ); + window = NULL; SDL_Quit(); } -void sdl_frame_delay( void ) { +void sdl_frame_delay( int frame_rate ) { if( frame_rate ) { SDL_framerateDelay( &manager ); } } void sdl_swap( void ) { - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow( window ); } int sdl_hat_dir_value( int direction ) { diff --git a/snap.c b/snap.c index cbe12d7..137ed66 100644 --- a/snap.c +++ b/snap.c @@ -90,7 +90,6 @@ int snap_set( struct game *game ) { video = 0; platform_texture = game->platform->texture; - filename = game_media_get( game, MEDIA_VIDEO, NULL ); if( filename && filename[0] ) { if( video_open( filename ) == 0 ) { @@ -98,7 +97,7 @@ int snap_set( struct game *game ) { texture = video_texture(); } } - + // no video ? ok screenshot // if( !texture ) { filename = game_media_get( game, MEDIA_IMAGE, image_type_name(IMAGE_SCREENSHOT) ); if( filename && filename[0] ) { @@ -136,7 +135,7 @@ int snap_set( struct game *game ) { } return 0; } - + return -1; } @@ -171,19 +170,17 @@ void snap_hide( void ) { void snap_draw( void ) { const struct config_snap *config = &config_get()->iface.theme.snap; - if( visible ) { struct texture *t = texture; GLfloat xfactor = ogl_xfactor(); GLfloat yfactor = ogl_yfactor(); GLfloat xsize, ysize, hide_offset; - if( video ) + if( video ){ t = video_get_frame(); - - if( t == NULL ) + } + if( t == NULL ) t = noise[frame/noise_skip]; - xsize = (width/2) * scale * xfactor; ysize = (height/2) * scale * xfactor; diff --git a/sound.c b/sound.c index a38a3fc..a685fdc 100644 --- a/sound.c +++ b/sound.c @@ -1,15 +1,18 @@ +#include +#include #include "sound.h" #include "config.h" -#include +#include +#include -static const int AUDIO_CHUNK_SIZE = 4096; +static const int AUDIO_CHUNK_SIZE = 1024; static Mix_Chunk *sounds[NUM_SOUNDS]; static char *names[] = { "back", "blip", "no", "select" }; static int mixer_open = 0; int sound_open_mixer( void ) { if( !mixer_open ) { - if( Mix_OpenAudio( 22050, AUDIO_S16SYS, 4, AUDIO_CHUNK_SIZE ) == -1 ) { + if( Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT,1,AUDIO_CHUNK_SIZE) == -1 ) { fprintf( stderr, "Error: Unable to initialise sound: %s\n", Mix_GetError() ); return -1; } @@ -26,10 +29,10 @@ void sound_close_mixer( void ) { int sound_init( void ) { int i; - + for( i = 0 ; i < NUM_SOUNDS ; i++ ) sounds[i] = NULL; - + if( sound_open_mixer() != 0 ) return -1; @@ -45,15 +48,15 @@ int sound_init( void ) { void sound_free( void ) { int i; - for( i = 0 ; i < NUM_SOUNDS ; i++ ) { if( sounds[i] ) { Mix_FreeChunk( sounds[i] ); sounds[i] = NULL; } } - + stopmusic(); sound_close_mixer(); + } void sound_pause( void ) { @@ -89,3 +92,52 @@ const char *sound_name( int s ) { return NULL; } +void playmusic(void) { +#ifdef __WIN32__ + static const char dir_separator = '\\'; +#else + static const char dir_separator = '/'; +#endif + if (!music) + free( music ); + if ( config_get()->iface.theme.music[strlen(config_get()->iface.theme.music)-1] == dir_separator ) + { + DIR *dir = opendir( config_get()->iface.theme.music ); + struct dirent *e; + int nr_music = 0; + if ( dir != NULL ) + { + while ( ( e = readdir( dir )) != NULL ) + if ( (fnmatch( "*.mp3", e->d_name, 0) == 0) || + (fnmatch( "*.ogg", e->d_name, 0) == 0) ) + nr_music++; + if ( nr_music > 0 ) + { + int sel_music = rand( )%nr_music; + closedir( dir ); + dir = opendir( config_get()->iface.theme.music ); + e = readdir( dir ); + while ( sel_music > 0 ) + { + e = readdir( dir ); + sel_music--; + } + char music_name[CONFIG_FILE_NAME_LENGTH]; + snprintf( music_name, CONFIG_FILE_NAME_LENGTH, "%s%s", config_get()->iface.theme.music, e->d_name ); + music = Mix_LoadMUS( music_name ); + } + closedir( dir ); + } + } + else + music = Mix_LoadMUS( config_get()->iface.theme.music ); + if (music != NULL) + Mix_PlayMusic(music, 0); + if ( config_get()->iface.music_volume > 0 && config_get()->iface.music_volume <= 128 ) + Mix_VolumeMusic(config_get()->iface.music_volume); +} + +void stopmusic(void) { + if (music != NULL) + Mix_FreeMusic(music); +} diff --git a/submenu.c b/submenu.c index 131ee56..af2c2f3 100644 --- a/submenu.c +++ b/submenu.c @@ -27,6 +27,7 @@ static const int MAX_STEPS = 100; static struct category *prev_category = NULL; static struct category *category = NULL; static struct category_value *category_value = NULL; + static struct platform *platform = NULL; static struct texture *message = NULL; static struct arrow arrow_retreat; @@ -343,7 +344,7 @@ void submenu_draw( void ) { ty *=zoom; if( step-- == 1 ) { - /* Animation complete */ + // Animation complete if( hide_direction == -1 ) visible = 1; else @@ -403,11 +404,13 @@ void submenu_draw( void ) { if( focus_has() == FOCUS_SUBMENU ) { hint_draw_arrow( &arrow_retreat ); hint_draw_arrow( &arrow_advance ); - } + } } int submenu_do_filter( void ) { int count = 0; + + count = game_list_unfilter(); switch( type ) { case( MENU_ALL ): count = game_list_unfilter(); diff --git a/video.c b/video.c index 8a30700..1e503ac 100644 --- a/video.c +++ b/video.c @@ -4,21 +4,24 @@ * and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) */ -#include -#include +#include +#include #include "video.h" #include "sound.h" #include "packet.h" #include "frame.h" #include "config.h" #include "ogl.h" +#include -#define AUDIO_BUFFER_SIZE ((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2) +#define AUDIO_BUFFER_SIZE ((192000 * 3) / 2) static const int VIDEO_SIZE = 256; +static const int VIDEO_SIZE_SCALE = 512; static const int CONV_FORMAT = PIX_FMT_RGB24; static const int VIDEO_BPP = 3; static const int MAX_QUEUE_PACKETS = 20; static const int QUEUE_FULL_DELAY = 10; +//static const GLfloat VIDEO_SCALE = 0.005; static const int MAX_QUEUE_FRAMES = 30; static const int SAMPLES = 1024; static const float FUDGE_FACTOR = 0.02; @@ -48,17 +51,11 @@ SDL_AudioSpec audio_spec; static int audio_open = 0; static SDL_Thread *reader_thread = NULL; -static int stop = 0; static int audio_running = 0; -static int reader_running = 0; static int got_texture = 0; static struct texture *texture; - - -int video_stopped( void ) { - return stop; -} - +static int stop = 0; +int reader_running = 0; int video_init( void ) { avcodec_register_all(); av_register_all(); @@ -73,15 +70,13 @@ int video_init( void ) { packet_queue_init( &audio_queue ); frame_queue_init( &video_queue ); - url_set_interrupt_cb( video_stopped ); - return 0; } void video_free( void ) { video_close(); - if( conv_frame ); + if( conv_frame ) av_free( conv_frame ); conv_frame = NULL; } @@ -89,15 +84,17 @@ void video_free( void ) { void video_close( void ) { int timeout = 10; stop = 1; + const struct config *config = config_get(); packet_queue_flush( &audio_queue ); frame_queue_flush( &video_queue ); while( (reader_running || audio_running) && timeout-- ) SDL_Delay( 10 ); - - if( audio_open ) - SDL_CloseAudio(); + if (config->iface.video_sound) { + if( audio_open ) + SDL_CloseAudio(); + } audio_open = 0; if( video_codec_context ) @@ -109,7 +106,7 @@ void video_close( void ) { audio_codec_context = NULL; if( format_context ) - av_close_input_file( format_context ); + avformat_close_input( &format_context ); format_context = NULL; if( video_buffer ) @@ -172,48 +169,130 @@ int video_decode_video_frame( AVPacket *packet ) { int video_decode_audio_frame( AVCodecContext *context, uint8_t *buffer, int buffer_size ) { static AVPacket packet; int used, data_size; - + int i; +#if LIBAVCODEC_VERSION_MAJOR > 53 +// Libavcodec54 + int plane_size; + int sampleIndex, channelIndex; + AVFrame * frame = avcodec_alloc_frame (); +#endif /* LIBAVCODEC_VERSION_MAJOR > 53 */ for(;;) { - while( audio_packet.size > 0 ) { - data_size = buffer_size; - used = avcodec_decode_audio3( context, (int16_t *)audio_buffer, &data_size, - &audio_packet); - if( used < 0 ) { - /* if error, skip frame */ - audio_packet.size = 0; - break; + while (audio_packet.size > 0) { +#if LIBAVCODEC_VERSION_MAJOR > 53 + used = avcodec_decode_audio4( context, frame, &data_size, &audio_packet); + if( used < 0 ) { + // if error, skip frame // + fprintf(stderr, "Error while decoding\n"); + audio_packet.size = 0; + break; + } + audio_packet.data += used; + audio_packet.size -= used; + audio_packet.dts = AV_NOPTS_VALUE; + audio_packet.pts = AV_NOPTS_VALUE; + if( data_size <= 0 ) { + // No data yet, get more frames // + continue; + } + + + // if a frame has been decoded, output it // + data_size = av_samples_get_buffer_size(&plane_size, context->channels,frame->nb_samples, context->sample_fmt, 1); + audio_clock += (double)data_size / + (double)(format_context->streams[audio_stream]->codec->sample_rate * + (sizeof(float) * format_context->streams[audio_stream]->codec->channels)); + + // We need to convert the decoded frame to the right format (AUDIO_S16SYS) + // It may be a better idea to use dedicated function rather than manualy performing + // the conversion. + data_size = 0; + if (context->sample_fmt == AV_SAMPLE_FMT_FLTP) { + int16_t* buffer16 = (int16_t*)buffer; + for (sampleIndex = 0; sampleIndex < frame->nb_samples; sampleIndex++) { + for (channelIndex = 0; channelIndex < context->channels; channelIndex++) { + float* extended_data = (float*)(frame->extended_data[channelIndex]); + float sample = extended_data[sampleIndex]; + + + if (sample < -1.0f) { + sample = -1.0f; + } else if (sample > 1.0f) { + sample = 1.0f; + } + buffer16[(sampleIndex * context->channels + channelIndex)] = (int16_t)(sample * 32767.0f); + } + } + + data_size = context->channels * frame->nb_samples * sizeof(int16_t); } - audio_packet.data += used; - audio_packet.size -= used; - - if( data_size <= 0 ) { - /* No data yet, get more frames */ - continue; + else if (context->sample_fmt == AV_SAMPLE_FMT_S16P) { + // Note : planar size is in frame->linesize[0] for all plans + // as they must have the same size. + int16_t* buffer16 = (int16_t*) buffer; + for (channelIndex = 0; channelIndex < context->channels; channelIndex++) { + int16_t* extended_data = (int16_t*)(frame->data[channelIndex]); + for (i = 0; i < frame->linesize[0] / 2; i++) { + int16_t sample = extended_data[i]; + buffer16[channelIndex + i * 2] = sample; + } + } + data_size = context->channels * frame->linesize[0]; + } + else + { + data_size = -1; } + + av_free(frame); + return data_size; + } + + +#endif /* LIBAVCODEC_VERSION_MAJOR > 53 */ +// Libavcodec53 +#if LIBAVCODEC_VERSION_MAJOR <= 53 + + data_size = buffer_size; + // Todo depreciated // + used = avcodec_decode_audio3( context, (int16_t *)audio_buffer, &data_size, + &audio_packet); + if( used < 0 ) { + // if error, skip frame // + audio_packet.size = 0; + break; + } + audio_packet.data += used; + audio_packet.size -= used; - audio_clock += (double)data_size / - (double)(format_context->streams[audio_stream]->codec->sample_rate * - (2 * format_context->streams[audio_stream]->codec->channels)); + if( data_size <= 0 ) { + // No data yet, get more frames // + continue; + } - /* We have data, return it and come back for more later */ - return data_size; + audio_clock += (double)data_size / + (double)(format_context->streams[audio_stream]->codec->sample_rate * + (2 * format_context->streams[audio_stream]->codec->channels)); + // We have data, return it and come back for more later // + return data_size; } + +#endif /* LIBAVCODEC_VERSION_MAJOR < 53 */ if( packet.data ) av_free_packet( &packet ); if( stop ) { + av_free(frame); audio_running = 0; return -1; } - if( packet_queue_get( &audio_queue, &packet, 1 ) < 0 ) + if( packet_queue_get( &audio_queue, &audio_packet, 1 ) < 0 ) { + av_free(frame); return -1; + } + if( audio_packet.pts != AV_NOPTS_VALUE ) { + audio_clock = audio_packet.pts * av_q2d( format_context->streams[audio_stream]->time_base ); - audio_packet.data = packet.data; - audio_packet.size = packet.size; - - if( packet.pts != AV_NOPTS_VALUE ) { - audio_clock = packet.pts * av_q2d( format_context->streams[audio_stream]->time_base ); } } } @@ -255,34 +334,41 @@ void video_release_buffer( struct AVCodecContext *c, AVFrame *f ) { int video_reader_thread( void *data ) { static AVPacket packet; + const struct config *config = config_get(); if( !format_context || !video_codec_context || !video_buffer ) return -1; - reader_running = 1; - + int value; while( !stop ) { if( video_queue.frames >= MAX_QUEUE_FRAMES || audio_queue.packets >= MAX_QUEUE_PACKETS ) { SDL_Delay( QUEUE_FULL_DELAY ); } else { if( av_read_frame( format_context, &packet ) >= 0 ) { - if( packet.stream_index == video_stream ) { + value = packet.stream_index; + if( value == video_stream ) { video_decode_video_frame( &packet ); } - else if( packet.stream_index == audio_stream && audio_codec_context ) { + if (!config->iface.video_sound) { + // Yes I know very ugly ishould find another way ... + usleep( 20000 ); + } else { packet_queue_put( &audio_queue, &packet ); - } - else { + } + if (( value != video_stream ) && (value != audio_stream && audio_codec_context)) av_free_packet( &packet ); + } else { + // stop video loop + if(!config->iface.video_loop) { + stop = 1; + video_close(); + } else { + av_seek_frame( format_context, -1, 0, 0 ); } } - else { - av_seek_frame( format_context, -1, 0, AVSEEK_FLAG_BACKWARD|AVSEEK_FLAG_BYTE ); - } } } - reader_running = 0; return 0; } @@ -290,6 +376,7 @@ int video_reader_thread( void *data ) { int video_open( const char *filename ) { int i = -1; + const struct config *config = config_get(); format_context = NULL; video_codec_context = NULL; video_stream = -1; @@ -300,17 +387,17 @@ int video_open( const char *filename ) { audio_buffer_size = 0; audio_buffer_index = 0; - av_init_packet(&audio_packet); + av_init_packet(&audio_packet); if( !filename ) return -1; - - if( av_open_input_file( &format_context, filename, NULL, 0, NULL ) != 0 ) { + + if( avformat_open_input( &format_context, filename, NULL, 0 ) != 0 ) { fprintf( stderr, "Warning: Error opening video file '%s'\n", filename ); return -1; } - if( av_find_stream_info( format_context ) < 0 ) { + if( avformat_find_stream_info( format_context, NULL ) < 0 ) { fprintf( stderr, "Warning: Error reading stream info from '%s'\n", filename ); return -1; } @@ -330,14 +417,14 @@ int video_open( const char *filename ) { return -1; } - video_codec_context->release_buffer = video_release_buffer; + video_codec_context->release_buffer = video_release_buffer; video_codec = avcodec_find_decoder( video_codec_context->codec_id ); if( !video_codec ) { fprintf( stderr, "Warning: Video codec in video '%s' not supported\n", filename ); return -1; } - if( avcodec_open( video_codec_context, video_codec ) != 0 ) { + if( avcodec_open2( video_codec_context, video_codec, NULL ) != 0 ) { fprintf( stderr, "Warning: Couldn't open video codec '%s' for '%s'\n", video_codec->name, filename ); return -1; } @@ -353,6 +440,9 @@ int video_open( const char *filename ) { avpicture_fill( (AVPicture*)conv_frame, video_buffer, CONV_FORMAT, VIDEO_SIZE, VIDEO_SIZE ); + if (music && config->iface.video_sound){ + Mix_HaltMusic(); + } if( audio_codec_context ) { audio_codec = avcodec_find_decoder( audio_codec_context->codec_id ); if( !audio_codec ) { @@ -360,7 +450,7 @@ int video_open( const char *filename ) { audio_codec_context = NULL; } else { - if( avcodec_open( audio_codec_context, audio_codec ) != 0 ) { + if( avcodec_open2( audio_codec_context, audio_codec, NULL ) != 0 ) { fprintf( stderr, "Warning: Couldn't open audio codec '%s' for '%s'\n", audio_codec->name, filename ); audio_codec_context = NULL; } @@ -374,19 +464,23 @@ int video_open( const char *filename ) { desired.samples = SAMPLES; desired.callback = video_audio_callback; desired.userdata = audio_codec_context; - - sound_close_mixer(); - - if( SDL_OpenAudio( &desired, &audio_spec ) < 0 ) { - fprintf( stderr, "Warning: Couldn't open audio for video: %s\n", SDL_GetError() ); - audio_codec_context = NULL; - } - else { - packet_queue_flush( &audio_queue ); - audio_open = 1; - audio_running = 1; - SDL_PauseAudio( 0 ); - } + if (config->iface.video_sound) { + sound_close_mixer(); + if ( SDL_OpenAudio( &desired, &audio_spec ) < 0 ) { + fprintf( stderr, "Warning: Couldn't open audio for video: %s\n", SDL_GetError() ); + audio_codec_context = NULL; + } else { + packet_queue_flush( &audio_queue ); + audio_open = 1; + audio_running = 1; + SDL_PauseAudio( 0 ); + } + } else { + audio_open = 1; + audio_running = 1; + SDL_PauseAudio( 0 ); + } + } } } @@ -400,12 +494,11 @@ int video_open( const char *filename ) { got_texture = 0; stop = 0; - reader_thread = SDL_CreateThread( video_reader_thread, NULL ); + reader_thread = SDL_CreateThread( video_reader_thread, NULL, NULL ); if( !reader_thread ) { fprintf( stderr, "Warning: Couldn't start video reader thread\n" ); return -1; } - return 0; } @@ -449,7 +542,6 @@ void video_clock_tick( void ) { struct texture *video_get_frame( void ) { static AVFrame *frame = NULL; - int ret = -1; GLenum error = GL_NO_ERROR; double clock = video_master_clock(); @@ -479,7 +571,7 @@ struct texture *video_get_frame( void ) { } else { sws_scale( scale_context, (const uint8_t **)frame->data, frame->linesize, 0, - VIDEO_SIZE, conv_frame->data, conv_frame->linesize ); + VIDEO_SIZE_SCALE, conv_frame->data, conv_frame->linesize ); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture( GL_TEXTURE_2D, texture->id ); @@ -503,7 +595,6 @@ struct texture *video_get_frame( void ) { } else { got_texture = 1; - ret = 0; } }