|
From: rainbyte <rai...@us...> - 2012-07-17 10:47:15
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 13 03:16:20 2012 +0200
Refresh the song list only twice a second while loading to reduce CPU load and to make the loading faster. Lower-case log categories.
---
game/songs.cc | 14 ++++++++------
game/songs.hh | 1 +
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/game/songs.cc b/game/songs.cc
index f132523..d0ec553 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -18,6 +18,7 @@
#include <cstdlib>
Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_typeFilter(), m_database(database), m_order(), m_dirty(false), m_loading(false) {
+ m_updateTimer.setTarget(getInf()); // Using this as a simple timer counting seconds
reload();
}
@@ -44,13 +45,13 @@ void Songs::reload_internal() {
for (Paths::iterator it = paths.begin(); m_loading && it != paths.end(); ++it) {
try {
if (!fs::is_directory(*it)) { m_debug << "Songs/info: >>> Not scanning: " << *it << " (no such directory)" << std::endl; continue; }
- m_debug << "Songs/info: >>> Scanning " << *it << std::endl;
+ m_debug << "songs/info: >>> Scanning " << *it << std::endl;
size_t count = m_songs.size();
reload_internal(*it);
size_t diff = m_songs.size() - count;
if (diff > 0 && m_loading) m_debug << diff << " songs loaded" << std::endl;
} catch (std::exception& e) {
- m_debug << "Songs/error: >>> Error scanning " << *it << ": " << e.what() << std::endl;
+ m_debug << "songs/error: >>> Error scanning " << *it << ": " << e.what() << std::endl;
}
}
prof("total");
@@ -60,7 +61,7 @@ void Songs::reload_internal() {
void Songs::reload_internal(fs::path const& parent) {
namespace fs = fs;
- if (std::distance(parent.begin(), parent.end()) > 20) { m_debug << "Songs/info: >>> Not scanning: " << parent.string() << " (maximum depth reached, possibly due to cyclic symlinks)" << std::endl; return; }
+ if (std::distance(parent.begin(), parent.end()) > 20) { m_debug << "songs/info: >>> Not scanning: " << parent.string() << " (maximum depth reached, possibly due to cyclic symlinks)" << std::endl; return; }
try {
boost::regex expression("(.*\\.txt|^song\\.ini|notes\\.xml|.*\\.sm)$", boost::regex_constants::icase);
boost::cmatch match;
@@ -85,13 +86,13 @@ void Songs::reload_internal(fs::path const& parent) {
} catch (SongParserException& e) {
if (e.silent()) continue;
// Construct error message
- m_debug << "Songs/error: -!- Error in " << path << "\n " << name;
+ m_debug << "songs/error: -!- Error in " << path << "\n " << name;
if (e.line()) m_debug << " line " << e.line();
m_debug << ": " << e.what() << std::endl;
}
}
} catch (std::exception const& e) {
- m_debug << "Songs/error: Error accessing " << parent << e.what() << std::endl;
+ m_debug << "songs/error: Error accessing " << parent << e.what() << std::endl;
}
}
@@ -120,7 +121,7 @@ class Songs::RestoreSel {
};
void Songs::update() {
- if (m_dirty) filter_internal(); // Update with newly loaded songs
+ if (m_dirty && m_updateTimer.get() > 0.5) filter_internal(); // Update with newly loaded songs
// 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()); }
@@ -139,6 +140,7 @@ void Songs::setTypeFilter(unsigned char filter) {
}
void Songs::filter_internal() {
+ m_updateTimer.setValue(0.0);
boost::mutex::scoped_lock l(m_mutex);
// Print messages when loading has finished
if (!m_loading) {
diff --git a/game/songs.hh b/game/songs.hh
index 70b5a2a..45a0bd7 100644
--- a/game/songs.hh
+++ b/game/songs.hh
@@ -69,6 +69,7 @@ class Songs: boost::noncopyable {
typedef std::vector<boost::shared_ptr<Song> > SongVector;
std::string m_songlist;
SongVector m_songs, m_filtered;
+ AnimValue m_updateTimer;
AnimAcceleration math_cover;
std::string m_filter;
unsigned char m_typeFilter;
|