rnd-20131028-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 28 Oct 2013 19:39:08 +0000 (20:39 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:00:03 +0000 (11:00 +0200)
* added volume controls for sounds, loops and music to sound setup
* version number set to 3.3.1.1

ChangeLog
src/conftime.h
src/files.c
src/libgame/setup.c
src/libgame/sound.c
src/libgame/system.h
src/main.h
src/screens.c

index 0ae29c85ebc8d3a274f0bb11277c334d478133e5..89a2779fa9ba0d62b19f7680a8e3b408966a9092 100644 (file)
--- 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
 
index 4adc2a409ece2e1103de5986238b6fa7ba3e52bd..0b68beac43e3313cd79aeb7d0466d38de2fd600e 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2013-10-24 13:45"
+#define COMPILE_DATE_STRING "2013-10-28 20:34"
index 7ff37822dd2d3a7ed3a2c4fe3a100d33c9319652..0f74fc00a00e31f9ed5843ce4be57b0e40ccfa71 100644 (file)
@@ -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));
index fe4c98ba697d173d7294e25bc9c3264199dfabba..246e3891f486e44cdfb1abf58c60be87d7e3e593 100644 (file)
@@ -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);
index ff42562a19da8ce3249efbfaea7ab9ab6fe3807d..fed5e3e9a2a3dd8546d0daa75ab91edc9aa15c73 100644 (file)
 #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)
index 11670c698785428a14fad8d5844908f03e6a0c45..98225eae1d4c4bff71a029823facd8bdae9a98e4 100644 (file)
@@ -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;
index 434d3c93162b159d6410b9478c3cc7d5360edd77..c484b859d5c0aeb829c7ac581c7e3230a6481d5e 100644 (file)
 #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"
index 77b906030d440733ce5c9451365af96acec53d54..b56ffe585e015b786223fd9257dd9702146405c7 100644 (file)
 #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);