summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/Makefile3
-rw-r--r--uisimulator/alpha.c137
-rw-r--r--uisimulator/screenhack.c6
-rw-r--r--uisimulator/yarandom.c115
4 files changed, 1 insertions, 260 deletions
diff --git a/uisimulator/Makefile b/uisimulator/Makefile
index 1ad5649eb7..16ace5db6b 100644
--- a/uisimulator/Makefile
+++ b/uisimulator/Makefile
@@ -28,8 +28,7 @@ LDFLAGS = -lX11 -lm -lXt -lXmu -lsocket -lnsl
28 28
29DEPEND = .depends 29DEPEND = .depends
30 30
31OBJS= alpha.o screenhack.o yarandom.o uibasic.o resources.o visual.o\ 31OBJS= screenhack.o uibasic.o resources.o visual.o lcd.o lcd-x11.o
32 lcd.o lcd-x11.o
33 32
34SRCS = $(OBJS:%.o=%.c) 33SRCS = $(OBJS:%.o=%.c)
35HDRS = $(OBJS:%.o=%.h) 34HDRS = $(OBJS:%.o=%.h)
diff --git a/uisimulator/alpha.c b/uisimulator/alpha.c
deleted file mode 100644
index 39abd33251..0000000000
--- a/uisimulator/alpha.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/* xscreensaver, Copyright (c) 1992, 1995, 1996, 1997
2 * Jamie Zawinski <jwz@jwz.org>
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. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
10 * implied warranty.
11 */
12
13/* Beauty is only skin deep, unless you've got an alpha channel. */
14
15
16#include "utils.h"
17#include "alpha.h"
18#include "visual.h"
19#include "hsv.h"
20#include "yarandom.h"
21#include "resources.h"
22
23#include <X11/Xutil.h>
24
25#ifndef countof
26# define countof(x) (sizeof(*(x))/sizeof((x)))
27#endif
28
29
30/* I don't believe this fucking language doesn't have builtin exponentiation.
31 I further can't believe that the fucking ^ character means fucking XOR!! */
32static int
33i_exp (int i, int j)
34{
35 int k = 1;
36 while (j--) k *= i;
37 return k;
38}
39
40
41static void
42merge_colors (int argc, XColor **argv, XColor *into_color, int mask,
43 Bool additive_p)
44{
45 int j;
46 *into_color = *argv [0];
47 into_color->pixel |= mask;
48
49 for (j = 1; j < argc; j++)
50 {
51# define SHORT_INC(x,y) (x = ((((x)+(y)) > 0xFFFF) ? 0xFFFF : ((x)+(y))))
52# define SHORT_DEC(x,y) (x = ((((x)-(y)) < 0) ? 0 : ((x)-(y))))
53 if (additive_p)
54 {
55 SHORT_INC (into_color->red, argv[j]->red);
56 SHORT_INC (into_color->green, argv[j]->green);
57 SHORT_INC (into_color->blue, argv[j]->blue);
58 }
59 else
60 {
61 SHORT_DEC (into_color->red, argv[j]->red);
62 SHORT_DEC (into_color->green, argv[j]->green);
63 SHORT_DEC (into_color->blue, argv[j]->blue);
64 }
65# undef SHORT_INC
66# undef SHORT_DEC
67 }
68}
69
70static void
71permute_colors (XColor *pcolors, XColor *colors,
72 int count,
73 unsigned long *plane_masks,
74 Bool additive_p)
75{
76 int out = 0;
77 int max = i_exp (2, count);
78 if (count > 31) abort ();
79 for (out = 1; out < max; out++)
80 {
81 XColor *argv [32];
82 int this_mask = 0;
83 int argc = 0;
84 int bit;
85 for (bit = 0; bit < 32; bit++)
86 if (out & (1<<bit))
87 {
88 argv [argc++] = &pcolors [bit];
89 this_mask |= plane_masks [bit];
90 }
91 merge_colors (argc, argv, &colors [out-1], this_mask, additive_p);
92 }
93}
94
95
96static int
97allocate_color_planes (Display *dpy, Colormap cmap,
98 int nplanes, unsigned long *plane_masks,
99 unsigned long *base_pixel_ret)
100{
101 while (nplanes > 1 &&
102 !XAllocColorCells (dpy, cmap, False, plane_masks, nplanes,
103 base_pixel_ret, 1))
104 nplanes--;
105
106 return nplanes;
107}
108
109
110static void
111initialize_transparency_colormap (Display *dpy, Colormap cmap,
112 int nplanes,
113 unsigned long base_pixel,
114 unsigned long *plane_masks,
115 XColor *colors,
116 Bool additive_p)
117{
118 int i;
119 int total_colors = i_exp (2, nplanes);
120 XColor *all_colors = (XColor *) calloc (total_colors, sizeof (XColor));
121
122 for (i = 0; i < nplanes; i++)
123 colors[i].pixel = base_pixel | plane_masks [i];
124 permute_colors (colors, all_colors, nplanes, plane_masks, additive_p);
125
126 /* clone the default background of the window into our "base" pixel */
127 all_colors [total_colors - 1].pixel =
128 get_pixel_resource ("background", "Background", dpy, cmap);
129 XQueryColor (dpy, cmap, &all_colors [total_colors - 1]);
130 all_colors [total_colors - 1].pixel = base_pixel;
131
132 for (i = 0; i < total_colors; i++)
133 all_colors[i].flags = DoRed|DoGreen|DoBlue;
134 XStoreColors (dpy, cmap, all_colors, total_colors);
135 XFree ((XPointer) all_colors);
136}
137
diff --git a/uisimulator/screenhack.c b/uisimulator/screenhack.c
index 538400944e..4e3c9c9146 100644
--- a/uisimulator/screenhack.c
+++ b/uisimulator/screenhack.c
@@ -570,12 +570,6 @@ main (int argc, char **argv)
570 570
571 XSync (dpy, False); 571 XSync (dpy, False);
572 572
573 /* This is the one and only place that the random-number generator is
574 seeded in any screenhack. You do not need to seed the RNG again,
575 it is done for you before your code is invoked. */
576# undef ya_rand_init
577 ya_rand_init ((int) time ((time_t *) 0));
578
579 screenhack (dpy, window); /* doesn't return */ 573 screenhack (dpy, window); /* doesn't return */
580 return 0; 574 return 0;
581} 575}
diff --git a/uisimulator/yarandom.c b/uisimulator/yarandom.c
deleted file mode 100644
index 3d24943e0e..0000000000
--- a/uisimulator/yarandom.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/* yarandom.c -- Yet Another Random Number Generator.
2
3 The unportable mess that is rand(), random(), drand48() and friends led me
4 to ask Phil Karlton <karlton@netscape.com> what the Right Thing to Do was.
5 He responded with this. It is non-cryptographically secure, reasonably
6 random (more so than anything that is in any C library), and very fast.
7
8 I don't understand how it works at all, but he says "look at Knuth,
9 Vol. 2 (original edition), page 26, Algorithm A. In this case n=55,
10 k=20 and m=2^32."
11
12 So there you have it.
13
14 ---------------------------
15 Note: xlockmore 4.03a10 uses this very simple RNG:
16
17 if ((seed = seed % 44488 * 48271 - seed / 44488 * 3399) < 0)
18 seed += 2147483647;
19 return seed-1;
20
21 of which it says
22
23 ``Dr. Park's algorithm published in the Oct. '88 ACM "Random Number
24 Generators: Good Ones Are Hard To Find" His version available at
25 ftp://cs.wm.edu/pub/rngs.tar Present form by many authors.''
26
27 Karlton says: ``the usual problem with that kind of RNG turns out to
28 be unexepected short cycles for some word lengths.''
29
30 Karlton's RNG is faster, since it does three adds and two stores, while the
31 xlockmore RNG does two multiplies, two divides, three adds, and one store.
32
33 Compiler optimizations make a big difference here:
34 gcc -O: difference is 1.2x.
35 gcc -O2: difference is 1.4x.
36 gcc -O3: difference is 1.5x.
37 SGI cc -O: difference is 2.4x.
38 SGI cc -O2: difference is 2.4x.
39 SGI cc -O3: difference is 5.1x.
40 Irix 6.2; Indy r5k; SGI cc version 6; gcc version 2.7.2.1.
41 */
42
43
44#ifdef HAVE_CONFIG_H
45# include "config.h"
46#endif
47
48#ifdef HAVE_UNISTD_H
49# include <unistd.h> /* for getpid() */
50#endif
51#include <sys/time.h> /* for gettimeofday() */
52
53#include "yarandom.h"
54# undef ya_rand_init
55
56
57/* The following 'random' numbers are taken from CRC, 18th Edition, page 622.
58 Each array element was taken from the corresponding line in the table,
59 except that a[0] was from line 100. 8s and 9s in the table were simply
60 skipped. The high order digit was taken mod 4.
61 */
62#define VectorSize 55
63static unsigned int a[VectorSize] = {
64 035340171546, 010401501101, 022364657325, 024130436022, 002167303062, /* 5 */
65 037570375137, 037210607110, 016272055420, 023011770546, 017143426366, /* 10 */
66 014753657433, 021657231332, 023553406142, 004236526362, 010365611275, /* 14 */
67 007117336710, 011051276551, 002362132524, 001011540233, 012162531646, /* 20 */
68 007056762337, 006631245521, 014164542224, 032633236305, 023342700176, /* 25 */
69 002433062234, 015257225043, 026762051606, 000742573230, 005366042132, /* 30 */
70 012126416411, 000520471171, 000725646277, 020116577576, 025765742604, /* 35 */
71 007633473735, 015674255275, 017555634041, 006503154145, 021576344247, /* 40 */
72 014577627653, 002707523333, 034146376720, 030060227734, 013765414060, /* 45 */
73 036072251540, 007255221037, 024364674123, 006200353166, 010126373326, /* 50 */
74 015664104320, 016401041535, 016215305520, 033115351014, 017411670323 /* 55 */
75};
76
77static int i1, i2;
78
79unsigned int
80ya_random (void)
81{
82 register int ret = a[i1] + a[i2];
83 a[i1] = ret;
84 if (++i1 >= VectorSize) i1 = 0;
85 if (++i2 >= VectorSize) i2 = 0;
86 return ret;
87}
88
89void
90ya_rand_init(unsigned int seed)
91{
92 int i;
93 if (seed == 0)
94 {
95 struct timeval tp;
96#ifdef GETTIMEOFDAY_TWO_ARGS
97 struct timezone tzp;
98 gettimeofday(&tp, &tzp);
99#else
100 gettimeofday(&tp);
101#endif
102 /* ignore overflow */
103 seed = (999*tp.tv_sec) + (1001*tp.tv_usec) + (1003 * getpid());
104 }
105
106 a[0] += seed;
107 for (i = 1; i < VectorSize; i++)
108 {
109 seed = a[i-1]*1001 + seed*999;
110 a[i] += seed;
111 }
112
113 i1 = a[0] % VectorSize;
114 i2 = (i1 + 024) % VectorSize;
115}