From 93493827b6e8ee23d841299b38842d0df2d5d52a Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 9 Aug 2009 19:50:44 +0000 Subject: [PATCH] (svn r17139) -Change: add the concept of sound sets --- Makefile.bundle.in | 1 + bin/data/orig_dos.obs | 19 ++++++ bin/data/orig_win.obs | 19 ++++++ docs/obs_format.txt | 56 +++++++++++++++++ os/win32/installer/install.nsi | 4 ++ projects/openttd_vs80.vcproj | 4 -- projects/openttd_vs90.vcproj | 4 -- source.list | 1 - src/base_media_base.h | 19 +++++- src/gfxinit.cpp | 13 ++-- src/lang/english.txt | 5 ++ src/misc.cpp | 3 + src/network/core/tcp_content.h | 1 + src/network/network_content.cpp | 6 ++ src/network/network_content_gui.cpp | 4 ++ src/openttd.cpp | 26 ++++++-- src/settings_gui.cpp | 97 ++++++++++++++++++++++------- src/sound.cpp | 41 +++++++++++- src/sound_func.h | 2 - src/table/files.h | 31 --------- src/table/settings.h | 1 + 21 files changed, 274 insertions(+), 83 deletions(-) create mode 100644 bin/data/orig_dos.obs create mode 100644 bin/data/orig_win.obs create mode 100644 docs/obs_format.txt delete mode 100644 src/table/files.h diff --git a/Makefile.bundle.in b/Makefile.bundle.in index 6aba0ed8de..6fb2f4070f 100644 --- a/Makefile.bundle.in +++ b/Makefile.bundle.in @@ -52,6 +52,7 @@ endif $(Q)cp "$(BIN_DIR)/$(TTD)" "$(TTD_DIR)/" $(Q)cp "$(BIN_DIR)/data/"*.grf "$(DATA_DIR)/" $(Q)cp "$(BIN_DIR)/data/"*.obg "$(DATA_DIR)/" + $(Q)cp "$(BIN_DIR)/data/"*.obs "$(DATA_DIR)/" $(Q)cp "$(BIN_DIR)/data/opntitle.dat" "$(DATA_DIR)/" $(Q)cp "$(BIN_DIR)/lang/"*.lng "$(LANG_DIR)/" $(Q)cp "$(ROOT_DIR)/readme.txt" "$(BUNDLE_DIR)/" diff --git a/bin/data/orig_dos.obs b/bin/data/orig_dos.obs new file mode 100644 index 0000000000..ced0628a2a --- /dev/null +++ b/bin/data/orig_dos.obs @@ -0,0 +1,19 @@ +; $Id$ +; +; This represents the original sounds as on the Transport +; Tycoon Deluxe DOS CD. +; +[metadata] +name = original_dos +shortname = TTDD +version = 0 +description = Original Transport Tycoon Deluxe DOS edition sounds + +[files] +samples = SAMPLE.CAT + +[md5s] +SAMPLE.CAT = 422ea3dd074d2859bb51639a6e0e85da + +[origin] +default = You can find it on your Transport Tycoon Deluxe CD-ROM. diff --git a/bin/data/orig_win.obs b/bin/data/orig_win.obs new file mode 100644 index 0000000000..5f57880346 --- /dev/null +++ b/bin/data/orig_win.obs @@ -0,0 +1,19 @@ +; $Id$ +; +; This represents the original sounds as on the Transport +; Tycoon Deluxe for Windows CD. +; +[metadata] +name = original_windows +shortname = TTDW +version = 0 +description = Original Transport Tycoon Deluxe Windows edition sounds + +[files] +samples = SAMPLE.CAT + +[md5s] +SAMPLE.CAT = 9212e81e72badd4bbe1eaeae66458e10 + +[origin] +default = You can find it on your Transport Tycoon Deluxe CD-ROM. diff --git a/docs/obs_format.txt b/docs/obs_format.txt new file mode 100644 index 0000000000..bb168ad305 --- /dev/null +++ b/docs/obs_format.txt @@ -0,0 +1,56 @@ +; +; Example file for the OpenTTD Base Sound replacement sets. +; This file consists of basically two different parts: +; * metadata +; * information about the files +; +; Metadata contains information about the name and version +; of the sound set. +; +; == Getting started == +; - you can't add comments after values +; - you have to fill the MD5 checksum for each file +; - you may not miss any of the metadata or files items +; - `openttd -h` lists all sound replacements sets it found to be correct +; - `openttd -d grf=1` shows warnings/errors when parsing an .obs file +; - `openttd -S ` starts OpenTTD with the given set (case sensitive) +; - adding `soundsset = ` to the misc section of openttd.cfg makes +; OpenTTD start with that sound set by default +; - there is a command line tool for all platforms called md5sum that can +; create the MD5 checksum you need. +; - all files specified in this file are search relatively to the path where +; this file is found, i.e. if the sound files are in a subdir you have +; to add that subdir to the names in this file to! It will NOT search for +; a file named like specified in here. + +[metadata] +; the name of the pack, preferably less than 16 characters +name = example +; the short name (4 characters), used to identify this set +shortname = XMPL +; the version of this sound set (read as single integer) +version = 0 +; a fairly short description of the set +description = foo + +; The files section lists the files that replace sprites. +; The file names are case sensitive. +[files] +; file with the samples +samples = SAMPLES.CAT + +; The md5s section lists the MD5 checksum for the files that replace them. +; Note that the list of files is case sensitive. Each file listed in the +; files section must be listed here with it's MD5 checksum, otherwise you +; will get a lot of warnings when starting OpenTTD. +[md5s] +SAMPLES.CAT = 422ea3dd074d2859bb51639a6e0e85da + +; The origin section provides the possibility to put and extra line into +; the warning that a file is missing/corrupt. This can be used to tell +; them where to find it. It works on the filename specified in the +; files section and if that is not found it will fall back to the default +; as shown below here. +[origin] +default = You can find it on your Transport Tycoon Deluxe CD-ROM. +SAMPLES.CAT = You can find it also on your Transport Tycoon Deluxe CD-ROM. diff --git a/os/win32/installer/install.nsi b/os/win32/installer/install.nsi index 6de16a16e3..893b3189f5 100644 --- a/os/win32/installer/install.nsi +++ b/os/win32/installer/install.nsi @@ -111,6 +111,7 @@ Section "!OpenTTD" Section1 SetOutPath "$INSTDIR\data\" File ${PATH_ROOT}bin\data\*.grf File ${PATH_ROOT}bin\data\*.obg + File ${PATH_ROOT}bin\data\*.obs File ${PATH_ROOT}bin\data\opntitle.dat ; Copy the scripts @@ -134,6 +135,7 @@ Section "!OpenTTD" Section1 Delete "$INSTDIR\*.lng" Delete "$INSTDIR\*.grf" Delete "$INSTDIR\*.obg" + Delete "$INSTDIR\*.obs" Delete "$INSTDIR\sample.cat" Delete "$INSTDIR\ttd.exe" @@ -272,6 +274,8 @@ Section "Uninstall" Delete "$INSTDIR\data\orig_win.obg" Delete "$INSTDIR\data\orig_dos.obg" Delete "$INSTDIR\data\orig_dos_de.obg" + Delete "$INSTDIR\data\orig_win.obs" + Delete "$INSTDIR\data\orig_dos.obs" Delete "$INSTDIR\data\sample.cat" ; Windows Data files diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 2be80fe4e5..5c87c17790 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2251,10 +2251,6 @@ RelativePath=".\..\src\table\engines.h" > - - diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index f4260c1849..6508cb1b02 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2248,10 +2248,6 @@ RelativePath=".\..\src\table\engines.h" > - - diff --git a/source.list b/source.list index 1d24b045ac..7c853f0d57 100644 --- a/source.list +++ b/source.list @@ -511,7 +511,6 @@ table/clear_land.h table/control_codes.h table/elrail_data.h table/engines.h -table/files.h table/genland.h table/industry_land.h table/landscape_sprite.h diff --git a/src/base_media_base.h b/src/base_media_base.h index 74185c72b2..b25661fa8f 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -75,7 +75,7 @@ struct BaseSet { }; /** - * Base for all base media (graphics, sound) + * Base for all base media (graphics, sounds) * @tparam Tbase_set the real set we're going to be */ template @@ -194,4 +194,21 @@ public: static void DeterminePalette(); }; +/** All data of a sounds set. */ +struct SoundsSet : BaseSet { + /** + * Is this set useable? Are enough files found to think it exists. + * @return true if it's useable. + */ + bool IsUseable() const + { + return this->found_files > 0; + } +}; + +/** All data/functions related with replacing the base sounds */ +class BaseSounds : public BaseMedia { +public: +}; + #endif /* BASE_MEDIA_BASE_H */ diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 32a9815eab..5ec306a4ea 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -30,7 +30,6 @@ const byte *_palette_remap = NULL; /** Palette map to go from the _use_palette to the !_use_palette */ const byte *_palette_reverse_remap = NULL; -#include "table/files.h" #include "table/landscape_sprite.h" static const SpriteID * const _landscape_spriteindexes[] = { @@ -94,6 +93,8 @@ static void LoadGrfIndexed(const char *filename, const SpriteID *index_tbl, int */ void CheckExternalFiles() { + if (BaseGraphics::GetUsedSet() == NULL || BaseSounds::GetUsedSet() == NULL) return; + BaseGraphics::DeterminePalette(); const GraphicsSet *used_set = BaseGraphics::GetUsedSet(); @@ -111,13 +112,9 @@ void CheckExternalFiles() } } - bool sound = false; - for (uint i = 0; !sound && i < lengthof(_sound_sets); i++) { - sound = _sound_sets[i].CheckMD5(); - } - - if (!sound) { - add_pos += seprintf(add_pos, last, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n"); + const SoundsSet *sounds_set = BaseSounds::GetUsedSet(); + if (!sounds_set->files->CheckMD5()) { + add_pos += seprintf(add_pos, last, "Your '%s' file is corrupted or missing! %s\n", sounds_set->files->filename, sounds_set->files->missing_warning); } if (add_pos != error_msg) ShowInfoF("%s", error_msg); diff --git a/src/lang/english.txt b/src/lang/english.txt index 6ed40ea981..4eb0659884 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -917,6 +917,10 @@ STR_GAME_OPTIONS_BASE_GRF_TOOLTIP :{BLACK}Select t STR_GAME_OPTIONS_BASE_GRF_STATUS :{RED}{NUM} missing/corrupted file{P "" s} STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP :{BLACK}Additional information about the base graphics set +STR_GAME_OPTIONS_BASE_SFX :{BLACK}Base sounds set +STR_GAME_OPTIONS_BASE_SFX_TOOLTIP :{BLACK}Select the base sounds set to use +STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP :{BLACK}Additional information about the base sounds set + STR_ERROR_FULLSCREEN_FAILED :{WHITE}Fullscreen mode failed # Custom currency window @@ -1770,6 +1774,7 @@ STR_CONTENT_TYPE_AI :AI STR_CONTENT_TYPE_AI_LIBRARY :AI library STR_CONTENT_TYPE_SCENARIO :Scenario STR_CONTENT_TYPE_HEIGHTMAP :Heightmap +STR_CONTENT_TYPE_BASE_SOUNDS :Base sounds # Content downloading progress window STR_CONTENT_DOWNLOAD_TITLE :{WHITE}Downloading content... diff --git a/src/misc.cpp b/src/misc.cpp index 34e68e8604..34acf28e69 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -30,6 +30,7 @@ extern TileIndex _cur_tileloop_tile; extern void MakeNewgameSettingsLive(); +void InitializeSound(); void InitializeVehicles(); void InitializeDepots(); void InitializeEngineRenews(); @@ -71,6 +72,8 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin _thd.redsq = INVALID_TILE; if (reset_settings) MakeNewgameSettingsLive(); + InitializeSound(); + if (reset_date) { SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1)); InitializeOldNames(); diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h index 50365c1090..9a7d0deb84 100644 --- a/src/network/core/tcp_content.h +++ b/src/network/core/tcp_content.h @@ -23,6 +23,7 @@ enum ContentType { CONTENT_TYPE_AI_LIBRARY = 4, ///< The content consists of an AI library CONTENT_TYPE_SCENARIO = 5, ///< The content consists of a scenario CONTENT_TYPE_HEIGHTMAP = 6, ///< The content consists of a heightmap + CONTENT_TYPE_BASE_SOUNDS = 7, ///< The content consists of base sounds CONTENT_TYPE_END, ///< Helper to mark the end of the types }; diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 5f1590f15b..2e9ea559d4 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -82,6 +82,10 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_INFO) proc = BaseGraphics::HasSet; break; + case CONTENT_TYPE_BASE_SOUNDS: + proc = BaseSounds::HasSet; + break; + case CONTENT_TYPE_AI: case CONTENT_TYPE_AI_LIBRARY: proc = AI::HasAI; break; @@ -149,6 +153,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type) { if (type == CONTENT_TYPE_END) { this->RequestContentList(CONTENT_TYPE_BASE_GRAPHICS); + this->RequestContentList(CONTENT_TYPE_BASE_SOUNDS); this->RequestContentList(CONTENT_TYPE_SCENARIO); this->RequestContentList(CONTENT_TYPE_HEIGHTMAP); this->RequestContentList(CONTENT_TYPE_AI); @@ -290,6 +295,7 @@ static char *GetFullFilename(const ContentInfo *ci, bool compressed) switch (ci->type) { default: return NULL; case CONTENT_TYPE_BASE_GRAPHICS: dir = DATA_DIR; break; + case CONTENT_TYPE_BASE_SOUNDS: dir = DATA_DIR; break; case CONTENT_TYPE_NEWGRF: dir = DATA_DIR; break; case CONTENT_TYPE_AI: dir = AI_DIR; break; case CONTENT_TYPE_AI_LIBRARY: dir = AI_LIBRARY_DIR; break; diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 44f5456d75..a57638394b 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -95,6 +95,10 @@ public: BaseGraphics::FindSets(); break; + case CONTENT_TYPE_BASE_SOUNDS: + BaseSounds::FindSets(); + break; + case CONTENT_TYPE_NEWGRF: ScanNewGRFFiles(); /* Yes... these are the NewGRF windows */ diff --git a/src/openttd.cpp b/src/openttd.cpp index e77a781a1e..0ef73a1403 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -177,6 +177,7 @@ static void ShowHelp() " Default value (2) lets OpenTTD use the palette\n" " specified in graphics set file (see below)\n" " -I graphics_set = Force the graphics set (see below)\n" + " -S sounds_set = Force the sounds set (see below)\n" " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" " -x = Do not automatically save to config file on exit\n" "\n", @@ -186,6 +187,9 @@ static void ShowHelp() /* List the graphics packs */ p = BaseGraphics::GetSetsList(p, lastof(buf)); + /* List the sounds packs */ + p = BaseSounds::GetSetsList(p, lastof(buf)); + /* List the drivers */ p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf)); @@ -401,6 +405,7 @@ int ttd_main(int argc, char *argv[]) char *videodriver = NULL; char *blitter = NULL; char *graphics_set = NULL; + char *sounds_set = NULL; Dimension resolution = {0, 0}; Year startyear = INVALID_YEAR; uint generation_seed = GENERATE_NEW_SEED; @@ -426,7 +431,7 @@ int ttd_main(int argc, char *argv[]) * a letter means: it accepts that param (e.g.: -h) * a ':' behind it means: it need a param (e.g.: -m) * a '::' behind it means: it can optional have a param (e.g.: -d) */ - optformat = "m:s:v:b:hD::n::ei::I:t:d::r:g::G:c:xl:p:P:" + optformat = "m:s:v:b:hD::n::ei::I:S:t:d::r:g::G:c:xl:p:P:" #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) "f" #endif @@ -437,6 +442,7 @@ int ttd_main(int argc, char *argv[]) while ((i = MyGetOpt(&mgo)) != -1) { switch (i) { case 'I': free(graphics_set); graphics_set = strdup(mgo.opt); break; + case 'S': free(sounds_set); sounds_set = strdup(mgo.opt); break; case 'm': free(musicdriver); musicdriver = strdup(mgo.opt); break; case 's': free(sounddriver); sounddriver = strdup(mgo.opt); break; case 'v': free(videodriver); videodriver = strdup(mgo.opt); break; @@ -526,6 +532,7 @@ int ttd_main(int argc, char *argv[]) * the debug console as that hasn't been configured yet. */ DeterminePaths(argv[0]); BaseGraphics::FindSets(); + BaseSounds::FindSets(); ShowHelp(); return 0; } @@ -538,6 +545,7 @@ int ttd_main(int argc, char *argv[]) DeterminePaths(argv[0]); BaseGraphics::FindSets(); + BaseSounds::FindSets(); #if defined(UNIX) && !defined(__MORPHOS__) /* We must fork here, or we'll end up without some resources we need (like sockets) */ @@ -584,16 +592,23 @@ int ttd_main(int argc, char *argv[]) /* initialize all variables that are allocated dynamically */ InitializeDynamicVariables(); - /* Sample catalogue */ - DEBUG(misc, 1, "Loading sound effects..."); - SoundInitialize("sample.cat"); - /* Initialize FreeType */ InitFreeType(); /* This must be done early, since functions use the InvalidateWindow* calls */ InitWindowSystem(); + /* Look for the sounds before the graphics. Otherwise none would be set and + * the first initialisation of the video happens on the wrong data. Now it + * can do the first initialisation right. */ + if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = strdup(BaseSounds::ini_set); + if (!BaseSounds::SetSet(sounds_set)) { + StrEmpty(sounds_set) ? + usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD.") : + usererror("Failed to select requested sounds set '%s'", sounds_set); + } + free(sounds_set); + if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = strdup(BaseGraphics::ini_set); if (!BaseGraphics::SetSet(graphics_set)) { StrEmpty(graphics_set) ? @@ -729,6 +744,7 @@ int ttd_main(int argc, char *argv[]) ShutdownGame(); free(const_cast(BaseGraphics::ini_set)); + free(const_cast(BaseSounds::ini_set)); free(_ini_musicdriver); free(_ini_sounddriver); free(_ini_videodriver); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 5578cc8cd6..372664c58b 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -123,6 +123,9 @@ enum GameOptionsWidgets { GOW_BASE_GRF_DROPDOWN, ///< Use to select a base GRF GOW_BASE_GRF_STATUS, ///< Info about missing files etc. GOW_BASE_GRF_DESCRIPTION,///< Description of selected base GRF + GOW_BASE_SFX_FRAME, ///< Base SFX selection frame + GOW_BASE_SFX_DROPDOWN, ///< Use to select a base SFX + GOW_BASE_SFX_DESCRIPTION,///< Description of selected base SFX }; /** @@ -151,17 +154,18 @@ static void ShowTownnameDropdown(Window *w, int sel) static void ShowCustCurrency(); -static void ShowGraphicsSetMenu(Window *w) +template +static void ShowSetMenu(Window *w, int widget) { - int n = BaseGraphics::GetNumSets(); - int current = BaseGraphics::GetIndexOfUsedSet(); + int n = T::GetNumSets(); + int current = T::GetIndexOfUsedSet(); DropDownList *list = new DropDownList(); for (int i = 0; i < n; i++) { - list->push_back(new DropDownListCharStringItem(BaseGraphics::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (current != i))); + list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (current != i))); } - ShowDropDownList(w, list, current, GOW_BASE_GRF_DROPDOWN); + ShowDropDownList(w, list, current, widget); } struct GameOptionsWindow : Window { @@ -196,6 +200,7 @@ struct GameOptionsWindow : Window { case GOW_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break; case GOW_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break; case GOW_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumMissing()); break; + case GOW_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break; } } @@ -206,20 +211,37 @@ struct GameOptionsWindow : Window { virtual void DrawWidget(const Rect &r, int widget) const { - if (widget != GOW_BASE_GRF_DESCRIPTION) return; + switch (widget) { + case GOW_BASE_GRF_DESCRIPTION: + SetDParamStr(0, BaseGraphics::GetUsedSet()->description); + DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); + break; - SetDParamStr(0, BaseGraphics::GetUsedSet()->description); - DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); + case GOW_BASE_SFX_DESCRIPTION: + SetDParamStr(0, BaseSounds::GetUsedSet()->description); + DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); + break; + } } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) { - if (widget != GOW_BASE_GRF_DESCRIPTION) return; + switch (widget) { + case GOW_BASE_GRF_DESCRIPTION: + /* Find the biggest description for the default size. */ + for (int i = 0; i < BaseGraphics::GetNumSets(); i++) { + SetDParamStr(0, BaseGraphics::GetSet(i)->description); + size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); + } + break; - /* Find the biggest description for the default size. */ - for (int i = 0; i < BaseGraphics::GetNumSets(); i++) { - SetDParamStr(0, BaseGraphics::GetSet(i)->description); - size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); + case GOW_BASE_SFX_DESCRIPTION: + /* Find the biggest description for the default size. */ + for (int i = 0; i < BaseSounds::GetNumSets(); i++) { + SetDParamStr(0, BaseSounds::GetSet(i)->description); + size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width)); + } + break; } } @@ -288,11 +310,36 @@ struct GameOptionsWindow : Window { break; case GOW_BASE_GRF_DROPDOWN: - ShowGraphicsSetMenu(this); + ShowSetMenu(this, GOW_BASE_GRF_DROPDOWN); + break; + + case GOW_BASE_SFX_DROPDOWN: + ShowSetMenu(this, GOW_BASE_SFX_DROPDOWN); break; } } + /** + * Set the base media set. + * @param index the index of the media set + * @tparam T class of media set + */ + template + void SetMediaSet(int index) + { + if (_game_mode == GM_MENU) { + const char *name = T::GetSet(index)->name; + + free(const_cast(T::ini_set)); + T::ini_set = strdup(name); + + T::SetSet(name); + this->reload = true; + this->SetDirty(); + this->OnInvalidateData(0); + } + } + virtual void OnDropdownSelect(int widget, int index) { switch (widget) { @@ -347,17 +394,11 @@ struct GameOptionsWindow : Window { break; case GOW_BASE_GRF_DROPDOWN: - if (_game_mode == GM_MENU) { - const char *name = BaseGraphics::GetSet(index)->name; - - free(const_cast(BaseGraphics::ini_set)); - BaseGraphics::ini_set = strdup(name); + this->SetMediaSet(index); + break; - BaseGraphics::SetSet(name); - this->reload = true; - this->SetDirty(); - this->OnInvalidateData(0); - } + case GOW_BASE_SFX_DROPDOWN: + this->SetMediaSet(index); break; } } @@ -421,6 +462,14 @@ static const NWidgetPart _nested_game_options_widgets[] = { EndContainer(), NWidget(WWT_TEXT, COLOUR_GREY, GOW_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetPadding(6, 10, 10, 10), EndContainer(), + + NWidget(WWT_FRAME, COLOUR_GREY, GOW_BASE_SFX_FRAME), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), + NWidget(NWID_HORIZONTAL), SetPIP(10, 30, 10), + NWidget(WWT_DROPDOWN, COLOUR_GREY, GOW_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP), SetPadding(14, 0, 0, 0), + NWidget(NWID_SPACER), SetFill(true, false), + EndContainer(), + NWidget(WWT_TEXT, COLOUR_GREY, GOW_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetPadding(6, 10, 10, 10), + EndContainer(), EndContainer(), }; diff --git a/src/sound.cpp b/src/sound.cpp index 0e4b705fb2..99799002d3 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -13,6 +13,10 @@ #include "vehicle_base.h" #include "debug.h" +/* The type of set we're replacing */ +#define SET_TYPE "sounds" +#include "base_media_func.h" + static SoundEntry _original_sounds[ORIGINAL_SAMPLE_COUNT]; MusicFileSettings msf; @@ -116,10 +120,10 @@ static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound) return true; } -bool SoundInitialize(const char *filename) +void InitializeSound() { - OpenBankFile(filename); - return true; + DEBUG(misc, 1, "Loading sound effects..."); + OpenBankFile(BaseSounds::GetUsedSet()->files->filename); } /* Low level sound player */ @@ -242,3 +246,34 @@ void SndPlayFx(SoundID sound) { StartSound(sound, 0, msf.effect_vol); } + +INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia, SoundsSet) + +/** Names corresponding to the sound set's files */ +template +/* static */ const char *BaseSet::file_names[Tnum_files] = { "samples" }; + +template +/* static */ const char *BaseMedia::GetExtension() +{ + return ".obs"; // OpenTTD Base Sounds +} + +template +/* static */ bool BaseMedia::DetermineBestSet() +{ + if (BaseMedia::used_set != NULL) return true; + + const Tbase_set *best = BaseMedia::available_sets; + for (const Tbase_set *c = BaseMedia::available_sets; c != NULL; c = c->next) { + if (best->found_files < c->found_files || + (best->found_files == c->found_files && + (best->shortname == c->shortname && best->version < c->version))) { + best = c; + } + } + + BaseMedia::used_set = best; + return BaseMedia::used_set != NULL; +} + diff --git a/src/sound_func.h b/src/sound_func.h index 10858c4633..dd700f20ee 100644 --- a/src/sound_func.h +++ b/src/sound_func.h @@ -11,8 +11,6 @@ extern MusicFileSettings msf; -bool SoundInitialize(const char *filename); - void SndPlayTileFx(SoundID sound, TileIndex tile); void SndPlayVehicleFx(SoundID sound, const Vehicle *v); void SndPlayFx(SoundID sound); diff --git a/src/table/files.h b/src/table/files.h deleted file mode 100644 index be573f93dd..0000000000 --- a/src/table/files.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $Id$ */ - -/** @file files.h MD5 checksum information and names of the original and extra data files. */ - -/* - * MD5 sums of graphics files - * - * DOS - - * - * TRG1.GRF 9311676280e5b14077a8ee41c1b42192 - * TRGC.GRF ed446637e034104c5559b32c18afe78d - * TRGH.GRF ee6616fb0e6ef6b24892c58c93d86fc9 - * TRGI.GRF da6a6c9dcc451eec88d79211437b76a8 - * TRGT.GRF e30e8a398ae86c03dc534a8ac7dfb3b6 (German: fcde1d7e8a74197d72a62695884b909e) - * SAMPLE.CAT 422ea3dd074d2859bb51639a6e0e85da - * - * WINDOWS - - * - * TRG1R.GRF b04ce593d8c5016e07473a743d7d3358 - * TRGCR.GRF 3668f410c761a050b5e7095a2b14879b - * TRGHR.GRF 06bf2b7a31766f048baac2ebe43457b1 - * TRGIR.GRF 0c2484ff6be49fc63a83be6ab5c38f32 - * TRGTR.GRF de53650517fe661ceaa3138c6edb0eb8 - * SAMPLE.CAT 9212e81e72badd4bbe1eaeae66458e10 - */ - - -static MD5File _sound_sets[] = { - { "SAMPLE.CAT", {0x42, 0x2e, 0xa3, 0xdd, 0x07, 0x4d, 0x28, 0x59, 0xbb, 0x51, 0x63, 0x9a, 0x6e, 0x0e, 0x85, 0xda}, NULL }, - { "SAMPLE.CAT", {0x92, 0x12, 0xe8, 0x1e, 0x72, 0xba, 0xdd, 0x4b, 0xbe, 0x1e, 0xae, 0xae, 0x66, 0x45, 0x8e, 0x10}, NULL }, -}; diff --git a/src/table/settings.h b/src/table/settings.h index 71f3b52266..c3380cca55 100644 --- a/src/table/settings.h +++ b/src/table/settings.h @@ -238,6 +238,7 @@ static const SettingDescGlobVarList _misc_settings[] = { SDTG_BOOL("news_ticker_sound", S, 0, _news_ticker_sound, true, STR_NULL, NULL), SDTG_BOOL("fullscreen", S, 0, _fullscreen, false, STR_NULL, NULL), SDTG_STR("graphicsset", SLE_STRQ, S, 0, BaseGraphics::ini_set, NULL, STR_NULL, NULL), + SDTG_STR("soundsset", SLE_STRQ, S, 0, BaseSounds::ini_set, NULL, STR_NULL, NULL), SDTG_STR("videodriver", SLE_STRQ, S, 0, _ini_videodriver, NULL, STR_NULL, NULL), SDTG_STR("musicdriver", SLE_STRQ, S, 0, _ini_musicdriver, NULL, STR_NULL, NULL), SDTG_STR("sounddriver", SLE_STRQ, S, 0, _ini_sounddriver, NULL, STR_NULL, NULL),