From 7f414f4946354a3b960b1f6a15cfdad014d7e199 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 21 May 2020 20:33:44 +0000 Subject: Added timer to control update speed. --- README | 6 ++---- lunar.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/README b/README index 3f8f739..3ae25dc 100644 --- a/README +++ b/README @@ -23,10 +23,8 @@ Though written under FreeBSD, it should compile OK on most flavours of unix. USAGE ----- -lunar [-noshm] [scale] - Use scale to magnify and impact overly fast servers. - Use -noshm as well if your server is still too fast - to disable MIT-SHM usage. (Note shm usage will be - disabled if your server doesn't support it anyway). +lunar [-noshm] [scale] - Use scale to magnify the screen. Use -noshm to + disable MIT_SHM usage if it causes problems. ledit diff --git a/lunar.c b/lunar.c index f57d899..86d0619 100644 --- a/lunar.c +++ b/lunar.c @@ -37,6 +37,7 @@ static char rcs_id[]="$Id$"; #include #include #include +#include #include #include @@ -79,6 +80,8 @@ static uchar *coll_data; static double si[3600],co[3600]; +static struct timespec frame_start; + static XFuncControl Key(Window w, XPressRelease s, XEvent *e); static XFuncControl ProcessTitle(void),ProcessIntro(void),ProcessGame(void), ProcessGameOver(void),ProcessHiScore(void); @@ -356,6 +359,8 @@ static int Paused(int k); static void ReadScores(void); static void WriteScores(void); static void ReadLevels(void); +static void StartFrame(void); +static void EndFrame(void); int main(int argc,char *argv[]) @@ -1164,6 +1169,7 @@ static XFuncControl ProcessTitle(void) ctr++; + StartFrame(); Cls(); for(f=0;f<10;f++) @@ -1198,6 +1204,7 @@ static XFuncControl ProcessTitle(void) DoDebugMenu(); Update(); + EndFrame(); k=GetKey(); @@ -1345,6 +1352,7 @@ static XFuncControl ProcessGame(void) if (Paused(k)) return XFUNCCONT; + StartFrame(); Cls(); /* Process movement @@ -1471,6 +1479,7 @@ static XFuncControl ProcessGame(void) CheckCollisions(&landed,&dead); Update(); + EndFrame(); if (k==SCALE_UP) { @@ -1643,6 +1652,7 @@ static XFuncControl ProcessHiScore(void) first=False; } + StartFrame(); Cls(); Centre(16,WHITE,"CONGRATULATIONS!"); @@ -1689,6 +1699,7 @@ static XFuncControl ProcessHiScore(void) bounce--; Update(); + EndFrame(); if (len==3) { @@ -1860,3 +1871,40 @@ static void ReadLevels(void) for(f=0;f 0) + { + diff.tv_sec--; + diff.tv_nsec += 1000000000; + } + + if (diff.tv_nsec >= 1000000000) + { + diff.tv_sec++; + diff.tv_nsec -= 1000000000; + } + + if (diff.tv_sec == 0 && diff.tv_nsec < FRAME) + { + diff.tv_nsec = FRAME - diff.tv_nsec; + + nanosleep(&diff, NULL); + } +} -- cgit v1.2.3