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.
This commit is contained in:
Keegan McAllister
2012-05-02 19:12:49 -04:00
committed by Keith Winstein
parent 02c04fbdaa
commit 24d2b6e185
2 changed files with 36 additions and 35 deletions
+15 -25
View File
@@ -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 ) void OverlayManager::apply( Framebuffer &fb )
{ {
predictions.cull( fb ); predictions.cull( fb );
@@ -286,31 +301,6 @@ void OverlayManager::apply( Framebuffer &fb )
title.apply( 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 ) void TitleEngine::set_prefix( const wstring s )
{ {
prefix = deque<wchar_t>( s.begin(), s.end() ); prefix = deque<wchar_t>( s.begin(), s.end() );
+21 -10
View File
@@ -133,16 +133,17 @@ namespace Overlay {
bool message_is_network_exception; bool message_is_network_exception;
uint64_t message_expiration; uint64_t message_expiration;
public:
bool server_late( uint64_t ts ) const { return (ts - last_word_from_server) > 6500; } 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 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 ); } bool need_countup( uint64_t ts ) const { return server_late( ts ) || reply_late( ts ); }
public:
void adjust_message( void ); void adjust_message( void );
void apply( Framebuffer &fb ) const; void apply( Framebuffer &fb ) const;
const wstring &get_notification_string( void ) const { return message; } 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_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; } 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 ) void set_notification_string( const wstring &s_message, bool permanent = false )
{ {
@@ -236,6 +237,13 @@ namespace Overlay {
private: private:
DisplayPreference display_preference; 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: public:
void set_display_preference( DisplayPreference s_pref ) { display_preference = s_pref; } void set_display_preference( DisplayPreference s_pref ) { display_preference = s_pref; }
@@ -245,19 +253,19 @@ namespace Overlay {
void reset( void ); 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_sent( uint64_t x ) { local_frame_sent = x; }
void set_local_frame_acked( uint64_t x ) { local_frame_acked = 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_local_frame_late_acked( uint64_t x ) { local_frame_late_acked = x; }
void set_send_interval( unsigned int x ) { send_interval = 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(), PredictionEngine( void ) : last_byte( 0 ), parser(), overlays(), cursors(),
local_frame_sent( 0 ), local_frame_acked( 0 ), local_frame_sent( 0 ), local_frame_acked( 0 ),
local_frame_late_acked( 0 ), local_frame_late_acked( 0 ),
@@ -300,7 +308,10 @@ namespace Overlay {
OverlayManager() : notifications(), predictions(), title() {} OverlayManager() : notifications(), predictions(), title() {}
int wait_time( void ); int wait_time( void ) const
{
return std::min( notifications.wait_time(), predictions.wait_time() );
}
}; };
} }