Index: xscreensaver-4.02/hacks/speedmine.c
diff -c xscreensaver-4.02/hacks/speedmine.c:1.1 xscreensaver-3.33/hacks/speedmine.c:1.2
*** xscreensaver-3.33/hacks/speedmine.c:1.1	Thu Oct  4 11:02:27 2001
--- xscreensaver-3.33/hacks/speedmine.c	Thu Oct  4 11:04:35 2001
***************
*** 32,38 ****
   * 			i	iterates along the tunnel in the direction of travel
   * 			j	iterates around the tunnel clockwise
   * 			t	iterates along the length of the perspective mapped values
!  * 				from the furthest to the nearest
   *
   * Thus, the buffers are used with these iterators:
   *
--- 32,38 ----
   * 			i	iterates along the tunnel in the direction of travel
   * 			j	iterates around the tunnel clockwise
   * 			t	iterates along the length of the perspective mapped values
!  * 				from the furthest to the closest
   *
   * Thus, the buffers are used with these iterators:
   *
***************
*** 116,122 ****
  #define BACKWARDS -1
  static int direction = FORWARDS;
  
! static int pindex=0, nearest=0;
  static int flipped_at=0;
  static int xoffset=0, yoffset=0;
  
--- 116,122 ----
  #define BACKWARDS -1
  static int direction = FORWARDS;
  
! static int pindex=0, closest=0;
  static int flipped_at=0;
  static int xoffset=0, yoffset=0;
  
***************
*** 232,238 ****
  
  	depth = TERRAIN_PDIST - INTERP + pindex;
  
! 	view_pos = (nearest+3*TERRAIN_LENGTH/4)%TERRAIN_LENGTH;
  	
  	xoffset += - xcurvature[view_pos]*curviness/8;
  	xoffset /= 2;
--- 232,238 ----
  
  	depth = TERRAIN_PDIST - INTERP + pindex;
  
! 	view_pos = (closest+3*TERRAIN_LENGTH/4)%TERRAIN_LENGTH;
  	
  	xoffset += - xcurvature[view_pos]*curviness/8;
  	xoffset /= 2;
***************
*** 240,246 ****
  	yoffset += - ycurvature[view_pos]*curviness/4;
  	yoffset /= 2;
  
! 	rotation_offset += (int)((zcurvature[view_pos]-zcurvature[nearest])*ROTS/8);
  	rotation_offset /= 2;
  	rotation_bias = orientation + spin_bonus - rotation_offset;
  
--- 240,246 ----
  	yoffset += - ycurvature[view_pos]*curviness/4;
  	yoffset /= 2;
  
! 	rotation_offset += (int)((zcurvature[view_pos]-zcurvature[closest])*ROTS/8);
  	rotation_offset /= 2;
  	rotation_bias = orientation + spin_bonus - rotation_offset;
  
