MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildPlaylists

Method BuildPlaylists

src/music_gui.cpp:103–141  ·  view source on GitHub ↗

Rebuild all playlists for the current music set */

Source from the content-addressed store, hash-verified

101
102/** Rebuild all playlists for the current music set */
103void MusicSystem::BuildPlaylists()
104{
105 const MusicSet *set = BaseMusic::GetUsedSet();
106
107 /* Clear current playlists */
108 for (auto &playlist : this->standard_playlists) playlist.clear();
109 this->music_set.clear();
110
111 /* Build standard playlists, and a list of available music */
112 for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
113 PlaylistEntry entry(set, i);
114 if (!entry.IsValid()) continue;
115
116 this->music_set.push_back(entry);
117
118 /* Add theme song to theme-only playlist */
119 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(std::move(entry));
120
121 /* Don't add the theme song to standard playlists */
122 if (i > 0) {
123 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
124 uint theme = (i - 1) / NUM_SONGS_CLASS;
125 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(std::move(entry));
126 }
127 }
128
129 /* Load custom playlists
130 * Song index offsets are 1-based, zero indicates invalid/end-of-list value */
131 for (uint i = 0; i < NUM_SONGS_PLAYLIST; i++) {
132 if (_settings_client.music.custom_1[i] > 0 && _settings_client.music.custom_1[i] <= NUM_SONGS_AVAILABLE) {
133 PlaylistEntry entry(set, _settings_client.music.custom_1[i] - 1);
134 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(std::move(entry));
135 }
136 if (_settings_client.music.custom_2[i] > 0 && _settings_client.music.custom_2[i] <= NUM_SONGS_AVAILABLE) {
137 PlaylistEntry entry(set, _settings_client.music.custom_2[i] - 1);
138 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(std::move(entry));
139 }
140 }
141}
142
143/**
144 * Switch to another playlist, or reload the current one.

Callers 2

ChangeMusicSetMethod · 0.95
InitializeMusicFunction · 0.80

Calls 3

push_backMethod · 0.80
clearMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected