|
From: Lasse Kärkkäi. <tr...@us...> - 2012-02-12 03:23:55
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 12 05:22:28 2012 +0200
Fix regression: vocal note power glow.
Make the glow fade away smoothly.
---
game/engine.hh | 2 --
game/notes.cc | 9 ++++++---
game/notes.hh | 10 ++++++----
game/player.cc | 6 +++++-
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/game/engine.hh b/game/engine.hh
index 5fcb10b..7ea1cea 100644
--- a/game/engine.hh
+++ b/game/engine.hh
@@ -59,8 +59,6 @@ class Engine {
double timeLeft = m_time * TIMESTEP - t;
if (timeLeft != timeLeft || timeLeft > 1.0) timeLeft = 1.0; // FIXME: Workaround for NaN values and other weirdness (should fix the weirdness instead)
if (timeLeft > 0.0) { boost::thread::sleep(now() + std::min(TIMESTEP, timeLeft)); continue; }
- // FIXME: Implement
- //for (Notes::const_iterator it = m_vocal.notes.begin(); it != m_vocal.notes.end(); ++it) it->power = 0.0f;
std::for_each(m_database.cur.begin(), m_database.cur.end(), boost::bind(&Player::update, _1));
++m_time;
}
diff --git a/game/notes.cc b/game/notes.cc
index 258fec2..0e365f7 100644
--- a/game/notes.cc
+++ b/game/notes.cc
@@ -10,10 +10,13 @@ Note::Note(): begin(getNaN()), end(getNaN()), phase(getNaN()), power(getNaN()),
double Note::diff(double note, double n) { return remainder(n - note, 12.0); }
double Note::maxScore() const { return scoreMultiplier() * (end - begin); }
-double Note::score(double n, double b, double e) const {
+double Note::clampDuration(double b, double e) const {
double len = std::min(e, end) - std::max(b, begin);
- if (len <= 0.0 || !(n > 0.0)) return 0.0;
- return scoreMultiplier() * powerFactor(n) * len;
+ return len > 0.0 ? len : 0.0;
+}
+
+double Note::score(double n, double b, double e) const {
+ return scoreMultiplier() * powerFactor(n) * clampDuration(b, e);
}
double Note::scoreMultiplier() const {
diff --git a/game/notes.hh b/game/notes.hh
index ebc5daf..444c68f 100644
--- a/game/notes.hh
+++ b/game/notes.hh
@@ -71,15 +71,17 @@ struct Note {
double diff(double n) const { return diff(note, n); }
/// Difference of n from note, so that note + diff(note, n) is n (mod 12)
static double diff(double note, double n);
- /// maximum score
+ /// Maximum score
double maxScore() const;
- /// score when singing over time period (a, b), which needs not to be entirely within the note
+ /// The length of the time period [a,b] that falls within the note in seconds
+ double clampDuration(double b, double e) const;
+ /// Score when singing over time period (a, b), which needs not to be entirely within the note
double score(double freq, double b, double e) const;
/// How precisely the note is hit (always 1.0 for freestyle, 0..1 for others)
double powerFactor(double note) const;
- /// compares begin of two notes
+ /// Compares begin of two notes
static bool ltBegin(Note const& a, Note const& b) { return a.begin < b.begin; }
- /// compares end of two notes
+ /// Compares end of two notes
static bool ltEnd(Note const& a, Note const& b) { return a.end < b.end; }
private:
double scoreMultiplier() const;
diff --git a/game/player.cc b/game/player.cc
index 01f5254..d92a989 100644
--- a/game/player.cc
+++ b/game/player.cc
@@ -9,6 +9,8 @@ Player::Player(VocalTrack& vocal, Analyzer& analyzer, size_t frames):
m_prevLineScore(-1), m_feedbackFader(0.0, 2.0), m_activitytimer(),
m_scoreIt(m_vocal.notes.begin())
{
+ // Initialize note powers
+ for (Notes::const_iterator it = m_vocal.notes.begin(); it != m_vocal.notes.end(); ++it) it->power = 0.0f;
// Assign colors
if (m_analyzer.getId() == "blue") m_color = Color(0.2, 0.5, 0.7);
else if (m_analyzer.getId() == "red") m_color = Color(0.8, 0.3, 0.3);
@@ -34,6 +36,7 @@ void Player::update() {
while (m_scoreIt != m_vocal.notes.end()) {
if (endTime < m_scoreIt->begin) break; // The note begins later than on this timestep
// If tone was detected, calculate score
+ m_scoreIt->power *= std::pow(0.05, m_scoreIt->clampDuration(beginTime, endTime)); // Fade glow
if (t) {
double note = m_vocal.scale.getNote(t->freq);
// Add score
@@ -57,6 +60,7 @@ void Player::update() {
m_scoreIt->stars.push_back(m_color);
}
m_noteScore = 0; // Reset noteScore as we are moving on to the next one
+ m_scoreIt->power = 0.0; // Remove glow
++m_scoreIt;
}
if (m_scoreIt == m_vocal.notes.end()) calcRowRank();
@@ -68,7 +72,7 @@ void Player::calcRowRank() {
m_prevLineScore = m_lineScore;
// Calculate max score of the completed row
Notes::const_reverse_iterator maxScoreIt(m_scoreIt);
- // FIXME: MacOSX needs the following cast to compile correctly
+ // NOTE: MacOSX needs the following cast to compile correctly
// it is related to the fact that OSX default compiler is 4.0.1 that is buggy when not casting
while ((maxScoreIt != static_cast<Notes::const_reverse_iterator>(m_vocal.notes.rend())) && (maxScoreIt->type != Note::SLEEP)) {
m_maxLineScore += m_vocal.m_scoreFactor * maxScoreIt->maxScore();
|