lap => 0,
laptime => 0,
avg_lap => 0,
- state => 'greenflag',
car_img => $args->{car_img},
id => $args->{id},
- order => $args->{id},
track => $args->{track},
};
bless $self, $class;
+ $self->set_order($self->{id});
+
return $self;
}
if (defined $lap_time) {
if ($lap_time > 1.0 && !$self->{in_pit_lane}
- && $self->track->{race_running}
&& (!defined $self->{best_lap}
|| $self->{best_lap} > $lap_time
)) {
$self->gui->set_fuel($self->{order}, $self->{fuel});
$self->gui->set_car_id($self->{order}, $self->{id} + 1);
$self->gui->set_distance($self->{order},
- $self->{time_diff}, $self->{lap_diff});
- $self->gui->set_state($self->{order}, $self->{state});
- if ($self->{in_pit_lane}) {
- $self->gui->enter_pit_lane;
- }
+ $self->{time_diff}, $self->{lap_diff}, $self->{grey_diff});
+ $self->print_state;
}
sub print_state {
$self->{first_finish_time} = undef;
$self->{time_diff} = undef;
$self->{lap_diff} = undef;
+ $self->{total_time} = undef;
+ $self->{grey_diff} = undef;
}
sub finish_line {
}
sub recalc_distance {
- my ($self, $lap_first, $time_first) = @_;
+ my ($self, $lap_first, $time_first, $finishing) = @_;
return if !defined $lap_first || !defined $self->{lap}
|| !defined $time_first || !defined $self->{first_finish_time};
- my $time;
+ $self->{total_time} = undef;
+ $self->{lap_diff} = undef;
+ $self->{time_diff} = undef;
+ $self->{grey_diff} = undef;
if ($self->{lap} == $lap_first) {
if ($self->{first_finish_time} == $time_first) {
- $time = $self->{first_finish_time}
+ $self->{total_time} = $self->{first_finish_time}
- $self->track->{race_running_since};
} else {
$self->{time_diff} = $self->{first_finish_time}
$self->{lap_diff} = $lap_first - $self->{lap};
}
- $self->gui->set_distance($self->{order}, $time,
- $self->{lap_diff}, $self->{time_diff});
- $self->{grey_diff} = undef;
+ $self->gui->set_distance($self->{order}, $self->{total_time},
+ $self->{lap_diff}, $self->{time_diff}, $self->{grey_diff});
+
+ if ($finishing) {
+ $self->{finished} = 1;
+ $self->print_state;
+ }
+}
+
+sub greyout_distance {
+ my ($self) = @_;
+
+ return if $self->{grey_diff};
+ $self->{grey_diff} = 1;
+ $self->gui->set_distance($self->{order}, $self->{total_time},
+ $self->{lap_diff}, $self->{time_diff}, $self->{grey_diff});
}
1;
}
sub set_distance {
- my ($self, $row, $time, $lap_diff, $time_diff) = @_;
+ my ($self, $row, $time, $lap_diff, $time_diff, $greyout) = @_;
my $text = '--';
} elsif (defined $time_diff) {
$text = '−' . format_lap_time($time_diff);
} elsif (defined $lap_diff) {
- $text = '−' . $lap_diff . ' laps';
+ $text = '−' . $lap_diff
+ . ($lap_diff == 1 ? ' lap' : ' laps');
+ }
+
+ if ($greyout) {
+ $text = '<span fgcolor="grey">' . $text . '</span>';
}
$self->set_label('label_distance', $row, $text);
sub new {
my ($class, $args) = @_;
- my $self;
-
- $self->{gui} = $args->{gui} or croak;
- $self->{race_running} = 0;
- $self->{lap_counting_up} = 1;
+ my $self = {
+ gui => $args->{gui},
+ race_running => 0,
+ lap_counting_up => 1,
+ round => 0,
+ };
bless $self, $class;
id => $i,
track => $self,
});
- $self->car($i)->set_order($i);
}
+ $self->print_rounds;
+ $self->{gui}->time(undef);
+ $self->{gui}->best_lap(undef, undef);
+
return $self;
}
$self->{race_running} = 0;
$self->{start_in_progress} = 0;
+ $self->{race_finishing} = 0;
$self->{best_lap} = undef;
$self->{round} = 0;
sub print_rounds {
my ($self) = @_;
- $self->{gui}->rounds($self->{qualification_running}
- ? 'Qualification'
- : $self->{race_rounds}
- ? $self->{round} . '/' . $self->{race_rounds}
- : $self->{round}
- );
+ my $msg;
+ if ($self->{qualification_running}) {
+ $msg = 'Qualification';
+ } elsif ($self->{race_rounds}) {
+ $msg = $self->{round} . '/' . $self->{race_rounds};
+ } else {
+ $msg = $self->{round};
+ }
+
+ $self->{gui}->rounds($msg);
}
sub check_best_lap {
} (0..5);
my $lap_max = $laps[$new_order[0]];
- if (defined $lap_max && $self->{round} && $lap_max != $self->{round}
- && (!$self->{race_rounds}
- || $lap_max <= $self->{race_rounds})) {
+ my $lap_max_changed = 0;
+ if (defined $lap_max && defined $self->{round}
+ && $lap_max != $self->{round}) {
$self->{round} = $lap_max;
+ $lap_max_changed = 1;
$self->print_rounds;
}
+ if ($self->{round} && $self->{race_rounds}
+ && $self->{round} > $self->{race_rounds}) {
+ $self->{race_finishing} = 1;
+ }
+
for my $id (0..5) {
my $car = $new_order[$id];
if ($self->car($car)->{order} != $id) {
$self->car($car)->set_order($id);
}
}
- return ($new_order[0], $lap_max, $times[$new_order[0]]);
+ return ($lap_max_changed, $lap_max, $times[$new_order[0]]);
}
sub finish_line {
}
}
-
- if ($was_processed) {
- my ($first_car, $lap_max, $time_min)
- = $self->recalc_order($time);
-
- for my $car (0..5) {
- if ($processed{$car}) {
- $self->car($car)->recalc_distance(
- $lap_max, $time_min
- );
- } else {
- #$self->car($car)->greyout_distance;
- }
+ return if !$was_processed;
+
+ my ($lap_max_changed, $lap_max, $time_min)
+ = $self->recalc_order($time);
+
+ for my $car (0..5) {
+ if ($processed{$car}) {
+ $self->car($car)->recalc_distance(
+ $lap_max, $time_min, $self->{race_finishing},
+ );
+ } elsif ($lap_max_changed) {
+ $self->car($car)->greyout_distance;
}
}
}