From: Matthew Mondor Date: Tue, 18 Apr 2023 00:14:38 +0000 (+0000) Subject: - Performance improvement, disabling a full forced refresh per frame. X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=ad8428115ffd641e1e37908f5bafb6964422babd;p=ninvaders.git - Performance improvement, disabling a full forced refresh per frame. - Addition of the -f command line option to lower the FPS if needed. --- diff --git a/MATT-README.txt b/MATT-README.txt index 5d37d87..7ef88be 100644 --- a/MATT-README.txt +++ b/MATT-README.txt @@ -10,6 +10,9 @@ BUG FIXES 64-bit. Fixed. - Memory was leaked everytime the title screen was displayed in the form of unnecessarily created pads that were never deleted. +- The refresh function forced a full screen refresh everytime, + making user input unresponsive whenever a terminal was slightly + restricted in bandwidth. IMPROVEMENTS @@ -27,6 +30,9 @@ IMPROVEMENTS - Add high score keeping and display the scores on the title screen. +- Bandwidth efficiency improvent and addition of the -f option to + lower the frame rate from the default (very high) 50, if necessary. + TODO diff --git a/globals.c b/globals.c index c1e6026..aadc608 100644 --- a/globals.c +++ b/globals.c @@ -68,11 +68,15 @@ void showVersion(void) void showUsage(void) { - fprintf(stderr, "\n\nUsage: nInvaders [-l skill] [-L]\n"); - fprintf(stderr, " where -l 0=NIGHTMARE\n"); - fprintf(stderr, " -l 1=okay\n"); - fprintf(stderr, " -l 9=May I play daddy?!\n"); - fprintf(stderr, "\n -L display the distribution license\n"); + fprintf(stderr, "\n\nUsage: nInvaders [-f ] [-l skill] [-L]\n"); + fprintf(stderr, + " Where:\n\n" + " -f - Frame rate, lower if unresponsive on low bps\n\n" + " -l 0=NIGHTMARE\n" + " -l 1=okay\n" + " -l 9=May I play daddy?!\n\n" + " -L display the distribution license\n"); + fprintf(stderr, "\n"); } diff --git a/nInvaders.c b/nInvaders.c index a24e8bb..b2f4e0c 100644 --- a/nInvaders.c +++ b/nInvaders.c @@ -33,7 +33,9 @@ #include "aliens.h" #include "ufo.h" -#define FPS 50 +#define DEFAULT_FPS 50 + +int fps = DEFAULT_FPS; int lives; long score = 0, hiscore = 0; @@ -73,8 +75,12 @@ static void evaluateCommandLine(int argc, char **argv) { int ch, i; - while ((ch = getopt(argc, argv, "?l:L")) != -1) { + while ((ch = getopt(argc, argv, "?f:l:L")) != -1) { switch (ch) { + case 'f': + if ((i = atoi(optarg)) >= 5 && i <= 50) + fps = i; + break; case 'l': if ((i = atoi(optarg)) > -1 && i < 10) skill_level = i; @@ -335,9 +341,9 @@ void setUpTimer(void) struct itimerval myTimer; struct sigaction myAction; myTimer.it_value.tv_sec = 0; - myTimer.it_value.tv_usec = 1000000 / FPS; + myTimer.it_value.tv_usec = 1000000 / fps; myTimer.it_interval.tv_sec = 0; - myTimer.it_interval.tv_usec = 1000000 / FPS; + myTimer.it_interval.tv_usec = 1000000 / fps; setitimer(ITIMER_REAL, &myTimer, NULL); myAction.sa_handler = handleTimer; diff --git a/view.c b/view.c index c617c4d..d3add9e 100644 --- a/view.c +++ b/view.c @@ -594,9 +594,20 @@ void battleFieldClear(void) */ void refreshScreen(void) { - redrawwin(wBattleField); // needed to display graphics properly at startup on some terminals + /* + * The following is claimed to be necessary on some terminals for + * graphics to properly display at startup. It however is prohibitive + * in that it forces a full refresh every FPS, which by default is 50. + * For this reason, whenever a terminal is restricted in bandwidth, + * even with speeds as high as 19200bps, it becomes completely + * unresponsive to user input, even with the added -f option to lower + * the FPS. Without the following line, everything is fine. + * If the issue was really at startup, it theoretically would be + * possible to only force this refresh once or twice. Disabled for + * now. + */ + /* redrawwin(wBattleField); XXX */ wrefresh(wBattleField); - }