[Commit] grrobot/src grr_icon.c,NONE,1.1 grr_icon.h,NONE,1.1
grr_util.c,NONE,1.1 grr_util.h,NONE,1.1 Makefile.am,1.2,1.3
grr_board_view.c,1.6,1.7 grrobot.c,1.6,1.7
Carl Worth
commit at keithp.com
Thu Jun 19 05:40:37 PDT 2003
- Previous message: [Commit] grrobot ChangeLog,1.1.1.1,1.2 configure.in,1.1.1.1,1.2
- Next message: [Commit] grrobot/src/svg .cvsignore,NONE,1.1 Makefile.am,NONE,1.1
bin2cstring.c,NONE,1.1 w.svg,1.1.1.1,NONE whirl.svg,1.1.1.1,NONE
whirl_non_sodi.svg,1.1.1.1,NONE whirl_sodi.svg,1.1.1.1,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: cworth
Update of /local/src/CVS/grrobot/src
In directory home.keithp.com:/tmp/cvs-serv21730/src
Modified Files:
Makefile.am grr_board_view.c grrobot.c
Added Files:
grr_icon.c grr_icon.h grr_util.c grr_util.h
Log Message:
Fixed messages and scrolling
--- NEW FILE: grr_icon.c ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: grr_icon.h ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: grr_util.c ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: grr_util.h ---
(This appears to be a binary file; contents omitted.)
Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/grrobot/src/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am 14 Jun 2003 08:17:41 -0000 1.2
+++ Makefile.am 19 Jun 2003 11:40:34 -0000 1.3
@@ -1,3 +1,5 @@
+SUBDIRS = . svg
+
bin_PROGRAMS = grrobot
grrobot_SOURCES = \
@@ -5,11 +7,9 @@
args.h \
grrobot.c \
grr_board_view.c \
- grr_board_view.h
+ grr_board_view.h \
+ grr_util.c \
+ grr_util.h
-INCLUDES = $(GRROBOT_CFLAGS)
+INCLUDES = $(GRROBOT_CFLAGS) -DGRR_ICON_DIR=\"$(pkgdatadir)\"
LDFLAGS = $(GRROBOT_LIBS)
-
-
-
-
Index: grr_board_view.c
===================================================================
RCS file: /local/src/CVS/grrobot/src/grr_board_view.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- grr_board_view.c 15 Jun 2003 07:07:49 -0000 1.6
+++ grr_board_view.c 19 Jun 2003 11:40:34 -0000 1.7
@@ -28,7 +28,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdarg.h>
#include <Xr.h>
#include <xsvg.h>
@@ -38,6 +37,7 @@
#include <gdk/gdkx.h>
#include "grr_board_view.h"
+#include "grr_util.h"
#define SCROLL_DELAY_LENGTH 300
#define GRR_BOARD_VIEW_DEFAULT_SIZE 100
@@ -78,13 +78,6 @@
/* Forward declarations */
-static int
-grr_sprintf_alloc (char **str, const char *fmt, ...);
-
-static int
-grr_sprintf_alloc_va (char **str, const char *fmt, va_list ap);
-
-
static void grr_board_view_class_init (grr_board_view_class_t *klass);
static void grr_board_view_init (grr_board_view_t *view);
static void grr_board_view_destroy (GtkObject *object);
@@ -761,46 +754,3 @@
gtk_widget_queue_draw (GTK_WIDGET (view));
}
-static int
-grr_sprintf_alloc (char **str, const char *fmt, ...)
-{
- int ret;
- va_list ap;
-
- va_start(ap, fmt);
- ret = grr_sprintf_alloc_va (str, fmt, ap);
- va_end(ap);
-
- return ret;
-}
-
-/* ripped more or less straight out of PRINTF(3) */
-static int
-grr_sprintf_alloc_va (char **str, const char *fmt, va_list ap)
-{
- char *new_str;
- /* Guess we need no more than 100 bytes. */
- int n, size = 100;
-
- if ((*str = malloc (size)) == NULL)
- return -1;
- while (1) {
- /* Try to print in the allocated space. */
- n = vsnprintf (*str, size, fmt, ap);
- /* If that worked, return the size. */
- if (n > -1 && n < size)
- return n;
- /* Else try again with more space. */
- if (n > -1) /* glibc 2.1 */
- size = n+1; /* precisely what is needed */
- else /* glibc 2.0 */
- size *= 2; /* twice the old size */
- new_str = realloc(*str, size);
- if (new_str == NULL) {
- free(*str);
- *str = NULL;
- return -1;
- }
- *str = new_str;
- }
-}
Index: grrobot.c
===================================================================
RCS file: /local/src/CVS/grrobot/src/grrobot.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- grrobot.c 15 Jun 2003 01:48:29 -0000 1.6
+++ grrobot.c 19 Jun 2003 11:40:34 -0000 1.7
@@ -30,9 +30,12 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
#include <gtk/gtk.h>
#include "grr_board_view.h"
+#include "grr_util.h"
#include "args.h"
typedef struct grr_game {
@@ -41,13 +44,25 @@
GtkWidget *window;
GtkWidget *board_view;
+ GtkWidget *command_entry;
+
GtkTextBuffer *message_buffer;
GtkWidget *message_view;
- GtkWidget *command_entry;
- GtkTextIter message_iter;
+ int msg_id;
+ int last_move_msg_id;
+ rr_robot_t last_move_robot;
} grr_game_t;
static int
+grr_game_printf (grr_game_t *game, const char *fmt, ...);
+
+static int
+grr_game_vprintf (grr_game_t *game, const char *fmt, va_list ap);
+
+static int
+grr_game_print (grr_game_t *game, const char *msg);
+
+static int
grr_game_start_gui (grr_game_t *game);
static void
@@ -83,6 +98,9 @@
}
game.board = rr_board_create (16, 16);
+ game.msg_id = 0;
+ game.last_move_msg_id = 0;
+ game.last_move_robot = RR_ROBOT_NONE;
source = grr_game_notices_source_new (&game);
g_source_set_priority (source, GDK_PRIORITY_EVENTS);
@@ -165,63 +183,108 @@
{
rr_board_t *board = game->board;
rr_status_t status;
- char **notice_s;
rr_notice_t *notice;
- int i;
while (rr_client_notice_pending (game->client)) {
- status = rr_client_next_notice (game->client, ¬ice_s);
+ status = rr_client_next_notice (game->client, ¬ice);
if (status) {
- fprintf (stderr, "Error during rr_client_notice: %s\n",
+ fprintf (stderr, "Error during rr_client_next_notice: %s\n",
rr_status_str (status));
gtk_exit (1);
return;
}
- for (i=0; notice_s[i]; i++) {
- gtk_text_buffer_insert_at_cursor (game->message_buffer, notice_s[i], -1);
- gtk_text_buffer_insert_at_cursor (game->message_buffer, " ", -1);
- }
- gtk_text_buffer_insert_at_cursor (game->message_buffer, "\n", -1);
- gtk_text_buffer_get_iter_at_offset (game->message_buffer,
- &game->message_iter,
- -1);
- gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (game->message_view),
- &game->message_iter,
- 0.0, FALSE, 0.0, 0.0);
-
- notice = rr_client_parse_notice (game->client, notice_s);
- if (notice == NULL) {
- int i;
- fprintf (stderr, "Failed to parse notice: ");
- for (i=0; notice_s[i]; i++)
- fprintf (stderr, " %s", notice_s[i]);
- fprintf (stderr, "\n");
- return;
- }
switch (notice->type) {
case RR_NOTICE_USER:
+ grr_game_printf (game,
+ "\nGLOBAL: %s has connected.", notice->u.string);
+ break;
case RR_NOTICE_QUIT:
+ grr_game_printf (game,
+ "\nGLOBAL: %s has disconnected.", notice->u.string);
+ break;
case RR_NOTICE_GAME:
+ grr_game_printf (game,
+ "\nGLOBAL: New game available: %s.", notice->u.string);
+ break;
case RR_NOTICE_DISPOSE:
+ grr_game_printf (game,
+ "\nGLOBAL: Game %s has been disposed.", notice->u.string);
+ break;
case RR_NOTICE_MESSAGE:
+ grr_game_printf (game, "\n%s> %s",
+ notice->u.message.username,
+ notice->u.message.text);
+ break;
case RR_NOTICE_GAMESTATE:
+ grr_game_printf (game, "\nGame state changed to: %s.",
+ rr_gamestate_str (notice->u.gamestate));
+ break;
case RR_NOTICE_JOIN:
+ grr_game_printf (game, "\nUser %s has joined the game.",
+ notice->u.string);
+ break;
case RR_NOTICE_WATCH:
+ grr_game_printf (game, "\nUser %s has started watching the game.",
+ notice->u.string);
+ break;
case RR_NOTICE_PART:
+ grr_game_printf (game, "\nUser %s has left the game.",
+ notice->u.string);
+ break;
case RR_NOTICE_BID:
+ grr_game_printf (game, "\nUser %s bids %d.",
+ notice->u.bid.username,
+ notice->u.bid.number);
+ break;
case RR_NOTICE_REVOKE:
- case RR_NOTICE_TIMER:
+ grr_game_printf (game, "\nUser %s revokes previous bid.",
+ notice->u.string);
+ break;
case RR_NOTICE_ABANDON:
+ grr_game_printf (game, "\nUser %s is willing to abandon this turn.",
+ notice->u.string);
+ break;
case RR_NOTICE_NOBID:
- case RR_NOTICE_ACTIVE:
+ grr_game_printf (game, "\nUser %s sees no point in bidding further this round",
+ notice->u.string);
+ break;
case RR_NOTICE_MOVE:
+ if (game->msg_id == game->last_move_msg_id
+ && game->last_move_robot == notice->u.move.robot) {
+ game->last_move_msg_id = grr_game_printf (game, " %s",
+ rr_direction_str (notice->u.move.direction));
+ } else {
+ game->last_move_msg_id = grr_game_printf (game, "\nMove #%d: %s %s",
+ notice->u.move.count,
+ rr_robot_str (notice->u.move.robot),
+ rr_direction_str (notice->u.move.direction));
+ game->last_move_robot = notice->u.move.robot;
+ }
+ break;
case RR_NOTICE_UNDO:
+ grr_game_print (game, "\nUNDO");
+ break;
case RR_NOTICE_RESET:
+ grr_game_print (game, "\nRESET");
+ break;
case RR_NOTICE_SCORE:
+ grr_game_printf (game, "\nScore for %s: %d.",
+ notice->u.bid.username,
+ notice->u.bid.number);
+ break;
case RR_NOTICE_ACTIVATE:
- /* XXX: Need to actually handle many of these. */
- fprintf (stderr, "Warning: Ignoring notice of type %d\n", notice->type);
+ grr_game_printf (game, "\nYour turn.",
+ notice->u.number);
+ break;
+ case RR_NOTICE_ACTIVE:
+ grr_game_printf (game, "\nUser %s now active to demonstrate solution in %d moves.",
+ notice->u.bid.username,
+ notice->u.bid.number);
+ break;
+ case RR_NOTICE_TIMER:
+ grr_game_printf (game, "\nTime remaining: %d seconds.",
+ notice->u.number);
break;
case RR_NOTICE_POSITION:
rr_board_position (board, notice->u.position.robot,
@@ -229,6 +292,7 @@
gtk_widget_queue_draw (GTK_WIDGET (game->window));
break;
case RR_NOTICE_TURN:
+ grr_game_print (game, "\nNew round!");
rr_board_set_goal_target (board, notice->u.target);
gtk_widget_queue_draw (GTK_WIDGET (game->window));
break;
@@ -250,20 +314,13 @@
status = rr_client_request (game->client, entry_text, &response);
if (status) {
- gtk_text_buffer_insert_at_cursor (game->message_buffer,
- "ERROR: ", -1);
- gtk_text_buffer_insert_at_cursor (game->message_buffer,
- rr_status_str (status), -1);
- gtk_text_buffer_insert_at_cursor (game->message_buffer,
- "\n", -1);
+ grr_game_printf (game, "\nERROR: %s.", rr_status_str (status));
} else {
- for (i=0; response[i]; i++) {
- gtk_text_buffer_insert_at_cursor (game->message_buffer,
- response[i], -1);
- gtk_text_buffer_insert_at_cursor (game->message_buffer,
- " ", -1);
+ if (response[0]) {
+ grr_game_print (game, "\n");
+ for (i=0; response[i]; i++)
+ grr_game_printf (game, "%s ", response[i]);
}
- gtk_text_buffer_insert_at_cursor (game->message_buffer, "\n", -1);
}
gtk_entry_set_text (GTK_ENTRY (game->command_entry), "");
@@ -275,6 +332,60 @@
}
static int
+grr_game_printf (grr_game_t *game, const char *fmt, ...)
+{
+ int msg_id;
+
+ va_list ap;
+
+ va_start (ap, fmt);
+ msg_id = grr_game_vprintf (game, fmt, ap);
+ va_end (ap);
+
+ return msg_id;
+}
+
+static int
+grr_game_vprintf (grr_game_t *game, const char *fmt, va_list ap)
+{
+ char *msg;
+ int msg_id;
+
+ grr_sprintf_alloc_va (&msg, fmt, ap);
+ if (msg == NULL)
+ return 0;
+
+ msg_id = grr_game_print (game, msg);
+
+ free (msg);
+
+ return msg_id;
+}
+
+static int
+grr_game_print (grr_game_t *game, const char *msg)
+{
+ GtkTextIter iter;
+ GtkTextMark *mark;
+
+ /* There might be a lighter way to do this, but this seems to
+ work. */
+
+ gtk_text_buffer_get_end_iter (game->message_buffer, &iter);
+
+ mark = gtk_text_buffer_get_mark (game->message_buffer, "end");
+
+ gtk_text_buffer_move_mark (game->message_buffer, mark, &iter);
+
+ gtk_text_buffer_insert (game->message_buffer, &iter, msg, -1);
+
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (game->message_view),
+ mark, 0.0, TRUE, 0.0, 1.0);
+
+ return ++game->msg_id;
+}
+
+static int
grr_game_start_gui (grr_game_t *game)
{
GtkWidget *board_frame;
@@ -298,9 +409,14 @@
vbox = gtk_vbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (window), vbox);
{
+ GtkTextIter iter;
game->board_view = grr_board_view_new (game->board);
grr_board_view_set_client (GRR_BOARD_VIEW (game->board_view), game->client);
game->message_buffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_get_iter_at_offset (game->message_buffer,
+ &iter, -1);
+ gtk_text_buffer_create_mark (game->message_buffer,
+ "end", &iter, FALSE);
game->message_view = gtk_text_view_new_with_buffer (game->message_buffer);
game->command_entry = gtk_entry_new ();
- Previous message: [Commit] grrobot ChangeLog,1.1.1.1,1.2 configure.in,1.1.1.1,1.2
- Next message: [Commit] grrobot/src/svg .cvsignore,NONE,1.1 Makefile.am,NONE,1.1
bin2cstring.c,NONE,1.1 w.svg,1.1.1.1,NONE whirl.svg,1.1.1.1,NONE
whirl_non_sodi.svg,1.1.1.1,NONE whirl_sodi.svg,1.1.1.1,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list