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

Re: the cursor movement bug



Hello Mike and everyone,

On Friday 08 March 2002 15:50, capmikee@home.martnet.com wrote:
> Hi everyone,

...
> I've been looking at it all day (after several weeks away from the
> computer; I moved house recently) and I can't figure out where the
> problem is.

Sounds great Mikee, I hope you found a nice place for yourself !  :)


I've had a look in the new board (shame on me for not doing it sooner :-),
here's what I found:

> I thought originally that I'd just made a typo somewhere in my recent
> changes that caused this problem, but I think it may go deeper.
>
> My current guess is that it has to do with player configs. I think the
> config data for the human player is filled with garbage. It's acting

Yep, the evil bug is in iface_start(), where it does:
	human_start(i, &players[i]->human, board);
The address-of operator is the bug.  How it never caused any problems
before now, is anyone's guess. ;)

There were a few other old nasties that I stumbled upon and fixed.


That is half the problem, the second half is that the board isn't controlling 
the iface too good.   I had to restore iface_turn (in place of 
iface_field_turn), so the board can tell the iface who's playing when.


Please give it a try, maybe I can commit if it's working ok?
Index: src/board.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/board.c,v
retrieving revision 1.6
diff -u -3 -p -r1.6 board.c
--- src/board.c	8 Mar 2002 20:03:48 -0000	1.6
+++ src/board.c	9 Mar 2002 17:15:41 -0000
@@ -111,7 +111,6 @@ void board_start_game(BOARD_DATA *board,
    board_start_turn(board, 1); /* starting a turn is the same as ending one */
 
    board_refresh(board);
-   /*  board_iface_turn(&board->iface); * surely we don't need this? */
 }
 
 /*--------------------------------------------------------------------------*/
@@ -465,6 +464,7 @@ void board_init_spell_target(BOARD_DATA 
       break;
    default:
       /* we should never get here */
+      break;
    }
 }
 
@@ -499,9 +499,11 @@ void board_set_cmove(BOARD_DATA *board)
          break;
       default:
          /* we should never get here */
+         break;
       }
    default:
       /* or here */
+      break;
    }
    if (board->cmove == CMOVE_ANIMATE) 
       board_iface_reset(&board->iface);
