summaryrefslogtreecommitdiff
path: root/src/music.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2018-06-24 20:06:05 +0200
committerMichael Lutz <michi@icosahedron.de>2018-06-24 20:06:05 +0200
commit6298b9657103f5dca0f85c1117e720530cc4b037 (patch)
tree138961409147f12009377eb2655e02672641eeae /src/music.cpp
parent889175f7adaeae9e23041363fe2d3f685b6df695 (diff)
downloadopenttd-6298b9657103f5dca0f85c1117e720530cc4b037.tar.xz
Change: Modernise music control logic implementation (#6839)
Rewrite of almost the entire music control logic to a more modern style, hopefully also easier to understand. The old playlist handling made it look like arcane magic, which it doesn't have to be. - Playlists are now stored in std::vector of objects instead of arrays of bytes with magic sentinel values, that need to be rotated around all the time. Position in playlist is stored as a simple index. - The theme song is now reserved for the title screen, it doesn't play on any of the standard playlists, but is still available for use on custom playlists. - When the player enters/leaves the game from the main menu, the music always restarts. - Playback state (playing or not) is kept even if music becomes unavailable due to an empty playlist (or an empty music set), so it can restart immediately if music becomes available again. - The shuffle algorithm was changed to a standard Fisher-Yates. - Possibly better behavior when editing a custom playlist while it's playing. - Custom playlists should be compatible. - Framework for supporting custom playlists with songs from multiple music sets.
Diffstat (limited to 'src/music.cpp')
-rw-r--r--src/music.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/music.cpp b/src/music.cpp
index ffb1d7590..3d0e40bf9 100644
--- a/src/music.cpp
+++ b/src/music.cpp
@@ -126,7 +126,8 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
IniGroup *names = ini->GetGroup("names");
IniGroup *catindex = ini->GetGroup("catindex");
IniGroup *timingtrim = ini->GetGroup("timingtrim");
- for (uint i = 0, j = 1; i < lengthof(this->songinfo); i++) {
+ uint tracknr = 1;
+ for (uint i = 0; i < lengthof(this->songinfo); i++) {
const char *filename = this->files[i].filename;
if (names == NULL || StrEmpty(filename) || this->files[i].check_result == MD5File::CR_NO_FILE) {
this->songinfo[i].songname[0] = '\0';
@@ -175,7 +176,12 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
}
this->num_available++;
- this->songinfo[i].tracknr = j++;
+ /* Number the theme song (if any) track 0, rest are normal */
+ if (i == 0) {
+ this->songinfo[i].tracknr = 0;
+ } else {
+ this->songinfo[i].tracknr = tracknr++;
+ }
item = timingtrim->GetItem(trimmed_filename, false);
if (item != NULL && !StrEmpty(item->value)) {