commit e538442beac77bfd2a9d07706979c560dccfd973
parent 11f0b2e678557e0e9529eb840de8b78c6bd91229
Author: D. Auer <dauer@posteo.de>
Date: Fri, 13 Jul 2018 23:37:12 +0200
Improve the system (usually Xorg) load by increasing the wait time between redraws
The time to wait is set to the time between pings but restricted to a range between
0.03 seconds as a minimum (this was the fixed wait time before this patch) and
0.20 seconds as a maximum (needed to increase the size of the red bars in case
of no response and to redraw the window content in case of window resize or similar)
Fix https://github.com/cnlohr/cnping/issues/44
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/cnping.c b/cnping.c
@@ -559,6 +559,7 @@ int main( int argc, const char ** argv )
double LastFPSTime = OGGetAbsoluteTime();
double LastFrameTime = OGGetAbsoluteTime();
double SecToWait;
+ double frameperiodseconds;
#ifdef WIN32
ShowWindow (GetConsoleWindow(), SW_HIDE);
@@ -671,6 +672,9 @@ int main( int argc, const char ** argv )
OGCreateThread( PingListen, 0 );
}
+
+ frameperiodseconds = fmin(.2, fmax(.03, pingperiodseconds));
+
while(1)
{
iframeno++;
@@ -712,8 +716,9 @@ int main( int argc, const char ** argv )
LastFPSTime+=1;
}
- SecToWait = .030 - ( ThisTime - LastFrameTime );
- LastFrameTime += .030;
+ SecToWait = frameperiodseconds - ( ThisTime - LastFrameTime );
+ LastFrameTime += frameperiodseconds;
+ //printf("iframeno = %d; SecToWait = %f; pingperiodseconds = %f; frameperiodseconds = %f \n", iframeno, SecToWait, pingperiodseconds, frameperiodseconds);
if( SecToWait > 0 )
OGUSleep( (int)( SecToWait * 1000000 ) );
}
diff --git a/cnping.exe b/cnping.exe
Binary files differ.