From b49a491544fbd21beb14a44f6ccf5983b6a2f8dc Mon Sep 17 00:00:00 2001 From: Gerfried Fuchs Date: Wed, 14 Jul 2010 21:37:37 +0200 Subject: [PATCH] Imported Upstream version 0.5 --- Configure | 23 ++++++++++--- FAQ | 19 ++++++++++- README | 23 +++++++------ VERSION | 2 +- board.c | 6 ++-- curses.c | 94 ++++++++++++++++++++++++++++++++++++++++-------------- game.c | 9 ++++-- netris.h | 10 +++--- robot_desc | 8 ++--- shapes.c | 18 +++++------ util.c | 21 ++++++------ 11 files changed, 160 insertions(+), 73 deletions(-) diff --git a/Configure b/Configure index 7fe293e..fbc57a8 100755 --- a/Configure +++ b/Configure @@ -1,7 +1,7 @@ : # # Netris -- A free networked version of T*tris -# Copyright (C) 1994,1995,1996 Mark H. Weaver +# Copyright (C) 1994-1996,1999 Mark H. Weaver # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,13 +17,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -# $Id: Configure,v 1.17 1996/02/09 08:22:03 mhw Exp $ +# $Id: Configure,v 1.18 1999/05/16 06:56:19 mhw Exp $ # CC="gcc" COPT="-g -O" CEXTRA="" LEXTRA="" +CURSES_HACK=false while [ $# -ge 1 ]; do opt="$1" @@ -53,6 +54,9 @@ while [ $# -ge 1 ]; do LEXTRA="$1" shift ;; + --curses-hack) + CURSES_HACK=true + ;; *) cat << "END" Usage: ./Configure [options...] @@ -62,6 +66,7 @@ Usage: ./Configure [options...] --copt : Set C optimization flags --cextra : Set extra C flags --lextra : Set extra linker flags + --curses-hack: Disable scroll-optimization for broken curses END exit 1 ;; @@ -73,8 +78,12 @@ CFLAGS="$COPT $CEXTRA" echo "Checking for libraries" echo 'main(){}' > test.c LFLAGS="" -for lib in -lsocket -lnsl -lcurses -ltermcap -do +for lib in -lcurses -lncurses; do + if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then + LFLAGS="$lib" + fi +done +for lib in -lsocket -lnsl -ltermcap; do if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then LFLAGS="$LFLAGS $lib" fi @@ -144,7 +153,8 @@ echo "Creating Makefile" sed -e "s/-LFLAGS-/$LFLAGS/g" -e "s/-SRCS-/$SRCS/g" \ -e "s/-OBJS-/$OBJS/g" -e "s/-DISTFILES-/$DISTFILES/g" \ -e "s/-COPT-/$COPT/g" -e "s/-CEXTRA-/$CEXTRA/g" \ - -e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" << "END" > Makefile + -e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" \ + << "END" > Makefile # # Automatically generated by ./Configure -- DO NOT EDIT! # @@ -244,6 +254,9 @@ fi if [ "$HAS_SIGPROCMASK" = "true" ]; then echo "#define HAS_SIGPROCMASK" >> config.h fi +if [ "$CURSES_HACK" = "true" ]; then + echo "#define CURSES_HACK" >> config.h +fi echo "Running 'make depend'" if make depend; then :; else cat << END; fi diff --git a/FAQ b/FAQ index 18a203c..4148983 100644 --- a/FAQ +++ b/FAQ @@ -2,7 +2,7 @@ # Netris # Frequently asked questions # -# $Id: FAQ,v 1.3 1996/02/09 08:47:23 mhw Exp $ +# $Id: FAQ,v 1.4 1999/05/16 06:56:21 mhw Exp $ # Questions @@ -18,6 +18,8 @@ Questions [6] I'm using a slow terminal, and the game response is sluggish. What can I do? [7] Why can't my terminal hide the cursor? +[8] Occasionally when clearing a line, the display jerks, scrolling + very awkwardly. How can I fix it? Answers ======= @@ -109,4 +111,19 @@ Answers before running Netris. If that doesn't work, your terminal probably doesn't support cursor invisibility. +[8] Occasionally when clearing a line, the display jerks, scrolling + very awkwardly. How can I fix it? + + You can try running ./Configure with the "--curses-hack" option + and recompile. This utilizes a non-portable hack which will only + work with certain curses libraries, so it's disabled by default. + + All screen updating is done by your curses library, which means + it's not something that Netris can control. Netris never tells + curses to scroll, but curses does so automatically in order to + optimize screen updates. This hack modifies curses's internal + variables, making it think that your terminal doesn't know how to + region-scroll. + + # vi: tw=70 ai diff --git a/README b/README index fc7d155..9420e20 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ # # Netris -- A free networked version of T*tris -# Copyright (C) 1994,1995,1996 Mark H. Weaver +# Copyright (C) 1994-1996,1999 Mark H. Weaver # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,13 +16,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -# $Id: README,v 1.20 1996/02/09 08:22:06 mhw Exp $ +# $Id: README,v 1.21 1999/05/16 06:56:22 mhw Exp $ # This is an unfinished developmental version of Netris, a free networked version of T*tris. It is distributed under the terms of the GNU General Public License, which is described in the -file "COPYING" included with this distribution. +file "COPYING" included with this distribution. For more +information about GNU and the Free Software Foundation, +check out . In order to compile Netris you will need gcc. You may be able to compile it with another ANSI C compiler, but if you attempt this @@ -30,8 +32,9 @@ you are on your own. It's been built and tested on at least the following systems: + GNU/Linux + FreeBSD 2.1.5, 2.1.6, 2.2 NetBSD 1.0, 1.1 - Linux SunOS 4.1.1, 4.1.3 Solaris 2.3, 2.4 HP-UX @@ -48,12 +51,12 @@ how it goes, and send me diffs if needed! See the FAQ in this directory if you have any problems. -NEW IN VERSION 0.4 +NEW IN VERSION 0.5 ================== -- Netris now attempts to make the cursor invisible for terminals that - support it. Xterm no, vt220 yes, vt100 maybe? -- Ctrl-L (by default) will now redraw the screen. -- Various cleanup and documentation changes. +Netris now specifically looks for ncurses and uses color if it's +available, unless the -C option is given. Thanks to A.P.J. van Loo + for providing code which these changes are +based on. INSTALLATION @@ -97,7 +100,7 @@ The keys are: 'm' down faster 's' toggle spying on the other player 'p' pause - 'f' make game faster (irreversable) + 'f' make game faster (irreversible) Ctrl-L redraw the screen To see usage information, type "netris -h". diff --git a/VERSION b/VERSION index bd73f47..2eb3c4f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4 +0.5 diff --git a/board.c b/board.c index 125cdd0..d1cb66b 100644 --- a/board.c +++ b/board.c @@ -1,6 +1,6 @@ /* * Netris -- A free networked version of T*tris - * Copyright (C) 1994,1995,1996 Mark H. Weaver + * Copyright (C) 1994-1996,1999 Mark H. Weaver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: board.c,v 1.14 1996/02/09 08:22:08 mhw Exp $ + * $Id: board.c,v 1.15 1999/05/16 06:56:24 mhw Exp $ */ #include "netris.h" @@ -237,7 +237,7 @@ ExtFunc void InsertJunk(int scr, int count, int column) CopyLine(scr, y, y + count); for (y = 0; y < count; ++y) for (x = 0; x < boardWidth[scr]; ++x) - SetBlock(scr, y, x, (x == column) ? BT_none : BT_piece1); + SetBlock(scr, y, x, (x == column) ? BT_none : BT_white); curY[scr] += count; } diff --git a/curses.c b/curses.c index 047efa4..14e9ce4 100644 --- a/curses.c +++ b/curses.c @@ -1,6 +1,6 @@ /* * Netris -- A free networked version of T*tris - * Copyright (C) 1994,1995,1996 Mark H. Weaver + * Copyright (C) 1994-1996,1999 Mark H. Weaver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: curses.c,v 1.32 1996/02/09 08:47:25 mhw Exp $ + * $Id: curses.c,v 1.33 1999/05/16 06:56:25 mhw Exp $ */ #include "netris.h" @@ -26,6 +26,28 @@ #include #include +#ifdef NCURSES_VERSION +# define HAVE_NCURSES +#endif + +#ifdef HAVE_NCURSES +static struct +{ + BlockType type; + short color; +} myColorTable[] = +{ + { BT_white, COLOR_WHITE }, + { BT_blue, COLOR_BLUE }, + { BT_magenta, COLOR_MAGENTA }, + { BT_cyan, COLOR_CYAN }, + { BT_yellow, COLOR_YELLOW }, + { BT_green, COLOR_GREEN }, + { BT_red, COLOR_RED }, + { BT_none, 0 } +}; +#endif + static void PlotBlock1(int scr, int y, int x, BlockType type); static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event); @@ -34,6 +56,7 @@ static EventGenRec keyGen = static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS]; static int statusYPos, statusXPos; +static int haveColor; static char *term_vi; /* String to make cursor invisible */ static char *term_ve; /* String to make cursor visible */ @@ -45,11 +68,35 @@ ExtFunc void InitScreens(void) GetTermcapInfo(); /* - * Do this atomically. Otherwise a badly timed Ctrl-C during - * initialization will leave your terminal in a bad state. + * Block signals while initializing curses. Otherwise a badly timed + * Ctrl-C during initialization might leave the terminal in a bad state. */ BlockSignals(&oldMask, SIGINT, 0); initscr(); + +#ifdef CURSES_HACK + { + extern char *CS; + + CS = 0; + } +#endif + +#ifdef HAVE_NCURSES + haveColor = colorEnable && has_colors(); + if (haveColor) + { + int i = 0; + + start_color(); + for (i = 0; myColorTable[i].type != BT_none; ++i) + init_pair(myColorTable[i].type, COLOR_BLACK, + myColorTable[i].color); + } +#else + haveColor = 0; +#endif + AtExit(CleanupScreens); RestoreSignals(NULL, &oldMask); @@ -61,7 +108,7 @@ ExtFunc void InitScreens(void) move(0, 0); addstr("Netris "); addstr(version_string); - addstr(" (C) 1994,1995,1996 Mark H. Weaver " + addstr(" (C) 1994-1996,1999 Mark H. Weaver " "\"netris -h\" for more info"); statusYPos = 22; statusXPos = 0; @@ -172,27 +219,26 @@ ExtFunc void CleanupScreen(int scr) static void PlotBlock1(int scr, int y, int x, BlockType type) { + int colorIndex = abs(type); + move(boardYPos[scr] - y, boardXPos[scr] + 2 * x); - switch (type) { - case BT_none: - addstr(" "); - break; - case -BT_piece1: - if (standoutEnable) - standout(); - addstr("$$"); - if (standoutEnable) - standend(); - break; - case BT_piece1: - if (standoutEnable) + + if (type == BT_none) + addstr(" "); + else + { + if (standoutEnable) + { +#ifdef HAVE_NCURSES + if (haveColor) + attrset(COLOR_PAIR(colorIndex)); + else +#endif standout(); - addstr("[]"); - if (standoutEnable) - standend(); - break; - default: - assert(0); + } + + addstr(type > 0 ? "[]" : "$$"); + standend(); } } diff --git a/game.c b/game.c index 26ab6a8..b40c129 100644 --- a/game.c +++ b/game.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: game.c,v 1.38 1996/02/09 08:22:11 mhw Exp $ + * $Id: game.c,v 1.39 1999/05/16 06:56:27 mhw Exp $ */ #define NOEXT @@ -359,10 +359,10 @@ ExtFunc int main(int argc, char **argv) int initConn = 0, waitConn = 0, ch; char *hostStr = NULL, *portStr = NULL; - standoutEnable = 1; + standoutEnable = colorEnable = 1; stepDownInterval = DEFAULT_INTERVAL; MapKeys(DEFAULT_KEYS); - while ((ch = getopt(argc, argv, "hHRs:r:Fk:c:woDSp:i:")) != -1) + while ((ch = getopt(argc, argv, "hHRs:r:Fk:c:woDSCp:i:")) != -1) switch (ch) { case 'c': initConn = 1; @@ -393,6 +393,9 @@ ExtFunc int main(int argc, char **argv) case 'D': dropModeEnable = 1; break; + case 'C': + colorEnable = 0; + break; case 'S': standoutEnable = 0; break; diff --git a/netris.h b/netris.h index 5864cf7..45d61bf 100644 --- a/netris.h +++ b/netris.h @@ -1,6 +1,6 @@ /* * Netris -- A free networked version of T*tris - * Copyright (C) 1994,1995,1996 Mark H. Weaver + * Copyright (C) 1994-1996,1999 Mark H. Weaver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: netris.h,v 1.27 1996/02/09 08:22:14 mhw Exp $ + * $Id: netris.h,v 1.28 1999/05/16 06:56:29 mhw Exp $ */ #ifndef NETRIS_H @@ -91,7 +91,9 @@ typedef long netint4; #define EM_any 000777 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType; -typedef enum _BlockTypeA { BT_none, BT_piece1, BT_wall, BT_len } BlockTypeA; +typedef enum _BlockTypeA { BT_none, BT_white, BT_blue, BT_magenta, + BT_cyan, BT_yellow, BT_green, BT_red, + BT_wall, BT_len } BlockTypeA; typedef enum _Dir { D_down, D_right, D_up, D_left } Dir; typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd; typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType; @@ -156,7 +158,7 @@ EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS]; EXT Shape *curShape[MAX_SCREENS]; EXT int curY[MAX_SCREENS], curX[MAX_SCREENS]; EXT char opponentName[16], opponentHost[256]; -EXT int standoutEnable; +EXT int standoutEnable, colorEnable; EXT int robotEnable, robotVersion, fairRobot; EXT int protocolVersion; diff --git a/robot_desc b/robot_desc index 01c6970..53415b2 100644 --- a/robot_desc +++ b/robot_desc @@ -1,4 +1,4 @@ -$Id: robot_desc,v 1.3 1996/02/09 08:22:16 mhw Exp $ +$Id: robot_desc,v 1.4 1999/05/16 06:56:30 mhw Exp $ GENERAL PROTOCOL @@ -12,7 +12,7 @@ spaces. The first token in a line is the name of the command. The robot should ignore commands which it doesn't recognize. The protocol may be extended by adding extra commands without incrementing the version -number. The version number will only be increased when the command cannot +number. The version number will only be increased when a command cannot be safely ignored. Netris will also ignore commands which it doesn't recognize, for the same @@ -61,7 +61,7 @@ NewPiece -------------- This command is never sent in "fair" robot mode. -Everytime a new piece is created, this command is sent to the robot. +Every time a new piece is created, this command is sent to the robot. is a positive integer uniquely identifying the piece. should be sent as a parameter to each movement command (sent to Netris) in order to prevent accidental movement of the wrong piece. @@ -116,7 +116,7 @@ Pause our side. is 0 or 1, indicating whether any player other than our side has paused the game. If either is 1, the game is paused. -You may actually receive this command even when none of the flags change. +You may actually receive this command even when neither of the flags change. NORMAL GAME (robot --> Netris) diff --git a/shapes.c b/shapes.c index c62f69b..5ae8ac9 100644 --- a/shapes.c +++ b/shapes.c @@ -1,6 +1,6 @@ /* * Netris -- A free networked version of T*tris - * Copyright (C) 1994,1995,1996 Mark H. Weaver + * Copyright (C) 1994-1996,1999 Mark H. Weaver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: shapes.c,v 1.15 1996/02/09 08:22:17 mhw Exp $ + * $Id: shapes.c,v 1.16 1999/05/16 06:56:31 mhw Exp $ */ #include "netris.h" @@ -46,26 +46,26 @@ static Cmd cmds_long[] = { C_back, C_plot, C_forw, C_plot, C_forw, C_plot, C_forw, C_plot, C_end }; -TwoWayDecl(long, long, 0, BT_piece1); +TwoWayDecl(long, long, 0, BT_blue); static Cmd cmds_square[] = { C_plot, C_forw, C_left, C_plot, C_forw, C_left, C_plot, C_forw, C_left, C_plot, C_end }; -static Shape shape_square = { &shape_square, 0, 0, D_up, 0, BT_piece1, +static Shape shape_square = { &shape_square, 0, 0, D_up, 0, BT_magenta, cmds_square }; static Cmd cmds_l[] = { C_right, C_back, C_plot, C_forw, C_plot, C_forw, C_plot, C_left, C_forw, C_plot, C_end }; -FourWayDecl(l, l, 0, BT_piece1); -FourWayDecl(l1, l, 1, BT_piece1); +FourWayDecl(l, l, 0, BT_cyan); +FourWayDecl(l1, l, 1, BT_yellow); static Cmd cmds_t[] = { C_plot, C_forw, C_plot, C_back, C_right, C_forw, C_plot, C_back, C_back, C_plot, C_end }; -FourWayDecl(t, t, 0, BT_piece1); +FourWayDecl(t, t, 0, BT_white); static Cmd cmds_s[] = { C_back, C_plot, C_forw, C_plot, C_left, C_forw, C_plot, C_right, C_forw, C_plot, C_end }; -TwoWayDecl(s, s, 0, BT_piece1); -TwoWayDecl(s1, s, 1, BT_piece1); +TwoWayDecl(s, s, 0, BT_green); +TwoWayDecl(s1, s, 1, BT_red); ShapeOption stdOptions[] = { {1, &shape_long_horiz}, diff --git a/util.c b/util.c index 98248ed..cb7f421 100644 --- a/util.c +++ b/util.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: util.c,v 1.27 1996/02/09 08:22:23 mhw Exp $ + * $Id: util.c,v 1.29 1999/05/16 06:56:33 mhw Exp $ */ #include "netris.h" @@ -66,7 +66,7 @@ ExtFunc void AtExit(void (*handler)(void)) ExtFunc void Usage(void) { fprintf(stderr, - "Netris version %s (C) 1994,1995,1996 Mark H. Weaver \n" + "Netris version %s (C) 1994-1996,1999 Mark H. Weaver \n" "Usage: netris \n" " -h Print usage information\n" " -w Wait for connection\n" @@ -84,7 +84,8 @@ ExtFunc void Usage(void) " -D Drops go into drop mode\n" " This means that sliding off a cliff after a drop causes\n" " another drop automatically\n" - " -S Disable standout mode (inverse/bold) for slow terminals\n" + " -S Disable inverse/bold/color for slow terminals\n" + " -C Disable color\n" " -H Show distribution and warranty information\n" " -R Show rules\n", version_string, DEFAULT_PORT, DEFAULT_KEYS); @@ -93,7 +94,7 @@ ExtFunc void Usage(void) ExtFunc void DistInfo(void) { fprintf(stderr, - "Netris version %s (C) 1994,1995,1996 Mark H. Weaver \n" + "Netris version %s (C) 1994-1996,1999 Mark H. Weaver \n" "\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" @@ -318,11 +319,13 @@ ExtFunc void AddEventGen(EventGenRec *gen) ExtFunc void RemoveEventGen(EventGenRec *gen) { - assert(gen->next != NULL); - while (nextGen->next != gen) - nextGen = nextGen->next; - nextGen->next = gen->next; - gen->next = NULL; + /* assert(gen->next != NULL); /* Be more forgiving, for SIGINTs */ + if (gen->next) { + while (nextGen->next != gen) + nextGen = nextGen->next; + nextGen->next = gen->next; + gen->next = NULL; + } } ExtFunc MyEventType WaitMyEvent(MyEvent *event, int mask) -- 2.39.5