Scratch predictions on character we don't know how to handle

This commit is contained in:
Keith Winstein
2011-10-13 04:51:10 -04:00
parent 0d34dfaa60
commit 1f23219047
2 changed files with 16 additions and 15 deletions
+8 -9
View File
@@ -262,30 +262,28 @@ void NotificationEngine::apply( Framebuffer &fb ) const
void OverlayManager::apply( Framebuffer &fb ) void OverlayManager::apply( Framebuffer &fb )
{ {
calculate_score( fb ); predictions.calculate_score( fb );
predictions.cull( fb ); predictions.cull( fb );
if ( prediction_score > 3 ) { if ( predictions.get_score() > 3 ) {
predictions.apply( fb ); predictions.apply( fb );
} else if ( prediction_score == -1 ) {
predictions.clear();
prediction_score = 0;
} }
notifications.apply( fb ); 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 ) ) { switch( (*i)->get_validity( fb ) ) {
case Pending: case Pending:
break; break;
case Correct: case Correct:
prediction_score++; score++;
break; break;
case IncorrectOrExpired: case IncorrectOrExpired:
prediction_score = -1; score = 0;
clear();
return; return;
} }
} }
@@ -330,6 +328,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb, int
elements.push_back( coc ); elements.push_back( coc );
} else { } else {
clear(); clear();
score = 0;
} }
} }
+8 -6
View File
@@ -106,8 +106,15 @@ namespace Overlay {
}; };
class PredictionEngine : public OverlayEngine { class PredictionEngine : public OverlayEngine {
private:
int score;
public: public:
void new_user_byte( char the_byte, const Framebuffer &fb, int prediction_len ); 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 */ /* the overlay manager */
@@ -116,18 +123,13 @@ namespace Overlay {
NotificationEngine notifications; NotificationEngine notifications;
PredictionEngine predictions; PredictionEngine predictions;
int prediction_score;
void calculate_score( const Framebuffer &fb );
public: public:
void apply( Framebuffer &fb ); void apply( Framebuffer &fb );
NotificationEngine & get_notification_engine( void ) { return notifications; } NotificationEngine & get_notification_engine( void ) { return notifications; }
PredictionEngine & get_prediction_engine( void ) { return predictions; } PredictionEngine & get_prediction_engine( void ) { return predictions; }
OverlayManager() : notifications(), predictions(), OverlayManager() : notifications(), predictions() {}
prediction_score( 0 ) {}
int wait_time( void ); int wait_time( void );
}; };