Re: [PATCHES] gTetriNET



Hello Friedrich,

On Sat, Apr 28, 2007 at 01:01:23PM +0200, Friedrich Kröner wrote:
> as I reinstalled my Gentoo recently I searched for some patches my brother 
> made for gTetriNET, adding BPM-Statistics and making the taskbar flash if a 
> new game starts. I did myself a new ebuild and checked out your last release 
> where those patches applied without any problem. I thought gtetrinet was 
> dead - but now I think it would be great if it would be possible to add these 
> patches to the official built. 
> 
> The blocks-per-minute-modification looks like this: 
>  1,00 Seconds played.
> fRiEdRiCh:Blocks dropped: 9 @ 541,08bpm. 
> (Of course this was TetriFast). 
> 
> The raise-patch make gTetriNET flash in the taskbar with a 
> non-gtk-wm-environnement (normally it should raise the window, but it doesn't 
> for me in kde) if a game starts. 
> Both settings are triggered in "Properties". 
> 
> I don't know if you are or were an excessive player - but these patches are 
> very usefull in my opinion. Please tell me if you like them and if you are 
> gonna integrate them. 
> Credits would go to coroner aka Christian Kröner. 
> Thank you for your time, I'm looking forward to see these patches in official 
> gTetriNET! 

The patches I am willing to apply, with some modifications, probably (I
wouldn't make the raise-patch configurable in the prefs. I would do it
inconditionally or we'll start cluttering the prefs too much for no good
gain). The bpm thing I guess is something you hardcore players like, so
we can have a look at applying it.

I'm Cc:ing the gtetrinet list in case anyone wants to comment on the
patches.

Thanks for fishing these from your brother :)

Jordi
-- 
Jordi Mallach Pérez  --  Debian developer     http://www.debian.org/
jordi sindominio net     jordi debian org     http://www.sindominio.net/
GnuPG public key information available at http://oskuro.net/
diff -u -r gtetrinet-0.7.9/src/config.c gtetrinet-0.7.9-new/src/config.c
--- gtetrinet-0.7.9/src/config.c	2003-08-16 16:15:55.000000000 +0200
+++ gtetrinet-0.7.9-new/src/config.c	2006-03-06 17:49:16.000000000 +0100
@@ -371,6 +371,11 @@
 
     /* Get the channel list option */
     list_enabled = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/partyline/enable_channel_list", NULL);
+
+    raise_enabled = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/partyline/enable_raise", NULL);
+
+    /* Get the BPM option */
+    bpm_enabled = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/partyline/enable_bpm", NULL);
     
     config_loadtheme (currenttheme->str);
 }
@@ -648,3 +653,32 @@
   partyline_show_channel_list (gconf_value_get_bool (gconf_entry_get_value (entry)));
 }
 
+void
+partyline_enable_raise_changed (GConfClient *client,
+                                guint cnxn_id,
+                                GConfEntry *entry)
+{
+
+  client = client;	/* Suppress compile warnings */
+  cnxn_id = cnxn_id;	/* Suppress compile warnings */
+
+  raise_enabled = gconf_value_get_bool (gconf_entry_get_value (entry));
+  if (!raise_enabled)
+    gconf_client_set_bool (gconf_client, "/apps/gtetrinet/partyline/enable_raise", FALSE, NULL);
+}
+
+
+void
+partyline_enable_bpm_changed (GConfClient *client,
+                                guint cnxn_id,
+                                GConfEntry *entry)
+{
+
+  client = client;      /* Suppress compile warnings */
+  cnxn_id = cnxn_id;    /* Suppress compile warnings */
+
+  bpm_enabled = gconf_value_get_bool (gconf_entry_get_value (entry));
+  if (!bpm_enabled)
+    gconf_client_set_bool (gconf_client, "/apps/gtetrinet/partyline/enable_bpm", FALSE, NULL);
+}
+
diff -u -r gtetrinet-0.7.9/src/config.h gtetrinet-0.7.9-new/src/config.h
--- gtetrinet-0.7.9/src/config.h	2003-08-16 16:15:55.000000000 +0200
+++ gtetrinet-0.7.9-new/src/config.h	2006-03-06 15:13:09.000000000 +0100
@@ -111,6 +111,17 @@
                                        guint cnxn_id,
                                        GConfEntry *entry);
 
