6 use Time::HiRes qw(gettimeofday);
9 my ($class, $args) = @_;
13 driver => $args->{driver} || '--',
19 car_img => $args->{car_img},
21 track => $args->{track},
29 sub gui { return shift->{gui}; }
31 sub track { return shift->{track}; }
34 my ($self, $key, $val) = @_;
36 return 1 if !defined $self->{$key} && !defined $val
37 || (defined $self->{$key} && defined $val
38 && $self->{$key} eq $val);
45 my ($self, $val) = @_;
47 return if $self->same('throttle', $val);
49 if ($self->track->{start_in_progress} && $val) {
50 $self->{early_start} = 1;
51 $self->gui->set_driver('Early start!');
54 if ($self->{in_pit_lane} && defined $val && $val > 3) {
55 $self->leave_pit_lane;
58 $self->gui->set_throttle($self->{order}, $val);
63 my ($self, $val) = @_;
65 return if $self->same('fuel', $val);
66 $self->gui->set_fuel($self->{order}, $val);
78 my ($self, $name) = @_;
80 return if $self->same('car_img', $name);
81 $self->gui->set_car_icon($self->{order}, $name);
85 my ($self, $lap_nr) = @_;
87 return if $self->same('lap', $lap_nr);
88 $self->gui->set_lap($self->{order}, defined $lap_nr ? $lap_nr : '--');
89 if ($self->track->{race_running} && $self->{lap} > 1) {
90 my $now = $self->{last_finish_time};
91 my $avg = ($now - $self->track->{race_running_since})
93 $self->{avg_lap} = $avg;
94 $self->gui->set_avg_lap($self->{order}, $avg);
96 $self->gui->set_avg_lap($self->{order}, undef);
101 my ($self, $lap_time) = @_;
103 return if $self->same('laptime', $lap_time);
105 $self->gui->set_laptime($self->{order}, $lap_time);
107 if (defined $lap_time) {
108 if ($lap_time > 1.0 && !$self->{in_pit_lane}
109 && (!defined $self->{best_lap}
110 || $self->{best_lap} > $lap_time
113 $self->{best_lap} = $lap_time;
114 my $global = $self->{track}->check_best_lap($lap_time,
117 $self->gui->set_best_lap($self->{order}, $lap_time,
121 $self->gui->set_best_lap($self->{order}, $lap_time);
122 $self->{best_lap} = undef;
127 my ($self, $driver_name) = @_;
129 return if $self->same('driver', $driver_name);
130 $self->gui->set_name($self->{order}, $driver_name);
136 return if $self->{in_pit_lane};
138 $self->{in_pit_lane} = 1;
139 $self->gui->enter_pit_lane;
145 return if !$self->{in_pit_lane};
147 $self->{in_pit_lane} = 0;
148 $self->gui->leave_pit_lane;
152 my ($self, $pos) = @_;
154 $self->{order} = $pos;
156 $self->gui->set_name($self->{order}, $self->{driver});
157 $self->gui->set_car_icon($self->{order}, $self->{car_icon});
158 $self->gui->set_throttle($self->{order}, $self->{throttle});
159 $self->gui->set_lap($self->{order}, $self->{lap});
160 $self->gui->set_laptime($self->{order}, $self->{laptime});
161 $self->gui->set_best_lap($self->{order}, $self->{best_lap});
162 $self->gui->set_avg_lap($self->{order}, $self->{avg_lap});
163 $self->gui->set_fuel($self->{order}, $self->{fuel});
164 if ($self->{in_pit_lane}) {
165 $self->gui->enter_pit_lane;
173 $self->set_laptime(undef);
174 $self->{in_pit_lane} = 0;
175 $self->{early_start} = undef;
179 my ($self, $time, $regular) = @_;
182 if defined $self->{last_finish_time}
183 && $time - $self->{last_finish_time} < 2;
186 if (defined $self->{last_finish_time}) {
187 $self->set_laptime($time - $self->{last_finish_time});
190 $self->enter_pit_lane;
193 $self->{last_finish_time} = $time;
194 $self->set_lap(++$self->{lap});