From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / petri.c
index 84722bbf8e52c4276142cc66231d3bdc36c681cf..97299d65073154fed5362aa9f4db5f08d231182f 100644 (file)
@@ -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)
@@ -141,7 +141,7 @@ static void setup_random_colormap (struct state *st, XWindowAttributes *xgwa)
     colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                           "background", "Background");
     
-    make_random_colormap (st->dpy, xgwa->visual, xgwa->colormap,
+    make_random_colormap (xgwa->screen, xgwa->visual, xgwa->colormap,
                          colors+1, &ncolors, True, True, 0, True);
     if (ncolors < 1)
       {
@@ -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",
@@ -731,6 +732,9 @@ static const char *petri_defaults [] = {
   "*originalcolors:    false",
   "*memThrottle:        22M",  /* don't malloc more than this much.
                                    Scale the pixels up if necessary. */
+#ifdef HAVE_MOBILE
+  "*ignoreRotation:     True",
+#endif
     0
 };