Dynamic prediction timeout
This commit is contained in:
@@ -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(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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;
|
||||
|
||||
+30
-2
@@ -2,6 +2,7 @@
|
||||
#include <wchar.h>
|
||||
#include <list>
|
||||
#include <typeinfo>
|
||||
#include <limits.h>
|
||||
|
||||
#include "terminaloverlay.hpp"
|
||||
|
||||
@@ -19,9 +20,11 @@ void OverlayCell::apply( Framebuffer &fb ) const
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -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 );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user