From: Holger Schemel Date: Sat, 10 Feb 2024 19:59:33 +0000 (+0100) Subject: added support for sound configuration parameters (not used yet) X-Git-Tag: 4.4.0.0-test-1~416 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9f0fd9ccc8b367c5cca4de7b4504fdd7231c866c;p=rocksndiamonds.git added support for sound configuration parameters (not used yet) --- diff --git a/build-scripts/create_element_defs.pl b/build-scripts/create_element_defs.pl index b75d86ac..08d4e946 100755 --- a/build-scripts/create_element_defs.pl +++ b/build-scripts/create_element_defs.pl @@ -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 () + { + 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) { diff --git a/src/files.c b/src/files.c index 4352da65..34d9f6d0 100644 --- a/src/files.c +++ b/src/files.c @@ -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(); diff --git a/src/files.h b/src/files.h index 887a9fdf..8301b781 100644 --- a/src/files.h +++ b/src/files.h @@ -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); diff --git a/src/init.c b/src/init.c index 73b9348e..9d3fa544 100644 --- a/src/init.c +++ b/src/init.c @@ -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"); diff --git a/src/main.c b/src/main.c index a1ba5c7c..168a650b 100644 --- a/src/main.c +++ b/src/main.c @@ -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; diff --git a/src/main.h b/src/main.h index 92585c34..e5f50a4e 100644 --- a/src/main.h +++ b/src/main.h @@ -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;