diff --git a/networktransport.hpp b/networktransport.hpp index 2581686..7c2adaf 100644 --- a/networktransport.hpp +++ b/networktransport.hpp @@ -77,6 +77,8 @@ namespace Network { int fd( void ) { return connection.fd(); } void set_verbose( void ) { sender.set_verbose(); verbose = true; } + + uint64_t timeout( void ) { return connection.timeout(); } }; } diff --git a/stmclient.cpp b/stmclient.cpp index 460c851..e05113e 100644 --- a/stmclient.cpp +++ b/stmclient.cpp @@ -164,7 +164,8 @@ bool STMClient::process_user_input( int fd ) for ( int i = 0; i < bytes_read; i++ ) { char the_byte = buf[ i ]; - overlays.get_prediction_engine().new_user_byte( the_byte, *local_framebuffer ); + overlays.get_prediction_engine().new_user_byte( the_byte, *local_framebuffer, + network->timeout() ); if ( quit_sequence_started ) { if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */ @@ -259,7 +260,7 @@ void STMClient::main( void ) try { output_new_frame(); - int active_fds = poll( pollfds, 4, network->wait_time() ); + int active_fds = poll( pollfds, 4, min( network->wait_time(), overlays.wait_time() ) ); if ( active_fds < 0 ) { perror( "poll" ); break; diff --git a/terminaloverlay.cpp b/terminaloverlay.cpp index 44a2a7f..0597200 100644 --- a/terminaloverlay.cpp +++ b/terminaloverlay.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "terminaloverlay.hpp" @@ -19,8 +20,10 @@ void OverlayCell::apply( Framebuffer &fb ) const return; } - *(fb.get_mutable_cell( row, col )) = replacement; - fb.get_mutable_cell( row, col )->renditions.bold = true; /* XXX */ + if ( !(*(fb.get_mutable_cell( row, col )) == replacement) ) { + *(fb.get_mutable_cell( row, col )) = replacement; + fb.get_mutable_cell( row, col )->renditions.bold = true; /* XXX */ + } } Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb ) const @@ -288,10 +291,9 @@ void OverlayManager::calculate_score( const Framebuffer &fb ) } } -void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) +void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb, int prediction_len ) { uint64_t now = timestamp(); - int prediction_len = 1000; /* XXX */ if ( elements.empty() ) { /* starting from scratch */ @@ -330,3 +332,29 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) clear(); } } + +int OverlayManager::wait_time( void ) +{ + uint64_t now = timestamp(); + + uint64_t next_expiry = uint64_t( -1 ); + + for ( auto i = notifications.begin(); i != notifications.end(); i++ ) { + if ( (*i)->expiration_time < next_expiry ) { + next_expiry = (*i)->expiration_time; + } + } + + for ( auto i = predictions.begin(); i != predictions.end(); i++ ) { + if ( (*i)->expiration_time < next_expiry ) { + next_expiry = (*i)->expiration_time; + } + } + + int ret = next_expiry - now; + if ( ret < 0 ) { + return INT_MAX; + } else { + return ret; + } +} diff --git a/terminaloverlay.hpp b/terminaloverlay.hpp index dd43843..0a927f1 100644 --- a/terminaloverlay.hpp +++ b/terminaloverlay.hpp @@ -107,7 +107,7 @@ namespace Overlay { class PredictionEngine : public OverlayEngine { public: - void new_user_byte( char the_byte, const Framebuffer &fb ); + void new_user_byte( char the_byte, const Framebuffer &fb, int prediction_len ); }; /* the overlay manager */ @@ -126,7 +126,10 @@ namespace Overlay { NotificationEngine & get_notification_engine( void ) { return notifications; } PredictionEngine & get_prediction_engine( void ) { return predictions; } - OverlayManager() : notifications(), predictions(), prediction_score( 0 ) {} + OverlayManager() : notifications(), predictions(), + prediction_score( 0 ) {} + + int wait_time( void ); }; }