- Replace the halfdelay() using function by the simulated frame one.
authorMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 10 Apr 2023 17:48:00 +0000 (17:48 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 10 Apr 2023 17:48:00 +0000 (17:48 +0000)
- 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().

src/draw.cpp
src/main.cpp
src/mishaps.cpp
src/radar_plot.cpp

index 165a17c..8229db7 100644 (file)
@@ -1,4 +1,4 @@
-#include <ncurses.h>
+#include <curses.h>
 #include <cstdlib>
 
 #include "game_object.h"
index 05c0d2c..6af4b5b 100644 (file)
@@ -19,7 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include <err.h>
-#include <ncurses.h>
+#include <curses.h>
 #include <cstring>
 #include <cstdlib>
 #include <cstdio>
@@ -64,7 +64,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 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__
index cb8a36c..4d37530 100644 (file)
@@ -1,4 +1,4 @@
-#include <ncurses.h>
+#include <curses.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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);
   };
 
index 8401255..7a738d0 100644 (file)
@@ -1,4 +1,4 @@
-#include <ncurses.h>
+#include <curses.h>
 #include <cstdlib>
 
 #include "game_object.h"