Avoid visual corruption if the game runs too fast.
If we run too fast while not in timedemo mode the game will
return immediately rather than rendering a frame.
If we go ahead and return to GLSurfaceView, it will swap the GL buffer
without having drawn anything into it, which will lead to garbage
being displayed.
The work-around is to detect that the game has decided to not render
anything, sleep for a ms and then try again.
Change-Id: Iba9d759547ddbc30534db963f5c47011038cc246
diff --git a/quake/src/WinQuake/host.cpp b/quake/src/WinQuake/host.cpp
index 670d7a0..f1af56a 100644
--- a/quake/src/WinQuake/host.cpp
+++ b/quake/src/WinQuake/host.cpp
@@ -42,6 +42,7 @@
double realtime; // without any filtering or bounding
double oldrealtime; // last frame run
int host_framecount;
+qboolean host_framethrottled; // Running too fast
int host_hunklevel;
@@ -644,7 +645,8 @@
rand ();
// decide the simulation time
- if (!Host_FilterTime (time))
+ host_framethrottled = !Host_FilterTime (time);
+ if (host_framethrottled)
return; // don't run too fast, or packets will flood out
// get new key events
diff --git a/quake/src/WinQuake/quakedef.h b/quake/src/WinQuake/quakedef.h
index 6b42720..807b47d 100644
--- a/quake/src/WinQuake/quakedef.h
+++ b/quake/src/WinQuake/quakedef.h
@@ -308,6 +308,7 @@
extern byte *host_basepal;
extern byte *host_colormap;
extern int host_framecount; // incremented every frame, never reset
+extern qboolean host_framethrottled; // Running too fast
extern double realtime; // not bounded in any way, changed at
// start of every frame, never reset
diff --git a/quake/src/WinQuake/sys_android.cpp b/quake/src/WinQuake/sys_android.cpp
index 1537814..c66f01c 100644
--- a/quake/src/WinQuake/sys_android.cpp
+++ b/quake/src/WinQuake/sys_android.cpp
@@ -622,7 +622,7 @@
currentFrame++;
}
-int AndroidStep(int width, int height)
+int AndroidStepImp(int width, int height)
{
// PMPBEGIN(("AndroidStep"));
double time, newtime;
@@ -645,6 +645,18 @@
return key_dest == key_game;
}
+int AndroidStep(int width, int height)
+{
+ for(;;) {
+ host_framethrottled = false;
+ int result = AndroidStepImp(width, height);
+ if (!host_framethrottled) {
+ return result;
+ }
+ usleep(1000);
+ }
+}
+
extern void Host_Quit();
void AndroidQuit() {
soft_quit = true;