***************
*** 259,265 ****
  	MODULO(rotation_bias, ROTS);
  
  	for (t=0; t < TERRAIN_LENGTH; t++) {
! 		i = nearest + t; MODULO(i, TERRAIN_LENGTH);
  		xc += xcurvature[i]; yc += ycurvature[i]; zc += zcurvature[i];
  		xcc += xc; ycc += yc; zcc += zc;
  		maxx[i] = maxy[i] = 0;
--- 259,265 ----
  	MODULO(rotation_bias, ROTS);
  
  	for (t=0; t < TERRAIN_LENGTH; t++) {
! 		i = closest + t; MODULO(i, TERRAIN_LENGTH);
  		xc += xcurvature[i]; yc += ycurvature[i]; zc += zcurvature[i];
  		xcc += xc; ycc += yc; zcc += zc;
  		maxx[i] = maxy[i] = 0;
***************
*** 267,273 ****
  	}
  
  	for (t=0; t < TERRAIN_LENGTH; t++) {
! 		i = nearest - 1 - t; MODULO(i, TERRAIN_LENGTH);
  
  		zfactor = (double)depth* (12.0 - TERRAIN_LENGTH/8.0) * zf;
  		for (j=0; j < TERRAIN_BREADTH; j++) {
--- 267,273 ----
  	}
  
  	for (t=0; t < TERRAIN_LENGTH; t++) {
! 		i = closest - 1 - t; MODULO(i, TERRAIN_LENGTH);
  
  		zfactor = (double)depth* (12.0 - TERRAIN_LENGTH/8.0) * zf;
  		for (j=0; j < TERRAIN_BREADTH; j++) {
***************
*** 345,352 ****
  	bonus_bright = 20;
  
  	for (i=0; i < TERRAIN_LENGTH; i++) {
! 		in = nearest + i; MODULO(in, TERRAIN_BREADTH);
! 		ip = nearest - i; MODULO(ip, TERRAIN_BREADTH);
  		for (j=0; j < TERRAIN_BREADTH; j++) {
  			t = terrain[ip][j];
  			terrain[ip][j] = terrain[in][j];
--- 345,352 ----
  	bonus_bright = 20;
  
  	for (i=0; i < TERRAIN_LENGTH; i++) {
! 		in = closest + i; MODULO(in, TERRAIN_BREADTH);
! 		ip = closest - i; MODULO(ip, TERRAIN_BREADTH);
  		for (j=0; j < TERRAIN_BREADTH; j++) {
  			t = terrain[ip][j];
  			terrain[ip][j] = terrain[in][j];
***************
*** 598,604 ****
  
  	if (jamming > 0) {
  		jamming--;
! 		nearest -= 2; MODULO(nearest, TERRAIN_LENGTH);
  		return;
  	}
  
--- 598,604 ----
  
  	if (jamming > 0) {
  		jamming--;
! 		closest -= 2; MODULO(closest, TERRAIN_LENGTH);
  		return;
  	}
  
***************
*** 618,624 ****
  		spin_bonus -= ROTS;
  		break;
  	case 4: /* look backwards / look forwards */
! 		flipped_at = nearest;
  		flip_direction ();
  		backwards_bonus = (backwards_bonus?0:10);
  		break;
--- 618,624 ----
  		spin_bonus -= ROTS;
  		break;
  	case 4: /* look backwards / look forwards */
! 		flipped_at = closest;
  		flip_direction ();
  		backwards_bonus = (backwards_bonus?0:10);
  		break;
***************
*** 626,632 ****
  		change_colors();
  		break;
  	case 6: /* jam against the bonus a few times; deja vu! */
! 		nearest -= 2; MODULO(nearest, TERRAIN_LENGTH);
  		jamming = 3;
  		break;
  	default:
--- 626,632 ----
  		change_colors();
  		break;
  	case 6: /* jam against the bonus a few times; deja vu! */
! 		closest -= 2; MODULO(closest, TERRAIN_LENGTH);
  		jamming = 3;
  		break;
  	default:
***************
*** 648,656 ****
  	if (!bonuses_flag) return;
  
  	if (step >= 0.0) {
! 		start = nearest; end = nearest + (int)floor(step);
  	} else {
! 		end = nearest; start = nearest + (int)floor(step);
  	}
  
  	if (be_wormy) {
--- 648,656 ----
  	if (!bonuses_flag) return;
  
  	if (step >= 0.0) {
! 		start = closest; end = closest + (int)floor(step);
  	} else {
! 		end = closest; start = closest + (int)floor(step);
  	}
  
  	if (be_wormy) {
***************
*** 683,690 ****
  
  	if (backwards_bonus > 1) backwards_bonus--;
  	else if (backwards_bonus == 1) {
! 		nearest += 2*(MAX(flipped_at, nearest) - MIN(flipped_at,nearest));
! 		MODULO(nearest, TERRAIN_LENGTH);
  		flip_direction ();
  		backwards_bonus = 0;
  	}
--- 683,690 ----
  
  	if (backwards_bonus > 1) backwards_bonus--;
  	else if (backwards_bonus == 1) {
! 		closest += 2*(MAX(flipped_at, closest) - MIN(flipped_at,closest));
! 		MODULO(closest, TERRAIN_LENGTH);
  		flip_direction ();
  		backwards_bonus = 0;
  	}
***************
*** 733,739 ****
  	int start, end;
  	int passed;
  
! 	passed = nearest % (TERRAIN_LENGTH/4);
  
  	if (speed == 0.0 ||
  		(speed > 0.0 && passed > (int)step) ||
--- 733,739 ----
  	int start, end;
  	int passed;
  
! 	passed = closest % (TERRAIN_LENGTH/4);
  
  	if (speed == 0.0 ||
  		(speed > 0.0 && passed > (int)step) ||
***************
*** 742,748 ****
  		return;
  	}
  
! 	end = nearest - passed - 1; MODULO(end, TERRAIN_LENGTH);
  	start = end - TERRAIN_LENGTH/4 + 1; MODULO(start, TERRAIN_LENGTH);
  
  	if (DEBUG_FLAG) printf ("Regenerating [%d - %d]\n", start, end);
--- 742,748 ----
  		return;
  	}
  
! 	end = closest - passed - 1; MODULO(end, TERRAIN_LENGTH);
  	start = end - TERRAIN_LENGTH/4 + 1; MODULO(start, TERRAIN_LENGTH);
  
  	if (DEBUG_FLAG) printf ("Regenerating [%d - %d]\n", start, end);
***************
*** 842,848 ****
  	XPoint points[4];
  	GC gc;
  
! 	assert (i == (nearest - (t + dt) + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	in = i + 1; MODULO(in, TERRAIN_LENGTH);
  
--- 842,848 ----
  	XPoint points[4];
  	GC gc;
  
! 	assert (i == (closest - (t + dt) + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	in = i + 1; MODULO(in, TERRAIN_LENGTH);
  
***************
*** 907,913 ****
  	XPoint points[5];
  	GC gc;
  
! 	assert (i == (nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	in = i + 1; MODULO(in, TERRAIN_LENGTH);
  
--- 907,913 ----
  	XPoint points[5];
  	GC gc;
  
! 	assert (i == (closest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	in = i + 1; MODULO(in, TERRAIN_LENGTH);
  
***************
*** 1029,1035 ****
  {
  	int bt;
  
! 	assert (i == (nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	if (!bonuses[i] || wireframe) return;
  
--- 1029,1035 ----
  {
  	int bt;
  
! 	assert (i == (closest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH);
  
  	if (!bonuses[i] || wireframe) return;
  
***************
*** 1068,1077 ****
  static void
  render_speedmine (Display * dpy, Drawable d)
  {
! 	int t, i=nearest, dt=1;
  	GC gc;
  
! 	assert (nearest >= 0 && nearest < TERRAIN_LENGTH);
  
  	if (be_wormy || wireframe) {
  		XFillRectangle (dpy, d, erase_gc, 0, 0, width, height);
--- 1068,1077 ----
  static void
  render_speedmine (Display * dpy, Drawable d)
  {
! 	int t, i=closest, dt=1;
  	GC gc;
  
! 	assert (closest >= 0 && closest < TERRAIN_LENGTH);
  
  	if (be_wormy || wireframe) {
  		XFillRectangle (dpy, d, erase_gc, 0, 0, width, height);
***************
*** 1088,1094 ****
  		t = MAX(begin_at(), TERRAIN_LENGTH/4);
  		/*t = TERRAIN_LENGTH/4; dt = 2; */
  		dt = (t >= 3*TERRAIN_LENGTH/4 ? 1 : 2);
! 		i = (nearest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH;
  		render_block (dpy, d, tunnelend_gc, t);
  	}
  
--- 1088,1094 ----
  		t = MAX(begin_at(), TERRAIN_LENGTH/4);
  		/*t = TERRAIN_LENGTH/4; dt = 2; */
  		dt = (t >= 3*TERRAIN_LENGTH/4 ? 1 : 2);
! 		i = (closest -t + TERRAIN_LENGTH) % TERRAIN_LENGTH;
  		render_block (dpy, d, tunnelend_gc, t);
  	}
  
***************
*** 1137,1143 ****
   * move (step)
   *
   * move to the position for the next frame, and modify the state variables
!  * nearest, pindex, pos, speed
   */
  static void
  move (double step)
--- 1137,1143 ----
   * move (step)
   *
   * move to the position for the next frame, and modify the state variables
!  * closest, pindex, pos, speed
   */
  static void
  move (double step)
***************
*** 1149,1167 ****
  
  	pindex += SIGN3(effective_speed) + INTERP;
  	while (pindex >= INTERP) {
! 		nearest --;
  		pindex -= INTERP;
  	}
  	while (pindex < 0) {
! 		nearest ++;
  		pindex += INTERP;
  	}
  
!     nearest += dpos; MODULO(nearest, TERRAIN_LENGTH);
  
  	pos -= dpos;
  
! 	accel = thrust + ycurvature[nearest] * gravity;
  	speed += accel;
  	if (speed > maxspeed) speed = maxspeed;
  	if (speed < -maxspeed) speed = -maxspeed;
--- 1149,1167 ----
  
  	pindex += SIGN3(effective_speed) + INTERP;
  	while (pindex >= INTERP) {
! 		closest --;
  		pindex -= INTERP;
  	}
  	while (pindex < 0) {
! 		closest ++;
  		pindex += INTERP;
  	}
  
!     closest += dpos; MODULO(closest, TERRAIN_LENGTH);
  
  	pos -= dpos;
  
! 	accel = thrust + ycurvature[closest] * gravity;
  	speed += accel;
  	if (speed > maxspeed) speed = maxspeed;
  	if (speed < -maxspeed) speed = -maxspeed;