+void
+partyline_enable_raise_changed (GConfClient *client,
+                                guint cnxn_id,
+                                GConfEntry *entry);
+
+void
+partyline_enable_bpm_changed (GConfClient *client,
+                                guint cnxn_id,
+                                GConfEntry *entry);
+
+
 
 #define GTETRINET_THEMES GTETRINET_DATA"/themes"
 #define DEFAULTTHEME GTETRINET_THEMES"/default/"
Nur in gtetrinet-0.7.9-new/src: .deps.
diff -u -r gtetrinet-0.7.9/src/dialogs.c gtetrinet-0.7.9-new/src/dialogs.c
--- gtetrinet-0.7.9/src/dialogs.c	2005-03-18 22:02:23.000000000 +0100
+++ gtetrinet-0.7.9-new/src/dialogs.c	2006-03-06 15:21:55.000000000 +0100
@@ -663,6 +663,18 @@
 			 GTK_TOGGLE_BUTTON (widget)->active, NULL);
 }
 
+void prefdialog_raisetoggle (GtkWidget *widget)
+{
+  gconf_client_set_bool (gconf_client, "/apps/gtetrinet/partyline/enable_raise",
+			 GTK_TOGGLE_BUTTON (widget)->active, NULL);
+}
+
+void prefdialog_bpmtoggle (GtkWidget *widget)
+{
+  gconf_client_set_bool (gconf_client, "/apps/gtetrinet/partyline/enable_bpm",
+                         GTK_TOGGLE_BUTTON (widget)->active, NULL);
+}
+
 void prefdialog_miditoggle (GtkWidget *widget)
 {
     if (GTK_TOGGLE_BUTTON(widget)->active) {
@@ -817,6 +829,8 @@
     GtkWidget *label, *table, *frame, *button, *button1, *widget, *table1, *divider, *notebook;
     GtkWidget *themelist_scroll, *key_scroll, *url;
     GtkWidget *channel_list_check;
+    GtkWidget *raise_check;
+    GtkWidget *bpm_check;
     GtkListStore *theme_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
     GtkListStore *keys_store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
     GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
@@ -906,21 +920,36 @@
     gtk_widget_show(timestampcheck);
     channel_list_check = gtk_check_button_new_with_mnemonic (_("Enable Channel _List"));
     gtk_widget_show (channel_list_check);
+    raise_check = gtk_check_button_new_with_mnemonic(_("Raise Window on _Game Start"));
+    gtk_widget_show (raise_check);
 
+    bpm_check = gtk_check_button_new_with_mnemonic(_("Collect _BPM statistics"));
+    gtk_widget_show (bpm_check);
+    
     frame = gtk_vbox_new (FALSE, 0);
     gtk_box_pack_start (GTK_BOX(frame), timestampcheck, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX(frame), channel_list_check, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(frame), raise_check, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(frame), bpm_check, FALSE, FALSE, 0);
     gtk_widget_show (frame);
 
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(timestampcheck),
                                   timestampsenable);
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (channel_list_check),
 				  list_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (raise_check),
+				  raise_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bpm_check),
+                                  bpm_enabled);
 
     g_signal_connect (G_OBJECT(timestampcheck), "toggled",
                       G_CALLBACK(prefdialog_timestampstoggle), NULL);
     g_signal_connect (G_OBJECT (channel_list_check), "toggled",
 		      G_CALLBACK (prefdialog_channeltoggle), NULL);
