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
=== modified file 'src/sound/songset.cc'
--- src/sound/songset.cc 2018-04-07 16:59:00 +0000
+++ src/sound/songset.cc 2018-06-05 13:11:10 +0000
@@ -51,7 +51,7 @@
51 */51 */
52void Songset::add_song(const std::string& filename) {52void Songset::add_song(const std::string& filename) {
53 songs_.push_back(filename);53 songs_.push_back(filename);
54 current_song_ = songs_.begin();54 current_song_ = 0;
55}55}
5656
57/** Get a song from the songset. Depending on57/** Get a song from the songset. Depending on
@@ -66,14 +66,16 @@
66 if (g_sound_handler.get_disable_music() || songs_.empty())66 if (g_sound_handler.get_disable_music() || songs_.empty())
67 return nullptr;67 return nullptr;
6868
69 if (g_sound_handler.random_order_)69 if (songs_.size() > 1) {
70 filename = songs_.at(g_sound_handler.rng_.rand() % songs_.size());70 if (g_sound_handler.random_order_) {
71 else {71 // exclude current_song from playing two times in a row
72 if (current_song_ == songs_.end())72 current_song_ += 1 + g_sound_handler.rng_.rand() % (songs_.size() - 1);
73 current_song_ = songs_.begin();73 } else {
7474 ++current_song_;
75 filename = *(current_song_++);75 }
76 current_song_ = current_song_ % songs_.size();
76 }77 }
78 filename = songs_.at(current_song_);
7779
78 // First, close the previous song and remove it from memory80 // First, close the previous song and remove it from memory
79 if (m_) {81 if (m_) {
8082
=== modified file 'src/sound/songset.h'
--- src/sound/songset.h 2018-04-07 16:59:00 +0000
+++ src/sound/songset.h 2018-06-05 13:11:10 +0000
@@ -53,10 +53,10 @@
53 /// The filenames of all configured songs53 /// The filenames of all configured songs
54 std::vector<std::string> songs_;54 std::vector<std::string> songs_;
5555
56 /** Pointer to the song that is currently playing (actually the one that56 /** Index of the song that is currently playing
57 * was last started); needed for linear playback57 * (actually the one that was last started)
58 */58 */
59 std::vector<std::string>::iterator current_song_;59 uint32_t current_song_;
6060
61 /// The current song61 /// The current song
62 Mix_Music* m_;62 Mix_Music* m_;

Subscribers

People subscribed via source and target branches

to status/vote changes: