CSE342 - Lab 12: Add GUI

PURPOSE: Add window display and management functions to your semester project.

EXERCISE:

The file ~brian/cse342/bin/robowindow-solaris10-x86.o (and robowindow-solaris10-sparc.o for the older Suns) contains four functions:

Display *init_window(int argc, char *argv[], float wscale)
opens and initializes the display window, and
returns a pointer to the X display in use
process_event() handles X events related to the display window
update_player(long id, char *name)
adds a new player id to name mapping
for the display labeling function
struct status{
long id, x, y, angle, score;
};

update_window(int nobj, struct *pstatus)

redraws the display window according to the
new status (received from the Robowar server);
parameters are an array of nobj structures
of type status
These functions should provide all of the services your client program needs to display the Robowar simulation status graphically.

Your client should call init_window once, with any command line arguments not otherwise processed by your client (e.g., -display). init_window returns a pointer to a Display data type. In its main processing loop, your client should call XPending and process_event (if XPending returns true).

In response to a PLAYER_ID message from the server, your client should call update_player to update the list of players. Periodically, your client should call update_window to display the current simulation status.

Here's a code fragment that might be of use:

    Display *dpy = NULL, *init_window();
    struct status {
        long id, x, y, angle, score;
    } statusbuf[50];

          .
          .
          .
    while(running) {
        if (dpy != NULL)
            while (XPending(dpy))
                process_event(); /* Handle window events */
        FD_ZERO(&readfds);
        FD_SET(s, &readfds); /* Watch for input from server */
        FD_SET(0, &readfds); /* Watch for input from kbd */

        i = select(getdtablesize(), &readfds, 0, 0, 0);
          .
          .
        case 'x':
            /* Open X window for Robowar */
            dpy = init_window(argc, argv, scale);
          .
          .
          .
        case 16:
            /* read nobj and status entries from Server */

            /* redraw objects in window */
            update_window(nobj, statusbuf);
          .
          .
          .
        case 1:
            /* read new player id and name from Server */

            /* inform the display system of the name id and name */
            update_player(id, name);
          .
          .
          .
        }

Last modified 11 November 2009.