Permalink
Browse files

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.
  • Loading branch information...
1 parent 02c04fb commit 24d2b6e1857dd02cbf11a39cc24863e07387eb1b @kmcallister kmcallister committed with keithw May 2, 2012
Showing with 34 additions and 33 deletions.
  1. +13 −23 src/frontend/terminaloverlay.cc
  2. +21 −10 src/frontend/terminaloverlay.h
@@ -277,40 +277,30 @@ void NotificationEngine::adjust_message( void )
}
}
-void OverlayManager::apply( Framebuffer &fb )
-{
- predictions.cull( fb );
- predictions.apply( fb );
- notifications.adjust_message();
- notifications.apply( fb );
- title.apply( fb );
-}
-
-int OverlayManager::wait_time( void )
+int NotificationEngine::wait_time( void ) const
{
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;
- }
+ next_expiry = std::min( next_expiry, message_expiration - now );
- if ( predictions.timing_tests_necessary()
- && predictions.active()
- && ( next_expiry > 50 ) ) {
- next_expiry = 50;
+ if ( need_countup( now ) ) {
+ next_expiry = std::min( next_expiry, uint64_t( 1000 ) );
}
return next_expiry;
}
+void OverlayManager::apply( Framebuffer &fb )
+{
+ predictions.cull( fb );
+ predictions.apply( fb );
+ notifications.adjust_message();
+ notifications.apply( fb );
+ title.apply( fb );
+}
+
void TitleEngine::set_prefix( const wstring s )
{
prefix = deque<wchar_t>( s.begin(), s.end() );
@@ -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() );
+ }
};
}

0 comments on commit 24d2b6e

Please sign in to comment.