/*
* Copyright (c) 1988-91 by Patrick J. Naughton.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
*/
/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*-
* life.c - Conway's game of Life for xlock, the X Window System lockscreen.
*
* Copyright (c) 1991 by Patrick J. Naughton.
*
* See xlock.c for copying information.
*
* Revision History:
* 24-May-91: Added wraparound code from johnson@bugs.comm.mot.com.
* Made old cells stay blue.
* Made batchcount control the number of generations till restart.
* 29-Jul-90: support for multiple screens.
* 07-Feb-90: remove bogus semi-colon after #include line.
* 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
* 08-Oct-89: Moved seconds() to an extern.
* 20-Sep-89: Written (life algorithm courtesy of Jim Graham, flar@sun.com).
*/
#include "xlock.h"
#include "lifeicon.bit"
#ifdef SYSV
#ifndef bcopy
#endif
#ifndef bzero
#endif
#endif
0, 0, /* width, height */
0, XYBitmap, 0, /* xoffset, format, data */
};
#define min(a, b) ((a)<(b)?(a):(b))
typedef struct {
int pixelmode;
int xs;
int ys;
int xb;
int yb;
int generation;
long shooterTime;
int nrows;
int ncols;
int width;
int height;
} lifestruct;
/* Buffer stores the data for each cell. Each cell is stored as
* 8 bits representing the presence of a critter in each of it's
* surrounding 8 cells. There is an empty row and column around
* the whole array to allow stores without bounds checking as well
* as an extra row at the end for the fetches into tempbuf.
*
* Tempbuf stores the data for the next two rows so that we know
* the state of those critter before he was modified by the fate
* of the critters that have already been processed.
*
* Agebuf stores the age of each critter.
*/
/* Fates is a lookup table for the fate of a critter. The 256
* entries represent the 256 possible combinations of the 8
* neighbor cells. Each entry is one of BIRTH (create a cell
* or leave one alive), SAME (leave the cell alive or dead),
* or DEATH (kill anything in the cell).
*/
#define BIRTH 0
static int initialized = 0;
{ /* EIGHT */
-3, -3, -2, -3, -1, -3,
-3, -2, -2, -2, -1, -2,
-3, -1, -2, -1, -1, -1,
0, 0, 1, 0, 2, 0,
0, 1, 1, 1, 2, 1,
0, 2, 1, 2, 2, 2,
99
},
{ /* PULSAR */
1, 1, 2, 1, 3, 1, 4, 1, 5, 1,
1, 2, 5, 2,
99
},
{ /* BARBER */
-7, -7, -6, -7,
-7, -6, -5, -6,
-5, -4, -3, -4,
-3, -2, -1, -2,
-1, 0, 1, 0,
1, 2, 3, 2,
3, 4, 5, 4,
4, 5, 5, 5,
99
},
{ /* HERTZ */
-2, -6, -1, -6,
-2, -5, -1, -5,
-7, -3, -6, -3, -2, -3, -1, -3, 0, -3, 1, -3, 5, -3, 6, -3,
-7, -2, -5, -2, -3, -2, 2, -2, 4, -2, 6, -2,
-5, -1, -3, -1, -2, -1, 2, -1, 4, -1,
-7, 0, -5, 0, -3, 0, 2, 0, 4, 0, 6, 0,
-7, 1, -6, 1, -2, 1, -1, 1, 0, 1, 1, 1, 5, 1, 6, 1,
-2, 3, -1, 3,
-2, 4, -1, 4,
99
},
{ /* TUMBLER */
-6, -6, -5, -6, 6, -6, 7, -6,
-6, -5, -5, -5, 6, -5, 7, -5,
-5, 5, 6, 5,
-7, 6, -5, 6, 6, 6, 8, 6,
-7, 7, -5, 7, 6, 7, 8, 7,
-7, 8, -6, 8, 7, 8, 8, 8,
99
},
{ /* PERIOD4 */
-5, -8, -4, -8,
-7, -7, -5, -7,
-8, -6, -2, -6,
-7, -5, -3, -5, -2, -5,
-5, -3, -3, -3,
-4, -2,
99
},
{ /* PERIOD5 */
-5, -8, -4, -8,
-6, -7, -3, -7,
-7, -6, -2, -6,
-8, -5, -1, -5,
-8, -4, -1, -4,
-7, -3, -2, -3,
-6, -2, -3, -2,
-5, -1, -4, -1,
99
},
{ /* PERIOD6 */
-4, -8, -3, -8,
-8, -7, -7, -7, -5, -7,
-8, -6, -7, -6, -4, -6, -1, -6,
-3, -5, -1, -5,
-2, -4,
-3, -2, -2, -2,
-3, -1, -2, -1,
99
},
{ /* PINWHEEL */
-4, -8, -3, -8,
-4, -7, -3, -7,
-4, -5, -3, -5, -2, -5, -1, -5,
-5, -4, -3, -4, 0, -4, 2, -4, 3, -4,
-5, -3, -1, -3, 0, -3, 2, -3, 3, -3,
-8, -2, -7, -2, -5, -2, -2, -2, 0, -2,
-8, -1, -7, -1, -5, -1, 0, -1,
-4, 0, -3, 0, -2, 0, -1, 0,
-2, 2, -1, 2,
-2, 3, -1, 3,
99
},
{ /* ] */
-1, -1, 0, -1, 1, -1,
0, 0, 1, 0,
-1, 1, 0, 1, 1, 1,
99
},
{ /* cc: */
-3, -1, -2, -1, -1, -1, 1, -1, 2, -1, 3, -1,
-3, 0, -2, 0, 1, 0, 2, 0,
-3, 1, -2, 1, -1, 1, 1, 1, 2, 1, 3, 1,
99
},
{ /* DOLBY */
-3, -1, -2, -1, -1, -1, 1, -1, 2, -1, 3, -1,
-3, 0, -2, 0, 2, 0, 3, 0,
-3, 1, -2, 1, -1, 1, 1, 1, 2, 1, 3, 1,
99
},
{ /* HORIZON */
-15, 0, -14, 0, -13, 0, -12, 0, -11, 0,
-10, 0, -9, 0, -8, 0, -7, 0, -6, 0,
-5, 0, -4, 0, -3, 0, -2, 0, -1, 0,
4, 0, 3, 0, 2, 0, 1, 0, 0, 0,
9, 0, 8, 0, 7, 0, 6, 0, 5, 0,
14, 0, 13, 0, 12, 0, 11, 0, 10, 0,
99
},
{ /* SHEAR */
-7, -2, -6, -2, -5, -2, -4, -2, -3, -2,
-2, -2, -1, -2, 0, -2, 1, -2, 2, -2,
-5, -1, -4, -1, -3, -1, -2, -1, -1, -1,
0, -1, 1, -1, 2, -1, 3, -1, 4, -1,
-3, 0, -2, 0, -1, 0, 0, 0, 1, 0,
2, 0, 3, 0, 4, 0, 5, 0, 6, 0,
-10, 1, -9, 1, -8, 1, -7, 1, -6, 1,
-5, 1, -4, 1, -3, 1, -2, 1, -1, 1,
-10, 2, -9, 2, -8, 2, -7, 2, -6, 2,
-5, 2, -4, 2, -3, 2, -2, 2, -1, 2,
99
},
{ /* VERTIGO */
0, -7,
0, -6,
0, -5,
0, -4,
0, -3,
0, -2,
0, -1,
0, 0,
0, 7,
0, 6,
0, 5,
0, 4,
0, 3,
0, 2,
0, 1,
99
},
{ /* CROSSBAR */
-5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 4, 0, 3, 0, 2, 0, 1, 0, 0, 0,
99
},
{ /* GOALPOSTS */
-8, -7, 8, -7,
-8, -6, 8, -6,
-8, -5, 8, -5,
-8, -4, 8, -4,
-8, -3, 8, -3,
-8, -2, 8, -2,
-8, -1, 8, -1,
-8, 0, 8, 0,
-8, 1, 8, 1,
-8, 2, 8, 2,
-8, 3, 8, 3,
-8, 4, 8, 4,
-8, 5, 8, 5,
-8, 6, 8, 6,
-8, 7, 8, 7,
99
},
{ /* \ */
-8, -8, -7, -8,
-7, -7, -6, -7,
-6, -6, -5, -6,
-5, -5, -4, -5,
-4, -4, -3, -4,
-3, -3, -2, -3,
-2, -2, -1, -2,
-1, -1, 0, -1,
0, 0, 1, 0,
1, 1, 2, 1,
2, 2, 3, 2,
3, 3, 4, 3,
4, 4, 5, 4,
5, 5, 6, 5,
6, 6, 7, 6,
7, 7, 8, 7,
99
},
{ /* LABYRINTH */
-4, -4, -3, -4, -2, -4, -1, -4, 0, -4, 1, -4, 2, -4, 3, -4, 4, -4,
-4, -3, 0, -3, 4, -3,
-4, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 4, -2,
-4, -1, -2, -1, 2, -1, 4, -1,
-4, 0, -2, 0, -1, 0, 0, 0, 1, 0, 2, 0, 4, 0,
-4, 1, -2, 1, 2, 1, 4, 1,
-4, 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2, 4, 2,
-4, 3, 0, 3, 4, 3,
-4, 4, -3, 4, -2, 4, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4,
99
}
};
static void
{
/* if we aren't up to blue yet, then keep aging the cell. */
++age;
}
else
}
static void
{
}
static void
unsigned char *loc;
{
*arloc;
if (row == 1) {
}
}
if (col == 1) {
}
}
}
static void
unsigned char *loc;
{
if (row == 1) {
}
}
if (col == 1) {
}
}
}
static void
int row;
int col;
{
unsigned char *loc;
}
static void
{
for (i = 0; i < 256; i++) {
neighbors = 0;
neighbors++;
if (neighbors == 3)
else if (neighbors == 2)
else
}
}
void
{
int *patptr;
lp->generation = 0;
if (!initialized) {
initialized = 1;
init_fates();
}
} else {
}
}
}
void
{
unsigned char fate;
/* copy the first 2 rows to the tempbuf */
/* copy the last row to another buffer for wraparound */
switch (fate) {
case BIRTH:
}
/* NO BREAK */
case SAME:
}
break;
case DEATH:
}
break;
}
loc++;
temploc++;
}
loc += 2;
}
/*
* generate a randomized shooter aimed roughly toward the center of the
* screen after timeout.
*/
voff = -1;
hoff = -1;
}
}