X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fant.c;h=56d3036cc8e8baa718e3343671325df3037a34dc;hb=39809ded547bdbb08207d3e514950425215b4410;hp=bb0d3eba3c6a6e1df3bdf3b93c8513c67eaf903f;hpb=447db08c956099b3b183886729108bf5b364c4b8;p=xscreensaver diff --git a/hacks/ant.c b/hacks/ant.c index bb0d3eba..56d3036c 100644 --- a/hacks/ant.c +++ b/hacks/ant.c @@ -52,22 +52,25 @@ static const char sccsid[] = "@(#)ant.c 5.00 2000/11/01 xlockmore"; Neighbors 6 and neighbors 3 produce the same Turk ants. */ +#ifndef HAVE_JWXYZ +/*# define DO_STIPPLE*/ +#endif + #ifdef STANDALONE -#define MODE_ant -#define PROGCLASS "Ant" -#define HACK_INIT init_ant -#define HACK_DRAW draw_ant -#define ant_opts xlockmore_opts -#define DEFAULTS "*delay: 1000 \n" \ - "*count: -3 \n" \ - "*cycles: 40000 \n" \ - "*size: -12 \n" \ - "*ncolors: 64 \n" \ - -#include "xlockmore.h" /* in xscreensaver distribution */ -#include "erase.h" +# define MODE_ant +# define DEFAULTS "*delay: 20000 \n" \ + "*count: -3 \n" \ + "*cycles: 40000 \n" \ + "*size: -12 \n" \ + "*ncolors: 64 \n" \ + "*fpsSolid: true \n" \ + +# define reshape_ant 0 +# define release_ant 0 +# define ant_handle_event 0 +# include "xlockmore.h" /* in xscreensaver distribution */ #else /* STANDALONE */ -#include "xlock.h" /* in xlockmore distribution */ +# include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ #include "automata.h" @@ -112,14 +115,14 @@ static OptionStruct desc[] = {"-/+sharpturn", "turn on/off sharp turns (6, 8 or 12 neighbors only)"} }; -ModeSpecOpt ant_opts = +ENTRYPOINT ModeSpecOpt ant_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; #ifdef USE_MODULES const ModStruct ant_description = {"ant", - "init_ant", "draw_ant", "release_ant", - "refresh_ant", "init_ant", (char *) NULL, &ant_opts, + "init_ant", "draw_ant", (char *) NULL, + "refresh_ant", "init_ant", "free_ant", &ant_opts, 1000, -3, 40000, -12, 64, 1.0, "", "Shows Langton's and Turk's generalized ants", 0, NULL}; @@ -128,7 +131,7 @@ const ModStruct ant_description = #define ANTBITS(n,w,h)\ if ((ap->pixmaps[ap->init_bits]=\ XCreatePixmapFromBitmapData(display,window,(char *)n,w,h,1,0,1))==None){\ - free_ant(display,ap); return;} else {ap->init_bits++;} + free_ant(mi); return;} else {ap->init_bits++;} /* If you change the table you may have to change the following 2 constants */ #define STATES 2 @@ -172,7 +175,9 @@ typedef struct { antstruct *ants; int init_bits; unsigned char colors[NUMSTIPPLES - 1]; +# ifdef DO_STIPPLE GC stippledGC; +# endif /* DO_STIPPLE */ Pixmap pixmaps[NUMSTIPPLES - 1]; union { XPoint hexagon[7]; /* Need more than 6 for truchet */ @@ -637,19 +642,20 @@ drawcell(ModeInfo * mi, int col, int row, unsigned char color) if (!color) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); - } else if (MI_NPIXELS(mi) > 2) { - XSetForeground(MI_DISPLAY(mi), MI_GC(mi), - MI_PIXEL(mi, ap->colors[color - 1])); - gc = MI_GC(mi); - } else { +# ifdef DO_STIPPLE + } else if (MI_NPIXELS(mi) <= 2) { XGCValues gcv; - - gcv.stipple = ap->pixmaps[color - 1]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); + gcv.stipple = ap->pixmaps[color - 1]; XChangeGC(MI_DISPLAY(mi), ap->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = ap->stippledGC; +# endif /* !DO_STIPPLE */ + } else { + XSetForeground(MI_DISPLAY(mi), MI_GC(mi), + MI_PIXEL(mi, ap->colors[color - 1])); + gc = MI_GC(mi); } fillcell(mi, gc, col, row); } @@ -966,15 +972,19 @@ getTurk(ModeInfo * mi, int i) ap->n, ap->neighbors, number, ap->ncolors); } -static void -free_ant(Display *display, antfarmstruct *ap) +ENTRYPOINT void +free_ant(ModeInfo * mi) { + Display *display = MI_DISPLAY(mi); + antfarmstruct *ap = &antfarms[MI_SCREEN(mi)]; int shade; +#ifdef DO_STIPPLE if (ap->stippledGC != None) { XFreeGC(display, ap->stippledGC); ap->stippledGC = None; } +#endif /* DO_STIPPLE */ for (shade = 0; shade < ap->init_bits; shade++) { XFreePixmap(display, ap->pixmaps[shade]); } @@ -993,32 +1003,35 @@ free_ant(Display *display, antfarmstruct *ap) } } -void +ENTRYPOINT void init_ant(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); - Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); antfarmstruct *ap; int col, row, dir; int i; - if (antfarms == NULL) { + MI_INIT(mi, antfarms); + /*if (antfarms == NULL) { if ((antfarms = (antfarmstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (antfarmstruct))) == NULL) return; - } + }*/ ap = &antfarms[MI_SCREEN(mi)]; ap->redrawing = 0; +#ifdef DO_STIPPLE if (MI_NPIXELS(mi) <= 2) { - if (ap->stippledGC == None) { + Window window = MI_WINDOW(mi); + if (ap->stippledGC == None) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; - if ((ap->stippledGC = XCreateGC(display, window, GCFillStyle, + if ((ap->stippledGC = XCreateGC(display, window, + GCFillStyle, &gcv)) == None) { - free_ant(display, ap); + free_ant(mi); return; } } @@ -1028,6 +1041,7 @@ init_ant(ModeInfo * mi) } } } +#endif /* DO_STIPPLE */ ap->generation = 0; ap->n = MI_COUNT(mi); if (ap->n < -MINANTS) { @@ -1177,7 +1191,7 @@ init_ant(ModeInfo * mi) if (ap->ants == NULL) { if ((ap->ants = (antstruct *) malloc(ap->n * sizeof (antstruct))) == NULL) { - free_ant(display, ap); + free_ant(mi); return; } } @@ -1185,14 +1199,14 @@ init_ant(ModeInfo * mi) (void) free((void *) ap->tape); if ((ap->tape = (unsigned char *) calloc(ap->ncols * ap->nrows, sizeof (unsigned char))) == NULL) { - free_ant(display, ap); + free_ant(mi); return; } if (ap->truchet_state != NULL) (void) free((void *) ap->truchet_state); if ((ap->truchet_state = (unsigned char *) calloc(ap->ncols * ap->nrows, sizeof (unsigned char))) == NULL) { - free_ant(display, ap); + free_ant(mi); return; } @@ -1216,7 +1230,7 @@ init_ant(ModeInfo * mi) draw_anant(mi, dir, col, row); } -void +ENTRYPOINT void draw_ant(ModeInfo * mi) { antstruct *anant; @@ -1292,9 +1306,6 @@ draw_ant(ModeInfo * mi) draw_anant(mi, anant->direction, anant->col, anant->row); } if (++ap->generation > MI_CYCLES(mi)) { -#ifdef STANDALONE - erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi)); -#endif init_ant(mi); } if (ap->redrawing) { @@ -1316,20 +1327,8 @@ draw_ant(ModeInfo * mi) } } -void -release_ant(ModeInfo * mi) -{ - if (antfarms != NULL) { - int screen; - - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) - free_ant(MI_DISPLAY(mi), &antfarms[screen]); - (void) free((void *) antfarms); - antfarms = (antfarmstruct *) NULL; - } -} - -void +#ifndef STANDALONE +ENTRYPOINT void refresh_ant(ModeInfo * mi) { antfarmstruct *ap; @@ -1344,5 +1343,8 @@ refresh_ant(ModeInfo * mi) ap->redrawpos = 0; } } +#endif + +XSCREENSAVER_MODULE ("Ant", ant) #endif /* MODE_ant */