X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fpetri.c;h=860d0349e95e39cb28a293f2f77086e6641bba77;hb=50be9bb40dc60130c99ffa568e6677779904ff70;hp=84722bbf8e52c4276142cc66231d3bdc36c681cf;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/petri.c b/hacks/petri.c index 84722bbf..860d0349 100644 --- a/hacks/petri.c +++ b/hacks/petri.c @@ -121,8 +121,8 @@ struct state { }; -#define cell_x(c) (((c) - st->arr) % st->arr_width) -#define cell_y(c) (((c) - st->arr) / st->arr_width) +#define cell_x(c) (st->arr_width ? ((c) - st->arr) % st->arr_width : 0) +#define cell_y(c) (st->arr_width ? ((c) - st->arr) / st->arr_width : 0) static int random_life_value (struct state *st) @@ -243,7 +243,6 @@ static void setup_display (struct state *st) { XWindowAttributes xgwa; - Colormap cmap; int cell_size = get_integer_resource (st->dpy, "size", "Integer"); int osize, alloc_size, oalloc; @@ -398,8 +397,6 @@ setup_display (struct state *st) st->mindeathspeed *= st->diaglim; st->maxdeathspeed *= st->diaglim; - cmap = xgwa.colormap; - st->windowWidth = xgwa.width; st->windowHeight = xgwa.height; @@ -437,8 +434,8 @@ setup_display (struct state *st) } } - st->xSize = st->windowWidth / st->arr_width; - st->ySize = st->windowHeight / st->arr_height; + st->xSize = st->arr_width ? st->windowWidth / st->arr_width : 0; + st->ySize = st->arr_height ? st->windowHeight / st->arr_height : 0; if (st->xSize > st->ySize) { st->xSize = st->ySize; @@ -482,6 +479,9 @@ static void setup_arr (struct state *st) XFillRectangle (st->dpy, st->window, st->coloredGCs[0], 0, 0, st->windowWidth, st->windowHeight); + + if (!st->arr_width) st->arr_width = 1; + if (!st->arr_height) st->arr_height = 1; st->arr = (cell *) calloc (sizeof(cell), st->arr_width * st->arr_height); if (!st->arr) @@ -494,7 +494,7 @@ static void setup_arr (struct state *st) for (y = 0; y < st->arr_height; y++) { int row = y * st->arr_width; - for (x = 0; x < st->arr_width; x++) + for (x = 0; x < st->arr_width; x++) { st->arr[row+x].speed = 0.0; st->arr[row+x].growth = 0.0; @@ -586,8 +586,8 @@ static void randblip (struct state *st, int doit) while (n--) { - int x = random () % st->arr_width; - int y = random () % st->arr_height; + int x = st->arr_width ? random () % st->arr_width : 0; + int y = st->arr_height ? random () % st->arr_height : 0; int c; FLOAT s; if (b) @@ -597,7 +597,7 @@ static void randblip (struct state *st, int doit) } else { - c = (random () % (st->count-1)) + 1; + c = ((st->count - 1) ? random () % (st->count-1) : 0) + 1; s = RAND_FLOAT * (st->maxlifespeed - st->minlifespeed) + st->minlifespeed; } newcell (st, &st->arr[y * st->arr_width + x], c, s); @@ -637,7 +637,7 @@ static void update (struct state *st) int x = cell_x(a) + coords->x; int y = cell_y(a) + coords->y; coords++; - + if (x < 0) x = st->arr_width - 1; else if (x >= st->arr_width) x = 0; @@ -650,9 +650,9 @@ static void update (struct state *st) if (a->growth >= st->diaglim) killcell (st, a); } - + randblip (st, (st->head->next) == st->tail); - + for (a = st->head->next; a != st->tail; a = a->next) { if (a->isnext) @@ -715,6 +715,7 @@ petri_free (Display *dpy, Window window, void *closure) static const char *petri_defaults [] = { ".background: black", ".foreground: white", + "*fpsSolid: true", "*delay: 10000", "*count: 20", "*size: 2",