static void * critical_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); int model_w, model_h; st->dpy = dpy; st->window = window; /* Find window attributes */ XGetWindowAttributes (st->dpy, st->window, &st->wattr); st->batchcount = get_integer_resource (st->dpy, "batchcount", "Integer"); if (st->batchcount < 5) st->batchcount = 5; st->lines_per_color = 10; /* For the moment the model size is just fixed -- making it vary with the screen size just makes the hack boring on large screens. */ model_w = 80; st->settings.cell_size = st->wattr.width / model_w; model_h = st->settings.cell_size ? st->wattr.height / st->settings.cell_size : 1; /* Construct the initial model state. */ st->settings.trail = clip(2, get_integer_resource (st->dpy, "trail", "Integer"), 1000); st->history = calloc (st->settings.trail, sizeof (st->history[0])); if (!st->history) { fprintf (stderr, "critical: " "couldn't allocate trail history of %d cells\n", st->settings.trail); abort(); } st->model = model_allocate (model_w, model_h); if (!st->model) { fprintf (stderr, "critical: error preparing the model\n"); abort(); } /* make a black gc for the background */ st->gcv.foreground = get_pixel_resource (st->dpy, st->wattr.colormap, "background", "Background"); st->bgc = XCreateGC (st->dpy, st->window, GCForeground, &st->gcv); st->fgc = XCreateGC (st->dpy, st->window, 0, &st->gcv); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (dpy, st->fgc, False); jwxyz_XSetAntiAliasing (dpy, st->bgc, False); #endif st->delay_usecs = get_integer_resource (st->dpy, "delay", "Integer"); st->n_restart = get_integer_resource (st->dpy, "restart", "Integer"); setup_colormap (st, &st->d_colors, &st->d_n_colors); model_initialize (st->model); model_step (st->model, &st->history[0]); st->d_pos = 1; st->d_wrapped = 0; st->i_restart = 0; st->d_i_batch = st->batchcount; return st; }
static unsigned long critical_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; if (st->eraser) { st->eraser = erase_window (st->dpy, st->window, st->eraser); return st->delay_usecs; } /* for (d_i_batch = batchcount; d_i_batch; d_i_batch--) */ { /* Set color */ if ((st->d_i_batch % st->lines_per_color) == 0) { st->d_i_color = (st->d_i_color + 1) % st->d_n_colors; st->gcv.foreground = st->d_colors[st->d_i_color].pixel; XChangeGC (st->dpy, st->fgc, GCForeground, &st->gcv); } assert(st->d_pos >= 0 && st->d_pos < st->settings.trail); model_step (st->model, &st->history[st->d_pos]); draw_step (st, st->fgc, st->d_pos); /* we use the history as a ring buffer, but don't start erasing until we've d_wrapped around once. */ if (++st->d_pos >= st->settings.trail) { st->d_pos -= st->settings.trail; st->d_wrapped = 1; } if (st->d_wrapped) { draw_step (st, st->bgc, st->d_pos+1); } } st->d_i_batch--; if (st->d_i_batch < 0) st->d_i_batch = st->batchcount; else return st->delay_usecs; st->i_restart = (st->i_restart + 1) % st->n_restart; if (st->i_restart == 0) { /* Time to start a new simulation, this one has probably got to be a bit boring. */ free_colormap (st, &st->d_colors, st->d_n_colors); setup_colormap (st, &st->d_colors, &st->d_n_colors); st->eraser = erase_window (st->dpy, st->window, st->eraser); model_initialize (st->model); model_step (st->model, &st->history[0]); st->d_pos = 1; st->d_wrapped = 0; st->d_i_batch = st->batchcount; } return st->delay_usecs; }
bool server_game_start(char *game_script_name,int skill,network_reply_join_remotes *remotes,char *err_str) { int n; network_request_object_add *obj_add; // initialize lists model_initialize(); object_initialize_list(); weapon_initialize_list(); proj_setup_initialize_list(); scripts_initialize(); script_globals_initialize(); timers_initialize(); // setup skill level server.skill=skill; // run game script map.info.name[0]=0x0; map.info.player_start_name[0]=0x0; map.info.player_start_type[0]=0x0; map.info.in_load=FALSE; server.player_obj_uid=-1; js.game_attach.thing_type=thing_type_game; js.game_attach.thing_uid=-1; scripts_clear_attach_data(&js.game_attach); if (!scripts_add(&js.game_attach,"Game",game_script_name,NULL,err_str)) return(FALSE); // editor map override? if (setup.editor_override.on) { strcpy(map.info.name,setup.editor_override.map); } // can't start a game without a map if (map.info.name[0]==0x0) { strcpy(err_str,"Game: No start map specified in game script"); return(FALSE); } // prepare for any script based spawns object_script_spawn_start(); // put in additional objects (remotes, bots) if (remotes!=NULL) { obj_add=remotes->objects; for (n=0;n!=remotes->count;n++) { remote_add(obj_add,FALSE); obj_add++; } } // start player object server.player_obj_uid=object_start(NULL,TRUE,bt_game,-1,err_str); if (server.player_obj_uid==-1) { scripts_dispose(js.game_attach.script_uid); return(FALSE); } // force player to auto-spawn // spawing of player needs to happen before map_start events object_spawn(object_find_uid(server.player_obj_uid)); // finish any script based spawns object_script_spawn_finish(); return(TRUE); }