home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2611 / special_xv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  26.6 KB  |  1,234 lines

  1. #ifndef lint
  2. static    char    sccsid[] = "@(#)special_xv.c 1.2 92/05/28 SMI" ;
  3.     /* from special.c 1.5 90/07/23 SMI */
  4. #endif
  5.  
  6. /*
  7.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  8.  */
  9.  
  10. /*
  11.  * this file contains stuff that varies between fighter, robot etc.
  12.  *
  13.  * It contains these routines:
  14.  *
  15.  * init_game_special(&argc,argv)
  16.  *    initialize all window system stuff etc.  Called once at startup.
  17.  *
  18.  * init_communications()
  19.  *    sign on to the game.    Called once at startup.
  20.  *
  21.  * dstar_main_loop()
  22.  *    Start the game, calls window_main_loop().  Called once at startup.
  23.  *
  24.  * terminate_game()
  25.  *    called from sigint handler (not interrupt time) to shut down.
  26.  *
  27.  * special_welcome()
  28.  *    set id & team from data sent by daemon
  29.  *
  30.  * normal_action()
  31.  *    called from time function, once per slice
  32.  *
  33.  * blast_action()
  34.  *    called from time function, once per time slice while dead
  35.  *
  36.  * set_blast_state()
  37.  *    called from time function, once per state change while dead
  38.  *
  39.  * special_add_player(object)
  40.  *    called when a new object joins the game
  41.  *
  42.  * special_remove_player(object)
  43.  *    called when an object leaves the game
  44.  *
  45.  * special_got_blasted(object)
  46.  *    called got shot (by player "object")
  47.  *
  48.  * special_new_status(object)
  49.  *    called when an object changes status
  50.  */
  51.  
  52.  
  53.  
  54. #include <fcntl.h>
  55. #include <stdio.h>
  56. #include <xview/window_hs.h>
  57. #include <X11/Xlib.h>
  58. #include <X11/Xatom.h>
  59. #include <xview/xview.h>
  60. #include <xview/canvas.h>
  61. #include <xview/cursor.h>
  62. #include <xview/cms.h>
  63. #include <math.h>
  64. #include <sys/time.h>
  65. #include "graphics.h"
  66. #include "dstar.h"
  67.  
  68. static    Server_image    Main_Image, Main_sleep_Image, Main_no_Image ;
  69. static    Server_image    current_image ;
  70.  
  71.     Frame    Main_Frame ;
  72.     Canvas    Main_Canvas ;
  73.     Icon    Main_Icon ;
  74.     Cursor    Main_Cursor ;
  75.     Cursor    Default_Cursor ;
  76.  
  77. Xgl_X_window    Main_x_win, Control_x_win, xgl_x_win;
  78. Atom            catom;
  79. Window          frame_window;
  80. Window          Main_canvas_window, Control_canvas_window, 
  81.         canvas_window;
  82. Display            *display;
  83. Xv_Window       Main_pw;
  84.  
  85.  
  86. static    struct timeval    First_Time ;
  87. static    int        nframes ;
  88.  
  89.     int        status_display ;
  90.  
  91. #ifdef    XGL
  92. static    Xgl_sys_st    Main_state ;
  93. static    Xgl_cmap    cmap1, cmap2 ;
  94. static    Xgl_color_list    ctable ;
  95. static    Xgl_color    ctab1[64], ctab2[64] ;
  96. static    Xgl_win_ras    Main_ras, Control_ras ;
  97.     Xgl_mem_ras    Cursor_ras;
  98.     Xgl_3d_ctx    Main_gfx, Control_gfx ;
  99.     Xgl_2d_ctx    Text_gfx;
  100. static    Xgl_bounds_f3d    Idwin = {-1.,1.,-1.,1.,-1.,1.} ;
  101. static    Xgl_bounds_f2d    Ctrldcvp = {0.,500.,600.,740.} ;
  102. static    Xgl_bounds_f3d    Ctrlwin = {0.0,2.0,0.0,5.0,0.,1.} ;
  103. static    Xgl_bounds_f2d    Textdcvp = {200.,740.,600.,740.} ;
  104. static    Xgl_bounds_f2d    Textwin = {-0.5,1.5,0.0,5.0} ;
  105. static    int        dbuffer = 0 ;
  106.  
  107. #define    Dev_gp1_dbuf_putcolormap(ctx,start,len,r,g,b)    \
  108.             dbuf_putcolormap(start,len,r,g,b)
  109. #else
  110.     GP1_handle    Main_gfx, Control_gfx ;
  111. #endif    XGL
  112.  
  113. static    unsigned char    red[]   = {  0, 255, 192, 128, 255,   0,   0, 255 } ;
  114. static    unsigned char    green[] = {  0, 255, 192, 128,   0, 255,   0, 255 } ;
  115. static    unsigned char    blue[]  = { 64, 255, 192, 128,   0,   0, 255,   0 } ;
  116.  
  117. static    short    dstar_icon[] = {
  118. #include "dstar.icon"
  119. } ;
  120.  
  121. static    short    dstar_sleep_icon[] = {
  122. #include "dstar_sleep.icon"
  123. } ;
  124.  
  125. static    short    nodstar_icon[] = {
  126. #include "nodstar.icon"
  127. } ;
  128.  
  129. static short    dstar_cursor[] = {
  130. #include "cursor2.pr"
  131. } ;
  132.  
  133.  
  134. static    void    open_graphics() ;
  135. static    void    Canvas_Proc() ;
  136. static    void    Canvas_Resize_Proc(), Fake_Resize_Proc() ;
  137. static    void    Control_Proc() ;
  138. static    void    Control_Repaint_Proc() ;
  139. static    void    Control_Resize_Proc() ;
  140. static    Notify_value    Destroy_func(), Close_func() ;
  141.     void    timefunc(), sleepfunc() ;
  142. static    int    sigint() ;
  143. extern    Notify_value    dstar_prioritizer() ;
  144.  
  145.  
  146. #define    MAX_FIGHTERS    2
  147.  
  148. static    int    fighters[MAX_FIGHTERS] ;
  149.  
  150.  
  151.  
  152. static    char    *help_info ="\
  153. -k n        kill flag, 1=robots, 2=humans, 3=both\n\
  154. -t n        time interval for above\n\
  155. -free        free-for-all\n\
  156. -teams        players divided into two teams\n\
  157. -help        this list\n\
  158. hostname    used to slave one local net to another" ;
  159.  
  160. static        need_resize = FALSE;
  161. Xv_window   resize_win;
  162. int        resize_width, resize_height;
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. init_game_special(argc,argv)
  172.     int    argc ;
  173.     char    **argv ;
  174. {
  175.     int        i,j,k,iret ;
  176.     int        c ;
  177.     Pt3d        p1, p2, p3, p4 ;
  178.     char        *mastername = NULL ;
  179.     unsigned char    r[256], g[256], b[256] ;
  180.     static Xv_singlecolor    cursor_color = {255,255,0} ;
  181.     unsigned char   *mem;
  182.         Xgl_color    rop_color, space_color, text_color;
  183.     int        panel_flag = 0 ;
  184. extern    fptr        fighter_vector[VECTOR_LENGTH] ;
  185.     Server_image    svr_image ;
  186.  
  187.  
  188.     xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv,NULL);
  189.  
  190.     Main_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
  191.         XV_WIDTH,            64,
  192.         XV_HEIGHT,            64,
  193.         SERVER_IMAGE_BITS,        dstar_icon,
  194.         NULL);
  195.  
  196.     Main_sleep_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
  197.         XV_WIDTH,            64,
  198.         XV_HEIGHT,            64,
  199.         SERVER_IMAGE_BITS,        dstar_sleep_icon,
  200.         NULL);
  201.  
  202.     Main_no_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
  203.         XV_WIDTH,            64,
  204.         XV_HEIGHT,            64,
  205.         SERVER_IMAGE_BITS,        nodstar_icon,
  206.         NULL);
  207.  
  208.     Main_Icon = (Icon)xv_create(XV_NULL, ICON,
  209.         ICON_IMAGE,            Main_no_Image,
  210.         XV_X,            100,
  211.         XV_Y,            100,
  212.         NULL);
  213.  
  214.     svr_image = (Server_image)xv_create(XV_NULL, SERVER_IMAGE,
  215.         XV_WIDTH,            16,
  216.         XV_HEIGHT,            16,
  217.         SERVER_IMAGE_BITS,        dstar_cursor,
  218.         NULL);
  219.  
  220.     Main_Cursor = (Xv_Cursor)xv_create(XV_NULL, CURSOR,
  221.         CURSOR_IMAGE,           svr_image,
  222.         CURSOR_XHOT, 8, CURSOR_YHOT, 8,
  223.         CURSOR_FOREGROUND_COLOR, cursor_color,
  224.         NULL);
  225.  
  226.     Main_Frame = window_create(NULL, FRAME,
  227.         FRAME_ICON, Main_Icon,
  228.         FRAME_LABEL, "Dstar - experimental",
  229.         FRAME_ARGC_PTR_ARGV, &argc, argv,
  230.     0 ) ;
  231.     if(Main_Frame == NULL)
  232.       exit(1) ;
  233.  
  234.     current_image = Main_no_Image ;
  235.  
  236.     Main_Canvas = window_create(Main_Frame, CANVAS,
  237.         WIN_WIDTH, 1000,
  238.         WIN_HEIGHT, 750,
  239.         OPENWIN_AUTO_CLEAR, FALSE,
  240.         CANVAS_RESIZE_PROC, Fake_Resize_Proc,
  241.         CANVAS_RETAINED, FALSE,
  242.         CANVAS_FIXED_IMAGE, FALSE,
  243.         NULL);
  244.     if(Main_Canvas == NULL)
  245.       exit(1) ;
  246.     Main_pw = (Xv_Window) canvas_paint_window(Main_Canvas);
  247.     xv_set(Main_pw,
  248.         WIN_EVENT_PROC, Canvas_Proc,
  249.         WIN_CONSUME_EVENTS, WIN_MOUSE_BUTTONS, 
  250.                 LOC_MOVE,
  251.                 LOC_DRAG,
  252.                 WIN_IN_TRANSIT_EVENTS,
  253.                 WIN_ASCII_EVENTS, 
  254.                 WIN_LEFT_KEYS, 
  255.                 WIN_RIGHT_KEYS, 
  256.                 WIN_TOP_KEYS,
  257.                 NULL,
  258.     0 ) ;
  259.  
  260.     Default_Cursor = (Cursor) window_get(Main_pw, WIN_CURSOR) ;
  261.  
  262.     window_fit(Main_Frame);
  263.  
  264. #ifdef    XGL
  265.     Main_state = xgl_open(XGL_SYS_ST_ERROR_DETECTION, TRUE, 0 ) ;
  266.     if(Main_state == NULL)
  267.       exit(1) ;
  268.  
  269.     /* compute d.b. colormaps */
  270.  
  271.     for(i=0; i<8; ++i)
  272.       for(j=0; j<8; ++j)
  273.       {
  274.         ctab1[i+8*j].rgb.r = (float)red[j]/256. ;
  275.         ctab1[i+8*j].rgb.g = (float)green[j]/256. ;
  276.         ctab1[i+8*j].rgb.b = (float)blue[j]/256. ;
  277.         ctab2[8*i+j].rgb.r = (float)red[j]/256. ;
  278.         ctab2[8*i+j].rgb.g = (float)green[j]/256. ;
  279.         ctab2[8*i+j].rgb.b = (float)blue[j]/256. ;
  280.       }
  281.     for(i=0; i<8; ++i)
  282.       dbmap[i] = (i << 3) | i ;
  283.  
  284.     ctable.start_index = 0 ;
  285.     ctable.length = 64 ;
  286.     ctable.colors = ctab1 ;
  287.     cmap1 = xgl_color_map_create(
  288.             XGL_CMAP_COLOR_TABLE_SIZE,    64,
  289.             XGL_CMAP_COLOR_TABLE,        &ctable, 0) ;
  290.     if(cmap1 == NULL)
  291.       exit(1) ;
  292.     ctable.colors = ctab2 ;
  293.     cmap2 = xgl_color_map_create(
  294.             XGL_CMAP_COLOR_TABLE_SIZE,    64,
  295.             XGL_CMAP_COLOR_TABLE,        &ctable, 0) ;
  296.     if(cmap2 == NULL)
  297.       exit(1) ;
  298.  
  299.     display = (Display *) xv_get(Main_Frame, XV_DISPLAY);
  300.  
  301.     Main_canvas_window = (Window) xv_get(Main_pw, XV_XID);
  302.     frame_window = (Window) xv_get(Main_Frame, XV_XID);
  303.  
  304.     catom = XInternAtom(display, "WM_COLORMAP_WINDOWS", False);
  305.     XChangeProperty(display, frame_window, catom, XA_WINDOW, 32, 
  306.         PropModeAppend, &Main_canvas_window, 1);
  307.  
  308.     Main_x_win.X_display = (void *) display;
  309.     Main_x_win.X_window = (Xgl_usgn32) Main_canvas_window;
  310.     Main_x_win.X_screen = (int) DefaultScreen(display);
  311.  
  312.     Main_ras = xgl_window_raster_device_create(
  313.             XGL_WIN_X, &Main_x_win,
  314.             XGL_RAS_COLOR_MAP,    cmap1,
  315.             XGL_RAS_COLOR_TYPE,    XGL_COLOR_INDEX, 
  316.             0 ) ;
  317.     if(Main_ras == NULL)
  318.       exit(1) ;
  319.  
  320.     Cursor_ras = xgl_memory_raster_device_create(
  321.         XGL_RAS_DEPTH, 1,
  322.         XGL_RAS_WIDTH, 16,
  323.         XGL_RAS_HEIGHT, 16,
  324.         0);
  325.     xgl_object_get(Cursor_ras, XGL_MEM_RAS_MEMORY_ADDRESS, &mem);
  326.     for (i = 0; i < 16; i++) {
  327.         mem[i * 2] = dstar_cursor[i] >> 8;
  328.         mem[i * 2 + 1] = dstar_cursor[i];
  329.     }
  330.  
  331.  
  332.     WIN_MAT = xgl_transform_create(0) ;
  333.     OBJ_MAT = xgl_transform_create(0) ;
  334.     ROT_MAT = xgl_transform_create(0) ;
  335.     TM1 = xgl_transform_create(0) ;
  336.     TM2 = xgl_transform_create(0) ;
  337.     TM3 = xgl_transform_create(0) ;
  338.     Ctrl_view_mat = xgl_transform_create(0) ;
  339.     PERSP_MAT = xgl_transform_create(0) ;
  340.     ID_MAT = xgl_transform_create(0) ;
  341.     xgl_transform_identity(ID_MAT) ;
  342.  
  343.     space_color.index = dbmap[0];
  344.     rop_color.index = dbmap[YELLOW];
  345.     Main_gfx = xgl_3d_context_create(
  346.             XGL_CTX_DEFERRAL_MODE,    XGL_DEFER_ASAP,
  347.             XGL_CTX_DEVICE,        Main_ras,
  348.             XGL_CTX_NEW_FRAME_ACTION, XGL_CTX_NEW_FRAME_VRETRACE|
  349.                           XGL_CTX_NEW_FRAME_CLEAR,
  350.             XGL_CTX_PICK_ENABLE,    FALSE,
  351.             XGL_CTX_VDC_MAP,    XGL_VDC_MAP_ALL,
  352.             XGL_CTX_VDC_WINDOW,    &Idwin,
  353.             XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
  354.             XGL_CTX_GLOBAL_MODEL_TRANS, WIN_MAT,
  355.             XGL_CTX_SURF_FRONT_COLOR, &rop_color,
  356.             XGL_3D_CTX_SURF_FACE_DISTINGUISH, 0,
  357.             XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_NONE,
  358.             XGL_3D_CTX_SURF_BACK_ILLUMINATION,  XGL_ILLUM_NONE,
  359.             XGL_3D_CTX_SURF_FACE_CULL, XGL_CULL_OFF,
  360.             XGL_3D_CTX_VIEW_CLIP_PLUS_W_ONLY, FALSE,
  361.             0 ) ;
  362.  
  363.     Control_gfx = xgl_3d_context_create(
  364.             XGL_CTX_DEFERRAL_MODE,    XGL_DEFER_ASAP,
  365.             XGL_CTX_DEVICE,        Main_ras,
  366.             XGL_CTX_PICK_ENABLE,    FALSE,
  367.             XGL_CTX_VDC_MAP,    XGL_VDC_MAP_ALL,
  368.             XGL_CTX_VDC_WINDOW,    &Ctrlwin,
  369.             XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
  370.             XGL_CTX_VIEW_TRANS, Ctrl_view_mat,
  371.             XGL_3D_CTX_SURF_FACE_DISTINGUISH, 0,
  372.             XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_NONE,
  373.             XGL_3D_CTX_SURF_BACK_ILLUMINATION,  XGL_ILLUM_NONE,
  374.             XGL_3D_CTX_SURF_FACE_CULL, XGL_CULL_OFF,
  375.             XGL_3D_CTX_VIEW_CLIP_PLUS_W_ONLY, FALSE,
  376.             0 ) ;
  377.     text_color.index = dbmap[RED];
  378.     Text_gfx = xgl_2d_context_create(
  379.             XGL_CTX_DEFERRAL_MODE,    XGL_DEFER_ASAP,
  380.             XGL_CTX_DEVICE,        Main_ras,
  381.             XGL_CTX_VDC_MAP,    XGL_VDC_MAP_ALL,
  382.             XGL_CTX_VDC_WINDOW,    &Textwin,
  383.             XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
  384.             XGL_CTX_LINE_COLOR, &text_color, 
  385.             XGL_CTX_SFONT_TEXT_COLOR, &text_color, 
  386.             XGL_CTX_SFONT_CHAR_HEIGHT,  0.05, 
  387.             XGL_CTX_SFONT_CHAR_EXPANSION_FACTOR,  0.35, 
  388.             XGL_CTX_SFONT_TEXT_ALIGN_HORIZ,  XGL_TEXT_ALIGN_HORIZ_LEFT, 
  389.             XGL_CTX_SFONT_TEXT_ALIGN_VERT,  XGL_TEXT_ALIGN_VERT_HALF, 
  390.             0 ) ;
  391.  
  392.  
  393. #else
  394.     Main_gfx = Dev_gp1_create(Main_pw, 3, &iret) ;
  395.     if(!Main_gfx) {
  396.       printf("can't open gp, err=%d\n",iret) ;
  397.       exit(1) ;
  398.     }
  399.     Dev_gp1_reset_to_defaults(Main_gfx) ;
  400.  
  401.     hwdb = pw_dbl_get(Main_pw, PW_DBL_AVAIL) ;
  402.     hwdb = 0 ;
  403.     printf("hwdb=%d\n",hwdb) ;
  404. #endif    XGL
  405.  
  406.  
  407.     status_display = 0 ;
  408.  
  409.     while(--argc > 0)
  410.     {
  411.       ++argv ;
  412.       if(strcmp(*argv,"-free")==0)
  413.         game_type = GAME_FREE ;
  414.  
  415.       else if(strcmp(*argv,"-teams")==0)
  416.         game_type = GAME_TEAMS ;
  417.  
  418.       else if(strcmp(*argv,"-help")==0)
  419.       {
  420.         printf(help_info) ;
  421.         exit(0) ;
  422.       }
  423.  
  424.       else if(strcmp(*argv,"-ctdb")==0)
  425.         hwdb = 0 ;
  426.  
  427.       else if(strcmp(*argv,"-panel")==0)
  428.         panel_flag = 1 ;
  429.  
  430.       else if(strcmp(*argv,"-status")==0)
  431.         status_display = 1 ;
  432.  
  433.       else if(strcmp(*argv,"-debug")==0)
  434.         debug_level = 1 ;
  435.  
  436.       else if(**argv == '-')
  437.         printf("unknown option %s, '-help' for more info\n",*argv) ;
  438.  
  439.       else
  440.         mastername = *argv ;
  441.     }
  442.  
  443. #ifdef    DEBUG
  444.     if(panel_flag)
  445.     {
  446.       init_panel(Main_Frame) ;
  447.       window_fit_height(Main_Frame) ;
  448.     }
  449. #endif    DEBUG
  450.  
  451.  
  452. #ifndef    XGL
  453.     if(!hwdb)
  454.     {
  455.       Dev_gp1_set_dbuf(Main_gfx, 3, "dstar") ;
  456.       Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 8, red, green, blue) ;
  457.       Dev_gp1_dbuf_control(Main_gfx, 3) ;
  458.       Dev_gp1_dbuf_write_mask(Main_gfx, 7) ;
  459.       Dev_gp1_dbuf_color(Main_gfx,4) ;
  460.     }
  461.     else
  462.     {
  463.       pw_dbl_access(Main_pw) ;
  464.       pw_dbl_set(Main_pw, PW_DBL_WRITE, PW_DBL_BOTH, 0) ;
  465.       hwdb = 1 ;
  466.       Dev_gp1_set_sbuf(Main_gfx, 3, "dstar") ;
  467.       Dev_gp1_set_write_mask(Main_gfx, 7) ;
  468.       Dev_gp1_set_color(Main_gfx,4) ;
  469.     }
  470.  
  471.     Dev_gp1_getcmsname(Main_gfx, cmsname) ;
  472.     pw_setcmsname(Control_pw, cmsname) ;
  473.     pw_putcolormap(Control_pw, 0,1, red,green,blue) ;
  474. #endif    !XGL
  475.  
  476.  
  477. #ifdef    XGL
  478.     persp_window_mat(0.,1.,-1.,1.,-1.,1.,1.,10000.,P_matrix) ;
  479. #else
  480.     Dev_gp1_persp_window_mat(0.,1.,-1.,1.,-1.,1.,1.,10000.,P_matrix) ;
  481. #endif    XGL
  482.  
  483.  
  484.     notify_interpose_destroy_func(Main_Frame, Destroy_func) ;
  485.     notify_interpose_event_func(Main_Frame, Close_func, NOTIFY_SAFE) ;
  486.  
  487.     Me->id = -1 ;
  488.     Me->team = 0 ;
  489.     Me->score = 0 ;
  490.     Me->class = OBJ_PLAYER ;
  491.     Me->status = (int) window_get(Main_Frame, FRAME_CLOSED) ?
  492.         OBJ_SLEEPING : OBJ_ACTIVE ;
  493.     Me->flags = 0 ;
  494.     Me->Posn.x = (random() % 3000) - 1500.0 ;
  495.     Me->Posn.y = (random() % 3000) - 1500.0 ;
  496.     Me->Posn.z = - 2000.0 ;
  497.     Me->Forward.x = 0.0 ;
  498.     Me->Forward.y = 0.0 ;
  499.     Me->Forward.z = 1.0 ;
  500.     Me->Up.x = 0.0 ;
  501.     Me->Up.y = 1.0 ;
  502.     Me->Up.z = 0.0 ;
  503.     Me->Right.x = 1.0 ;
  504.     Me->Right.y = 0.0 ;
  505.     Me->Right.z = 0.0 ;
  506.     Me->Delta.x = 0.0 ;
  507.     Me->Delta.y = 0.0 ;
  508.     Me->Delta.z = 0.0 ;
  509.     Me->Pointing = Me->Forward ;
  510.     Me->Speed = DEFAULT_SPEED ;
  511.     Me->description = FIGHTER1_DESC ;
  512.     bcopy(fighter_vector, Me->f_vector, sizeof(fighter_vector)) ;
  513.  
  514.     Left_But = 1 ;
  515.     Middle_But = 0 ;
  516.     Right_But = 0 ;
  517.     Side_1 = Side_2 = Side_3 = Side_4 = Side_5 =
  518.     Side_6 = Side_7 = Side_8 = Side_9 = Side_10 = 0 ;
  519.  
  520.     init_blasts(BLAST_DESC) ;
  521.     init_fighter1(FIGHTER1_DESC) ;
  522.     init_fighter2(FIGHTER2_DESC) ;
  523.     init_planet(PLANET1_DESC) ;
  524.     init_monolith(MONOLITH_DESC) ;
  525.     init_missile(MISSILE_DESC) ;
  526.     missile_init() ;
  527.  
  528.  
  529.  
  530.  
  531.     fighters[0] = FIGHTER1_DESC ;
  532.     fighters[1] = FIGHTER2_DESC ;
  533.  
  534.     for(i=0; i<MAX_OBJECTS; sort_list[i++] = 0) ;
  535.     nobjects = 0 ;
  536.  
  537.     init_netio(getenv("USER"), mastername) ;
  538.  
  539.     First_Time.tv_sec = -1 ;
  540.     nframes = 0 ;
  541.  
  542.     auto_pilot = 0 ;
  543.     mouse_control = 0 ;
  544. }
  545.  
  546.  
  547. #ifdef    DEBUG
  548. static
  549. report_rate()
  550. {
  551.     char    line[40] ;
  552.     float    dtime ;
  553.     float    rate ;
  554.  
  555.     if(First_Time.tv_sec == -1)
  556.       First_Time = Now ;
  557.     else
  558.     {
  559.       dtime = (Now.tv_sec - First_Time.tv_sec) +
  560.           (Now.tv_usec - First_Time.tv_usec)*.000001 ;
  561.  
  562.       ++nframes ;
  563.       if(nframes%10 == 0)
  564.       {
  565.         rate = nframes/dtime ;
  566.         sprintf(line,"%7.2f %4d %8.3f",dtime,nframes,rate) ;
  567.         window_set(Main_Frame, FRAME_LABEL, line, 0) ;
  568.       }
  569.     }
  570. }
  571. #endif    DEBUG
  572.  
  573.  
  574.  
  575. void
  576. dstar_main_loop()
  577. {
  578.     window_main_loop(Main_Frame) ;
  579. }
  580.  
  581.  
  582.  
  583. int
  584. terminate_game()
  585. {
  586.     window_set(Main_Frame, FRAME_NO_CONFIRM, TRUE, 0);
  587.     window_destroy(Main_Frame) ;
  588. }
  589.  
  590.  
  591.  
  592. void
  593. special_welcome()
  594. {
  595.     set_ship_description() ;
  596. }
  597.  
  598.  
  599.  
  600. special_sleep_func()
  601. {
  602.     int    i, nawake = 0, nsleep = 0 ;
  603. register Object    *obj = &objects[0] ;
  604.     Server_image    new_image ;
  605.  
  606.     for(i=0; i<MAX_OBJECTS; ++i)
  607.     {
  608.       if( obj->class == OBJ_PLAYER  &&
  609.           !(obj->flags & ROBOT_FLAG)  &&
  610.           obj != Me )
  611.       {
  612.         if( obj->status == OBJ_SLEEPING )
  613.           ++nsleep ;
  614.         else
  615.           ++nawake ;
  616.       }
  617.       ++obj ;
  618.     }
  619.     if(nawake > 0)
  620.       new_image = Main_Image ;
  621.     else if(nsleep > 0)
  622.       new_image = Main_sleep_Image ;
  623.     else
  624.       new_image = Main_no_Image ;
  625.  
  626.     if(new_image != current_image)
  627.     {
  628.       window_set(Main_Icon, ICON_IMAGE, new_image, 0 ) ;
  629.       current_image = new_image ;
  630.     }
  631. }
  632.  
  633.  
  634.  
  635. void
  636. normal_action()
  637. {
  638.     if (need_resize == TRUE) {
  639.         Canvas_Resize_Proc(resize_win, resize_width, resize_height);
  640.         need_resize = FALSE;
  641.     }
  642.     get_input() ;
  643.     if(Me->flags & RADAR_FLAG)
  644.       do_radar() ;
  645.     else
  646.       Me->target = NULL ;
  647.     control_ship() ;    /* read inputs, set position */
  648.     control_enemies() ;
  649. #ifdef    DEBUG
  650.     report_rate() ;
  651. #endif
  652.     draw_image() ;
  653.     if(Me->flags & LASER_FLAG)
  654.       test_objects() ;
  655.  
  656.  
  657.     if( Me->id != -1 )
  658.     {
  659.       net_start_message( NULL ) ;
  660.       send_status(Me) ;    /* tell everyone where I am */
  661.       fly_missiles() ;
  662.     }
  663. }
  664.  
  665.  
  666.  
  667. void
  668. blast_action()
  669. {
  670. register Object    *me = Me ;
  671.     control_object(me) ;
  672. #ifdef    DEBUG
  673.     report_rate() ;
  674. #endif
  675.     draw_image() ;
  676.  
  677.     if( me->id != -1 )
  678.     {
  679.       net_start_message( NULL ) ;
  680.       fly_missiles() ;
  681.     }
  682. }
  683.  
  684.  
  685.  
  686.  
  687.  
  688. /* this routine is called whenever the blast state changes */
  689.  
  690.  
  691. set_blast_state(state)
  692.     Blast_State    state ;
  693. {
  694. static    char    red0[]    = {192} ;
  695. static    char    green0[] = {  0} ;
  696. static    char    blue0[]    = {  0} ;
  697. static    char    red1[]    = {  0} ;
  698. static    char    green1[] = {  0} ;
  699. static    char    blue1[]    = { 64} ;
  700.  
  701.     switch(state)
  702.     {
  703.       case B_FLASH:
  704.         Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 1, red0, green0, blue0) ;
  705.         break ;
  706.  
  707.       case B_WAIT:
  708.         Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 1, red1, green1, blue1) ;
  709.         break ;
  710.  
  711.       case B_NIL:
  712.         Me->status = OBJ_ACTIVE ;
  713.         Me->Posn.x = (random() % 3000) - 1500.0 ;
  714.         Me->Posn.y = (random() % 3000) - 1500.0 ;
  715.         Me->Posn.z = (random() % 3000) - 1500.0 ;
  716.         Me->Speed = DEFAULT_SPEED ;
  717.         set_ship_description() ;
  718.         net_start_message( NULL ) ;
  719.         send_status(Me) ;        /* tell everyone I'm back */
  720.         break ;
  721.     }
  722. }
  723.  
  724.  
  725.  
  726. special_add_player(object)
  727. register Object    *object ;
  728. {
  729.     sort_list[nobjects++] = object->id ;
  730. }
  731.  
  732.  
  733.  
  734.  
  735. special_remove_player(object)
  736. register Object    *object ;
  737. {
  738. register int    i = 0 ;
  739. register int    done = 0 ;
  740. register int    j ;
  741. register int    id = object->id ;
  742.     int    nobj = 0 ;
  743. register Object    *obj = &objects[0] ;
  744.  
  745.     if(object != Me)
  746.       while(!done)
  747.       {
  748.         if(sort_list[i] == id)
  749.         {
  750.           for(j=i+1; j<MAX_OBJECTS; sort_list[i++] = sort_list[j++]) ;
  751.           --nobjects ;
  752.           done = 1 ;
  753.         }
  754.         else if (++i >= nobjects)
  755.         {
  756.           fprintf(stderr,
  757.           "internal error: object %d: %s not found in sort_list\n",
  758.           object->id, object->name) ;
  759.           done = 1 ;
  760.         }
  761.       }
  762. }
  763.  
  764.  
  765. special_got_blasted(object)
  766.     Object    *object ;
  767. {
  768.     missiles_remaining = MISSILES_PER_LIFE ;
  769. }
  770.  
  771.  
  772.  
  773.  
  774. special_someone_got_blasted(object,victim)
  775.     Object    *object,*victim ;
  776. {}
  777.  
  778.  
  779.  
  780.  
  781. special_new_status(object)
  782.     Object    *object ;
  783. {}
  784.  
  785.  
  786.  
  787.  
  788. static
  789. set_ship_description()
  790. {
  791.     Me->description = fighters[Me->team % MAX_FIGHTERS] ;
  792. }
  793.  
  794.  
  795.  
  796.  
  797. /****
  798.  *
  799.  * read control inputs, update ship's position/velocity/"up" vectors
  800.  *
  801.  ****/
  802.  
  803.  
  804. #ifdef    XGL
  805. static
  806. get_input()
  807. {
  808.     Xgl_bounds_f2d    bounds ;
  809.  
  810.     xgl_object_get(Main_gfx, XGL_CTX_DC_VIEWPORT, &bounds) ;
  811.  
  812.     Mouse_ax = (float) Mouse_x / (bounds.xmax - bounds.xmin) ;
  813.     Mouse_ay = 1.0 - (float) Mouse_y / (bounds.ymax - bounds.ymin) ;
  814. }
  815.  
  816. #else
  817.  
  818. static
  819. get_input()
  820. {
  821.     Rect        *rect, *Dev_gp1_rect() ;
  822.  
  823.     rect = Dev_gp1_rect(Main_gfx) ;
  824.  
  825.     Mouse_ax = (float) Mouse_x / rect->r_width ;
  826.     Mouse_ay = 1.0 - (float) Mouse_y / rect->r_height ;
  827. }
  828. #endif    XGL
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835. static    void
  836. Canvas_Proc(window, event, arg)
  837.     Window    window ;
  838.     Event    *event ;
  839.     caddr_t    arg ;
  840. {
  841.     Cursor    new_cursor ;
  842.  
  843.     Mouse_x = event_x(event) ;
  844.     Mouse_y = event_y(event) ;
  845.  
  846.     if (event_is_ascii(event) && event_is_up(event))
  847.         return;
  848. #if FALSE
  849. printf("in Canvas_Proc: %d\n", event_id(event));
  850. #endif
  851.     switch(event_id(event))
  852.     {
  853.       case 'A':
  854.         auto_fire = !auto_pilot ;
  855.       case 'a':
  856.         if(auto_pilot)
  857.         {
  858.           auto_pilot = auto_fire = 0 ;
  859.         }
  860.         else
  861.         {
  862.           auto_pilot = 1 ;
  863.         }
  864.         save_auto_state();
  865.         if(!mouse_control || auto_pilot)
  866.         {
  867.           new_cursor = Default_Cursor ;
  868.         }
  869.         else
  870.         {
  871.           new_cursor = Main_Cursor ;
  872.         }
  873.         window_set(Main_pw, WIN_CURSOR, new_cursor, 0) ;
  874.         break ;
  875.  
  876.       case 'r':
  877.         if (event_is_down(event)) {
  878.         if( !((Me->flags ^= RADAR_FLAG) & RADAR_FLAG))
  879.           Me->target = NULL ;
  880.         }
  881.         break ;
  882.  
  883.       case MS_LEFT:
  884.         Left_But = event_is_down(event) ;
  885.         if(Left_But)
  886.         {
  887.           mouse_control = !mouse_control ;
  888.           if(!mouse_control)
  889.         {
  890.           restore_auto_state();
  891.           new_cursor = Default_Cursor ;
  892.         }
  893.           else
  894.         {
  895.               if(auto_pilot)
  896.           {
  897.             save_auto_state();
  898.             auto_pilot = auto_fire = 0;
  899.           }
  900.         new_cursor = Main_Cursor ;
  901.         }
  902.           window_set(Main_pw, WIN_CURSOR, new_cursor, 0) ;
  903.         }
  904.         break ;
  905.  
  906.       case MS_MIDDLE:
  907.         Middle_But = event_is_down(event) ;
  908.         break ;
  909.  
  910.       case MS_RIGHT:
  911.         Right_But = event_is_down(event) ;
  912.         break ;
  913.  
  914. #if FALSE
  915.       case KEY_TOP(1):
  916. #endif
  917.       case KEY_TOP(2):
  918.         if(event_is_down(event))
  919.           missile_arm() ;
  920.         break ;
  921.  
  922. #if FALSE
  923.       case KEY_TOP(2):
  924. #endif
  925.       case KEY_TOP(3):
  926.         if(event_is_down(event))
  927.           missile_launch(NULL) ;
  928.         break ;
  929.  
  930.       case KEY_LEFT(1):
  931.       case KEY_RIGHT(1):
  932.         Side_1 = event_is_down(event) ;
  933.         break ;
  934.  
  935.       case KEY_LEFT(2):
  936.       case KEY_RIGHT(2):
  937.         Side_2 = event_is_down(event) ;
  938.         break ;
  939.  
  940.       case KEY_LEFT(3):
  941.       case KEY_RIGHT(4):
  942.         Side_3 = event_is_down(event) ;
  943.         break ;
  944.  
  945.       case KEY_LEFT(4):
  946.       case KEY_RIGHT(5):
  947.         Side_4 = event_is_down(event) ;
  948.         break ;
  949.  
  950.       case KEY_LEFT(6):
  951.       case KEY_RIGHT(8):
  952.         Side_6 = event_is_down(event) ;
  953.         break ;
  954.  
  955.       case KEY_LEFT(5):
  956.       case KEY_LEFT(7):
  957.         win_post_event(Main_Frame, event, NOTIFY_SAFE) ;
  958.         break ;
  959.  
  960.       case KEY_LEFT(8):
  961.       case KEY_RIGHT(11):
  962.         Side_8 = event_is_down(event) ;
  963.         break ;
  964.  
  965.       case KEY_LEFT(9):
  966.       case KEY_RIGHT(13):
  967.         Side_9 = event_is_down(event) ;
  968.         break ;
  969.  
  970.       case KEY_LEFT(10):
  971.       case KEY_RIGHT(14):
  972.         Side_10 = event_is_down(event) ;
  973.         break ;
  974.  
  975.       case LOC_WINEXIT:
  976. #ifdef COMMENT
  977.         Left_But = 0 ;
  978.         Middle_But = 0 ;
  979.         Right_But = 0 ;
  980.         Side_1 = Side_2 = Side_3 = Side_4 = Side_5 =
  981.         Side_6 = Side_7 = Side_8 = Side_9 = Side_10 = 0 ;
  982. #endif COMMENT
  983.  
  984.       case LOC_WINENTER:
  985. #if FALSE
  986.       case LOC_RGNENTER:
  987.         Left_But = (int) window_get(window, WIN_EVENT_STATE, MS_LEFT) ;
  988.         Middle_But = (int) window_get(window, WIN_EVENT_STATE, MS_MIDDLE) ;
  989.         Right_But = (int) window_get(window, WIN_EVENT_STATE, MS_RIGHT) ;
  990.         Side_1 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(1)) ;
  991.         Side_2 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(2)) ;
  992.         Side_3 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(3)) ;
  993.         Side_4 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(4)) ;
  994.         Side_5 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(5)) ;
  995.         Side_6 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(6)) ;
  996.         Side_7 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(7)) ;
  997.         Side_8 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(8)) ;
  998.         Side_9 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(9)) ;
  999.         Side_10 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(10)) ;
  1000. #endif
  1001.         break ;
  1002.     }
  1003. }
  1004.  
  1005. static    void
  1006. Fake_Resize_Proc(canvas, width, height)
  1007. Canvas    canvas ;
  1008. int    width, height ;
  1009. {
  1010.     resize_win    = canvas;
  1011.     resize_width  = width;
  1012.     resize_height = height;
  1013.     need_resize   = TRUE;
  1014. }
  1015.  
  1016. static    void
  1017. Canvas_Resize_Proc(canvas, width, height)
  1018.     Canvas    canvas ;
  1019.     int    width, height ;
  1020. {
  1021.     Xgl_bounds_f2d    new_ctrldcvp ;
  1022.     Xgl_bounds_f2d    new_textdcvp ;
  1023.  
  1024.     if (!Main_Canvas) 
  1025.     return;
  1026.     if (Main_ras) {
  1027.     xgl_window_raster_resize(Main_ras);
  1028.     }
  1029. #if FALSE
  1030.     if (!Control_gfx || !Text_gfx) 
  1031.     return;
  1032.     xgl_object_get(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp);
  1033.     xgl_object_get(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp);
  1034. #if FALSE
  1035.     fprintf(stderr, "old ctrl: %f %f %f %f\n", 
  1036.         new_ctrldcvp.xmin, new_ctrldcvp.xmax, 
  1037.         new_ctrldcvp.ymin, new_ctrldcvp.ymax);
  1038.     fprintf(stderr, "old text: %f %f %f %f\n", 
  1039.             new_textdcvp.xmin, new_textdcvp.xmax, 
  1040.         new_textdcvp.ymin, new_textdcvp.ymax);
  1041. #endif
  1042.     new_ctrldcvp.xmin = 0.02 * (float)width;
  1043.     new_ctrldcvp.xmax = 0.50 * (float)width;
  1044.     new_ctrldcvp.ymin = 0.80 * (float)height;
  1045.     new_ctrldcvp.ymax = 0.98 * (float)height;
  1046.     new_textdcvp.xmin = 0.20 * (float)width;
  1047.     new_textdcvp.xmax = 0.74 * (float)width;
  1048.     new_textdcvp.ymin = 0.80 * (float)height;
  1049.     new_textdcvp.ymax = 0.98 * (float)height;
  1050. #if FALSE
  1051.     fprintf(stderr, "%d %d\n", width, height);
  1052.     fprintf(stderr, "%d %d\n", w, h);
  1053.     fprintf(stderr, "setting ctrl to: %f %f %f %f\n", 
  1054.         new_ctrldcvp.xmin, new_ctrldcvp.xmax, 
  1055.         new_ctrldcvp.ymin, new_ctrldcvp.ymax);
  1056.     fprintf(stderr, "setting text to: %f %f %f %f\n", 
  1057.             new_textdcvp.xmin, new_textdcvp.xmax, 
  1058.         new_textdcvp.ymin, new_textdcvp.ymax);
  1059. #endif
  1060.  
  1061.     xgl_object_set(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp, 0);
  1062. #if FALSE
  1063.     fprintf(stderr, "between 1st and 2nd resizes\n");
  1064.     fflush(stdout);
  1065. #endif
  1066.     xgl_object_set(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp, 0);
  1067.     xgl_object_get(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp);
  1068.     xgl_object_get(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp);
  1069. #if FALSE
  1070.     fprintf(stderr, "new ctrl: %f %f %f %f\n", 
  1071.         new_ctrldcvp.xmin, new_ctrldcvp.xmax, 
  1072.         new_ctrldcvp.ymin, new_ctrldcvp.ymax);
  1073.     fprintf(stderr, "new text: %f %f %f %f\n", 
  1074.             new_textdcvp.xmin, new_textdcvp.xmax, 
  1075.         new_textdcvp.ymin, new_textdcvp.ymax);
  1076. #endif
  1077. #endif
  1078. }
  1079.  
  1080.  
  1081.  
  1082. static    void
  1083. Control_Proc(window, event, arg)
  1084.     Window    window ;
  1085.     Event    *event ;
  1086.     caddr_t    arg ;
  1087. {
  1088. }
  1089.  
  1090.  
  1091.  
  1092. static    void
  1093. Control_Repaint_Proc(canvas, pixwin, repaint_area)
  1094.     Canvas    canvas ;
  1095.     Pixwin    *pixwin ;
  1096.     Rectlist *repaint_area ;
  1097. {
  1098. }
  1099.  
  1100.  
  1101.  
  1102. static    void
  1103. Control_Resize_Proc(canvas, width, height)
  1104.     Canvas    canvas ;
  1105.     int    width, height ;
  1106. {
  1107. }
  1108.  
  1109.  
  1110.  
  1111. static    Notify_value
  1112. Destroy_func(frame, status)
  1113.     Frame    frame ;
  1114.     Destroy_status    status ;
  1115. {
  1116.     if(status != DESTROY_CHECKING)
  1117.     {
  1118.       (void) notify_set_itimer_func(&Main_Timer, timefunc,
  1119.           ITIMER_REAL, NULL, 0) ;
  1120.       if( Me->id != -1 )
  1121.       {
  1122.         net_remove_player(Me->id) ;
  1123.         net_flush() ;
  1124.       }
  1125.     }
  1126.  
  1127.     return(notify_next_destroy_func(frame, status)) ;
  1128. }
  1129.  
  1130.  
  1131.  
  1132. static    Notify_value
  1133. Close_func(frame, event, arg, type)
  1134.     Frame            frame ;
  1135.     Event            *event ;
  1136.     Notify_arg        arg ;
  1137.     Notify_event_type    type ;
  1138. {
  1139.     int        closed_initial, closed_current ;
  1140.     Notify_value    value ;
  1141.  
  1142.     closed_initial = (int) window_get(frame, FRAME_CLOSED) ;
  1143.  
  1144.     value = notify_next_event_func(frame, event, arg, type) ;
  1145.  
  1146.     closed_current = (int) window_get(frame, FRAME_CLOSED) ;
  1147.  
  1148.     if(closed_initial != closed_current)
  1149.       if(closed_current)
  1150.       {
  1151.         Me->status = OBJ_SLEEPING ;
  1152.         (void) notify_set_itimer_func(&Main_Timer, sleepfunc,
  1153.             ITIMER_REAL, &Sleep_Timer, 0) ;
  1154.         if( Me->id != -1 )
  1155.         {
  1156.           net_start_message( NULL ) ;
  1157.           send_status(Me) ;    /* tell everyone where I am */
  1158.         }
  1159.       }
  1160.       else
  1161.       {
  1162.         Me->status = OBJ_ACTIVE ;
  1163.         (void) notify_set_itimer_func(&Main_Timer, timefunc,
  1164.             ITIMER_REAL, &Main_Timer, 0) ;
  1165.       }
  1166.  
  1167.     return( value ) ;
  1168. }
  1169.  
  1170. static int    auto_saved;
  1171. /* really should come up with an "auto-word" with defined bits/fields */
  1172.  
  1173. save_auto_state()
  1174. {
  1175.     auto_saved = auto_pilot;
  1176.     auto_saved |= auto_fire << 1;
  1177. }
  1178.  
  1179. restore_auto_state()
  1180. {
  1181.     auto_pilot = auto_saved & 0x1;
  1182.     auto_fire = (auto_saved >> 1) & 0x1;
  1183. }
  1184.  
  1185.  
  1186.  
  1187. #ifdef    XGL
  1188. dbuf_putcolormap(start, len, r,g,b)
  1189.     int    start, len ;
  1190.     u_char    *r,*g,*b ;
  1191. {
  1192.     int    i,j ;
  1193.  
  1194.     for(j=start; j<start+len; ++j)
  1195.       for(i=0; i<8; ++i)
  1196.       {
  1197.         ctab1[i+8*j].rgb.r = (float)r[j]/256. ;
  1198.         ctab1[i+8*j].rgb.g = (float)g[j]/256. ;
  1199.         ctab1[i+8*j].rgb.b = (float)b[j]/256. ;
  1200.         ctab2[8*i+j].rgb.r = (float)r[j]/256. ;
  1201.         ctab2[8*i+j].rgb.g = (float)g[j]/256. ;
  1202.         ctab2[8*i+j].rgb.b = (float)b[j]/256. ;
  1203.       }
  1204.     ctable.start_index = 0 ;
  1205.     ctable.length = 64 ;
  1206.     ctable.colors = ctab1 ;
  1207.     xgl_object_set(cmap1, XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
  1208.     ctable.colors = ctab2 ;
  1209.     xgl_object_set(cmap2, XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
  1210. }
  1211.  
  1212.  
  1213. dbuf_control(ctx, ctrl)
  1214.     Xgl_3d_ctx    ctx ;
  1215.     int        ctrl ;
  1216. {
  1217.     int    mask ;
  1218. static    int    masks[2][4] = {{0,070,007,077}, {0,007,070,077}} ;
  1219.  
  1220.     mask = masks[dbuffer][ctrl] ;
  1221.  
  1222.     xgl_object_set(ctx, XGL_CTX_PLANE_MASK, mask, 0) ;
  1223. }
  1224.  
  1225.  
  1226. dbuf_swap()
  1227. {
  1228.     dbuffer = 1-dbuffer ;
  1229.  
  1230.     xgl_object_set(Main_ras, XGL_RAS_COLOR_MAP,
  1231.         dbuffer == 0 ? cmap1 : cmap2, 0 ) ;
  1232. }
  1233. #endif    XGL
  1234.