|
From: Lasse Kärkkäi. <tr...@us...> - 2010-01-14 02:53:16
|
Module: performous
Branch: master
Commit: 5bd9676a9fb1f1b197e594bd4127caf112506f8a
Author: Lasse Karkkainen <tro...@tr...>
Date: Thu Jan 14 04:52:44 2010 +0200
Simplified song shuffling. Set position at first song when the song browser entered the first time.
---
game/screen_songs.cc | 1 -
game/songs.cc | 32 +++++---------------------------
game/songs.hh | 5 -----
3 files changed, 5 insertions(+), 33 deletions(-)
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index d495486..ecc3719 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -96,7 +96,6 @@ void ScreenSongs::manageEvent(SDL_Event event) {
// The rest are only available when there are songs available
else if (m_songs.empty()) return;
else if (!m_jukebox && key == SDLK_F4) m_jukebox = true;
- else if (key == SDLK_TAB && !(mod & KMOD_ALT)) m_songs.randomize();
else if (key == SDLK_END) {
ScreenManager* sm = ScreenManager::getSingletonPtr();
Screen* s = sm->getScreen("Hiscore");
diff --git a/game/songs.cc b/game/songs.cc
index 033d2f6..eb1ced2 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -16,7 +16,7 @@
#include <stdexcept>
#include <cstdlib>
-Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_database(database), m_order(), m_dirty(false), m_loading(false), m_needShuffle(false) {
+Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_database(database), m_order(), m_dirty(false), m_loading(false) {
reload();
}
@@ -28,7 +28,6 @@ Songs::~Songs() {
void Songs::reload() {
if (m_loading) return;
// Run loading thread
- m_needShuffle = false;
m_loading = true;
m_thread.reset(new boost::thread(boost::bind(&Songs::reload_internal, boost::ref(*this))));
}
@@ -50,11 +49,9 @@ void Songs::reload_internal() {
}
if (m_loading) dumpSongs_internal(); // Dump the songlist to file (if requested)
m_loading = false;
- m_needShuffle = true; // Force shuffle
}
void Songs::reload_internal(fs::path const& parent) {
- static int randomIdx = 0;
namespace fs = fs;
if (std::distance(parent.begin(), parent.end()) > 20) { m_debug << ">>> Not scanning: " << parent.string() << " (maximum depth reached, possibly due to cyclic symlinks)" << std::endl; return; }
try {
@@ -69,7 +66,7 @@ void Songs::reload_internal(fs::path const& parent) {
if (!regex_match(name.c_str(), match, expression)) continue;
try {
boost::shared_ptr<Song>s(new Song(path, name));
- s->randomIdx = ++randomIdx; // Not so random during loading, they are shuffled after load is finished
+ s->randomIdx = rand();
boost::mutex::scoped_lock l(m_mutex);
m_songs.push_back(s);
m_dirty = true;
@@ -112,28 +109,9 @@ class Songs::RestoreSel {
void Songs::update() {
if (m_dirty) filter_internal(); // Update with newly loaded songs
- if (m_needShuffle) randomize(); // Shuffle the songlist if needed
-}
-
-void Songs::randomize() {
- RestoreSel restore(*this);
- randomize_internal();
-}
-
-void Songs::randomize_internal() {
- boost::mutex::scoped_lock l(m_mutex);
- m_needShuffle = false;
- /* TR1-based random number generation
- TODO: it is enough that random_device is initialized once and not for every randomize_internal
- namespace rnd = std::tr1;
- rnd::random_device gendev; // Random number generator (using /dev/urandom usually)
- rnd::mt19937 gen(gendev); // Make Mersenne Twister random number generator, seeded with random_device.
- for (SongVector::const_iterator it = m_filtered.begin(); it != m_filtered.end(); ++it) (*it)->randomIdx = gen();
- */
- // Assign the songs randomIdx that is used for sorting in the "random" mode
- for (SongVector::const_iterator it = m_songs.begin(); it != m_songs.end(); ++it) (*it)->randomIdx = std::rand();
- m_order = 0; // Use randomIdx sort mode
- sort_internal();
+ // A hack to move to the first song when the song screen is entered the first time
+ static bool first = true;
+ if (first) { first = false; math_cover.setTarget(0, 0); math_cover.setTarget(0, size()); }
}
void Songs::setFilter(std::string const& val) {
diff --git a/game/songs.hh b/game/songs.hh
index faf974d..c49deac 100644
--- a/game/songs.hh
+++ b/game/songs.hh
@@ -55,10 +55,6 @@ class Songs: boost::noncopyable {
void setFilter(std::string const& regex);
/// sort descending
std::string sortDesc() const;
- /// randomizes songlist
- void randomize();
- /// randomizes if ordered
- void random() { if (m_order) randomize(); advance(1); }
/// changes sorting
void sortChange(int diff);
/// parses file into Song &tmp
@@ -81,7 +77,6 @@ class Songs: boost::noncopyable {
void sort_internal();
volatile bool m_dirty;
volatile bool m_loading;
- volatile bool m_needShuffle;
std::stringstream m_debug;
boost::scoped_ptr<boost::thread> m_thread;
mutable boost::mutex m_mutex;
|