@@ -574,6 +576,8 @@ void board_start_turn(BOARD_DATA *board,
 
    board_refresh(board);
    board_canvas_start_turn(&board->canvas, side);
+   
+   iface_turn(side, IFACE_BOARD);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -1715,7 +1719,7 @@ int board_iface_dir(BOARD_IFACE *iface, 
    for (dir = STATE_MOVE_LAST; dir >= STATE_MOVE_FIRST; dir--)
       if (iface_key_down(dir)) {
          fprintf(stderr, "key down: %d\n", dir);
-         /* break; */
+         break;
          /* do we need to check for validity here? */
          /* (ground creatures can't use diagonals) */
          /* if so, we could keep looping */
Index: src/canvas.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/canvas.c,v
retrieving revision 1.4
diff -u -3 -p -r1.4 canvas.c
--- src/canvas.c	8 Mar 2002 20:03:48 -0000	1.4
+++ src/canvas.c	9 Mar 2002 17:15:43 -0000
@@ -85,7 +85,7 @@ void canvas_init(Display *_display, Wind
    clip_rects = malloc(sizeof(XRectangle) * MAX_CLIP_RECTS);
    num_clip_rects = 0;
 
-   keys_down = calloc(sizeof(char), 512);
+   keys_down = calloc(512, sizeof(char));
    canvas_clear();
 }
 
Index: src/field.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/field.c,v
retrieving revision 1.6
diff -u -3 -p -r1.6 field.c
--- src/field.c	11 Jan 2002 18:50:05 -0000	1.6
+++ src/field.c	9 Mar 2002 17:15:46 -0000
@@ -835,7 +835,7 @@ void field_player(FIELD_ACTOR *fa)
 
    field_me = fa;
    field_he = (fa == &field.dark) ? &field.light : &field.dark;
-   iface_field_turn(fa == &field.dark);
+   iface_turn((fa == &field.dark), IFACE_FIELD);
    iface_frame();
    if (!board_pause_game(field.board, -1))
       return;
Index: src/human.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/human.h,v
retrieving revision 1.5
diff -u -3 -p -r1.5 human.h
--- src/human.h	11 Jan 2002 18:50:06 -0000	1.5
+++ src/human.h	9 Mar 2002 17:15:47 -0000
@@ -30,6 +30,10 @@ typedef struct {
 /* functions                                                                */
 /*--------------------------------------------------------------------------*/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void human_start(int side, HUMAN_CONFIG *config, BOARD_DATA *board);
 void human_turn(int side, int mode, COMMAND *cmd);
 void human_frame(int *keys_down);
Index: src/iface.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/iface.c,v
retrieving revision 1.4
diff -u -3 -p -r1.4 iface.c
--- src/iface.c	11 Jan 2002 18:50:06 -0000	1.4
+++ src/iface.c	9 Mar 2002 17:15:47 -0000
@@ -86,20 +86,21 @@ char *iface_start(BOARD_DATA *board, int
       side->num = i;
       side->iface = players[i]->type;
       if (side->iface == IFACE_HUMAN) {
-         human_start(i, &players[i]->human, board);
+         human_start(i, players[i]->human, board);
          side->turn_func = human_turn;
          side->frame_func = human_frame;
       } else if (side->iface == IFACE_COMPUTER) {
-         computer_start(i, &players[i]->computer, board);
+         computer_start(i, players[i]->computer, board);
          side->turn_func = computer_field_turn;
          side->frame_func = computer_board_frame;
       } else if (side->iface == IFACE_NETWORK) {
          iface_config.light_first = 1;  /* force light starts */
-         if (!network_start(i, &players[i]->network, board))
+         if (!network_start(i, players[i]->network, board))
             return "cannot start:  network player not connected";
          side->turn_func = network_turn;
          side->frame_func = network_frame;
       }
+      side->num_replies = side->next_reply = 0;
    }
 
    *light_first = iface_config.light_first;
@@ -107,22 +108,24 @@ char *iface_start(BOARD_DATA *board, int
 }
 
 /*--------------------------------------------------------------------------*/
-/* iface_field_turn                                                         */
+/* iface_turn                                                               */
 /*--------------------------------------------------------------------------*/
 
-void iface_field_turn(int side_num)
+void iface_turn(int side_num, int mode)
 {
    COMMAND cmd;
 
    side = &sides[side_num];
-   side->mode = IFACE_FIELD;
+   side->mode = mode;
    cmd.b.spell = -12345;                /* magic number */
-   side->turn_func(side_num, IFACE_FIELD, &cmd);
+   side->turn_func(side_num, mode, &cmd);
    if (cmd.b.spell != -12345) {         /* only if a reply was specified */
       side->num_replies = 0;
       side->next_reply = 0;
-      INSERT_REPLY(cmd.f.dir | ((cmd.f.fire) ? REPLY_FIRE : 0));
-      INSERT_REPLY(REPLY_LAST);
+      if (mode == IFACE_FIELD) {
+         INSERT_REPLY(cmd.f.dir | ((cmd.f.fire) ? REPLY_FIRE : 0));
+         INSERT_REPLY(REPLY_LAST);      /* end the reply */
+      }
    }
 }
 
@@ -159,9 +162,9 @@ int iface_key_down(int key)
 void iface_notify_computer(int mode)
 {
    if (sides[0].iface == IFACE_COMPUTER)
-      iface_field_turn(0);
+      iface_turn(0, mode);
    if (sides[1].iface == IFACE_COMPUTER)
-      iface_field_turn(1);
+      iface_turn(1, mode);
 }
 
 /*--------------------------------------------------------------------------*/
Index: src/iface.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/xarchon/src/iface.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 iface.h
--- src/iface.h	11 Jan 2002 18:50:06 -0000	1.4
+++ src/iface.h	9 Mar 2002 17:15:47 -0000
@@ -56,7 +56,7 @@ typedef struct {
 extern "C" {
 #endif
 char *iface_start(BOARD_DATA *board, int *light_first);
-void iface_field_turn(int side_num);
+void iface_turn(int side_num, int mode);
 void iface_frame(void);
 int iface_key_down(int key);
 void iface_notify_computer(int mode);