diff --git a/terminaloverlay.cpp b/terminaloverlay.cpp index 0597200..45122c9 100644 --- a/terminaloverlay.cpp +++ b/terminaloverlay.cpp @@ -262,30 +262,28 @@ void NotificationEngine::apply( Framebuffer &fb ) const void OverlayManager::apply( Framebuffer &fb ) { - calculate_score( fb ); + predictions.calculate_score( fb ); predictions.cull( fb ); - if ( prediction_score > 3 ) { + if ( predictions.get_score() > 3 ) { predictions.apply( fb ); - } else if ( prediction_score == -1 ) { - predictions.clear(); - prediction_score = 0; } notifications.apply( fb ); } -void OverlayManager::calculate_score( const Framebuffer &fb ) +void PredictionEngine::calculate_score( const Framebuffer &fb ) { - for ( auto i = predictions.begin(); i != predictions.end(); i++ ) { + for ( auto i = begin(); i != end(); i++ ) { switch( (*i)->get_validity( fb ) ) { case Pending: break; case Correct: - prediction_score++; + score++; break; case IncorrectOrExpired: - prediction_score = -1; + score = 0; + clear(); return; } } @@ -330,6 +328,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb, int elements.push_back( coc ); } else { clear(); + score = 0; } } diff --git a/terminaloverlay.hpp b/terminaloverlay.hpp index 0a927f1..a410d91 100644 --- a/terminaloverlay.hpp +++ b/terminaloverlay.hpp @@ -106,8 +106,15 @@ namespace Overlay { }; class PredictionEngine : public OverlayEngine { + private: + int score; + public: void new_user_byte( char the_byte, const Framebuffer &fb, int prediction_len ); + void calculate_score( const Framebuffer &fb ); + + PredictionEngine() : score( 0 ) {} + int get_score( void ) { return score; } }; /* the overlay manager */ @@ -116,18 +123,13 @@ namespace Overlay { NotificationEngine notifications; PredictionEngine predictions; - int prediction_score; - - void calculate_score( const Framebuffer &fb ); - public: void apply( Framebuffer &fb ); NotificationEngine & get_notification_engine( void ) { return notifications; } PredictionEngine & get_prediction_engine( void ) { return predictions; } - OverlayManager() : notifications(), predictions(), - prediction_score( 0 ) {} + OverlayManager() : notifications(), predictions() {} int wait_time( void ); };