From: kswong Date: Mon, 5 Nov 2001 05:18:21 +0000 (+0000) Subject: Added support for TetriFast. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=9e75440d4e4f837c43a2566d7a75f9b0e1908fe0;p=gtetrinet Added support for TetriFast. Merged page detach patch. Lots of little fixes. --- diff --git a/ChangeLog b/ChangeLog index de62ab8..284c5fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-11-05 + * Cleaned up page detach patch. + * Merged TetriFast support. + (tested compatible with Pihvi's Java Tetrinet Server) + * Added some fixes by Pihvi. + * Miscellaneous bug fixes. + 2001-01-13 * Merged page detach patch from Neil Bird . * Fixed stupid bug in tetrinet_specialkey(). diff --git a/Makefile.in b/Makefile.in index 236208e..b71dd2f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation @@ -117,7 +117,7 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) $(ACLOCAL_M4): configure.in cd $(srcdir) && $(ACLOCAL) -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) +config.status: $(srcdir)/configure.in $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) cd $(srcdir) && $(AUTOCONF) diff --git a/aclocal.m4 b/aclocal.m4 index 6787614..0609520 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 +dnl aclocal.m4 generated automatically by aclocal 1.4-p4 dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -676,3 +676,27 @@ int main () rm -f conf.esdtest ]) +dnl AM_ESD_SUPPORTS_MULTIPLE_RECORD([ACTION-IF-SUPPORTS [, ACTION-IF-NOT-SUPPORTS]]) +dnl Test, whether esd supports multiple recording clients (version >=0.2.21) +dnl +AC_DEFUN(AM_ESD_SUPPORTS_MULTIPLE_RECORD, +[dnl + AC_MSG_NOTICE([whether installed esd version supports multiple recording clients]) + ac_save_ESD_CFLAGS="$ESD_CFLAGS" + ac_save_ESD_LIBS="$ESD_LIBS" + AM_PATH_ESD(0.2.21, + ifelse([$1], , [ + AM_CONDITIONAL(ESD_SUPPORTS_MULTIPLE_RECORD, true) + AC_DEFINE(ESD_SUPPORTS_MULTIPLE_RECORD, 1, + [Define if you have esound with support of multiple recording clients.])], + [$1]), + ifelse([$2], , [AM_CONDITIONAL(ESD_SUPPORTS_MULTIPLE_RECORD, false)], [$2]) + if test "x$ac_save_ESD_CFLAGS" != x ; then + ESD_CFLAGS="$ac_save_ESD_CFLAGS" + fi + if test "x$ac_save_ESD_LIBS" != x ; then + ESD_LIBS="$ac_save_ESD_LIBS" + fi + ) +]) + diff --git a/configure b/configure index 7ff4130..08cef54 100755 --- a/configure +++ b/configure @@ -710,7 +710,7 @@ fi PACKAGE=gtetrinet -VERSION=0.4.1 +VERSION=0.5pre0 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index b3ae1f6..ce5f4b0 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(src/gtetrinet.c) -AM_INIT_AUTOMAKE(gtetrinet, 0.4.1) +AM_INIT_AUTOMAKE(gtetrinet, 0.5pre0) AC_PROG_CC diff --git a/src/Makefile.in b/src/Makefile.in index 21d6b0d..d980e71 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation diff --git a/src/client.c b/src/client.c index f6be555..7ce0e04 100644 --- a/src/client.c +++ b/src/client.c @@ -34,6 +34,7 @@ #include "partyline.h" #include "dialogs.h" #include "misc.h" +#include "gtetrinet.h" #define PORT 31457 #define SPECPORT 31458 @@ -60,6 +61,8 @@ struct outmsgt { char *str; }; +/* some of these strings change depending on the game mode selected */ +/* these changes are put into effect through the function inmsg_change */ struct inmsgt inmsgtable[] = { {IN_CONNECT, "connect"}, {IN_DISCONNECT, "disconnect"}, @@ -92,6 +95,27 @@ struct inmsgt inmsgtable[] = { {0, 0} }; +static struct inmsgt *get_inmsg_entry(enum inmsg_type num) +{ + int i; + for (i = 0; inmsgtable[i].num && inmsgtable[i].num != num; i ++); + return &inmsgtable[i]; +} + +static void inmsg_change() +{ + switch (gamemode) { + case ORIGINAL: + get_inmsg_entry(IN_PLAYERNUM)->str = "playernum"; + get_inmsg_entry(IN_NEWGAME)->str = "newgame"; + break; + case TETRIFAST: + get_inmsg_entry(IN_PLAYERNUM)->str = ")#)(!@(*3"; + get_inmsg_entry(IN_NEWGAME)->str = "*******"; + break; + } +} + struct outmsgt outmsgtable[] = { {OUT_DISCONNECT, "disconnect"}, {OUT_CONNECTED, "connected"}, @@ -160,6 +184,9 @@ void client_init (char *s, char *n) connectingdialog_new (); + /* set the game mode */ + inmsg_change(); + if ((clientpid = fork()) == 0) { client_process (); _exit (0); @@ -317,7 +344,11 @@ int client_connect (void) /* set up the connection */ h = gethostbyname (server); - if (h == 0) return -1; + if (h == 0) { + /* set errno = 0 so that we know it's a gethostbyname error */ + errno = 0; + return -1; + } memset (&sa, 0, sizeof (sa)); memcpy (&sa.sin_addr, h->h_addr, h->h_length); sa.sin_family = h->h_addrtype; @@ -336,7 +367,10 @@ int client_connect (void) unsigned char iphashbuf[6]; int i, l, len; /* construct message */ - sprintf (buf, "tetrisstart %s 1.13", nick); + if (gamemode == TETRIFAST) + sprintf (buf, "tetrifaster %s 1.13", nick); + else + sprintf (buf, "tetrisstart %s 1.13", nick); /* do that encoding thingy */ server_ip (ip); sprintf (iphashbuf, "%d", ip[0]*54 + ip[1]*41 + ip[2]*29 + ip[3]*17); diff --git a/src/dialogs.c b/src/dialogs.c index a22db13..117c2e8 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -148,6 +148,9 @@ void teamdialog_new (void) static int connecting; static GtkWidget *serveraddressentry, *nicknameentry, *teamnameentry, *spectatorcheck, *passwordentry; static GtkWidget *connectdialog, *passwordlabel, *teamnamelabel; +static GtkWidget *originalradio, *tetrifastradio; +static GSList *gametypegroup; +static int oldgamemode; void connectdialog_button (GnomeDialog *dialog, gint button, gpointer data) { @@ -161,6 +164,7 @@ void connectdialog_button (GnomeDialog *dialog, gint button, gpointer data) gtk_entry_get_text(GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(nicknameentry))))); break; case 1: + gamemode = oldgamemode; gtk_widget_destroy (connectdialog); break; } @@ -182,9 +186,18 @@ void connectdialog_spectoggle (GtkWidget *widget, gpointer data) } } -void connectdialog_cancel (GtkWidget *widget, gpointer data) +void connectdialog_originaltoggle (GtkWidget *widget, gpointer data) { - gtk_widget_destroy (connectdialog); + if (GTK_TOGGLE_BUTTON(widget)-> active) { + gamemode = ORIGINAL; + } +} + +void connectdialog_tetrifasttoggle (GtkWidget *widget, gpointer data) +{ + if (GTK_TOGGLE_BUTTON(widget)-> active) { + gamemode = TETRIFAST; + } } void connectdialog_connected (void) @@ -203,6 +216,10 @@ void connectdialog_new (void) /* check if dialog is already displayed */ if (connecting) return; connecting = TRUE; + + /* save some stuff */ + oldgamemode = gamemode; + /* make dialog that asks for address/nickname */ connectdialog = gnome_dialog_new (_("Connect to Server"), GNOME_STOCK_BUTTON_OK, @@ -218,7 +235,7 @@ void connectdialog_new (void) gtk_table_set_col_spacings (GTK_TABLE(table1), GNOME_PAD_SMALL); /* server address */ - table2 = gtk_table_new (1, 1, FALSE); + table2 = gtk_table_new (2, 1, FALSE); serveraddressentry = gnome_entry_new ("Server"); gtk_entry_set_text (GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(serveraddressentry))), @@ -227,6 +244,26 @@ void connectdialog_new (void) gtk_table_attach (GTK_TABLE(table2), serveraddressentry, 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); + /* game type radio buttons */ + originalradio = gtk_radio_button_new_with_label (NULL, _("Original")); + gametypegroup = gtk_radio_button_group (GTK_RADIO_BUTTON(originalradio)); + tetrifastradio = gtk_radio_button_new_with_label (gametypegroup, _("TetriFast")); + switch (gamemode) { + case ORIGINAL: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(originalradio), TRUE); + break; + case TETRIFAST: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tetrifastradio), TRUE); + break; + } + gtk_widget_show (originalradio); + gtk_widget_show (tetrifastradio); + widget = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); + gtk_box_pack_start (GTK_BOX(widget), originalradio, 0, 0, 0); + gtk_box_pack_start (GTK_BOX(widget), tetrifastradio, 0, 0, 0); + gtk_widget_show (widget); + gtk_table_attach (GTK_TABLE(table2), widget, + 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_set_row_spacings (GTK_TABLE(table2), GNOME_PAD_SMALL); gtk_table_set_col_spacings (GTK_TABLE(table2), GNOME_PAD_SMALL); @@ -299,7 +336,6 @@ void connectdialog_new (void) gtk_table_attach (GTK_TABLE(table1), frame, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); - gtk_widget_show (table1); gtk_box_pack_start (GTK_BOX(GNOME_DIALOG(connectdialog)->vbox), @@ -311,6 +347,10 @@ void connectdialog_new (void) GTK_SIGNAL_FUNC(connectdialog_destroy), NULL); gtk_signal_connect (GTK_OBJECT(spectatorcheck), "toggled", GTK_SIGNAL_FUNC(connectdialog_spectoggle), NULL); + gtk_signal_connect (GTK_OBJECT(originalradio), "toggled", + GTK_SIGNAL_FUNC(connectdialog_originaltoggle), NULL); + gtk_signal_connect (GTK_OBJECT(tetrifastradio), "toggled", + GTK_SIGNAL_FUNC(connectdialog_tetrifasttoggle), NULL); gtk_widget_show (connectdialog); } diff --git a/src/fields.c b/src/fields.c index f211202..556bbed 100644 --- a/src/fields.c +++ b/src/fields.c @@ -567,6 +567,7 @@ void fields_gmsginputback (void) { char buf[256]; strcpy (buf, gtk_entry_get_text(GTK_ENTRY(gmsginput))); + if (strlen(buf) == 0) return; buf[strlen(buf)-1] = 0; gtk_entry_set_text (GTK_ENTRY(gmsginput), buf); gtk_entry_set_position (GTK_ENTRY(gmsginput), strlen(buf)); diff --git a/src/gtetrinet.c b/src/gtetrinet.c index 545e6b8..369868d 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -45,12 +45,17 @@ static int gtetrinet_key (int keyval); gint keypress (GtkWidget *widget, GdkEventKey *key); gint keyrelease (GtkWidget *widget, GdkEventKey *key); -static GtkWidget *app, *pfields; +static GtkWidget *app, *pfields, *pparty, *pwinlist; +static GtkWidget *winlistwidget, *partywidget, *fieldswidget; GtkWidget *notebook; char *option_connect = 0, *option_nick = 0, *option_team = 0, *option_pass = 0; int option_spec = 0; +int gamemode = ORIGINAL; + +int fields_width, fields_height; + static const struct poptOption options[] = { {"connect", 'c', POPT_ARG_STRING, &option_connect, 0, N_("Connect to server"), N_("SERVER")}, {"nickname", 'n', POPT_ARG_STRING, &option_nick, 0, N_("Set nickname to use"), N_("NICKNAME")}, @@ -102,43 +107,46 @@ int main (int argc, char *argv[]) make_menus (GNOME_APP(app)); /* create the pages in the notebook */ - page = fields_page_new (); - gtk_widget_set_sensitive (page, TRUE); - gtk_widget_show (page); + fieldswidget = fields_page_new (); + gtk_widget_set_sensitive (fieldswidget, TRUE); + gtk_widget_show (fieldswidget); pfields = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pfields), 0); - gtk_container_add (GTK_CONTAINER(pfields), page); + gtk_container_add (GTK_CONTAINER(pfields), fieldswidget); gtk_widget_show (pfields); - gtk_object_set_data( GTK_OBJECT(page), "title", "Playing Fields"); // FIXME + gtk_object_set_data( GTK_OBJECT(fieldswidget), "title", "Playing Fields"); // FIXME label = pixmapdata_label (fields_xpm, "Playing Fields"); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pfields, label); - page = partyline_page_new (); - gtk_widget_show (page); - box = gtk_hbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER(box), 0); - gtk_container_add (GTK_CONTAINER(box), page); - gtk_widget_show (box); - gtk_object_set_data( GTK_OBJECT(page), "title", "Partyline"); // FIXME + partywidget = partyline_page_new (); + gtk_widget_show (partywidget); + pparty = gtk_hbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER(pparty), 0); + gtk_container_add (GTK_CONTAINER(pparty), partywidget); + gtk_widget_show (pparty); + gtk_object_set_data( GTK_OBJECT(partywidget), "title", "Partyline"); // FIXME label = pixmapdata_label (partyline_xpm, "Partyline"); gtk_widget_show (label); - gtk_notebook_append_page (GTK_NOTEBOOK(notebook), box, label); - - page = winlist_page_new (); - gtk_widget_show (page); - box = gtk_hbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER(box), 0); - gtk_container_add (GTK_CONTAINER(box), page); - gtk_widget_show (box); - gtk_object_set_data( GTK_OBJECT(page), "title", "Winlist"); // FIXME + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pparty, label); + + winlistwidget = winlist_page_new (); + gtk_widget_show (winlistwidget); + pwinlist = gtk_hbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER(pwinlist), 0); + gtk_container_add (GTK_CONTAINER(pwinlist), winlistwidget); + gtk_widget_show (pwinlist); + gtk_object_set_data( GTK_OBJECT(winlistwidget), "title", "Winlist"); // FIXME label = pixmapdata_label (winlist_xpm, "Winlist"); gtk_widget_show (label); - gtk_notebook_append_page (GTK_NOTEBOOK(notebook), box, label); + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pwinlist, label); gtk_widget_show (notebook); gtk_widget_show (app); + gtk_widget_set_usize(partywidget, 480, 360); + gtk_widget_set_usize(winlistwidget, 480, 360); + /* initialise some stuff */ textbox_setup (); commands_checkstate (); @@ -377,4 +385,11 @@ void move_current_page_to_window (void) (gpointer)(pageData)); gtk_widget_show_all( newWindow ); + + /* cure annoying side effect */ + if (gmsgstate) + fields_gmsginput(TRUE); + else + fields_gmsginput(FALSE); + } diff --git a/src/gtetrinet.h b/src/gtetrinet.h index 2eb0063..05d5d45 100644 --- a/src/gtetrinet.h +++ b/src/gtetrinet.h @@ -2,6 +2,11 @@ #define APPNAME "GTetrinet" #define APPVERSION VERSION +#define ORIGINAL 0 +#define TETRIFAST 1 + +extern int gamemode; + extern void destroymain (GtkWidget *widget, gpointer data); extern gint keypress (GtkWidget *widget, GdkEventKey *key); extern gint keyrelease (GtkWidget *widget, GdkEventKey *key); diff --git a/src/tetrinet.c b/src/tetrinet.c index a402d65..7830570 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -38,7 +38,7 @@ #include "dialogs.h" #include "sound.h" -#define NEXTBLOCKDELAY 1000 +#define NEXTBLOCKDELAY (gamemode==TETRIFAST?0:1000) #define DOWNDELAY 100 #define PARTYLINEDELAY1 100 #define PARTYLINEDELAY2 200 @@ -912,18 +912,18 @@ void tetrinet_dospecial (int from, int to, int type) break; case S_BLOCKQUAKE: for (y = 0; y < FIELDHEIGHT; y ++) { - /* - note: I actually measured these frequencies - the following - is an approximation of what I measured - */ - int s; - i = randomnum (20); - if (i < 9) s = 0; - else if (i < 15) s = 1; - else if (i < 18) s = 2; - else s = 3; + /* [ the original approximation of blockquake frequencies were + not quite correct ] */ + /* ### This is a much better approximation and probably how the */ + /* ### original tetrinet does it */ + int s = 0; + i = randomnum (22); + if (i < 1) s ++; + if (i < 4) s ++; + if (i < 11) s ++; if (randomnum(2)) s = -s; tetrinet_shiftline (y, s, field); + /* ### Corrected by Pihvi */ } tetrinet_updatefield (field); break; diff --git a/src/tetrinet.h b/src/tetrinet.h index 9450dbd..ff7feb5 100644 --- a/src/tetrinet.h +++ b/src/tetrinet.h @@ -9,6 +9,7 @@ extern FIELD fields[7]; extern int ingame, playing, paused; extern int moderator, spectating; extern int bigfieldnum; +extern int gmsgstate; extern char specialblocks[256]; extern int specialblocknum; diff --git a/src/tetris.c b/src/tetris.c index a1e2c2b..720e664 100644 --- a/src/tetris.c +++ b/src/tetris.c @@ -262,7 +262,7 @@ void tetris_blockdrop (void) void tetris_addlines (int count, int type) { - int x, y, ok, n, i; + int x, y, n, i; FIELD field; copyfield (field, fields[playernum]); for (i = 0; i < count; i ++) { @@ -282,25 +282,16 @@ void tetris_addlines (int count, int type) /* generate a random line with spaces in it */ switch (type) { case 1: /* addline lines */ - ok = FALSE; - while (!ok) { - for (x = 0; x < FIELDWIDTH; x ++) { - n = randomnum (13); - /* in the original tetrinet, spaces seem to have 1.5 times the - probability of other blocks */ - if (n < 10) field[FIELDHEIGHT-1][x] = n/2 + 1; - else { - field[FIELDHEIGHT-1][x] = 0; - ok = TRUE; - } - } - } + /* ### This is how the original tetrinet seems to do an add line */ + for (x = 0; x < FIELDWIDTH; x ++) + field[FIELDHEIGHT-1][x] = randomnum(6); + field[FIELDHEIGHT-1][randomnum(FIELDWIDTH)] = 0; + /* ### Corrected by Pihvi */ break; case 2: /* classicmode lines */ /* fill up the line */ - for (x = 0; x < FIELDWIDTH; x ++) { + for (x = 0; x < FIELDWIDTH; x ++) field[FIELDHEIGHT-1][x] = randomnum(5) + 1; - } /* add a single space */ field[FIELDHEIGHT-1][randomnum(FIELDWIDTH)] = 0; break; diff --git a/themes/Makefile.in b/themes/Makefile.in index e1fb72e..49a535c 100644 --- a/themes/Makefile.in +++ b/themes/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation diff --git a/themes/default/Makefile.in b/themes/default/Makefile.in index 0fd707f..5ca0f31 100644 --- a/themes/default/Makefile.in +++ b/themes/default/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation