1 /*
2 * XLife Copyright 1989 Jon Bennett jb7m+@andrew.cmu.edu, jcrb@cs.cmu.edu
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. The copyright holders make no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23 /*
24 A lot of modifications were added at 2001, 2011-14 by Vladimir Lidovski vol.litwr@gmail.com
25 (C) This version of XLife may be used under the same conditions as mentioned above
26 $Id: data.c 278 2014-01-13 18:19:40Z litwr $
27 */
28
29 #include "defs.h"
30
31 #if STATEBITS > 3
is_state(char c)32 int is_state(char c) {
33 return isalnum(c) || c == '~' || c == '@';
34 }
35
stoi(char c)36 int stoi(char c) {
37 if (isdigit(c)) return c - '0';
38 if (isupper(c)) return c - '7';
39 if (islower(c)) return c - 61;
40 if (c == '@') return 62;
41 if (c == '~') return 63;
42 return -1;
43 }
44
itos(int n)45 char itos(int n) {
46 if (n < 10) return '0' + n;
47 if (n < 36) return '7' + n;
48 if (n < 62) return 61 + n;
49 if (n == 62) return '@';
50 return '~';
51 }
52 #endif
53
54 char saveformat = 'M', scriptformat = 'I';
55
56 /* X I/O state information */
57 Display *disp;
58 Window rootw, mainw, lifew, helpw, inputw, coordw, rulew, statew, loadw;
59 int screen;
60 unsigned long fcolor, bcolor;
61 XEvent event;
62 XFontStruct *nfont, *cfont;
63 GC ntextgc, itextgc, cellgc[MAXCOLORS], xorgc, invgc;
64 KeySym ks;
65
66 char inpbuf[INPBUFLEN];
67 int minbuflen, numcomments;
68 char comments[MAXCOMMENTS][MAXCOMMENTLINELEN];
69 char keybuf[16];
70 u32bits lookup4[0x888900];
71 u16bits *lookup2 = (u16bits*)lookup4, tab6[65536];
72 u8bits *lookup = (u8bits*)lookup4, tab4[65536];
73 char fname[PATNAMESIZ];
74
75 unsigned maxstates, statescols, speed;
76 coord_t xpos, ypos; /* coords of upper left corner of viewport */
77 coord_t xorigin, yorigin;/* virtual origin */
78 coord_t lastx, lasty; /* last coord pair displayed on status line */
79 coord_t loadx, loady; /* location to load new points */
80 coord_t iloadx, iloady; /* initial location of load points */
81 int txx, txy, tyx, tyy; /* transform for tentative points */
82
83 int scale;
84 u32bits born = 8, live = 12;
85
86 int width, maxwidth, height, inputlength, state, ev_mode = VALENCE_DRIVEN,
87 paintcolor = 1;
88 int dispcoord, dispboxes, dispchanges, dispspeed = 1;
89 struct timeval timeout;
90
91 char active_rules[RULESNAMELEN], saved_rules[RULESNAMELEN];
92 int oldp, convmode, wireframe, dispmesh = 1, tilesize, limits, helpw_mode,
93 pseudocolor, oscillators, historymode, palettemod, nosymm, aloadmode, pivot,
94 rotate4reflect, truehistory, save_dispboxes, save_dispchanges, passive;
95 char *dirs[MAXDIRS], rfullpath[PATNAMESIZ];
96 unsigned delay, hideperiod = 1, randomseed, eo_comments, rulew_len, runcounter;
97 char stashed[PATNAMESIZ], outcome[PATNAMESIZ], topology = 'Q', topologyinfo[32],
98 pathtorules[PATNAMESIZ];
99
100 coord_t x_min_limit, x_max_limit, y_min_limit, y_max_limit;
101 float rnd_density = .9;
102
103 char curdir[PATNAMESIZ], inidir[PATNAMESIZ], colorfile[PATNAMESIZ];
104 cell_t *trans;
105
106 #if VFREQ != 0
107 struct timeval prev_vsync;
108 #endif
109
110