projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.06.tar.gz
[xscreensaver]
/
hacks
/
critical.c
diff --git
a/hacks/critical.c
b/hacks/critical.c
index 1e8f3a1ab19731ca7283f51a35402ef7647581a7..5acb478d2ff58f0b0d0f94c75fa8d138e4c529eb 100644
(file)
--- a/
hacks/critical.c
+++ b/
hacks/critical.c
@@
-96,7
+96,7
@@
model_allocate (int model_w, int model_h)
model->width = model_w;
model->height = model_h;
model->width = model_w;
model->height = model_h;
- model->cells = malloc (sizeof (
in
t) * model_w * model_h);
+ model->cells = malloc (sizeof (
unsigned shor
t) * model_w * model_h);
if (!model->cells)
return 0;
if (!model->cells)
return 0;
@@
-128,7
+128,7
@@
model_initialize (CriticalModel *model)
{
int i;
{
int i;
- for (i = model->width * model->height; i >= 0; i--)
+ for (i = model->width * model->height
- 1
; i >= 0; i--)
{
model->cells[i] = (unsigned short) random ();
}
{
model->cells[i] = (unsigned short) random ();
}
@@
-199,8
+199,8
@@
setup_colormap (Display *dpy, XWindowAttributes *wattr,
/* Make a colormap */
*n_colors = get_integer_resource ("ncolors", "Integer");
/* Make a colormap */
*n_colors = get_integer_resource ("ncolors", "Integer");
- if (*n_colors <
2
)
- *n_colors =
2
;
+ if (*n_colors <
3
)
+ *n_colors =
3
;
*colors = (XColor *) calloc (sizeof(XColor), *n_colors);
if (!*colors)
*colors = (XColor *) calloc (sizeof(XColor), *n_colors);
if (!*colors)
@@
-237,6
+237,17
@@
setup_colormap (Display *dpy, XWindowAttributes *wattr,
}
}
+/* Free allocated colormap created by setup_colormap. */
+static void
+free_colormap (Display *dpy, XWindowAttributes *wattr,
+ XColor **colors, int n_colors)
+{
+ free_colors (dpy, wattr->colormap, *colors, n_colors);
+ free (*colors);
+}
+
+
+
/* Draw one step of the hack. Positions are cell coordinates. */
static void
draw_step (CriticalSettings *settings,
/* Draw one step of the hack. Positions are cell coordinates. */
static void
draw_step (CriticalSettings *settings,
@@
-341,6
+352,7
@@
screenhack (Display *dpy, Window window)
setup_colormap (dpy, &wattr, &colors, &n_colors);
erase_full_window (dpy, window);
model_initialize (model);
setup_colormap (dpy, &wattr, &colors, &n_colors);
erase_full_window (dpy, window);
model_initialize (model);
+ model_step (model, &history[0]);
pos = 1;
wrapped = 0;
}
pos = 1;
wrapped = 0;
}
@@
-382,13
+394,11
@@
screenhack (Display *dpy, Window window)
}
i_restart = (i_restart + 1) % n_restart;
}
i_restart = (i_restart + 1) % n_restart;
+
+ if (i_restart == 0)
+ {
+ /* Clean up after completing a simulation. */
+ free_colormap (dpy, &wattr, &colors, n_colors);
+ }
}
}
}
}
-
-
-/*
- * Local variables:
- * c-indent-mode: gnu
- * compile-command "make critical && ./critical"
- * End:
- */