From: Matthew Mondor Date: Mon, 10 Apr 2023 17:48:00 +0000 (+0000) Subject: - Replace the halfdelay() using function by the simulated frame one. X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=1d017b76a83d605813b1182d3ba1fbcc9d713a2f;p=curblaster.git - Replace the halfdelay() using function by the simulated frame one. - Build and test against curses vs ncurses, better performance was achieved for me using it, versus using the ncurses port that poll(2)ed excessively long even with timeout(0). This seems to be fine on ncurses that is native on Linux systems. Thus, use X/Open standard curses.h instead of ncurses.h that works on both. - Remove explicit cursor displacement code now that its visibility is hidden with curs_set(). Theoretically curses should also do this transparently with leaveok(). --- diff --git a/src/draw.cpp b/src/draw.cpp index 165a17c..8229db7 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "game_object.h" diff --git a/src/main.cpp b/src/main.cpp index 05c0d2c..6af4b5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ along with this program. If not, see . */ #include -#include +#include #include #include #include @@ -64,7 +64,6 @@ along with this program. If not, see . static void cleanup(void); static int frame_getch(void); -static int halfdelay_getch(void); int block_getch(void); @@ -98,38 +97,29 @@ frame_getch(void) { int c; - (void)curs_set(0); - (void)usleep(1000000 / ANIM_FPS); - (void)keypad(win, TRUE); - (void)timeout(0); - - c = wgetch(win); + c = getch(); if (c != ERR) (void)flushinp(); return c; } -static int -halfdelay_getch(void) -{ - - (void)halfdelay(1); - (void)curs_set(1); - - return wgetch(win); -} - int block_getch(void) { + int c; - (void)timeout(-1); (void)curs_set(1); + (void)timeout(-1); + + c = getch(); + + (void)curs_set(0); + (void)timeout(0); - return wgetch(win); + return c; } @@ -578,14 +568,10 @@ int main(int argc, char *argv[]){ err(EXIT_FAILURE, "initscr()"); //Check screen size 80x24 and exit if not big enough - int maxx, maxy; - - getmaxyx(stdscr, maxx, maxy); - - if(maxx<24||maxy<80){ + if(LINES<24||COLS<80){ endwin(); - printf("Screen only %d x %d, needs to be at least 80x24\n", maxy, maxx); - exit(1); + printf("Screen only %d x %d, needs to be at least 80x24\n", COLS, LINES); + exit(EXIT_FAILURE); }; (void)atexit(cleanup); @@ -605,6 +591,11 @@ int main(int argc, char *argv[]){ cbreak(); noecho(); nonl(); + (void)keypad(win, TRUE); + (void)intrflush(stdscr, FALSE); + (void)curs_set(0); + (void)timeout(0); + //print title screen @@ -670,9 +661,6 @@ int main(int argc, char *argv[]){ mvprintw(13,34,"High Score: %d",hscore); - //get the cursor out of the way - mvprintw(23,79,"-"); - //load sound, music #ifdef __USE_SDL__ Mix_Chunk *shotsound = NULL; @@ -768,7 +756,7 @@ int main(int argc, char *argv[]){ int counter = 0; int show_controls = 30; while(pause_game!=' '){ - pause_game = halfdelay_getch(); + pause_game = frame_getch(); if(counter>=4){ //GO! mvprintw(18,28,"Press SPACE to start"); @@ -1079,9 +1067,6 @@ int main(int argc, char *argv[]){ show_controls--; }; - //get the cursor out of the way - mvprintw(23,79,"|"); - // Sleeps for a frame then checks for any input input = frame_getch(); @@ -2077,7 +2062,7 @@ int main(int argc, char *argv[]){ }; }; }; - //wrefresh(win); + refresh(); }; //end main loop #ifdef __USE_SDL__ diff --git a/src/mishaps.cpp b/src/mishaps.cpp index cb8a36c..4d37530 100644 --- a/src/mishaps.cpp +++ b/src/mishaps.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -62,8 +62,6 @@ int boom_object(int drawlocation, game_object boomstuff, game_object object){ for(int iterations=0;iterations<=loop;iterations++){ drawlocation = draw_object(boomstuff, drawlocation); }; - //get the cursor out of the way - mvprintw(23,79,"-"); refresh(); }; }; @@ -72,6 +70,7 @@ int boom_object(int drawlocation, game_object boomstuff, game_object object){ deathcycle++; }; if(object.number!=1){ + refresh(); usleep(50000); }; diff --git a/src/radar_plot.cpp b/src/radar_plot.cpp index 8401255..7a738d0 100644 --- a/src/radar_plot.cpp +++ b/src/radar_plot.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "game_object.h"