3 package SCX::RaceParser;
10 use base qw(SCX::Parser);
12 our $LOG_FILE_LIMIT = 10_000_000; # bytes
15 my ($class, $args) = @_;
17 my $self = SCX::Parser->new();
19 $self->{track} = $args->{track}
20 or die "Track argument not given";
21 $self->{logfile} = $args->{logfile};
23 if ($self->{logfile}) {
24 open my $fh, '>>', $self->{logfile}
25 or die "Can't open $self->{logfile}: $!";
35 my ($self, @data) = @_;
37 my $size = $self->{logfh}->tell;
39 if ($size >= $LOG_FILE_LIMIT) {
43 rename $self->{logfile} . '.' . $gen . '.bz2',
44 $self->{logfile} . '.' . $gen+1 . '.bz2';
48 rename $self->{logfile}, $self->{logfile} . '.1';
49 system 'bzip2 -9 ' . $self->{logfile} . '.1 &';
51 open my $fh, '>', $self->{logfile}
52 or die "Can't open $self->{logfile}: $!";
56 $self->{logfh}->print(sprintf('% 10.3f ', $self->now),
57 join(' ', map { sprintf('%02X', $_) } @data), "\n");
58 $self->{logfh}->flush;
62 my ($self, @data) = @_;
64 $self->track->packet_received($self->now);
66 $self->log_print(@data)
71 my ($self, @data) = @_;
73 $self->log_print(@data)
77 sub track { return shift->{track} }
80 my ($self, $rounds) = @_;
82 $self->track->race_setup($rounds, $self->now);
86 my ($self, @fuel) = @_;
89 $self->track->car($car)->set_fuel($fuel[$car]);
94 my ($self, $rounds, $cars) = @_;
96 $self->track->qualification_setup($rounds, $cars, $self->now);
102 $self->track->race_end;
108 $self->track->race_start($self->now);
112 my ($self, $regular, @cars_finished) = @_;
114 $self->track->finish_line(
121 sub controller_status {
122 my ($self, @controllers) = @_;
125 my $c = $controllers[$car];
126 $self->track->car($car)->set_throttle(
131 $self->track->car($car)->set_light($c->{light});