+    g_signal_connect (G_OBJECT (raise_check), "toggled",
+                      G_CALLBACK (prefdialog_raisetoggle),NULL);
+    g_signal_connect (G_OBJECT (bpm_check), "toggled",
+                      G_CALLBACK (prefdialog_bpmtoggle),NULL);
 
     table = gtk_table_new (3, 1, FALSE);
     gtk_container_set_border_width (GTK_CONTAINER(table), GNOME_PAD);
diff -u -r gtetrinet-0.7.9/src/gtetrinet.c gtetrinet-0.7.9-new/src/gtetrinet.c
--- gtetrinet-0.7.9/src/gtetrinet.c	2004-04-12 17:38:40.000000000 +0200
+++ gtetrinet-0.7.9-new/src/gtetrinet.c	2006-03-06 18:37:35.000000000 +0100
@@ -218,6 +218,14 @@
                              (GConfClientNotifyFunc) partyline_enable_channel_list_changed,
 			     NULL, NULL, NULL);
 
+    gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_raise",
+                             (GConfClientNotifyFunc) partyline_enable_raise_changed,
+			     NULL, NULL, NULL);
+
+    gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_bpm",
+                             (GConfClientNotifyFunc) partyline_enable_bpm_changed,
+                             NULL, NULL, NULL);
+
     /* load settings */
     config_loadconfig ();
 
Nur in gtetrinet-0.7.9-new/src/images: Makefile.
Nur in gtetrinet-0.7.9-new/src: Makefile.
diff -u -r gtetrinet-0.7.9/src/tetrinet.c gtetrinet-0.7.9-new/src/tetrinet.c
--- gtetrinet-0.7.9/src/tetrinet.c	2005-03-18 22:02:23.000000000 +0100
+++ gtetrinet-0.7.9-new/src/tetrinet.c	2006-03-07 10:59:14.000000000 +0100
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <sys/time.h>
 
 #include "gtetrinet.h"
 #include "config.h"
@@ -72,6 +73,12 @@
 char specialblocks[256];
 int specialblocknum = 0;
 
+int blocks_dropped = 0;
+unsigned long bpm_timer = 0;
+
+gboolean raise_enabled;
+gboolean bpm_enabled;
+
 /*
  * this will have the number of /list commands sended and waiting for answer
  */
@@ -166,6 +173,10 @@
 static void speclist_add (char *name);
 static void speclist_remove (char *name);
 
+static void bpm_starttimer (void);
+static void bpm_stoptimer (void);
+static double bpm_calc (unsigned long bpm_timer, int blocks_dropped);
+
 static FIELD sentfield; /* the field that the server thinks we have */
 
 /*
@@ -611,7 +622,9 @@
             commands_checkstate ();
             partyline_fmt (_("%c*** The game has %cstarted"),
                            TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD);
-            show_stop_button ();
+            if (raise_enabled)
+              gdk_window_raise(app->window);
+	    show_stop_button ();
             /* switch to playerfields when game starts */
             show_fields_page ();
         }
@@ -667,7 +680,20 @@
         commands_checkstate ();
         partyline_fmt (_("%c*** The game has %cended"),
                        TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD);
-        show_start_button ();
+	if(bpm_enabled && bpm_timer && blocks_dropped) {
+
+            g_snprintf (buf, sizeof(buf),
+                _("%c%5.2f Seconds played."),
+                TETRI_TB_C_DARK_BLUE,
+                ((float)bpm_timer)/1000.0);
+            partyline_text (buf);
+            g_snprintf (buf, sizeof(buf),
+                _("%c%s:Blocks dropped: %d @ %5.2fbpm."),
+                TETRI_TB_C_DARK_BLUE, nick, blocks_dropped,
+                bpm_calc(bpm_timer, blocks_dropped));
+            partyline_text (buf);
+	}
+	show_start_button ();
         /* go back to partyline when game ends */
         show_partyline_page ();
 
@@ -1470,6 +1496,9 @@
     }
     sound_playsound (S_GAMESTART);
     sound_playmidi (midifile);
