]> git.mxchange.org Git - flightgear.git/commitdiff
fgpanel: avoid lagging
authorThorstenB <brehmt@gmail.com>
Sat, 12 Nov 2011 10:24:08 +0000 (11:24 +0100)
committerThorstenB <brehmt@gmail.com>
Sat, 12 Nov 2011 10:24:08 +0000 (11:24 +0100)
Avoid lagging when data is sent at (slightly) higher rate than
fgpanel's display rate. Always read all available data - display
most recent.

utils/fgpanel/FGPanelProtocol.cxx

index 7efc849ed31144fdb505bf0d2a5c6eefa3776813..3f4b54a75f5e10439931e86bb55caf2a3ee30053 100644 (file)
@@ -123,15 +123,25 @@ FGPanelProtocol::~FGPanelProtocol()
 
 void FGPanelProtocol::update( double dt )
 {
-  char buf[8192];
+  char buf[2][8192];
 
   if( io == NULL )
     return;
 
-  int length = io->readline( buf, sizeof(buf)-1 );
-  buf[sizeof(buf)-1] = 0;
-  if ( length > 0 ) {
-    vector<string> tokens = simgear::strutils::split( buf, "," );
+  // read all available lines, keep last one
+  int Page = 0;
+  bool HaveData = false;
+  while ( io->readline( buf[Page], sizeof(buf[Page])-1 ) > 0 )
+  {
+      HaveData = true;
+      Page ^= 1;
+  }
+
+  if ( HaveData ) {
+    // process most recent line of data
+    Page ^= 1;
+    buf[Page][sizeof(buf[Page])-1] = 0;
+    vector<string> tokens = simgear::strutils::split( buf[Page], "," );
     for( vector<string>::size_type i = 0; i < tokens.size(); i++ ) {
       if( i < propertySetterVector.size() )
         propertySetterVector[i]->setValue( tokens[i].c_str() );