throttle => -1,
fuel => -1,
order => $args->{order},
+ track => $args->{track},
};
bless $self, $class;
sub gui { return shift->{gui}; }
+sub track { return shift->{track}; }
+
sub set_throttle {
my ($self, $val) = @_;
|| $self->{best_lap} > $lap_time
)) {
- $self->gui->set_best_lap($self->{order}, $lap_time);
$self->{best_lap} = $lap_time;
+ my $global = $self->{track}->check_best_lap($lap_time,
+ $self->{driver}
+ );
+ $self->gui->set_best_lap($self->{order}, $lap_time,
+ $global);
}
} else {
}
sub set_best_lap {
- my ($self, $row, $text) = @_;
+ my ($self, $row, $text, $global) = @_;
++$row;
my $label = $self->get_object("label_best_lap$row")
or die "Can't get label_best_lap$row";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+
+ if ($global) {
+ $global = ' foreground="#e00000"';
+ } else {
+ $global = '';
+ }
+
+ $label->set_markup('<span font_desc="18" weight="bold"'.$global.'>'
+ .$text.'</span>');
}
sub set_driver {
my $label = $self->get_object("label_lap_global")
or die "Can't get label_lap_global";
- $label->set_markup('<span font_desc="18" weight="bold">Lap '.$text.'</span>');
+ $label->set_markup('<span font_desc="18" weight="bold">Lap: '.$text.'</span>');
}
sub time {
my $label = $self->get_object("label_time_global")
or die "Can't get label_time_global";
- $label->set_markup('<span font_desc="18" weight="bold">Time '.$text.'</span>');
+ $label->set_markup('<span font_desc="18" weight="bold">Time: '.$text.'</span>');
}
sub best_lap {
- my ($self, $text) = @_;
+ my ($self, $time, $who) = @_;
+
+ my $text = $time;
+ $text .= ' by ' . $who
+ if defined $who;
my $label = $self->get_object("label_best_lap_global")
or die "Can't get label_best_lap_global";
- $label->set_markup('<span font_desc="18" weight="bold">Best lap '.$text.'</span>');
+ $label->set_markup('<span font_desc="18" weight="bold">Best lap: '.$text.'</span>');
}
1;
|| $bytes[4] != 0xFF
|| $bytes[5] != 0xFF;
- for my $car (0..5) {
- $self->track->car($car)->set_lap(0);
- $self->track->car($car)->set_laptime(undef);
- }
-
$self->track->race_setup($bytes[0] == 0x00
? 0
: $bytes[1] & 0x0F * 256
use strict;
use Carp;
+use Time::HiRes qw(gettimeofday);
use Glib qw(TRUE FALSE);
use SCX::Car;
$self->{race_running} = 0;
$self->{lap_counting_up} = 1;
+ bless $self, $class;
+
for my $i (0..5) {
$self->{cars}->[$i] = SCX::Car->new({
gui => $self->{gui},
order => $i,
+ track => $self,
});
}
- bless $self, $class;
+ return $self;
}
sub car { return shift->{cars}->[shift]; }
for my $car (0..5) {
$self->car($car)->set_order($car);
+ $self->car($car)->set_lap(0);
+ $self->car($car)->set_laptime(undef);
+ }
+}
+
+sub check_best_lap {
+ my ($self, $time, $who) = @_;
+
+ return if !defined $time || $time == 0;
+
+ if (!defined $self->{best_lap}
+ || $time < $self->{best_lap}) {
+ $self->{best_lap} = $time;
+ $self->{gui}->best_lap(sprintf("%.2f", $time), $who);
+ return 1;
}
+ return 0;
}
1;