+    if (bpm_enabled)
+        bpm_starttimer ();
+    
 }
 
 void tetrinet_pausegame (void)
@@ -1492,6 +1521,8 @@
     for (y = 0; y < FIELDHEIGHT; y ++)
         for (x = 0; x < FIELDWIDTH; x ++)
             field[y][x] = randomnum(5) + 1;
+    if(bpm_enabled)
+        bpm_stoptimer ();
     tetrinet_updatefield (field);
     fields_drawfield (playerfield(playernum), fields[playernum]);
     fields_drawnextblock (blankblock);
@@ -1514,10 +1545,13 @@
 void tetrinet_endgame (void)
 {
     int i, c = 0;
+    if(bpm_enabled && playing)
+        bpm_stoptimer ();
     for (i = 1; i <= 6; i ++)
         if (playerplaying[i]) c ++;
-    if (playing && playercount > 1 && c == 1)
+    if (playing && playercount > 1 && c == 1) {
         sound_playsound (S_YOUWIN);
+    }
     sound_stopmidi ();
     ingame = playing = FALSE;
     if (movedowntimeout)
@@ -2175,3 +2209,31 @@
         }
     }
 }
+
+void bpm_starttimer (void) {
+    
+    blocks_dropped = 0;
+    struct itimerval timerstart;
+    timerstart.it_interval.tv_sec = 600;
+    timerstart.it_interval.tv_usec = 999999;
+    timerstart.it_value.tv_sec = 600;
+    timerstart.it_value.tv_usec = 999999;
+
+    setitimer(ITIMER_REAL, &timerstart, NULL);
+}
+
+void bpm_stoptimer (void) {
+	
+    struct itimerval timervalue;
+    
+    getitimer(ITIMER_REAL, &timervalue);
+    bpm_timer = (600 - timervalue.it_value.tv_sec)*1000 + (999999 - timervalue.it_value.tv_usec)/1000;
+}
+
+double bpm_calc (unsigned long bpm_timer, int blocks_dropped) {
+    double timervalue;
+    double blocks;
+    timervalue = (double)bpm_timer;
+    blocks = (double)blocks_dropped;
+    return (blocks / (timervalue / 60000));
+}
diff -u -r gtetrinet-0.7.9/src/tetrinet.h gtetrinet-0.7.9-new/src/tetrinet.h
--- gtetrinet-0.7.9/src/tetrinet.h	2004-10-26 09:33:28.000000000 +0200
+++ gtetrinet-0.7.9-new/src/tetrinet.h	2006-03-07 08:54:46.000000000 +0100
@@ -10,15 +10,19 @@
 extern int playernum;
 extern char team[128], nick[128], specpassword[128];
 extern FIELD fields[7];
-extern int ingame, playing, paused;
+extern int ingame, playing, paused, blocks_dropped;
 extern int moderator, spectating;
 extern int bigfieldnum;
 extern int gmsgstate;
+extern unsigned long bpm_timer;
 
 extern char specialblocks[256];
 extern int specialblocknum;
 extern gint list_issued;
 
+extern gboolean raise_enabled;
+extern gboolean bpm_enabled;
+
 extern void tetrinet_inmessage (enum inmsg_type msgtype, char *data);
 extern void tetrinet_playerline (const char *text);
 extern void tetrinet_changeteam (const char *newteam);
diff -u -r gtetrinet-0.7.9/src/tetris.c gtetrinet-0.7.9-new/src/tetris.c
--- gtetrinet-0.7.9/src/tetris.c	2003-01-07 17:38:00.000000000 +0100
+++ gtetrinet-0.7.9-new/src/tetris.c	2006-03-06 16:13:02.000000000 +0100
@@ -259,6 +259,7 @@
 {
     if (blocknum < 0) return;
     while (tetris_blockdown () == 0);
+    blocks_dropped++;
 }
 
 void tetris_addlines (int count, int type)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]