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

Method Shuffle

src/music_gui.cpp:207–221  ·  view source on GitHub ↗

* Enable shuffle mode. */

Source from the content-addressed store, hash-verified

205 * Enable shuffle mode.
206 */
207void MusicSystem::Shuffle()
208{
209 _settings_client.music.shuffle = true;
210
211 uint set_index = this->GetSetIndex();
212 this->active_playlist = this->standard_playlists[this->selected_playlist];
213 for (size_t i = 0; i < this->active_playlist.size(); i++) {
214 size_t shuffle_index = InteractiveRandom() % (this->active_playlist.size() - i);
215 std::swap(this->active_playlist[i], this->active_playlist[i + shuffle_index]);
216 }
217 this->SetPositionBySetIndex(set_index);
218
219 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
220 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
221}
222
223/**
224 * Disable shuffle mode.

Callers 2

ChangePlaylistMethod · 0.95
OnClickMethod · 0.80

Calls 6

GetSetIndexMethod · 0.95
SetPositionBySetIndexMethod · 0.95
InteractiveRandomFunction · 0.85
swapFunction · 0.85
InvalidateWindowDataFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected