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 */
51 /*#include <assert.h>*/
57 #include "screenhack.h"
60 #define MIN(a,b) ((a)<(b)?(a):(b))
61 #define MAX(a,b) ((a)>(b)?(a):(b))
63 #define RAND(r) (int)(((r)>0)?(random() % (long)(r)): -(random() % (long)(-r)))
65 #define SIGN3(a) ((a)>0?1:((a)<0?-1:0))
67 #define MODULO(a,b) while ((a)<0) (a)+=(b); (a) %= (b);
69 /* No. of shades of each color (ground, walls, bonuses) */
76 /* Apparently AIX's math.h bogusly defines `nearest' as a function,
77 in violation of the ANSI C spec. */
79 #define nearest n3arest
81 #define wireframe (st->wire_flag||st->wire_bonus>8||st->wire_bonus%2==1)
82 #define effective_speed (st->direction*(st->speed+st->speed_bonus))
84 /* No. of levels of interpolation, for perspective */
87 /* These must be powers of 2 */
88 #define TERRAIN_LENGTH 256
89 #define TERRAIN_BREADTH 32
91 /* total "perspective distance" of terrain */
92 #define TERRAIN_PDIST (INTERP*TERRAIN_LENGTH)
95 #define TB_MUL (ROTS/TERRAIN_BREADTH)
97 #define random_elevation() (st->terrain_flag?(random() % 200):0)
98 #define random_curvature() (st->curviness>0.0?((double)(random() % 40)-20)*st->curviness:0.0)
99 #define random_twist() (st->twistiness>0.0?((double)(random() % 40)-20)*st->twistiness:0.0)
100 #define random_wideness() (st->widening_flag?(int)(random() % 1200):0)
102 #define STEEL_ELEVATION 300
108 Pixmap dbuf, stars_mask;
112 unsigned int default_fg_pixel;
113 GC draw_gc, erase_gc, tunnelend_gc, stars_gc, stars_erase_gc;
115 int ncolors, nr_ground_colors, nr_wall_colors, nr_bonus_colors;
116 XColor ground_colors[MAX_COLORS], wall_colors[MAX_COLORS];
117 XColor bonus_colors[MAX_COLORS];
118 GC ground_gcs[MAX_COLORS], wall_gcs[MAX_COLORS], bonus_gcs[MAX_COLORS];
133 int psychedelic_flag;
137 double thrust, gravity;
152 int xoffset, yoffset;
162 double sintab[ROTS], costab[ROTS];
166 int terrain[TERRAIN_LENGTH][TERRAIN_BREADTH];
167 double xcurvature[TERRAIN_LENGTH];
168 double ycurvature[TERRAIN_LENGTH];
169 double zcurvature[TERRAIN_LENGTH];
170 int wideness[TERRAIN_LENGTH];
171 int bonuses[TERRAIN_LENGTH];
172 int xvals[TERRAIN_LENGTH][TERRAIN_BREADTH];
173 int yvals[TERRAIN_LENGTH][TERRAIN_BREADTH];
174 double worldx[TERRAIN_LENGTH][TERRAIN_BREADTH];
175 double worldy[TERRAIN_LENGTH][TERRAIN_BREADTH];
176 int minx[TERRAIN_LENGTH], maxx[TERRAIN_LENGTH];
177 int miny[TERRAIN_LENGTH], maxy[TERRAIN_LENGTH];
182 double fps_start, fps_end;
183 struct timeval start_time;
189 /* a forward declaration ... */
190 static void change_colors(struct state *st);
197 * returns the total time elapsed since the beginning of the demo
199 static double get_time(struct state *st) {
202 #if GETTIMEOFDAY_TWO_ARGS
203 gettimeofday(&t, NULL);
207 t.tv_sec -= st->start_time.tv_sec;
208 f = ((double)t.tv_sec) + t.tv_usec*1e-6;
215 * initialises the timing structures
217 static void init_time(struct state *st) {
218 #if GETTIMEOFDAY_TWO_ARGS
219 gettimeofday(&st->start_time, NULL);
221 gettimeofday(&st->start_time);
223 st->fps_start = get_time(st);
230 * perspective map the world coordinates worldx[i][j], worldy[i][j] onto
231 * screen coordinates xvals[t][j], yvals[t][j]
234 perspective (struct state *st)
236 int i, j, jj, t=0, depth, view_pos;
237 int rotation_bias, r;
238 double xc=0.0, yc=0.0, zc=0.0;
239 double xcc=0.0, ycc=0.0, zcc=0.0;
243 zf = 8.0*28.0 / (double)(st->width*TERRAIN_LENGTH);
244 if (st->be_wormy) zf *= 3.0;
246 depth = TERRAIN_PDIST - INTERP + st->pindex;
248 view_pos = (st->nearest+3*TERRAIN_LENGTH/4)%TERRAIN_LENGTH;
250 st->xoffset += - st->xcurvature[view_pos]*st->curviness/8;
253 st->yoffset += - st->ycurvature[view_pos]*st->curviness/4;
256 st->rotation_offset += (int)((st->zcurvature[view_pos]-st->zcurvature[st->nearest])*ROTS/8);
257 st->rotation_offset /= 2;
258 rotation_bias = st->orientation + st->spin_bonus - st->rotation_offset;
260 if (st->bumps_flag) {
262 st->yoffset -= ((st->terrain[view_pos][TERRAIN_BREADTH/4] * st->width /(8*1600)));
263 rotation_bias += (st->terrain[view_pos][TERRAIN_BREADTH/4+2] -
264 st->terrain[view_pos][TERRAIN_BREADTH/4-2])/8;
266 st->yoffset -= ((st->terrain[view_pos][TERRAIN_BREADTH/4] * st->width /(2*1600)));
267 rotation_bias += (st->terrain[view_pos][TERRAIN_BREADTH/4+2] -
268 st->terrain[view_pos][TERRAIN_BREADTH/4-2])/16;
272 MODULO(rotation_bias, ROTS);
274 for (t=0; t < TERRAIN_LENGTH; t++) {
275 i = st->nearest + t; MODULO(i, TERRAIN_LENGTH);
276 xc += st->xcurvature[i]; yc += st->ycurvature[i]; zc += st->zcurvature[i];
277 xcc += xc; ycc += yc; zcc += zc;
278 st->maxx[i] = st->maxy[i] = 0;
279 st->minx[i] = st->width; st->miny[i] = st->height;
282 for (t=0; t < TERRAIN_LENGTH; t++) {
283 i = st->nearest - 1 - t; MODULO(i, TERRAIN_LENGTH);
285 zfactor = (double)depth* (12.0 - TERRAIN_LENGTH/8.0) * zf;
286 for (j=0; j < TERRAIN_BREADTH; j++) {
287 jj = st->direction * j; MODULO(jj, TERRAIN_BREADTH);
288 /* jwz: not totally sure if this is right, but it avoids div0 */
290 xx = (st->worldx[i][jj]-(st->vertigo*xcc))/zfactor;
291 yy = (st->worldy[i][j]-(st->vertigo*ycc))/zfactor;
296 r = rotation_bias + (int)(st->vertigo*zcc); MODULO(r, ROTS);
298 st->xvals[t][j] = st->xoffset + (st->width>>1) +
299 (int)(xx * st->costab[r] - yy * st->sintab[r]);
300 st->maxx[t] = MAX(st->maxx[t], st->xvals[t][j]);
301 st->minx[t] = MIN(st->minx[t], st->xvals[t][j]);
303 st->yvals[t][j] = st->yoffset + st->height/2 +
304 (int)(xx * st->sintab[r] + yy * st->costab[r]);
305 st->maxy[t] = MAX(st->maxy[t], st->yvals[t][j]);
306 st->miny[t] = MIN(st->miny[t], st->yvals[t][j]);
308 xcc -= xc; ycc -= yc; zcc -= zc;
309 xc -= st->xcurvature[i]; yc -= st->ycurvature[i]; zc -= st->zcurvature[i];
315 * wrap_tunnel (start, end)
317 * wrap the terrain terrain[i][j] around the semi-circular tunnel function
319 * x' = x/2 * cos(theta) - (y-k) * x * sin(theta)
320 * y' = x/4 * sin(theta) + y * cos(theta)
322 * between i=start and i=end inclusive, producing world coordinates
323 * worldx[i][j], worldy[i][j]
326 wrap_tunnel (struct state *st, int start, int end)
331 assert (start < end);
333 for (i=start; i <= end; i++) {
334 for (j=0; j < TERRAIN_BREADTH; j++) {
335 x = j * (1.0/TERRAIN_BREADTH);
336 v = st->terrain[i][j];
337 y = (double)(v==STEEL_ELEVATION?200:v) - st->wideness[i] - 1200;
340 if (j > TERRAIN_BREADTH/8 && j < 3*TERRAIN_BREADTH/8) y -= 300;
342 st->worldx[i][j] = x/2 * st->costab[j*TB_MUL] -
343 (y-st->height/4.0)*x*st->sintab[j*TB_MUL];
344 st->worldy[i][j] = x/4 * st->sintab[j*TB_MUL] +
345 y * st->costab[j*TB_MUL];
353 * perform the state transitions and terrain transformation for the
354 * "look backwards/look forwards" bonus
357 flip_direction (struct state *st)
361 st->direction = -st->direction;
363 st->bonus_bright = 20;
365 for (i=0; i < TERRAIN_LENGTH; i++) {
366 in = st->nearest + i; MODULO(in, TERRAIN_BREADTH);
367 ip = st->nearest - i; MODULO(ip, TERRAIN_BREADTH);
368 for (j=0; j < TERRAIN_BREADTH; j++) {
369 t = st->terrain[ip][j];
370 st->terrain[ip][j] = st->terrain[in][j];
371 st->terrain[in][j] = t;
377 * generate_smooth (start, end)
379 * generate smooth terrain between i=start and i=end inclusive
382 generate_smooth (struct state *st, int start, int end)
386 assert (start < end);
388 for (i=start; i <= end; i++) {
389 ii = i; MODULO(ii, TERRAIN_LENGTH);
390 for (j=0; j < TERRAIN_BREADTH; j++) {
391 st->terrain[i][j] = STEEL_ELEVATION;
397 * generate_straight (start, end)
399 * zero the curvature and wideness between i=start and i=end inclusive
402 generate_straight (struct state *st, int start, int end)
406 assert (start < end);
408 for (i=start; i <= end; i++) {
409 ii = i; MODULO(ii, TERRAIN_LENGTH);
410 for (j=0; j < TERRAIN_BREADTH; j++) {
411 st->xcurvature[ii] = 0;
412 st->ycurvature[ii] = 0;
413 st->zcurvature[ii] = 0;
414 st->wideness[ii] = 0;
420 * int generate_terrain_value (v1, v2, v3, v4, w)
422 * generate terrain value near the average of v1, v2, v3, v4, with
423 * perturbation proportional to w
426 generate_terrain_value (struct state *st, int v1, int v2, int v3, int v4, int w)
431 if (!st->terrain_flag) return 0;
433 sum = v1 + v2 + v3 + v4;
435 rval = w*sum/st->smoothness;
436 if (rval == 0) rval = 2;
438 ret = (sum/4 -(rval/2) + RAND(rval));
440 if (ret < -400 || ret > 400) {
448 * generate_terrain (start, end, final)
450 * generate terrain[i][j] between i=start and i=end inclusive
452 * This is performed by successive subdivision of the terrain into
453 * rectangles of decreasing size. Subdivision continues until the
454 * the minimum width or height of these rectangles is 'final'; ie.
455 * final=1 indicates to subdivide as far as possible, final=2 indicates
456 * to stop one subdivision before that (leaving a checkerboard pattern
460 generate_terrain (struct state *st, int start, int end, int final)
463 int ip, jp, in, jn; /* prev, next values */
466 assert (start < end);
467 assert (start >= 0 && start < TERRAIN_LENGTH);
468 assert (end >= 0 && end < TERRAIN_LENGTH);
470 diff = end - start + 1;
472 st->terrain[end][0] = random_elevation();
473 st->terrain[end][TERRAIN_BREADTH/2] = random_elevation();
475 for (w= diff/2, l=TERRAIN_BREADTH/4;
476 w >= final || l >= final; w /= 2, l /= 2) {
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->screen, st->visual, 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->screen, st->cmap, st->bonus_colors, st->nr_bonus_colors);
1290 free_colors (st->screen, st->cmap, st->wall_colors, st->nr_wall_colors);
1291 free_colors (st->screen, 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->screen, st->cmap, st->bonus_colors, st->nr_bonus_colors);
1300 free_colors (st->screen, 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->screen, st->visual, st->cmap,
1375 h1, s1, v1, h2, s2, v2,
1376 st->ground_colors, &st->ncolors, False, True, False);
1377 st->nr_ground_colors = st->ncolors;
1379 flags = GCForeground;
1380 for (i=0; i < st->ncolors; i++) {
1381 gcv.foreground = st->ground_colors[i].pixel;
1382 st->ground_gcs[i] = XCreateGC (st->dpy, st->dbuf, flags, &gcv);
1385 st->ncolors = MAX_COLORS;
1386 speedmine_color_ramp (st, st->wall_gcs, st->wall_colors, &st->ncolors,
1387 0.0, 0.6, 0.0, 0.9);
1388 st->nr_wall_colors = st->ncolors;
1390 st->ncolors = MAX_COLORS;
1391 speedmine_color_ramp (st, st->bonus_gcs, st->bonus_colors, &st->ncolors,
1392 0.6, 0.9, 0.4, 1.0);
1393 st->nr_bonus_colors = st->ncolors;
1399 * print out average FPS stats for the demo
1403 print_stats (struct state *st)
1405 if (st->total_nframes >= 1)
1406 printf ("Rendered %d frames averaging %f FPS\n", st->total_nframes,
1407 st->total_nframes / get_time(st));
1412 * init_speedmine (dpy, window)
1414 * initialise the demo
1417 speedmine_init (Display *dpy, Window window)
1419 struct state *st = (struct state *) calloc (1, sizeof(*st));
1421 XWindowAttributes xgwa;
1427 st->window = window;
1430 st->accel = 0.00000001;
1431 st->direction = FORWARDS;
1432 st->orientation = (17*ROTS)/22;
1434 XGetWindowAttributes (st->dpy, st->window, &xgwa);
1435 st->cmap = xgwa.colormap;
1436 st->visual = xgwa.visual;
1437 st->screen = xgwa.screen;
1438 st->width = xgwa.width;
1439 st->height = xgwa.height;
1441 st->verbose_flag = get_boolean_resource (st->dpy, "verbose", "Boolean");
1443 # ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */
1444 st->dbuf = st->window;
1446 st->dbuf = XCreatePixmap (st->dpy, st->window, st->width, st->height, xgwa.depth);
1448 st->stars_mask = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1);
1450 gcv.foreground = st->default_fg_pixel =
1451 get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
1452 st->draw_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
1454 st->stars_gc = XCreateGC (st->dpy, st->stars_mask, GCForeground, &gcv);
1456 gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
1457 st->erase_gc = XCreateGC (st->dpy, st->dbuf, GCForeground, &gcv);
1459 st->stars_erase_gc = XCreateGC (st->dpy, st->stars_mask, GCForeground, &gcv);
1461 st->wire_flag = get_boolean_resource (st->dpy, "wire", "Boolean");
1463 st->psychedelic_flag = get_boolean_resource (st->dpy, "psychedelic", "Boolean");
1465 st->delay = get_integer_resource(st->dpy, "delay", "Integer");
1467 st->smoothness = get_integer_resource(st->dpy, "smoothness", "Integer");
1468 if (st->smoothness < 1) st->smoothness = 1;
1470 st->maxspeed = get_float_resource(st->dpy, "maxspeed", "Float");
1471 st->maxspeed *= 0.01;
1472 st->maxspeed = fabs(st->maxspeed);
1474 st->thrust = get_float_resource(st->dpy, "thrust", "Float");
1477 st->gravity = get_float_resource(st->dpy, "gravity", "Float");
1478 st->gravity *= 0.002/9.8;
1480 st->vertigo = get_float_resource(st->dpy, "vertigo", "Float");
1483 st->curviness = get_float_resource(st->dpy, "curviness", "Float");
1484 st->curviness *= 0.25;
1486 st->twistiness = get_float_resource(st->dpy, "twistiness", "Float");
1487 st->twistiness *= 0.125;
1489 st->terrain_flag = get_boolean_resource (st->dpy, "terrain", "Boolean");
1490 st->widening_flag = get_boolean_resource (st->dpy, "widening", "Boolean");
1491 st->bumps_flag = get_boolean_resource (st->dpy, "bumps", "Boolean");
1492 st->bonuses_flag = get_boolean_resource (st->dpy, "bonuses", "Boolean");
1493 st->crosshair_flag = get_boolean_resource (st->dpy, "crosshair", "Boolean");
1495 st->be_wormy = get_boolean_resource (st->dpy, "worm", "Boolean");
1497 st->maxspeed *= 1.43;
1501 st->smoothness *= 2;
1503 st->twistiness *= 2;
1504 st->psychedelic_flag = True;
1505 st->crosshair_flag = False;
1508 if (st->psychedelic_flag) init_psychedelic_colors (st);
1509 else init_colors (st);
1511 for (i=0; i<ROTS; i++) {
1512 th = M_PI * 2.0 * i / ROTS;
1513 st->costab[i] = cos(th);
1514 st->sintab[i] = sin(th);
1517 wide = random_wideness();
1519 for (i=0; i < TERRAIN_LENGTH; i++) {
1520 st->wideness[i] = wide;
1526 wrap_tunnel (st, 0, TERRAIN_LENGTH-1);
1529 if (DEBUG_FLAG || st->verbose_flag) atexit(print_stats);
1532 st->step = effective_speed;
1541 speedmine_reshape (Display *dpy, Window window, void *closure,
1542 unsigned int w, unsigned int h)
1544 struct state *st = (struct state *) closure;
1547 if (st->dbuf != st->window) {
1548 XWindowAttributes xgwa;
1549 XGetWindowAttributes (st->dpy, st->window, &xgwa);
1550 XFreePixmap (dpy, st->dbuf);
1551 st->dbuf = XCreatePixmap (st->dpy, st->window,
1552 st->width, st->height, xgwa.depth);
1557 speedmine_event (Display *dpy, Window window, void *closure, XEvent *event)
1563 speedmine_free (Display *dpy, Window window, void *closure)
1565 struct state *st = (struct state *) closure;
1572 * Down the speedmine, you'll find speed
1573 * to satisfy your moving needs;
1574 * So if you're looking for a blast
1575 * then hit the speedmine, really fast.
1579 * Speedworm likes to choke and spit
1580 * and chase his tail, and dance a bit
1581 * he really is a funky friend;
1582 * he's made of speed from end to end.
1586 static const char *speedmine_defaults [] = {
1590 ".background: black",
1591 ".foreground: white",
1592 "*darkground: #101010",
1593 "*lightground: #a0a0a0",
1594 "*tunnelend: #000000",
1608 "*psychedelic: False",
1612 static XrmOptionDescRec speedmine_options [] = {
1613 { "-verbose", ".verbose", XrmoptionNoArg, "True"},
1614 { "-worm", ".worm", XrmoptionNoArg, "True"},
1615 { "-wireframe", ".wire", XrmoptionNoArg, "True"},
1616 { "-no-wireframe", ".wire", XrmoptionNoArg, "False"},
1617 { "-darkground", ".darkground", XrmoptionSepArg, 0 },
1618 { "-lightground", ".lightground", XrmoptionSepArg, 0 },
1619 { "-tunnelend", ".tunnelend", XrmoptionSepArg, 0 },
1620 { "-delay", ".delay", XrmoptionSepArg, 0 },
1621 { "-maxspeed", ".maxspeed", XrmoptionSepArg, 0 },
1622 { "-thrust", ".thrust", XrmoptionSepArg, 0 },
1623 { "-gravity", ".gravity", XrmoptionSepArg, 0 },
1624 { "-vertigo", ".vertigo", XrmoptionSepArg, 0 },
1625 { "-terrain", ".terrain", XrmoptionNoArg, "True"},
1626 { "-no-terrain", ".terrain", XrmoptionNoArg, "False"},
1627 { "-smoothness", ".smoothness", XrmoptionSepArg, 0 },
1628 { "-curviness", ".curviness", XrmoptionSepArg, 0 },
1629 { "-twistiness", ".twistiness", XrmoptionSepArg, 0 },
1630 { "-widening", ".widening", XrmoptionNoArg, "True"},
1631 { "-no-widening", ".widening", XrmoptionNoArg, "False"},
1632 { "-bumps", ".bumps", XrmoptionNoArg, "True"},
1633 { "-no-bumps", ".bumps", XrmoptionNoArg, "False"},
1634 { "-bonuses", ".bonuses", XrmoptionNoArg, "True"},
1635 { "-no-bonuses", ".bonuses", XrmoptionNoArg, "False"},
1636 { "-crosshair", ".crosshair", XrmoptionNoArg, "True"},
1637 { "-no-crosshair", ".crosshair", XrmoptionNoArg, "False"},
1638 { "-psychedelic", ".psychedelic", XrmoptionNoArg, "True"},
1639 { "-no-psychedelic", ".psychedelic", XrmoptionNoArg, "False"},
1644 XSCREENSAVER_MODULE ("SpeedMine", speedmine)