From 24d2b6e1857dd02cbf11a39cc24863e07387eb1b Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Wed, 2 May 2012 19:12:49 -0400 Subject: [PATCH] Calculate wait_time separately for {Notification,Prediction}Engine Simplifies access to private data, including the next commit. git renders this diff poorly. It's a bit better with --patience. --- src/frontend/terminaloverlay.cc | 40 +++++++++++++-------------------- src/frontend/terminaloverlay.h | 31 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/frontend/terminaloverlay.cc b/src/frontend/terminaloverlay.cc index 982ad8c..bbdd453 100644 --- a/src/frontend/terminaloverlay.cc +++ b/src/frontend/terminaloverlay.cc @@ -277,6 +277,21 @@ void NotificationEngine::adjust_message( void ) } } +int NotificationEngine::wait_time( void ) const +{ + uint64_t next_expiry = INT_MAX; + + uint64_t now = timestamp(); + + next_expiry = std::min( next_expiry, message_expiration - now ); + + if ( need_countup( now ) ) { + next_expiry = std::min( next_expiry, uint64_t( 1000 ) ); + } + + return next_expiry; +} + void OverlayManager::apply( Framebuffer &fb ) { predictions.cull( fb ); @@ -286,31 +301,6 @@ void OverlayManager::apply( Framebuffer &fb ) title.apply( fb ); } -int OverlayManager::wait_time( void ) -{ - uint64_t next_expiry = INT_MAX; - - uint64_t now = timestamp(); - - uint64_t message_delay = notifications.get_message_expiration() - now; - - if ( message_delay < next_expiry ) { - next_expiry = message_delay; - } - - if ( notifications.need_countup( now ) && ( next_expiry > 1000 ) ) { - next_expiry = 1000; - } - - if ( predictions.timing_tests_necessary() - && predictions.active() - && ( next_expiry > 50 ) ) { - next_expiry = 50; - } - - return next_expiry; -} - void TitleEngine::set_prefix( const wstring s ) { prefix = deque( s.begin(), s.end() ); diff --git a/src/frontend/terminaloverlay.h b/src/frontend/terminaloverlay.h index 2bbff53..932cb5c 100644 --- a/src/frontend/terminaloverlay.h +++ b/src/frontend/terminaloverlay.h @@ -133,16 +133,17 @@ namespace Overlay { bool message_is_network_exception; uint64_t message_expiration; - public: bool server_late( uint64_t ts ) const { return (ts - last_word_from_server) > 6500; } bool reply_late( uint64_t ts ) const { return (ts - last_acked_state) > 10000; } bool need_countup( uint64_t ts ) const { return server_late( ts ) || reply_late( ts ); } + + public: void adjust_message( void ); void apply( Framebuffer &fb ) const; const wstring &get_notification_string( void ) const { return message; } void server_heard( uint64_t s_last_word ) { last_word_from_server = s_last_word; } void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; } - uint64_t get_message_expiration( void ) const { return message_expiration; } + int wait_time( void ) const; void set_notification_string( const wstring &s_message, bool permanent = false ) { @@ -236,6 +237,13 @@ namespace Overlay { private: DisplayPreference display_preference; + bool active( void ) const; + + bool timing_tests_necessary( void ) const { + /* Are there any timing-based triggers that haven't fired yet? */ + return !( glitch_trigger && flagging ); + } + public: void set_display_preference( DisplayPreference s_pref ) { display_preference = s_pref; } @@ -245,19 +253,19 @@ namespace Overlay { void reset( void ); - bool active( void ) const; - - bool timing_tests_necessary( void ) const { - /* Are there any timing-based triggers that haven't fired yet? */ - return !( glitch_trigger && flagging ); - } - void set_local_frame_sent( uint64_t x ) { local_frame_sent = x; } void set_local_frame_acked( uint64_t x ) { local_frame_acked = x; } void set_local_frame_late_acked( uint64_t x ) { local_frame_late_acked = x; } void set_send_interval( unsigned int x ) { send_interval = x; } + int wait_time( void ) const + { + return ( timing_tests_necessary() && active() ) + ? 50 + : INT_MAX; + } + PredictionEngine( void ) : last_byte( 0 ), parser(), overlays(), cursors(), local_frame_sent( 0 ), local_frame_acked( 0 ), local_frame_late_acked( 0 ), @@ -300,7 +308,10 @@ namespace Overlay { OverlayManager() : notifications(), predictions(), title() {} - int wait_time( void ); + int wait_time( void ) const + { + return std::min( notifications.wait_time(), predictions.wait_time() ); + } }; }