camera_record.patch

terencehill, 05/20/2012 03:06 pm

Download (3.58 KB)

View differences:

defaultXonotic.cfg
1820 1820
set camera_look_player		0	"Always look to the player. Mouse input is ignored in this mode"
1821 1821
set camera_look_attenuation 	8	"Attenuation of \"looking\" movements, only if camera_look_player is set. Bigger is smoother"
1822 1822
set camera_forward_follows 	1	"0: Move the camera forwards without changing altitude. 1: Move towards what you are looking"
1823
set camera_record 		0	"save the cameras position to a file"
1824
set camera_playback		0	"replay the cameras position file"
1823 1825

  
1824 1826
// "Gentle mode": show no blood
1825 1827
seta sv_gentle 0		"force gentle mode for everyone, also remove references to acts of killing from the messages"
qcsrc/client/View.qc
1460 1460
    
1461 1461
}
1462 1462

  
1463
float open_file_value;
1463 1464

  
1465
void open_file_read(void) {
1466
	if (open_file_value)
1467
		return;
1468
	else
1469
		open_file_value = fopen("test_write", FILE_READ);
1470
}
1471

  
1472
void open_file_write(void) {
1473
	if (open_file_value)
1474
		return;
1475
	else
1476
		open_file_value = fopen("test_write", FILE_WRITE);
1477
}
1478

  
1479
void close_file(void) {
1480
	if (open_file_value) {
1481
		fclose(open_file_value);
1482
		open_file_value = 0;
1483
	}
1484
}
1485

  
1486
vector origin_next, angle_next;
1487
float time_next, playback_finished;
1464 1488
// following vectors must be global to allow seamless switching between camera modes
1465 1489
vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;
1466 1490
void CSQC_Demo_Camera()
1467 1491
{
1492
if (autocvar_camera_playback) {
1493
	open_file_read();
1494
	string s, s2;
1495

  
1496
	float t, n, l;
1497

  
1498
	if (time >= time_next) {
1499
		R_SetView(VF_ANGLES, angle_next);
1500
		R_SetView(VF_ORIGIN, origin_next);
1501

  
1502
		s = fgets(open_file_value);
1503

  
1504
		if(s == "") {
1505
			print("^1file closed\n");
1506
			close_file();
1507
			autocvar_camera_playback = 0;
1508
			return;
1509
		}
1510

  
1511
		s2 = substring(s, 0, 2);
1512

  
1513
		if(s2 == "//")
1514
			print("Comment\n");
1515
		else if(s2 == "##")
1516
			print("Do stuff\n");
1517
		else {
1518
			n = tokenizebyseparator(s, ",");
1519

  
1520
			if(n != 3) {
1521
				print("^1Error: ", s, "\n");
1522
				return;
1523
			}
1524

  
1525
			time_next = stof(argv(0));
1526

  
1527
			origin_next = stov(argv(1));
1528
			angle_next = stov(argv(2));
1529
		}
1530
	} else {
1531
		R_SetView(VF_ANGLES, angle_next);
1532
		R_SetView(VF_ORIGIN, origin_next);
1533
	}
1534
} else {
1468 1535
	float speed, attenuation, dimensions;
1469 1536
	vector tmp, delta;
1470 1537

  
......
1605 1672

  
1606 1673
	R_SetView(VF_ANGLES, current_angles);
1607 1674
	R_SetView(VF_ORIGIN, current_position);
1608
}
1675

  
1676
	if (autocvar_camera_record) {
1677
		open_file_write();
1678
		fputs(open_file_value, strcat(ftos(time), ",", vtos(current_position), ",", vtos(current_angles), "\n"));
1679
		} else {
1680
			close_file();
1681
		}
1682
	}
1683
}
qcsrc/client/autocvars.qh
343 343
var float autocvar_cl_eventchase_death = 1;
344 344
var float autocvar_cl_eventchase_distance = 140;
345 345
var float autocvar_cl_eventchase_speed = 1.3;
346
float autocvar_camera_playback;
347
float autocvar_camera_record;
346 348
float autocvar_cl_lerpexcess;