From: Holger Schemel Date: Mon, 28 Oct 2013 19:39:08 +0000 (+0100) Subject: rnd-20131028-1-src X-Git-Tag: 3.3.1.1^2~1 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=3d81daa33f1c59045b731ea422b5cd5505b7048e rnd-20131028-1-src * added volume controls for sounds, loops and music to sound setup * version number set to 3.3.1.1 --- diff --git a/ChangeLog b/ChangeLog index 0ae29c85..89a2779f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-10-26 + * added volume controls for sounds, loops and music to sound setup + +2013-10-24 + * version number set to 3.3.1.1 + 2013-10-23 * version 3.3.1.0 released diff --git a/src/conftime.h b/src/conftime.h index 4adc2a40..0b68beac 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2013-10-24 13:45" +#define COMPILE_DATE_STRING "2013-10-28 20:34" diff --git a/src/files.c b/src/files.c index 7ff37822..0f74fc00 100644 --- a/src/files.c +++ b/src/files.c @@ -9246,8 +9246,11 @@ void SaveScore(int nr) #define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 30 #define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 31 #define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 32 +#define SETUP_TOKEN_VOLUME_SIMPLE 33 +#define SETUP_TOKEN_VOLUME_LOOPS 34 +#define SETUP_TOKEN_VOLUME_MUSIC 35 -#define NUM_GLOBAL_SETUP_TOKENS 33 +#define NUM_GLOBAL_SETUP_TOKENS 36 /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0 @@ -9390,6 +9393,9 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_SWITCH3,&si.override_level_graphics, "override_level_graphics" }, { TYPE_SWITCH3,&si.override_level_sounds, "override_level_sounds" }, { TYPE_SWITCH3,&si.override_level_music, "override_level_music" }, + { TYPE_INTEGER,&si.volume_simple, "volume_simple" }, + { TYPE_INTEGER,&si.volume_loops, "volume_loops" }, + { TYPE_INTEGER,&si.volume_music, "volume_music" }, }; static boolean not_used = FALSE; @@ -9560,6 +9566,10 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->override_level_sounds = FALSE; si->override_level_music = FALSE; + si->volume_simple = 100; /* percent */ + si->volume_loops = 100; /* percent */ + si->volume_music = 100; /* percent */ + si->editor.el_boulderdash = TRUE; si->editor.el_emerald_mine = TRUE; si->editor.el_emerald_mine_club = TRUE; @@ -9822,7 +9832,8 @@ void SaveSetup() { /* just to make things nicer :) */ if (i == SETUP_TOKEN_PLAYER_NAME + 1 || - i == SETUP_TOKEN_GRAPHICS_SET) + i == SETUP_TOKEN_GRAPHICS_SET || + i == SETUP_TOKEN_VOLUME_SIMPLE) fprintf(file, "\n"); fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i)); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index fe4c98ba..246e3891 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1184,8 +1184,13 @@ void dumpTreeInfo(TreeInfo *node, int depth) for (i = 0; i < (depth + 1) * 3; i++) printf(" "); + printf("'%s' / '%s'\n", node->identifier, node->name); + + /* + // use for dumping artwork info tree printf("subdir == '%s' ['%s', '%s'] [%d])\n", node->subdir, node->fullpath, node->basepath, node->in_user_dir); + */ if (node->node_group != NULL) dumpTreeInfo(node->node_group, depth + 1); @@ -2772,7 +2777,7 @@ static int compareTreeInfoEntries(const void *object1, const void *object2) { const TreeInfo *entry1 = *((TreeInfo **)object1); const TreeInfo *entry2 = *((TreeInfo **)object2); - int class_sorting1, class_sorting2; + int class_sorting1 = 0, class_sorting2 = 0; int compare_result; if (entry1->type == TREE_TYPE_LEVEL_DIR) @@ -2780,7 +2785,9 @@ static int compareTreeInfoEntries(const void *object1, const void *object2) class_sorting1 = LEVELSORTING(entry1); class_sorting2 = LEVELSORTING(entry2); } - else + else if (entry1->type == TREE_TYPE_GRAPHICS_DIR || + entry1->type == TREE_TYPE_SOUNDS_DIR || + entry1->type == TREE_TYPE_MUSIC_DIR) { class_sorting1 = ARTWORKSORTING(entry1); class_sorting2 = ARTWORKSORTING(entry2); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index ff42562a..fed5e3e9 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -71,6 +71,21 @@ #define SAME_SOUND_NR(x,y) ((x).nr == (y).nr) #define SAME_SOUND_DATA(x,y) ((x).data_ptr == (y).data_ptr) +#define SOUND_VOLUME_FROM_PERCENT(v,p) ((p) < 0 ? SOUND_MIN_VOLUME : \ + (p) > 100 ? (v) : \ + (p) * (v) / 100) + +#define SOUND_VOLUME_SIMPLE(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_simple) +#define SOUND_VOLUME_LOOPS(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops) +#define SOUND_VOLUME_MUSIC(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music) + +#define SETUP_SOUND_VOLUME(v,s) ((s) == SND_CTRL_PLAY_MUSIC ? \ + SOUND_VOLUME_MUSIC(v) : \ + (s) == SND_CTRL_PLAY_LOOP ? \ + SOUND_VOLUME_LOOPS(v) : \ + SOUND_VOLUME_SIMPLE(v)) + + #if defined(AUDIO_UNIX_NATIVE) struct SoundHeader_WAV { @@ -721,7 +736,7 @@ static void Mixer_PlayMusicChannel() /* Mix_VolumeMusic() must be called _after_ Mix_PlayMusic() -- this looks like a bug in the SDL_mixer library */ Mix_PlayMusic(mixer[audio.music_channel].data_ptr, -1); - Mix_VolumeMusic(SOUND_MAX_VOLUME); + Mix_VolumeMusic(mixer[audio.music_channel].volume); } #endif } @@ -2104,6 +2119,8 @@ void PlaySoundExt(int nr, int volume, int stereo_position, int state) audio.sound_deactivated) return; + volume = SETUP_SOUND_VOLUME(volume, state); + if (volume < SOUND_MIN_VOLUME) volume = SOUND_MIN_VOLUME; else if (volume > SOUND_MAX_VOLUME) diff --git a/src/libgame/system.h b/src/libgame/system.h index 11670c69..98225eae 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -944,6 +944,10 @@ struct SetupInfo int override_level_sounds; /* not boolean -- can also be "AUTO" */ int override_level_music; /* not boolean -- can also be "AUTO" */ + int volume_simple; + int volume_loops; + int volume_music; + struct SetupEditorInfo editor; struct SetupEditorCascadeInfo editor_cascade; struct SetupShortcutInfo shortcut; diff --git a/src/main.h b/src/main.h index 434d3c93..c484b859 100644 --- a/src/main.h +++ b/src/main.h @@ -2066,7 +2066,7 @@ #define PROGRAM_VERSION_MAJOR 3 #define PROGRAM_VERSION_MINOR 3 #define PROGRAM_VERSION_PATCH 1 -#define PROGRAM_VERSION_BUILD 0 +#define PROGRAM_VERSION_BUILD 1 #define PROGRAM_TITLE_STRING "Rocks'n'Diamonds" #define PROGRAM_AUTHOR_STRING "Holger Schemel" diff --git a/src/screens.c b/src/screens.c index 77b90603..b56ffe58 100644 --- a/src/screens.c +++ b/src/screens.c @@ -63,8 +63,11 @@ #define SETUP_MODE_CHOOSE_GRAPHICS 18 #define SETUP_MODE_CHOOSE_SOUNDS 19 #define SETUP_MODE_CHOOSE_MUSIC 20 +#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 21 +#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 22 +#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 23 -#define MAX_SETUP_MODES 21 +#define MAX_SETUP_MODES 24 /* for input setup functions */ #define SETUPINPUT_SCREEN_POS_START 0 @@ -138,6 +141,7 @@ static void CustomizeKeyboard(int); static void CalibrateJoystick(int); static void execSetupGame(void); static void execSetupGraphics(void); +static void execSetupSound(void); static void execSetupArtwork(void); static void HandleChooseTree(int, int, int, int, int, TreeInfo **); @@ -176,6 +180,15 @@ static TreeInfo *scroll_delay_current = NULL; static TreeInfo *game_speeds = NULL; static TreeInfo *game_speed_current = NULL; +static TreeInfo *volumes_simple = NULL; +static TreeInfo *volume_simple_current = NULL; + +static TreeInfo *volumes_loops = NULL; +static TreeInfo *volume_loops_current = NULL; + +static TreeInfo *volumes_music = NULL; +static TreeInfo *volume_music_current = NULL; + static TreeInfo *level_number = NULL; static TreeInfo *level_number_current = NULL; @@ -229,6 +242,27 @@ static struct { -1, NULL }, }; +static struct +{ + int value; + char *text; +} volumes_list[] = +{ + { 0, "0 %" }, + { 10, "10 %" }, + { 20, "20 %" }, + { 30, "30 %" }, + { 40, "40 %" }, + { 50, "50 %" }, + { 60, "60 %" }, + { 70, "70 %" }, + { 80, "80 %" }, + { 90, "90 %" }, + { 100, "100 %" }, + + { -1, NULL }, +}; + #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \ (s) <= GAME_MODE_SETUP ? (s) : \ (s) == GAME_MODE_PSEUDO_TYPENAME ? \ @@ -3525,6 +3559,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE || setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) execSetupGraphics(); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE || + setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS || + setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC) + execSetupSound(); else execSetupArtwork(); } @@ -3711,6 +3749,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE || setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) execSetupGraphics(); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE || + setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS || + setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC) + execSetupSound(); else execSetupArtwork(); } @@ -3976,6 +4018,9 @@ static char *game_speed_text; static char *graphics_set_name; static char *sounds_set_name; static char *music_set_name; +static char *volume_simple_text; +static char *volume_loops_text; +static char *volume_music_text; static void execSetupMain() { @@ -4160,6 +4205,7 @@ static void execSetupGraphics() #endif setup_mode = SETUP_MODE_GRAPHICS; + DrawSetupScreen(); } @@ -4180,8 +4226,166 @@ static void execSetupChooseScrollDelay() DrawSetupScreen(); } +static void execSetupChooseVolumeSimple() +{ + setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE; + + DrawSetupScreen(); +} + +static void execSetupChooseVolumeLoops() +{ + setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS; + + DrawSetupScreen(); +} + +static void execSetupChooseVolumeMusic() +{ + setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC; + + DrawSetupScreen(); +} + static void execSetupSound() { +#if 1 + if (volumes_simple == NULL) + { + int i; + + for (i = 0; volumes_list[i].value != -1; i++) + { + TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED); + char identifier[32], name[32]; + int value = volumes_list[i].value; + char *text = volumes_list[i].text; + + ti->node_top = &volumes_simple; + ti->sort_priority = value; + + sprintf(identifier, "%d", value); + sprintf(name, "%s", text); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + setString(&ti->infotext, "Sound Volume"); + + pushTreeInfo(&volumes_simple, ti); + } + + /* sort volume values to start with lowest volume value */ + sortTreeInfo(&volumes_simple); + + /* set current volume value to configured volume value */ + volume_simple_current = + getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple)); + + /* if that fails, set current volume to reliable default value */ + if (volume_simple_current == NULL) + volume_simple_current = + getTreeInfoFromIdentifier(volumes_simple, i_to_a(100)); + + /* if that also fails, set current volume to first available value */ + if (volume_simple_current == NULL) + volume_simple_current = volumes_simple; + } + + if (volumes_loops == NULL) + { + int i; + + for (i = 0; volumes_list[i].value != -1; i++) + { + TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED); + char identifier[32], name[32]; + int value = volumes_list[i].value; + char *text = volumes_list[i].text; + + ti->node_top = &volumes_loops; + ti->sort_priority = value; + + sprintf(identifier, "%d", value); + sprintf(name, "%s", text); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + setString(&ti->infotext, "Loops Volume"); + + pushTreeInfo(&volumes_loops, ti); + } + + /* sort volume values to start with lowest volume value */ + sortTreeInfo(&volumes_loops); + + /* set current volume value to configured volume value */ + volume_loops_current = + getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops)); + + /* if that fails, set current volume to reliable default value */ + if (volume_loops_current == NULL) + volume_loops_current = + getTreeInfoFromIdentifier(volumes_loops, i_to_a(100)); + + /* if that also fails, set current volume to first available value */ + if (volume_loops_current == NULL) + volume_loops_current = volumes_loops; + } + + if (volumes_music == NULL) + { + int i; + + for (i = 0; volumes_list[i].value != -1; i++) + { + TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED); + char identifier[32], name[32]; + int value = volumes_list[i].value; + char *text = volumes_list[i].text; + + ti->node_top = &volumes_music; + ti->sort_priority = value; + + sprintf(identifier, "%d", value); + sprintf(name, "%s", text); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + setString(&ti->infotext, "Music Volume"); + + pushTreeInfo(&volumes_music, ti); + } + + /* sort volume values to start with lowest volume value */ + sortTreeInfo(&volumes_music); + + /* set current volume value to configured volume value */ + volume_music_current = + getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music)); + + /* if that fails, set current volume to reliable default value */ + if (volume_music_current == NULL) + volume_music_current = + getTreeInfoFromIdentifier(volumes_music, i_to_a(100)); + + /* if that also fails, set current volume to first available value */ + if (volume_music_current == NULL) + volume_music_current = volumes_music; + } + + setup.volume_simple = atoi(volume_simple_current->identifier); + setup.volume_loops = atoi(volume_loops_current->identifier); + setup.volume_music = atoi(volume_music_current->identifier); + + /* needed for displaying volume text instead of identifier */ + volume_simple_text = volume_simple_current->name; + volume_loops_text = volume_loops_current->name; + volume_music_text = volume_music_current->name; +#endif + setup_mode = SETUP_MODE_SOUND; DrawSetupScreen(); @@ -4394,6 +4598,13 @@ static struct TokenInfo setup_info_sound[] = { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" }, { TYPE_SWITCH, &setup.sound_music, "Music:" }, { TYPE_EMPTY, NULL, "" }, + { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" }, + { TYPE_STRING, &volume_simple_text, "" }, + { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" }, + { TYPE_STRING, &volume_loops_text, "" }, + { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" }, + { TYPE_STRING, &volume_music_text, "" }, + { TYPE_EMPTY, NULL, "" }, { TYPE_LEAVE_MENU, execSetupMain, "Back" }, { 0, NULL, NULL } @@ -5723,6 +5934,12 @@ void DrawSetupScreen() DrawChooseTree(&artwork.snd_current); else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC) DrawChooseTree(&artwork.mus_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE) + DrawChooseTree(&volume_simple_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS) + DrawChooseTree(&volume_loops_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC) + DrawChooseTree(&volume_music_current); else DrawSetupScreen_Generic(); @@ -5752,6 +5969,12 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current); else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC) HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE) + HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS) + HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current); + else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC) + HandleChooseTree(mx, my, dx, dy, button, &volume_music_current); else HandleSetupScreen_Generic(mx, my, dx, dy, button);