From f406e0695cdcf2f766588b635e1d6ba2b99971b9 Mon Sep 17 00:00:00 2001 From: ketmar Date: Wed, 24 Aug 2016 04:52:59 +0000 Subject: [PATCH] redraw each frame, or driver (system?) will decrease our priority, and we won't get our desired framerate FossilOrigin-Name: 0c20bea0df10ed1bc2a123cd60e53ca534783d6077a39abbd2f54e2b53723e53 --- xreader.d | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/xreader.d b/xreader.d index 05fedd0..c5eb21d 100644 --- a/xreader.d +++ b/xreader.d @@ -78,6 +78,7 @@ void run (string bookFileName) { auto stt = MonoTime.currTime; auto prevt = MonoTime.currTime; auto curt = prevt; + auto lastRedrawTime = curt; LayText laytext; int textHeight = GHeight-8; bool doSaveCheck = false; @@ -862,6 +863,7 @@ void run (string bookFileName) { //vg.endFrame(); } vg.endFrame(); + lastRedrawTime = MonoTime.currTime; }; void processThreads () { @@ -883,10 +885,11 @@ void run (string bookFileName) { } auto lastTimerEventTime = MonoTime.currTime; + bool somethingVisible = true; sdwindow.visibilityChanged = delegate (bool vis) { - //import core.stdc.stdio; - //printf("VISCHANGED: %s\n", (vis ? "tan" : "ona").ptr); + //import core.stdc.stdio; printf("VISCHANGED: %s\n", (vis ? "tan" : "ona").ptr); + somethingVisible = vis; }; sdwindow.eventLoop(1000/34, @@ -897,11 +900,9 @@ void run (string bookFileName) { auto ctt = MonoTime.currTime; { - auto spass = (lastTimerEventTime-ctt).total!"msecs"; - if (spass > 33) { - import core.stdc.stdio; - printf("WARNING: too long frame time: %u\n", cast(uint)spass); - } + auto spass = (ctt-lastTimerEventTime).total!"msecs"; + //if (spass >= 30) { import core.stdc.stdio; printf("WARNING: too long frame time: %u\n", cast(uint)spass); } + //{ import core.stdc.stdio; printf("FRAME TIME: %u\n", cast(uint)spass); } lastTimerEventTime = ctt; // update FPS timer prevt = curt; @@ -965,7 +966,12 @@ void run (string bookFileName) { refresh(); } } - if (needRedraw) sdwindow.redrawOpenGlSceneNow(); + if (somethingVisible) { + // sadly, to keep framerate we have to redraw each frame, or driver will throw us out of the ship + if (/*needRedraw*/true) sdwindow.redrawOpenGlSceneNow(); + } else { + refresh(); + } doSaveState(); // load new book? if (newBookFileName.length && formatWorks == 0) { -- 2.11.4.GIT