Dynamic prediction timeout
This commit is contained in:
@@ -77,6 +77,8 @@ namespace Network {
|
|||||||
int fd( void ) { return connection.fd(); }
|
int fd( void ) { return connection.fd(); }
|
||||||
|
|
||||||
void set_verbose( void ) { sender.set_verbose(); verbose = true; }
|
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++ ) {
|
for ( int i = 0; i < bytes_read; i++ ) {
|
||||||
char the_byte = buf[ 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 ( quit_sequence_started ) {
|
||||||
if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */
|
if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */
|
||||||
@@ -259,7 +260,7 @@ void STMClient::main( void )
|
|||||||
try {
|
try {
|
||||||
output_new_frame();
|
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 ) {
|
if ( active_fds < 0 ) {
|
||||||
perror( "poll" );
|
perror( "poll" );
|
||||||
break;
|
break;
|
||||||
|
|||||||
+32
-4
@@ -2,6 +2,7 @@
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "terminaloverlay.hpp"
|
#include "terminaloverlay.hpp"
|
||||||
|
|
||||||
@@ -19,8 +20,10 @@ void OverlayCell::apply( Framebuffer &fb ) const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(fb.get_mutable_cell( row, col )) = replacement;
|
if ( !(*(fb.get_mutable_cell( row, col )) == replacement) ) {
|
||||||
fb.get_mutable_cell( row, col )->renditions.bold = true; /* XXX */
|
*(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
|
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();
|
uint64_t now = timestamp();
|
||||||
int prediction_len = 1000; /* XXX */
|
|
||||||
|
|
||||||
if ( elements.empty() ) {
|
if ( elements.empty() ) {
|
||||||
/* starting from scratch */
|
/* starting from scratch */
|
||||||
@@ -330,3 +332,29 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
|
|||||||
clear();
|
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 {
|
class PredictionEngine : public OverlayEngine {
|
||||||
public:
|
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 */
|
/* the overlay manager */
|
||||||
@@ -126,7 +126,10 @@ namespace Overlay {
|
|||||||
NotificationEngine & get_notification_engine( void ) { return notifications; }
|
NotificationEngine & get_notification_engine( void ) { return notifications; }
|
||||||
PredictionEngine & get_prediction_engine( void ) { return predictions; }
|
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