1 /* -*- Mode: C; c-basic-offset: 4; tab-width: 4 -*-
2 * speedmine, Copyright (C) 2001 Conrad Parker <conrad@deephackmode.org>
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
14 * Written mostly over the Easter holiday, 2001. Psychedelic option due to
15 * a night at Home nightclub, Sydney. Three all-nighters of solid partying
16 * were involved in the week this hack was written.
18 * Happy Birthday to WierdArms (17 April) and Pat (18 April)
24 * This program generates a rectangular terrain grid and maps this onto
25 * a semi-circular tunnel. The terrain has length TERRAIN_LENGTH, which
26 * corresponds to length along the tunnel, and breadth TERRAIN_BREADTH,
27 * which corresponds to circumference around the tunnel. For each frame,
28 * the tunnel is perspective mapped onto a set of X and Y screen values.
30 * Throughout this code the following temporary variable names are used:
32 * i iterates along the tunnel in the direction of travel
33 * j iterates around the tunnel clockwise
34 * t iterates along the length of the perspective mapped values
35 * from the furthest to the nearest
37 * Thus, the buffers are used with these iterators:
39 * terrain[i][j] terrain map
40 * worldx[i][j], worldy[i][j] world coordinates (after wrapping)
41 * {x,y,z}curvature[i] tunnel curvature
42 * wideness[i] tunnel wideness
43 * bonuses[i] bonus values
45 * xvals[t][j], yvals[t][j] screen coordinates
46 * {min,max}{x,y}[t] bounding boxes of screen coords
49 /* Define or undefine NDEBUG to turn assert and abort debugging off or on */
55 #include "screenhack.h"
58 #define MIN(a,b) ((a)<(b)?(a):(b))
59 #define MAX(a,b) ((a)>(b)?(a):(b))
61 #define RAND(r) (int)(((r)>0)?(random() % (long)(r)): -(random() % (long)(-r)))
63 #define SIGN3(a) ((a)>0?1:((a)<0?-1:0))
65 #define MODULO(a,b) while ((a)<0) (a)+=(b); (a) %= (b);
67 /* No. of shades of each color (ground, walls, bonuses) */
79 /* Apparently AIX's math.h bogusly defines `nearest' as a function,
80 in violation of the ANSI C spec. */
82 #define nearest n3arest
84 #define wireframe (st->wire_flag||st->wire_bonus>8||st->wire_bonus%2==1)
85 #define effective_speed (st->direction*(st->speed+st->speed_bonus))
87 /* No. of levels of interpolation, for perspective */
90 /* These must be powers of 2 */
91 #define TERRAIN_LENGTH 256
92 #define TERRAIN_BREADTH 32
94 /* total "perspective distance" of terrain */
95 #define TERRAIN_PDIST (INTERP*TERRAIN_LENGTH)
98 #define TB_MUL (ROTS/TERRAIN_BREADTH)
100 #define random_elevation() (st->terrain_flag?(random() % 200):0)
101 #define random_curvature() (st->curviness>0.0?((double)(random() % 40)-20)*st->curviness:0.0)
102 #define random_twist() (st->twistiness>0.0?((double)(random() % 40)-20)*st->twistiness:0.0)
103 #define random_wideness() (st->widening_flag?(int)(random() % 1200):0)
105 #define STEEL_ELEVATION 300
111 Pixmap dbuf, stars_mask;
113 unsigned int default_fg_pixel;
114 GC draw_gc, erase_gc, tunnelend_gc, stars_gc, stars_erase_gc;
116 int ncolors, nr_ground_colors, nr_wall_colors, nr_bonus_colors;
117 XColor ground_colors[MAX_COLORS], wall_colors[MAX_COLORS];
118 XColor bonus_colors[MAX_COLORS];
119 GC ground_gcs[MAX_COLORS], wall_gcs[MAX_COLORS], bonus_gcs[MAX_COLORS];
134 int psychedelic_flag;
138 double thrust, gravity;
153 int xoffset, yoffset;
163 double sintab[ROTS], costab[ROTS];
167 int terrain[TERRAIN_LENGTH][TERRAIN_BREADTH];
168 double xcurvature[TERRAIN_LENGTH];
169 double ycurvature[TERRAIN_LENGTH];
170 double zcurvature[TERRAIN_LENGTH];
171 int wideness[TERRAIN_LENGTH];
172 int bonuses[TERRAIN_LENGTH];
173 int xvals[TERRAIN_LENGTH][TERRAIN_BREADTH];
174 int yvals[TERRAIN_LENGTH][TERRAIN_BREADTH];
175 double worldx[TERRAIN_LENGTH][TERRAIN_BREADTH];
176 double worldy[TERRAIN_LENGTH][TERRAIN_BREADTH];
177 int minx[TERRAIN_LENGTH], maxx[TERRAIN_LENGTH];
178 int miny[TERRAIN_LENGTH], maxy[TERRAIN_LENGTH];
183 double fps_start, fps_end;
184 struct timeval start_time;
190 /* a forward declaration ... */
191 static void change_colors(struct state *st);
198 * returns the total time elapsed since the beginning of the demo
200 static double get_time(struct state *st) {
203 #if GETTIMEOFDAY_TWO_ARGS
204 gettimeofday(&t, NULL);
208 t.tv_sec -= st->start_time.tv_sec;
209 f = ((double)t.tv_sec) + t.tv_usec*1e-6;
216 * initialises the timing structures
218 static void init_time(struct state *st) {
219 #if GETTIMEOFDAY_TWO_ARGS
220 gettimeofday(&st->start_time, NULL);
222 gettimeofday(&st->start_time);
224 st->fps_start = get_time(st);
231 * perspective map the world coordinates worldx[i][j], worldy[i][j] onto
232 * screen coordinates xvals[t][j], yvals[t][j]
235 perspective (struct state *st)
237 int i, j, jj, t=0, depth, view_pos;
238 int rotation_bias, r;
239 double xc=0.0, yc=0.0, zc=0.0;
240 double xcc=0.0, ycc=0.0, zcc=0.0;
244 zf = 8.0*28.0 / (double)(st->width*TERRAIN_LENGTH);
245 if (st->be_wormy) zf *= 3.0;
247 depth = TERRAIN_PDIST - INTERP + st->pindex;
249 view_pos = (st->nearest+3*TERRAIN_LENGTH/4)%TERRAIN_LENGTH;
251 st->xoffset += - st->xcurvature[view_pos]*st->curviness/8;
254 st->yoffset += - st->ycurvature[view_pos]*st->curviness/4;
257 st->rotation_offset += (int)((st->zcurvature[view_pos]-st->zcurvature[st->nearest])*ROTS/8);
258 st->rotation_offset /= 2;
259 rotation_bias = st->orientation + st->spin_bonus - st->rotation_offset;
261 if (st->bumps_flag) {
263 st->yoffset -= ((st->terrain[view_pos][TERRAIN_BREADTH/4] * st->width /(8*1600)));
264 rotation_bias += (st->terrain[view_pos][TERRAIN_BREADTH/4+2] -
265 st->terrain[view_pos][TERRAIN_BREADTH/4-2])/8;
267 st->yoffset -= ((st->terrain[view_pos][TERRAIN_BREADTH/4] * st->width /(2*1600)));
268 rotation_bias += (st->terrain[view_pos][TERRAIN_BREADTH/4+2] -
269 st->terrain[view_pos][TERRAIN_BREADTH/4-2])/16;
273 MODULO(rotation_bias, ROTS);
275 for (t=0; t < TERRAIN_LENGTH; t++) {
276 i = st->nearest + t; MODULO(i, TERRAIN_LENGTH);
277 xc += st->xcurvature[i]; yc += st->ycurvature[i]; zc += st->zcurvature[i];
278 xcc += xc; ycc += yc; zcc += zc;
279 st->maxx[i] = st->maxy[i] = 0;
280 st->minx[i] = st->width; st->miny[i] = st->height;
283 for (t=0; t < TERRAIN_LENGTH; t++) {
284 i = st->nearest - 1 - t; MODULO(i, TERRAIN_LENGTH);
286 zfactor = (double)depth* (12.0 - TERRAIN_LENGTH/8.0) * zf;
287 for (j=0; j < TERRAIN_BREADTH; j++) {
288 jj = st->direction * j; MODULO(jj, TERRAIN_BREADTH);
289 /* jwz: not totally sure if this is right, but it avoids div0 */
291 xx = (st->worldx[i][jj]-(st->vertigo*xcc))/zfactor;
292 yy = (st->worldy[i][j]-(st->vertigo*ycc))/zfactor;
297 r = rotation_bias + (int)(st->vertigo*zcc); MODULO(r, ROTS);
299 st->xvals[t][j] = st->xoffset + (st->width>>1) +
300 (int)(xx * st->costab[r] - yy * st->sintab[r]);
301 st->maxx[t] = MAX(st->maxx[t], st->xvals[t][j]);
302 st->minx[t] = MIN(st->minx[t], st->xvals[t][j]);
304 st->yvals[t][j] = st->yoffset + st->height/2 +
305 (int)(xx * st->sintab[r] + yy * st->costab[r]);
306 st->maxy[t] = MAX(st->maxy[t], st->yvals[t][j]);
307 st->miny[t] = MIN(st->miny[t], st->yvals[t][j]);
309 xcc -= xc; ycc -= yc; zcc -= zc;
310 xc -= st->xcurvature[i]; yc -= st->ycurvature[i]; zc -= st->zcurvature[i];
316 * wrap_tunnel (start, end)
318 * wrap the terrain terrain[i][j] around the semi-circular tunnel function
320 * x' = x/2 * cos(theta) - (y-k) * x * sin(theta)
321 * y' = x/4 * sin(theta) + y * cos(theta)
323 * between i=start and i=end inclusive, producing world coordinates
324 * worldx[i][j], worldy[i][j]
327 wrap_tunnel (struct state *st, int start, int end)
332 assert (start < end);
334 for (i=start; i <= end; i++) {
335 for (j=0; j < TERRAIN_BREADTH; j++) {
336 x = j * (1.0/TERRAIN_BREADTH);
337 v = st->terrain[i][j];
338 y = (double)(v==STEEL_ELEVATION?200:v) - st->wideness[i] - 1200;
341 if (j > TERRAIN_BREADTH/8 && j < 3*TERRAIN_BREADTH/8) y -= 300;
343 st->worldx[i][j] = x/2 * st->costab[j*TB_MUL] -
344 (y-st->height/4.0)*x*st->sintab[j*TB_MUL];
345 st->worldy[i][j] = x/4 * st->sintab[j*TB_MUL] +
346 y * st->costab[j*TB_MUL];
354 * perform the state transitions and terrain transformation for the
355 * "look backwards/look forwards" bonus
358 flip_direction (struct state *st)
362 st->direction = -st->direction;
364 st->bonus_bright = 20;
366 for (i=0; i < TERRAIN_LENGTH; i++) {
367 in = st->nearest + i; MODULO(in, TERRAIN_BREADTH);
368 ip = st->nearest - i; MODULO(ip, TERRAIN_BREADTH);
369 for (j=0; j < TERRAIN_BREADTH; j++) {
370 t = st->terrain[ip][j];
371 st->terrain[ip][j] = st->terrain[in][j];
372 st->terrain[in][j] = t;
378 * generate_smooth (start, end)
380 * generate smooth terrain between i=start and i=end inclusive
383 generate_smooth (struct state *st, int start, int end)
387 assert (start < end);
389 for (i=start; i <= end; i++) {
390 ii = i; MODULO(ii, TERRAIN_LENGTH);
391 for (j=0; j < TERRAIN_BREADTH; j++) {
392 st->terrain[i][j] = STEEL_ELEVATION;
398 * generate_straight (start, end)
400 * zero the curvature and wideness between i=start and i=end inclusive
403 generate_straight (struct state *st, int start, int end)
407 assert (start < end);
409 for (i=start; i <= end; i++) {
410 ii = i; MODULO(ii, TERRAIN_LENGTH);
411 for (j=0; j < TERRAIN_BREADTH; j++) {
412 st->xcurvature[ii] = 0;
413 st->ycurvature[ii] = 0;
414 st->zcurvature[ii] = 0;
415 st->wideness[ii] = 0;
421 * int generate_terrain_value (v1, v2, v3, v4, w)
423 * generate terrain value near the average of v1, v2, v3, v4, with
424 * perturbation proportional to w
427 generate_terrain_value (struct state *st, int v1, int v2, int v3, int v4, int w)
432 if (!st->terrain_flag) return 0;
434 sum = v1 + v2 + v3 + v4;
436 rval = w*sum/st->smoothness;
437 if (rval == 0) rval = 2;
439 ret = (sum/4 -(rval/2) + RAND(rval));
441 if (ret < -400 || ret > 400) {
449 * generate_terrain (start, end, final)
451 * generate terrain[i][j] between i=start and i=end inclusive
453 * This is performed by successive subdivision of the terrain into
454 * rectangles of decreasing size. Subdivision continues until the
455 * the minimum width or height of these rectangles is 'final'; ie.
456 * final=1 indicates to subdivide as far as possible, final=2 indicates
457 * to stop one subdivision before that (leaving a checkerboard pattern
461 generate_terrain (struct state *st, int start, int end, int final)
464 int ip, jp, in, jn; /* prev, next values */
467 assert (start < end);
468 assert (start >= 0 && start < TERRAIN_LENGTH);
469 assert (end >= 0 && end < TERRAIN_LENGTH);
471 diff = end - start + 1;
473 st->terrain[end][0] = random_elevation();
474 st->terrain[end][TERRAIN_BREADTH/2] = random_elevation();
476 for (w= diff/2, l=TERRAIN_BREADTH/4;
477 w >= final || l >= final; w /= 2, l /= 2) {
479 if (w<1) w=1; if (l<1) l=1;
481 for (i=start+w-1; i < end; i += (w*2)) {
482 ip = i-w; MODULO(ip, TERRAIN_LENGTH);
483 in = i+w; MODULO(in, TERRAIN_LENGTH);
484 for (j=l-1; j < TERRAIN_BREADTH; j += (l*2)) {
485 jp = j-1; MODULO(jp, TERRAIN_BREADTH);
486 jn = j+1; MODULO(jn, TERRAIN_BREADTH);
488 generate_terrain_value (st, st->terrain[ip][jp], st->terrain[in][jp],
489 st->terrain[ip][jn], st->terrain[in][jn], w);
493 for (i=start+(w*2)-1; i < end; i += (w*2)) {
494 ip = i-w; MODULO(ip, TERRAIN_LENGTH);
495 in = i+w; MODULO(in, TERRAIN_LENGTH);
496 for (j=l-1; j < TERRAIN_BREADTH; j += (l*2)) {
497 jp = j-1; MODULO(jp, TERRAIN_BREADTH);
498 jn = j+1; MODULO(jn, TERRAIN_BREADTH);
500 generate_terrain_value (st, st->terrain[ip][j], st->terrain[in][j],
501 st->terrain[i][jp], st->terrain[i][jn], w);
505 for (i=start+w-1; i < end; i += (w*2)) {
506 ip = i-w; MODULO(ip, TERRAIN_LENGTH);
507 in = i+w; MODULO(in, TERRAIN_LENGTH);
508 for (j=2*l-1; j < TERRAIN_BREADTH; j += (l*2)) {
509 jp = j-1; MODULO(jp, TERRAIN_BREADTH);
510 jn = j+1; MODULO(jn, TERRAIN_BREADTH);
512 generate_terrain_value (st, st->terrain[ip][j], st->terrain[in][j],
513 st->terrain[i][jp], st->terrain[i][jn], w);
520 * double generate_curvature_value (v1, v2, w)
522 * generate curvature value near the average of v1 and v2, with perturbation
526 generate_curvature_value (double v1, double v2, int w)
528 double sum, avg, diff, ret;
531 assert (!isnan(v1) && !isnan(v2));
536 diff = MIN(v1 - avg, v2 - avg);
538 rval = (int)diff * w;
539 if (rval == 0.0) return avg;
541 ret = (avg -((double)rval)/500.0 + ((double)RAND(rval))/1000.0);
543 assert (!isnan(ret));
549 * generate_curves (start, end)
551 * generate xcurvature[i], ycurvature[i], zcurvature[i] and wideness[i]
552 * between start and end inclusive
555 generate_curves (struct state *st, int start, int end)
557 int i, diff, ii, in, ip, w;
559 assert (start < end);
561 diff = end - start + 1; MODULO (diff, TERRAIN_LENGTH);
563 if (random() % 100 == 0)
564 st->xcurvature[end] = 30 * random_curvature();
565 else if (random() % 10 == 0)
566 st->xcurvature[end] = 20 * random_curvature();
568 st->xcurvature[end] = 10 * random_curvature();
570 if (random() % 50 == 0)
571 st->ycurvature[end] = 20 * random_curvature();
572 else if (random() % 25 == 0)
573 st->ycurvature[end] = 30 * random_curvature();
575 st->ycurvature[end] = 10 * random_curvature();
577 if (random() % 3 == 0)
578 st->zcurvature[end] = random_twist();
580 st->zcurvature[end] =
581 generate_curvature_value (st->zcurvature[end], random_twist(), 1);
584 st->wideness[end] = random_wideness();
587 generate_curvature_value (st->wideness[end], random_wideness(), 1);
589 for (w=diff/2; w >= 1; w /= 2) {
590 for (i=start+w-1; i < end; i+=(w*2)) {
591 ii = i; MODULO (ii, TERRAIN_LENGTH);
592 ip = i-w; MODULO (ip, TERRAIN_LENGTH);
593 in = i+w; MODULO (in, TERRAIN_LENGTH);
595 generate_curvature_value (st->xcurvature[ip], st->xcurvature[in], w);
597 generate_curvature_value (st->ycurvature[ip], st->ycurvature[in], w);
599 generate_curvature_value (st->zcurvature[ip], st->zcurvature[in], w);
601 generate_curvature_value (st->wideness[ip], st->wideness[in], w);
609 * choose a random bonus and perform its state transition
612 do_bonus (struct state *st)
614 st->bonus_bright = 20;
616 if (st->jamming > 0) {
618 st->nearest -= 2; MODULO(st->nearest, TERRAIN_LENGTH);
622 if (st->psychedelic_flag) change_colors(st);
624 switch (random() % 7) {
625 case 0: /* switch to or from wireframe */
626 st->wire_bonus = (st->wire_bonus?0:300);
628 case 1: /* speedup */
629 st->speed_bonus = 40.0;
632 st->spin_bonus += ROTS;
635 st->spin_bonus -= ROTS;
637 case 4: /* look backwards / look forwards */
638 st->flipped_at = st->nearest;
640 st->backwards_bonus = (st->backwards_bonus?0:10);
645 case 6: /* jam against the bonus a few times; deja vu! */
646 st->nearest -= 2; MODULO(st->nearest, TERRAIN_LENGTH);
658 * check if a bonus has been passed in the last frame, and handle it
661 check_bonuses (struct state *st)
663 int i, ii, start, end;
665 if (!st->bonuses_flag) return;
667 if (st->step >= 0.0) {
668 start = st->nearest; end = st->nearest + (int)floor(st->step);
670 end = st->nearest; start = st->nearest + (int)floor(st->step);
674 start += TERRAIN_LENGTH/4;
675 end += TERRAIN_LENGTH/4;
678 for (i=start; i < end; i++) {
679 ii = i; MODULO(ii, TERRAIN_LENGTH);
680 if (st->bonuses[ii] == 1) do_bonus (st);
685 * decrement_bonuses (double time_per_frame)
687 * decrement timers associated with bonuses
690 decrement_bonuses (struct state *st, double time_per_frame)
692 if (!st->bonuses_flag) return;
694 if (st->bonus_bright > 0) st->bonus_bright-=4;
695 if (st->wire_bonus > 0) st->wire_bonus--;
696 if (st->speed_bonus > 0) st->speed_bonus -= 2.0;
698 if (st->spin_bonus > 10) st->spin_bonus -= (int)(st->step*13.7);
699 else if (st->spin_bonus < -10) st->spin_bonus += (int)(st->step*11.3);
701 if (st->backwards_bonus > 1) st->backwards_bonus--;
702 else if (st->backwards_bonus == 1) {
703 st->nearest += 2*(MAX(st->flipped_at, st->nearest) - MIN(st->flipped_at,st->nearest));
704 MODULO(st->nearest, TERRAIN_LENGTH);
706 st->backwards_bonus = 0;
711 * set_bonuses (start, end)
713 * choose if to and where to set a bonus between i=start and i=end inclusive
716 set_bonuses (struct state *st, int start, int end)
720 if (!st->bonuses_flag) return;
722 assert (start < end);
726 for (i=start; i <= end; i++) {
727 ii = i; if (ii>=TERRAIN_LENGTH) ii -= TERRAIN_LENGTH;
730 if (random() % 4 == 0) {
731 i = start + RAND(diff-3);
732 ii = i; if (ii>=TERRAIN_LENGTH) ii -= TERRAIN_LENGTH;
733 st->bonuses[ii] = 2; /* marker */
734 ii = i+3; if (ii>=TERRAIN_LENGTH) ii -= TERRAIN_LENGTH;
735 st->bonuses[ii] = 1; /* real thing */
740 * regenerate_terrain ()
742 * regenerate a portion of the terrain map of length TERRAIN_LENGTH/4 iff
743 * we just passed between two quarters of the terrain.
745 * choose the kind of terrain to produce, produce it and wrap the tunnel
748 regenerate_terrain (struct state *st)
753 passed = st->nearest % (TERRAIN_LENGTH/4);
755 if (st->speed == 0.0 ||
756 (st->speed > 0.0 && passed > (int)st->step) ||
757 (st->speed < 0.0 && (TERRAIN_LENGTH/4)-passed > (int)fabs(st->step))) {
762 end = st->nearest - passed - 1; MODULO(end, TERRAIN_LENGTH);
763 start = end - TERRAIN_LENGTH/4 + 1; MODULO(start, TERRAIN_LENGTH);
765 if (DEBUG_FLAG) printf ("Regenerating [%d - %d]\n", start, end);
767 set_bonuses (st, start, end);
769 switch (random() % 64) {
772 generate_terrain (st, start, end, 1);
773 generate_smooth (st, start,
774 start + TERRAIN_LENGTH/8 + (random() % TERRAIN_LENGTH/8));
777 generate_smooth (st, start, end);
778 generate_terrain (st, start, end, 4); break;
780 generate_smooth (st, start, end);
781 generate_terrain (st, start, end, 2); break;
783 generate_terrain (st, start, end, 1);
786 if (random() % 16 == 0) {
787 generate_straight (st, start, end);
789 generate_curves (st, start, end);
792 wrap_tunnel (st, start, end);
798 * initialise the terrain map for the beginning of the demo
801 init_terrain (struct state *st)
805 for (i=0; i < TERRAIN_LENGTH; i++) {
806 for (j=0; j < TERRAIN_BREADTH; j++) {
807 st->terrain[i][j] = 0;
811 st->terrain[TERRAIN_LENGTH-1][0] = - (random() % 300);
812 st->terrain[TERRAIN_LENGTH-1][TERRAIN_BREADTH/2] = - (random() % 300);
814 generate_smooth (st, 0, TERRAIN_LENGTH-1);
815 generate_terrain (st, 0, TERRAIN_LENGTH/4 -1, 4);
816 generate_terrain (st, TERRAIN_LENGTH/4, TERRAIN_LENGTH/2 -1, 2);
817 generate_terrain (st, TERRAIN_LENGTH/2, 3*TERRAIN_LENGTH/4 -1, 1);
818 generate_smooth (st, 3*TERRAIN_LENGTH/4, TERRAIN_LENGTH-1);
824 * initialise the curvatures and wideness for the beginning of the demo.
827 init_curves (struct state *st)
831 for (i=0; i < TERRAIN_LENGTH-1; i++) {
832 st->xcurvature[i] = 0.0;
833 st->ycurvature[i] = 0.0;
834 st->zcurvature[i] = 0.0;
837 st->xcurvature[TERRAIN_LENGTH-1] = random_curvature();
838 st->ycurvature[TERRAIN_LENGTH-1] = random_curvature();
839 st->zcurvature[TERRAIN_LENGTH-1] = random_twist();
841 generate_straight (st, 0, TERRAIN_LENGTH/4-1);
842 generate_curves (st, TERRAIN_LENGTH/4, TERRAIN_LENGTH/2-1);
843 generate_curves (st, TERRAIN_LENGTH/2, 3*TERRAIN_LENGTH/4-1);
844 generate_straight (st, 3*TERRAIN_LENGTH/4, TERRAIN_LENGTH-1);
849 * render_quads (dpy, d, t, dt, i)
851 * renders the quadrilaterals from perspective depth t to t+dt.
852 * i is passed as a hint, where i corresponds to t as asserted.
855 render_quads (struct state *st, Drawable d, int t, int dt, int i)
862 assert (i == (st->nearest - (t + dt) + TERRAIN_LENGTH) % TERRAIN_LENGTH);
864 in = i + 1; MODULO(in, TERRAIN_LENGTH);
866 for (j=0; j < TERRAIN_BREADTH; j+=dt) {
867 t2 = t+dt; if (t2 >= TERRAIN_LENGTH) t2 -= TERRAIN_LENGTH;
868 j2 = j+dt; if (j2 >= TERRAIN_BREADTH) j2 -= TERRAIN_BREADTH;
869 points[0].x = st->xvals[t][j]; points[0].y = st->yvals[t][j];
870 points[1].x = st->xvals[t2][j]; points[1].y = st->yvals[t2][j];
871 points[2].x = st->xvals[t2][j2]; points[2].y = st->yvals[t2][j2];
872 points[3].x = st->xvals[t][j2]; points[3].y = st->yvals[t][j2];
874 index = st->bonus_bright + st->ncolors/3 +
875 t*(t*INTERP + st->pindex) * st->ncolors /
876 (3*TERRAIN_LENGTH*TERRAIN_PDIST);
878 index += (int)((points[0].y - points[3].y) / 8);
879 index += (int)((st->worldx[i][j] - st->worldx[in][j]) / 40);
880 index += (int)((st->terrain[in][j] - st->terrain[i][j]) / 100);
882 if (st->be_wormy && st->psychedelic_flag) index += st->ncolors/4;
884 if (st->ncolors > MAX_COLORS) abort();
885 index = MIN (index, st->ncolors-1);
886 index = MAX (index, 0);
888 if (st->bonuses[i]) {
889 XSetClipMask (st->dpy, st->bonus_gcs[index], None);
893 if (st->bonuses[i]) gc = st->bonus_gcs[index];
894 else gc = st->ground_gcs[index];
895 XDrawLines (st->dpy, d, gc, points, 4, CoordModeOrigin);
898 gc = st->bonus_gcs[index];
899 else if ((st->direction>0 && j < TERRAIN_BREADTH/8) ||
900 (j > TERRAIN_BREADTH/8 && j < 3*TERRAIN_BREADTH/8-1) ||
901 (st->direction < 0 && j > 3*TERRAIN_BREADTH/8-1 &&
902 j < TERRAIN_BREADTH/2) ||
903 st->terrain[i][j] == STEEL_ELEVATION ||
904 st->wideness[in] - st->wideness[i] > 200)
905 gc = st->ground_gcs[index];
907 gc = st->wall_gcs[index];
909 XFillPolygon (st->dpy, d, gc, points, 4, Nonconvex, CoordModeOrigin);
915 * render_pentagons (dpy, d, t, dt, i)
917 * renders the pentagons from perspective depth t to t+dt.
918 * i is passed as a hint, where i corresponds to t as asserted.
921 render_pentagons (struct state *st, Drawable d, int t, int dt, int i)
923 int j, t2, j2, j3, in;
928 assert (i == (st->nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
930 in = i + 1; MODULO(in, TERRAIN_LENGTH);
932 for (j=0; j < TERRAIN_BREADTH; j+=dt*2) {
933 t2 = t+(dt*2); if (t2 >= TERRAIN_LENGTH) t2 -= TERRAIN_LENGTH;
934 j2 = j+dt; if (j2 >= TERRAIN_BREADTH) j2 -= TERRAIN_BREADTH;
935 j3 = j+dt+dt; if (j3 >= TERRAIN_BREADTH) j3 -= TERRAIN_BREADTH;
936 points[0].x = st->xvals[t][j]; points[0].y = st->yvals[t][j];
937 points[1].x = st->xvals[t2][j]; points[1].y = st->yvals[t2][j];
938 points[2].x = st->xvals[t2][j2]; points[2].y = st->yvals[t2][j2];
939 points[3].x = st->xvals[t2][j3]; points[3].y = st->yvals[t2][j3];
940 points[4].x = st->xvals[t][j3]; points[4].y = st->yvals[t][j3];
942 index = st->bonus_bright + st->ncolors/3 +
943 t*(t*INTERP + st->pindex) * st->ncolors /
944 (3*TERRAIN_LENGTH*TERRAIN_PDIST);
946 index += (int)((points[0].y - points[3].y) / 8);
947 index += (int)((st->worldx[i][j] - st->worldx[in][j]) / 40);
948 index += (int)((st->terrain[in][j] - st->terrain[i][j]) / 100);
950 if (st->be_wormy && st->psychedelic_flag) index += st->ncolors/4;
952 index = MIN (index, st->ncolors-1);
953 index = MAX (index, 0);
955 if (st->bonuses[i]) {
956 XSetClipMask (st->dpy, st->bonus_gcs[index], None);
960 if (st->bonuses[i]) gc = st->bonus_gcs[index];
961 else gc = st->ground_gcs[index];
962 XDrawLines (st->dpy, d, gc, points, 5, CoordModeOrigin);
965 gc = st->bonus_gcs[index];
966 else if (j < TERRAIN_BREADTH/8 ||
967 (j > TERRAIN_BREADTH/8 && j < 3*TERRAIN_BREADTH/8-1) ||
968 st->terrain[i][j] == STEEL_ELEVATION ||
969 st->wideness[in] - st->wideness[i] > 200)
970 gc = st->ground_gcs[index];
972 gc = st->wall_gcs[index];
974 XFillPolygon (st->dpy, d, gc, points, 5, Complex, CoordModeOrigin);
980 * render_block (dpy, d, gc, t)
982 * render a filled polygon at perspective depth t using the given GC
985 render_block (struct state *st, Drawable d, GC gc, int t)
989 XPoint erase_points[TERRAIN_BREADTH/2];
991 for (i=0; i < TERRAIN_BREADTH/2; i++) {
992 erase_points[i].x = st->xvals[t][i*2];
993 erase_points[i].y = st->yvals[t][i*2];
996 XFillPolygon (st->dpy, d, gc, erase_points,
997 TERRAIN_BREADTH/2, Complex, CoordModeOrigin);
1001 * regenerate_stars_mask (dpy, t)
1003 * regenerate the clip mask 'stars_mask' for drawing the bonus stars at
1004 * random positions within the bounding box at depth t
1007 regenerate_stars_mask (struct state *st, int t)
1009 int i, w, h, a, b, l1, l2;
1010 const int lim = st->width*TERRAIN_LENGTH/(300*(TERRAIN_LENGTH-t));
1012 w = st->maxx[t] - st->minx[t];
1013 h = st->maxy[t] - st->miny[t];
1015 if (w<6||h<6) return;
1017 XFillRectangle (st->dpy, st->stars_mask, st->stars_erase_gc,
1018 0, 0, st->width, st->height);
1020 l1 = (t>3*TERRAIN_LENGTH/4?2:1);
1021 l2 = (t>7*TERRAIN_LENGTH/8?2:1);
1023 for (i=0; i < lim; i++) {
1024 a = RAND(w); b = RAND(h);
1025 XDrawLine (st->dpy, st->stars_mask, st->stars_gc,
1026 st->minx[t]+a-l1, st->miny[t]+b, st->minx[t]+a+l1, st->miny[t]+b);
1027 XDrawLine (st->dpy, st->stars_mask, st->stars_gc,
1028 st->minx[t]+a, st->miny[t]+b-l1, st->minx[t]+a, st->miny[t]+b+l1);
1030 for (i=0; i < lim; i++) {
1031 a = RAND(w); b = RAND(h);
1032 XDrawLine (st->dpy, st->stars_mask, st->stars_gc,
1033 st->minx[t]+a-l2, st->miny[t]+b, st->minx[t]+a+l2, st->miny[t]+b);
1034 XDrawLine (st->dpy, st->stars_mask, st->stars_gc,
1035 st->minx[t]+a, st->miny[t]+b-l2, st->minx[t]+a, st->miny[t]+b+l2);
1040 * render_bonus_block (dpy, d, t, i)
1042 * draw the bonus stars at depth t.
1043 * i is passed as a hint, where i corresponds to t as asserted.
1046 render_bonus_block (struct state *st, Drawable d, int t, int i)
1050 assert (i == (st->nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
1052 if (!st->bonuses[i] || wireframe) return;
1054 regenerate_stars_mask (st, t);
1056 bt = t * st->nr_bonus_colors / (2*TERRAIN_LENGTH);
1058 XSetClipMask (st->dpy, st->bonus_gcs[bt], st->stars_mask);
1060 render_block (st, d, st->bonus_gcs[bt], t);
1064 begin_at (struct state *st)
1067 int max_minx=0, min_maxx=st->width, max_miny=0, min_maxy=st->height;
1069 for (t=TERRAIN_LENGTH-1; t > 0; t--) {
1070 max_minx = MAX (max_minx, st->minx[t]);
1071 min_maxx = MIN (min_maxx, st->maxx[t]);
1072 max_miny = MAX (max_miny, st->miny[t]);
1073 min_maxy = MIN (min_maxy, st->maxy[t]);
1075 if (max_miny >= min_maxy || max_minx >= min_maxx) break;
1082 * render_speedmine (dpy, d)
1084 * render the current frame.
1087 render_speedmine (struct state *st, Drawable d)
1089 int t, i=st->nearest, dt=1;
1092 assert (st->nearest >= 0 && st->nearest < TERRAIN_LENGTH);
1094 if (st->be_wormy || wireframe) {
1095 XFillRectangle (st->dpy, d, st->erase_gc, 0, 0, st->width, st->height);
1098 for (t=0; t < TERRAIN_LENGTH/4; t+=dt) {
1099 render_bonus_block (st, d, t, i);
1100 i -= dt; MODULO(i, TERRAIN_LENGTH);
1101 render_quads (st, d, t, dt, i);
1104 assert (t == TERRAIN_LENGTH/4);
1106 t = MAX(begin_at(st), TERRAIN_LENGTH/4);
1107 /*t = TERRAIN_LENGTH/4; dt = 2; */
1108 /*dt = (t >= 3*TERRAIN_LENGTH/4 ? 1 : 2);*/
1109 i = (st->nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH;
1110 render_block (st, d, st->tunnelend_gc, t);
1115 if (t == TERRAIN_LENGTH/4)
1116 render_pentagons (st, d, t, dt, i);
1118 for (; t < 3*TERRAIN_LENGTH/4; t+=dt) {
1119 render_bonus_block (st, d, t, i);
1120 i -= dt; MODULO(i, TERRAIN_LENGTH);
1121 render_quads (st, d, t, dt, i);
1126 for (; t < TERRAIN_LENGTH-(1+(st->pindex<INTERP/2)); t+=dt) {
1127 render_bonus_block (st, d, t, i);
1128 i -= dt; MODULO(i, TERRAIN_LENGTH);
1131 if (wireframe) {assert (t == 3*TERRAIN_LENGTH/4);}
1133 if (t == 3*TERRAIN_LENGTH/4)
1134 render_pentagons (st, d, t, dt, i);
1136 for (; t < TERRAIN_LENGTH-(1+(st->pindex<INTERP/2)); t+=dt) {
1137 render_bonus_block (st, d, t, i);
1138 i -= dt; MODULO(i, TERRAIN_LENGTH);
1139 render_quads (st, d, t, dt, i);
1143 /* Draw crosshair */
1144 if (st->crosshair_flag) {
1145 gc = (wireframe ? st->bonus_gcs[st->nr_bonus_colors/2] : st->erase_gc);
1146 XFillRectangle (st->dpy, d, gc,
1147 st->width/2+(st->xoffset)-8, st->height/2+(st->yoffset*2)-1, 16, 3);
1148 XFillRectangle (st->dpy, d, gc,
1149 st->width/2+(st->xoffset)-1, st->height/2+(st->yoffset*2)-8, 3, 16);
1157 * move to the position for the next frame, and modify the state variables
1158 * st->nearest, pindex, pos, speed
1161 move (struct state *st)
1165 st->pos += st->step;
1166 dpos = SIGN3(st->pos) * floor(fabs(st->pos));
1168 st->pindex += SIGN3(effective_speed) + INTERP;
1169 while (st->pindex >= INTERP) {
1171 st->pindex -= INTERP;
1173 while (st->pindex < 0) {
1175 st->pindex += INTERP;
1178 st->nearest += dpos; MODULO(st->nearest, TERRAIN_LENGTH);
1182 st->accel = st->thrust + st->ycurvature[st->nearest] * st->gravity;
1183 st->speed += st->accel;
1184 if (st->speed > st->maxspeed) st->speed = st->maxspeed;
1185 if (st->speed < -st->maxspeed) st->speed = -st->maxspeed;
1189 * speedmine (dpy, window)
1191 * do everything required for one frame of the demo
1193 static unsigned long
1194 speedmine_draw (Display *dpy, Window window, void *closure)
1196 struct state *st = (struct state *) closure;
1197 double elapsed, time_per_frame = 0.04;
1199 regenerate_terrain (st);
1203 render_speedmine (st, st->dbuf);
1204 if (st->dbuf != st->window)
1205 XCopyArea (st->dpy, st->dbuf, st->window, st->draw_gc, 0, 0, st->width, st->height, 0, 0);
1207 st->fps_end = get_time(st);
1209 st->total_nframes++;
1211 if (st->fps_end > st->fps_start + 0.5) {
1212 elapsed = st->fps_end - st->fps_start;
1213 st->fps_start = get_time(st);
1215 time_per_frame = elapsed / st->nframes - st->delay*1e-6;
1216 st->fps = st->nframes / elapsed;
1218 printf ("%f s elapsed\t%3f s/frame\t%.1f FPS\n", elapsed,
1219 time_per_frame, st->fps);
1221 st->step = effective_speed * elapsed;
1229 decrement_bonuses (st, time_per_frame);
1237 * speedmine_color_ramp (dpy, gcs, colors, ncolors, s1, s2, v1, v2)
1239 * generate a color ramp of up to *ncolors between randomly chosen hues,
1240 * varying from saturation s1 to s2 and value v1 to v2, placing the colors
1241 * in 'colors' and creating corresponding GCs in 'gcs'.
1243 * The number of colors actually allocated is returned in ncolors.
1246 speedmine_color_ramp (struct state *st, GC *gcs, XColor * colors,
1247 int *ncolors, double s1, double s2, double v1, double v2)
1251 unsigned long flags;
1254 assert (*st->ncolors >= 0);
1255 assert (s1 >= 0.0 && s1 <= 1.0 && v1 >= 0.0 && v2 <= 1.0);
1257 if (st->psychedelic_flag) {
1258 h1 = RAND(360); h2 = (h1 + 180) % 360;
1260 h1 = h2 = RAND(360);
1263 make_color_ramp (st->dpy, st->cmap,
1264 h1, s1, v1, h2, s2, v2,
1265 colors, ncolors, False, True, False);
1267 flags = GCForeground;
1268 for (i=0; i < *ncolors; i++) {
1269 gcv.foreground = colors[i].pixel;
1270 if (gcs[i]) XFreeGC (st->dpy, gcs[i]);
1271 gcs[i] = XCreateGC (st->dpy, st->dbuf, flags, &gcv);
1279 * perform the color changing bonus. New colors are allocated for the
1280 * walls and bonuses, and if the 'psychedelic' option is set then new
1281 * colors are also chosen for the ground.
1284 change_colors (struct state *st)
1288 if (st->psychedelic_flag) {
1289 free_colors (st->dpy, st->cmap, st->bonus_colors, st->nr_bonus_colors);
1290 free_colors (st->dpy, st->cmap, st->wall_colors, st->nr_wall_colors);
1291 free_colors (st->dpy, st->cmap, st->ground_colors, st->nr_ground_colors);
1294 st->ncolors = MAX_COLORS;
1295 speedmine_color_ramp (st, st->ground_gcs, st->ground_colors,
1296 &st->ncolors, 0.0, 0.8, 0.0, 0.9);
1297 st->nr_ground_colors = st->ncolors;
1299 free_colors (st->dpy, st->cmap, st->bonus_colors, st->nr_bonus_colors);
1300 free_colors (st->dpy, st->cmap, st->wall_colors, st->nr_wall_colors);
1301 st->ncolors = st->nr_ground_colors;
1306 st->ncolors = MAX_COLORS;
1307 speedmine_color_ramp (st, st->wall_gcs, st->wall_colors, &st->ncolors,
1309 st->nr_wall_colors = st->ncolors;
1311 st->ncolors = MAX_COLORS;
1312 speedmine_color_ramp (st, st->bonus_gcs, st->bonus_colors, &st->ncolors,
1313 0.6, 0.9, 0.4, 1.0);
1314 st->nr_bonus_colors = st->ncolors;
1318 * init_psychedelic_colors (dpy, window, cmap)
1320 * initialise a psychedelic colormap
1323 init_psychedelic_colors (struct state *st)
1327 gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "tunnelend", "TunnelEnd");
1328 st->tunnelend_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
1330 st->ncolors = MAX_COLORS;
1331 speedmine_color_ramp (st, st->ground_gcs, st->ground_colors, &st->ncolors,
1332 0.0, 0.8, 0.0, 0.9);
1333 st->nr_ground_colors = st->ncolors;
1335 st->ncolors = MAX_COLORS;
1336 speedmine_color_ramp (st, st->wall_gcs, st->wall_colors, &st->ncolors,
1337 0.0, 0.6, 0.0, 0.9);
1338 st->nr_wall_colors = st->ncolors;
1340 st->ncolors = MAX_COLORS;
1341 speedmine_color_ramp (st, st->bonus_gcs, st->bonus_colors, &st->ncolors,
1342 0.6, 0.9, 0.4, 1.0);
1343 st->nr_bonus_colors = st->ncolors;
1347 * init_colors (dpy, window, cmap)
1349 * initialise a normal colormap
1352 init_colors (struct state *st)
1357 double s1, s2, v1, v2;
1358 unsigned long flags;
1361 gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "tunnelend", "TunnelEnd");
1362 st->tunnelend_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
1364 st->ncolors = MAX_COLORS;
1366 dark.pixel = get_pixel_resource (st->dpy, st->cmap, "darkground", "DarkGround");
1367 XQueryColor (st->dpy, st->cmap, &dark);
1369 light.pixel = get_pixel_resource (st->dpy, st->cmap, "lightground", "LightGround");
1370 XQueryColor (st->dpy, st->cmap, &light);
1372 rgb_to_hsv (dark.red, dark.green, dark.blue, &h1, &s1, &v1);
1373 rgb_to_hsv (light.red, light.green, light.blue, &h2, &s2, &v2);
1374 make_color_ramp (st->dpy, st->cmap, h1, s1, v1, h2, s2, v2,
1375 st->ground_colors, &st->ncolors, False, True, False);
1376 st->nr_ground_colors = st->ncolors;
1378 flags = GCForeground;
1379 for (i=0; i < st->ncolors; i++) {
1380 gcv.foreground = st->ground_colors[i].pixel;
1381 st->ground_gcs[i] = XCreateGC (st->dpy, st->dbuf, flags, &gcv);
1384 st->ncolors = MAX_COLORS;
1385 speedmine_color_ramp (st, st->wall_gcs, st->wall_colors, &st->ncolors,
1386 0.0, 0.6, 0.0, 0.9);
1387 st->nr_wall_colors = st->ncolors;
1389 st->ncolors = MAX_COLORS;
1390 speedmine_color_ramp (st, st->bonus_gcs, st->bonus_colors, &st->ncolors,
1391 0.6, 0.9, 0.4, 1.0);
1392 st->nr_bonus_colors = st->ncolors;
1398 * print out average FPS stats for the demo
1402 print_stats (struct state *st)
1404 if (st->total_nframes >= 1)
1405 printf ("Rendered %d frames averaging %f FPS\n", st->total_nframes,
1406 st->total_nframes / get_time(st));
1411 * init_speedmine (dpy, window)
1413 * initialise the demo
1416 speedmine_init (Display *dpy, Window window)
1418 struct state *st = (struct state *) calloc (1, sizeof(*st));
1420 XWindowAttributes xgwa;
1426 st->window = window;
1429 st->accel = 0.00000001;
1430 st->direction = FORWARDS;
1431 st->orientation = (17*ROTS)/22;
1433 XGetWindowAttributes (st->dpy, st->window, &xgwa);
1434 st->cmap = xgwa.colormap;
1435 st->width = xgwa.width;
1436 st->height = xgwa.height;
1438 st->verbose_flag = get_boolean_resource (st->dpy, "verbose", "Boolean");
1440 # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */
1441 st->dbuf = st->window;
1443 st->dbuf = XCreatePixmap (st->dpy, st->window, st->width, st->height, xgwa.depth);
1445 st->stars_mask = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1);
1447 gcv.foreground = st->default_fg_pixel =
1448 get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
1449 st->draw_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
1451 st->stars_gc = XCreateGC (st->dpy, st->stars_mask, GCForeground, &gcv);
1453 gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
1454 st->erase_gc = XCreateGC (st->dpy, st->dbuf, GCForeground, &gcv);
1456 st->stars_erase_gc = XCreateGC (st->dpy, st->stars_mask, GCForeground, &gcv);
1458 st->wire_flag = get_boolean_resource (st->dpy, "wire", "Boolean");
1460 st->psychedelic_flag = get_boolean_resource (st->dpy, "psychedelic", "Boolean");
1462 st->delay = get_integer_resource(st->dpy, "delay", "Integer");
1464 st->smoothness = get_integer_resource(st->dpy, "smoothness", "Integer");
1465 if (st->smoothness < 1) st->smoothness = 1;
1467 st->maxspeed = get_float_resource(st->dpy, "maxspeed", "Float");
1468 st->maxspeed *= 0.01;
1469 st->maxspeed = fabs(st->maxspeed);
1471 st->thrust = get_float_resource(st->dpy, "thrust", "Float");
1474 st->gravity = get_float_resource(st->dpy, "gravity", "Float");
1475 st->gravity *= 0.002/9.8;
1477 st->vertigo = get_float_resource(st->dpy, "vertigo", "Float");
1480 st->curviness = get_float_resource(st->dpy, "curviness", "Float");
1481 st->curviness *= 0.25;
1483 st->twistiness = get_float_resource(st->dpy, "twistiness", "Float");
1484 st->twistiness *= 0.125;
1486 st->terrain_flag = get_boolean_resource (st->dpy, "terrain", "Boolean");
1487 st->widening_flag = get_boolean_resource (st->dpy, "widening", "Boolean");
1488 st->bumps_flag = get_boolean_resource (st->dpy, "bumps", "Boolean");
1489 st->bonuses_flag = get_boolean_resource (st->dpy, "bonuses", "Boolean");
1490 st->crosshair_flag = get_boolean_resource (st->dpy, "crosshair", "Boolean");
1492 st->be_wormy = get_boolean_resource (st->dpy, "worm", "Boolean");
1494 st->maxspeed *= 1.43;
1498 st->smoothness *= 2;
1500 st->twistiness *= 2;
1501 st->psychedelic_flag = True;
1502 st->crosshair_flag = False;
1505 if (st->psychedelic_flag) init_psychedelic_colors (st);
1506 else init_colors (st);
1508 for (i=0; i<ROTS; i++) {
1509 th = M_PI * 2.0 * i / ROTS;
1510 st->costab[i] = cos(th);
1511 st->sintab[i] = sin(th);
1514 wide = random_wideness();
1516 for (i=0; i < TERRAIN_LENGTH; i++) {
1517 st->wideness[i] = wide;
1523 wrap_tunnel (st, 0, TERRAIN_LENGTH-1);
1526 if (DEBUG_FLAG || st->verbose_flag) atexit(print_stats);
1529 st->step = effective_speed;
1538 speedmine_reshape (Display *dpy, Window window, void *closure,
1539 unsigned int w, unsigned int h)
1541 struct state *st = (struct state *) closure;
1544 if (st->dbuf != st->window) {
1545 XWindowAttributes xgwa;
1546 XGetWindowAttributes (st->dpy, st->window, &xgwa);
1547 XFreePixmap (dpy, st->dbuf);
1548 st->dbuf = XCreatePixmap (st->dpy, st->window,
1549 st->width, st->height, xgwa.depth);
1554 speedmine_event (Display *dpy, Window window, void *closure, XEvent *event)
1560 speedmine_free (Display *dpy, Window window, void *closure)
1562 struct state *st = (struct state *) closure;
1569 * Down the speedmine, you'll find speed
1570 * to satisfy your moving needs;
1571 * So if you're looking for a blast
1572 * then hit the speedmine, really fast.
1576 * Speedworm likes to choke and spit
1577 * and chase his tail, and dance a bit
1578 * he really is a funky friend;
1579 * he's made of speed from end to end.
1583 static const char *speedmine_defaults [] = {
1587 ".background: black",
1588 ".foreground: white",
1589 "*darkground: #101010",
1590 "*lightground: #a0a0a0",
1591 "*tunnelend: #000000",
1605 "*psychedelic: False",
1609 static XrmOptionDescRec speedmine_options [] = {
1610 { "-verbose", ".verbose", XrmoptionNoArg, "True"},
1611 { "-worm", ".worm", XrmoptionNoArg, "True"},
1612 { "-wireframe", ".wire", XrmoptionNoArg, "True"},
1613 { "-no-wireframe", ".wire", XrmoptionNoArg, "False"},
1614 { "-darkground", ".darkground", XrmoptionSepArg, 0 },
1615 { "-lightground", ".lightground", XrmoptionSepArg, 0 },
1616 { "-tunnelend", ".tunnelend", XrmoptionSepArg, 0 },
1617 { "-delay", ".delay", XrmoptionSepArg, 0 },
1618 { "-maxspeed", ".maxspeed", XrmoptionSepArg, 0 },
1619 { "-thrust", ".thrust", XrmoptionSepArg, 0 },
1620 { "-gravity", ".gravity", XrmoptionSepArg, 0 },
1621 { "-vertigo", ".vertigo", XrmoptionSepArg, 0 },
1622 { "-terrain", ".terrain", XrmoptionNoArg, "True"},
1623 { "-no-terrain", ".terrain", XrmoptionNoArg, "False"},
1624 { "-smoothness", ".smoothness", XrmoptionSepArg, 0 },
1625 { "-curviness", ".curviness", XrmoptionSepArg, 0 },
1626 { "-twistiness", ".twistiness", XrmoptionSepArg, 0 },
1627 { "-widening", ".widening", XrmoptionNoArg, "True"},
1628 { "-no-widening", ".widening", XrmoptionNoArg, "False"},
1629 { "-bumps", ".bumps", XrmoptionNoArg, "True"},
1630 { "-no-bumps", ".bumps", XrmoptionNoArg, "False"},
1631 { "-bonuses", ".bonuses", XrmoptionNoArg, "True"},
1632 { "-no-bonuses", ".bonuses", XrmoptionNoArg, "False"},
1633 { "-crosshair", ".crosshair", XrmoptionNoArg, "True"},
1634 { "-no-crosshair", ".crosshair", XrmoptionNoArg, "False"},
1635 { "-psychedelic", ".psychedelic", XrmoptionNoArg, "True"},
1636 { "-no-psychedelic", ".psychedelic", XrmoptionNoArg, "False"},
1641 XSCREENSAVER_MODULE ("SpeedMine", speedmine)