From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / speedmine.c
index 1ff2db11076c3c7c41340a06085f906e09377048..17a3f2a4d695d6de696f12bdfd3c46d90e2d09f8 100644 (file)
  */
 
 /* Define or undefine NDEBUG to turn assert and abort debugging off or on */
-#define NDEBUG
-#include <assert.h>
+/*#define NDEBUG*/
+/*#include <assert.h>*/
+#define assert(X)
+#define DEBUG_FLAG 0
 
 #include <math.h>
 
 /* No. of shades of each color (ground, walls, bonuses) */
 #define MAX_COLORS 32
 
-#ifdef NDEBUG
-#define DEBUG_FLAG 0
-#else
-#define DEBUG_FLAG 1
-#endif
 
 
 #define FORWARDS 1
@@ -110,6 +107,8 @@ struct state {
 
     Pixmap dbuf, stars_mask;
     Colormap cmap;
+    Visual *visual;
+    Screen *screen;
     unsigned int default_fg_pixel;
     GC draw_gc, erase_gc, tunnelend_gc, stars_gc, stars_erase_gc;
 
@@ -476,7 +475,8 @@ generate_terrain (struct state *st, int start, int end, int final)
        for (w= diff/2, l=TERRAIN_BREADTH/4;
             w >= final || l >= final; w /= 2, l /= 2) {
 
-               if (w<1) w=1; if (l<1) l=1;
+               if (w<1) w=1;
+        if (l<1) l=1;
 
                for (i=start+w-1; i < end; i += (w*2)) {
                        ip = i-w; MODULO(ip, TERRAIN_LENGTH);
@@ -1105,7 +1105,7 @@ render_speedmine (struct state *st, Drawable d)
        } else {
                t = MAX(begin_at(st), TERRAIN_LENGTH/4);
                /*t = TERRAIN_LENGTH/4; dt = 2; */
-               dt = (t >= 3*TERRAIN_LENGTH/4 ? 1 : 2);
+               /*dt = (t >= 3*TERRAIN_LENGTH/4 ? 1 : 2);*/
                i = (st->nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH;
                render_block (st, d, st->tunnelend_gc, t);
        }
@@ -1260,7 +1260,7 @@ speedmine_color_ramp (struct state *st, GC *gcs, XColor * colors,
                h1 = h2 = RAND(360);
        }
 
-       make_color_ramp (st->dpy, st->cmap, 
+       make_color_ramp (st->screen, st->visual, st->cmap, 
                      h1, s1, v1, h2, s2, v2,
                                     colors, ncolors, False, True, False);
 
@@ -1286,9 +1286,9 @@ change_colors (struct state *st)
        double s1, s2;
 
        if (st->psychedelic_flag) {
-               free_colors (st->dpy, st->cmap, st->bonus_colors, st->nr_bonus_colors);
-               free_colors (st->dpy, st->cmap, st->wall_colors, st->nr_wall_colors);
-               free_colors (st->dpy, st->cmap, st->ground_colors, st->nr_ground_colors);
+               free_colors (st->screen, st->cmap, st->bonus_colors, st->nr_bonus_colors);
+               free_colors (st->screen, st->cmap, st->wall_colors, st->nr_wall_colors);
+               free_colors (st->screen, st->cmap, st->ground_colors, st->nr_ground_colors);
                s1 = 0.4; s2 = 0.9;
 
                st->ncolors = MAX_COLORS;
@@ -1296,8 +1296,8 @@ change_colors (struct state *st)
                                                          &st->ncolors, 0.0, 0.8, 0.0, 0.9);
                st->nr_ground_colors = st->ncolors;
        } else {
-               free_colors (st->dpy, st->cmap, st->bonus_colors, st->nr_bonus_colors);
-               free_colors (st->dpy, st->cmap, st->wall_colors, st->nr_wall_colors);
+               free_colors (st->screen, st->cmap, st->bonus_colors, st->nr_bonus_colors);
+               free_colors (st->screen, st->cmap, st->wall_colors, st->nr_wall_colors);
                st->ncolors = st->nr_ground_colors;
 
                s1 = 0.0; s2 = 0.6;
@@ -1371,7 +1371,8 @@ init_colors (struct state *st)
 
   rgb_to_hsv (dark.red, dark.green, dark.blue, &h1, &s1, &v1);
   rgb_to_hsv (light.red, light.green, light.blue, &h2, &s2, &v2);
-  make_color_ramp (st->dpy, st->cmap, h1, s1, v1, h2, s2, v2,
+  make_color_ramp (st->screen, st->visual, st->cmap,
+                   h1, s1, v1, h2, s2, v2,
                                  st->ground_colors, &st->ncolors, False, True, False);
   st->nr_ground_colors = st->ncolors;
 
@@ -1432,12 +1433,14 @@ speedmine_init (Display *dpy, Window window)
 
   XGetWindowAttributes (st->dpy, st->window, &xgwa);
   st->cmap = xgwa.colormap;
+  st->visual = xgwa.visual;
+  st->screen = xgwa.screen;
   st->width = xgwa.width;
   st->height = xgwa.height;
 
   st->verbose_flag = get_boolean_resource (st->dpy, "verbose", "Boolean");
 
-# ifdef HAVE_COCOA     /* Don't second-guess Quartz's double-buffering */
+# ifdef HAVE_JWXYZ     /* Don't second-guess Quartz's double-buffering */
   st->dbuf = st->window;
 #else
   st->dbuf = XCreatePixmap (st->dpy, st->window, st->width, st->height, xgwa.depth);
@@ -1538,6 +1541,16 @@ static void
 speedmine_reshape (Display *dpy, Window window, void *closure, 
                  unsigned int w, unsigned int h)
 {
+  struct state *st = (struct state *) closure;
+  st->width = w;
+  st->height = h;
+  if (st->dbuf != st->window) {
+      XWindowAttributes xgwa;
+      XGetWindowAttributes (st->dpy, st->window, &xgwa);
+      XFreePixmap (dpy, st->dbuf);
+      st->dbuf = XCreatePixmap (st->dpy, st->window, 
+                                st->width, st->height, xgwa.depth);
+  }
 }
 
 static Bool