Merge lp:~widelands-dev/widelands/previous_song_exclusion into lp:widelands

Proposed by ypopezios
Status: Merged
Merged at revision: 8728
Proposed branch: lp:~widelands-dev/widelands/previous_song_exclusion
Merge into: lp:widelands
Diff against target: 54 lines (+13/-11)
2 files modified
src/sound/songset.cc (+10/-8)
src/sound/songset.h (+3/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/previous_song_exclusion
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+347404@code.launchpad.net

Description of the change

- Changed current_song_ from iterator into simple index.
- Changed calculation of random song to exclude current_song_ from the possible results.
- Unified handling of random and linear selection.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3581. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/387978432.
Appveyor build 3384. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_previous_song_exclusion-3384.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, not tested

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3585. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/388279254.
Appveyor build 3388. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_previous_song_exclusion-3388.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested, thanks for the patch!

The Travis failure is caused by a problem in trunk, so I'm gonna force a merge

@bunnybot merge force

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sound/songset.cc'
2--- src/sound/songset.cc 2018-04-07 16:59:00 +0000
3+++ src/sound/songset.cc 2018-06-05 13:11:10 +0000
4@@ -51,7 +51,7 @@
5 */
6 void Songset::add_song(const std::string& filename) {
7 songs_.push_back(filename);
8- current_song_ = songs_.begin();
9+ current_song_ = 0;
10 }
11
12 /** Get a song from the songset. Depending on
13@@ -66,14 +66,16 @@
14 if (g_sound_handler.get_disable_music() || songs_.empty())
15 return nullptr;
16
17- if (g_sound_handler.random_order_)
18- filename = songs_.at(g_sound_handler.rng_.rand() % songs_.size());
19- else {
20- if (current_song_ == songs_.end())
21- current_song_ = songs_.begin();
22-
23- filename = *(current_song_++);
24+ if (songs_.size() > 1) {
25+ if (g_sound_handler.random_order_) {
26+ // exclude current_song from playing two times in a row
27+ current_song_ += 1 + g_sound_handler.rng_.rand() % (songs_.size() - 1);
28+ } else {
29+ ++current_song_;
30+ }
31+ current_song_ = current_song_ % songs_.size();
32 }
33+ filename = songs_.at(current_song_);
34
35 // First, close the previous song and remove it from memory
36 if (m_) {
37
38=== modified file 'src/sound/songset.h'
39--- src/sound/songset.h 2018-04-07 16:59:00 +0000
40+++ src/sound/songset.h 2018-06-05 13:11:10 +0000
41@@ -53,10 +53,10 @@
42 /// The filenames of all configured songs
43 std::vector<std::string> songs_;
44
45- /** Pointer to the song that is currently playing (actually the one that
46- * was last started); needed for linear playback
47+ /** Index of the song that is currently playing
48+ * (actually the one that was last started)
49 */
50- std::vector<std::string>::iterator current_song_;
51+ uint32_t current_song_;
52
53 /// The current song
54 Mix_Music* m_;

Subscribers

People subscribed via source and target branches

to status/vote changes: