added support for sound configuration parameters (not used yet)
authorHolger Schemel <info@artsoft.org>
Sat, 10 Feb 2024 19:59:33 +0000 (20:59 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 18 Feb 2024 14:57:40 +0000 (15:57 +0100)
build-scripts/create_element_defs.pl
src/files.c
src/files.h
src/init.c
src/main.c
src/main.h

index b75d86ac79c6752c99a3068df90604f530f9a6c4..08d4e946f2c5ebff89cd2ec93724a839d6be19f6 100755 (executable)
@@ -71,7 +71,7 @@ my $text_e2s_c = 'values for element/sounds mapping configuration';
 my $text_fnt_c = 'values for font/graphics mapping configuration';
 my $text_g2s_c = 'values for gamemode/sound mapping configuration';
 my $text_g2m_c = 'values for gamemode/music mapping configuration';
-my $text_var_c = 'values for image and layout parameter configuration';
+my $text_var_c = 'values for graphics and sound parameter configuration';
 my $text_act_c = 'values for active states of elements and fonts';
 
 my $num_custom_elements = 256;
@@ -1455,7 +1455,7 @@ sub print_gamemode_to_music_entry
     print "  },\n";
 }
 
-sub print_image_config_var_entry
+sub print_config_var_entry
 {
     my ($token, $var) = @_;
 
@@ -2480,7 +2480,7 @@ sub print_gamemode_to_music_list
     print_file_footer($filename_conf_g2m_c);
 }
 
-sub print_image_config_vars
+sub print_config_vars
 {
     # ---------- read graphic file definitions ----------
 
@@ -2587,7 +2587,7 @@ sub print_image_config_vars
                $var = $1 . "[GFX_SPECIAL_ARG_DEFAULT]" . $3;
            }
 
-           print_image_config_var_entry("\"$token\"", "&$var");
+           print_config_var_entry("\"$token\"", "&$var");
 
            if ($var =~ /^(title)_default/ ||
                $var =~ /^(title_initial)_default/ ||
@@ -2597,12 +2597,54 @@ sub print_image_config_vars
                my $prefix = $1;
                $var =~ s/^$prefix/${prefix}_first/;
 
-               print_image_config_var_entry("\"$token\"", "&$var");
+               print_config_var_entry("\"$token\"", "&$var");
            }
        }
     }
 
-    print_image_config_var_entry('NULL', 'NULL');
+    print_config_var_entry('NULL', 'NULL');
+
+    print "};\n";
+
+    close FILE;
+
+
+    # ---------- read sound file definitions ----------
+
+    $filename = "$src_path/conf_snd.c";
+
+    open(FILE, "$filename") ||
+       fail("cannot open file '$filename' for reading");
+
+    print "struct TokenIntPtrInfo sound_config_vars[] =\n";
+    print "{\n";
+
+    $start_parsing = 0;
+
+    while (<FILE>)
+    {
+       chomp;                          # cut trailing newline
+
+       if (/CONFIG_VARS_START/)        # keyword to start parsing file
+       {
+           $start_parsing = 1;
+       }
+
+       if (!$start_parsing)
+       {
+           next;
+       }
+
+       if (/^\s*\{\s*\"([^\"]+)\"/)    # config token found
+       {
+           my $token = $1;
+           my $var = $token;
+
+           print_config_var_entry("\"$token\"", "&$var");
+       }
+    }
+
+    print_config_var_entry('NULL', 'NULL');
 
     print "};\n";
 
@@ -2799,7 +2841,7 @@ sub main
     }
     elsif ($ARGV[0] eq $filename_conf_var_c)
     {
-       print_image_config_vars();
+       print_config_vars();
     }
     elsif ($ARGV[0] eq $filename_conf_act_c)
     {
index 4352da65bc291d13b09181d7e42ac84fe18f3ead..34d9f6d0b92f2e00810e63c5b799c9a5f566ebbc 100644 (file)
@@ -12888,6 +12888,65 @@ void LoadMenuDesignSettings_AfterGraphics(void)
   InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
 }
 
+void InitSoundSettings_FromHash(SetupFileHash *setup_file_hash,
+                               boolean ignore_defaults)
+{
+  int i;
+
+  for (i = 0; sound_config_vars[i].token != NULL; i++)
+  {
+    char *value = getHashEntry(setup_file_hash, sound_config_vars[i].token);
+
+    // (ignore definitions set to "[DEFAULT]" which are already initialized)
+    if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+      continue;
+
+    if (value != NULL)
+      *sound_config_vars[i].value =
+       get_token_parameter_value(sound_config_vars[i].token, value);
+  }
+}
+
+void InitSoundSettings_Static(void)
+{
+  // always start with reliable default values from static default config
+  InitSoundSettings_FromHash(sound_config_hash, FALSE);
+}
+
+static void LoadSoundSettingsFromFilename(char *filename)
+{
+  SetupFileHash *setup_file_hash;
+
+  if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
+    return;
+
+  // read (and overwrite with) values that may be specified in config file
+  InitSoundSettings_FromHash(setup_file_hash, TRUE);
+
+  freeSetupFileHash(setup_file_hash);
+}
+
+void LoadSoundSettings(void)
+{
+  char *filename_base = UNDEFINED_FILENAME, *filename_local;
+
+  InitSoundSettings_Static();
+
+  if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_SOUNDS))
+  {
+    // first look for special settings configured in level series config
+    filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+    if (fileExists(filename_base))
+      LoadSoundSettingsFromFilename(filename_base);
+  }
+
+  filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+  if (filename_local != NULL && !strEqual(filename_base, filename_local))
+    LoadSoundSettingsFromFilename(filename_local);
+}
+
 void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
 {
   char *filename = getEditorSetupFilename();
index 887a9fdf5e8825c220f3d78fa5dd3c0ca5cc9e81..8301b781769f92ad5c984600d8ee259d1178ece8 100644 (file)
@@ -103,6 +103,9 @@ void InitMenuDesignSettings_FromHash(SetupFileHash *, boolean);
 void InitMenuDesignSettings_Static(void);
 void LoadMenuDesignSettings(void);
 void LoadMenuDesignSettings_AfterGraphics(void);
+void InitSoundSettings_FromHash(SetupFileHash *, boolean);
+void InitSoundSettings_Static(void);
+void LoadSoundSettings(void);
 void LoadUserDefinedEditorElementList(int **, int *);
 void LoadMusicInfo(void);
 void LoadHelpAnimInfo(void);
index 73b9348efc7bce7b41769e0bcc55263cd85e6e7a..9d3fa544c7407fa80547811443b2fd241011812f 100644 (file)
@@ -5051,6 +5051,13 @@ static void InitGlobal(void)
                 image_config[i].token,
                 image_config[i].value);
 
+  // create hash from sound config list
+  sound_config_hash = newSetupFileHash();
+  for (i = 0; sound_config[i].token != NULL; i++)
+    setHashEntry(sound_config_hash,
+                sound_config[i].token,
+                sound_config[i].value);
+
   // create hash from element token list
   element_token_hash = newSetupFileHash();
   for (i = 0; element_name_info[i].token_name != NULL; i++)
@@ -5593,10 +5600,15 @@ static void InitArtworkConfig(void)
 
   // dynamically determine list of sound tokens to be ignored
   num_ignore_sound_tokens = num_ignore_generic_tokens;
+  for (i = 0; sound_config_vars[i].token != NULL; i++)
+    num_ignore_sound_tokens++;
   ignore_sound_tokens =
     checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
   for (i = 0; i < num_ignore_generic_tokens; i++)
     ignore_sound_tokens[i] = ignore_generic_tokens[i];
+  for (i = 0; i < num_ignore_sound_tokens - num_ignore_generic_tokens; i++)
+    ignore_sound_tokens[num_ignore_generic_tokens + i] =
+      sound_config_vars[i].token;
   ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
 
   // dynamically determine list of music tokens to be ignored
@@ -5938,6 +5950,29 @@ static void InitGfxBackground(void)
   redraw_mask = REDRAW_ALL;
 }
 
+static void InitSnd(void)
+{
+  InitSoundSettings_Static();
+
+  // read settings for initial sounds from default custom artwork config
+  char *snd_config_filename = getPath3(options.sounds_directory,
+                                      SND_DEFAULT_SUBDIR,
+                                      SOUNDSINFO_FILENAME);
+
+  if (fileExists(snd_config_filename))
+  {
+    SetupFileHash *setup_file_hash = loadSetupFileHash(snd_config_filename);
+
+    if (setup_file_hash)
+    {
+      // read values from custom sounds config file
+      InitSoundSettings_FromHash(setup_file_hash, FALSE);
+
+      freeSetupFileHash(setup_file_hash);
+    }
+  }
+}
+
 static void InitLevelInfo(void)
 {
   LoadLevelInfo();                             // global level info
@@ -6036,6 +6071,9 @@ static void InitSound(void)
   InitReloadCustomSounds();
   print_timestamp_time("InitReloadCustomSounds");
 
+  LoadSoundSettings();
+  print_timestamp_time("LoadSoundSettings");
+
   ReinitializeSounds();
   print_timestamp_time("ReinitializeSounds");
 
@@ -6559,6 +6597,7 @@ void OpenAll(void)
   print_timestamp_time("[init element properties stuff]");
 
   InitGfx();
+  InitSnd();
 
   print_timestamp_time("InitGfx");
 
index a1ba5c7c5cc6069b92d5ec07e8bb689848182b70..168a650b9e2ef8c3183eea6c450e4e19d2fb37eb 100644 (file)
@@ -173,6 +173,7 @@ struct HelpAnimInfo    *helpanim_info = NULL;
 
 SetupFileHash          *helptext_info = NULL;
 SetupFileHash         *image_config_hash = NULL;
+SetupFileHash         *sound_config_hash = NULL;
 SetupFileHash         *element_token_hash = NULL;
 SetupFileHash         *graphic_token_hash = NULL;
 SetupFileHash         *font_token_hash = NULL;
index 92585c34140f2c322253f4f22020689b808c6429..e5f50a4e73ce5dc6ffd6c68abdb0768273bccb5f 100644 (file)
@@ -3963,6 +3963,7 @@ extern struct ElementActionInfo   element_action_info[];
 extern struct ElementDirectionInfo element_direction_info[];
 extern struct SpecialSuffixInfo special_suffix_info[];
 extern struct TokenIntPtrInfo  image_config_vars[];
+extern struct TokenIntPtrInfo  sound_config_vars[];
 extern struct FontInfo         font_info[];
 extern struct GlobalAnimInfo   global_anim_info[];
 extern struct GlobalAnimNameInfo global_anim_name_info[];
@@ -3975,6 +3976,7 @@ extern struct MusicFileInfo    *music_file_info;
 extern struct HelpAnimInfo     *helpanim_info;
 extern SetupFileHash           *helptext_info;
 extern SetupFileHash          *image_config_hash;
+extern SetupFileHash          *sound_config_hash;
 extern SetupFileHash          *element_token_hash;
 extern SetupFileHash          *graphic_token_hash;
 extern SetupFileHash          *font_token_hash;