6 use Time::HiRes qw(gettimeofday);
9 my ($class, $args) = @_;
16 track => $args->{track},
24 sub gui { return shift->{gui}; }
26 sub track { return shift->{track}; }
29 my ($self, $val) = @_;
31 return if (!defined $self->{throttle} && !defined $val)
32 || (defined $self->{throttle} && defined $val
33 && $self->{throttle} == $val);
35 $self->{throttle} = $val;
36 $self->gui->set_throttle($self->{order}, $val);
41 my ($self, $val) = @_;
43 return if (!defined $self->{fuel} && !defined $val)
44 || (defined $self->{fuel} && defined $val
45 && $self->{fuel} == $val);
48 $self->gui->set_fuel($self->{order}, $val);
60 my ($self, $name) = @_;
62 return if (!defined $self->{car_icon} && !defined $name)
63 || (defined $self->{car_icon} && defined $name
64 && $self->{car_icon} eq $name);
66 $self->{car_icon} = $name;
67 $self->gui->set_car_icon($self->{order}, $name);
71 my ($self, $lap_nr) = @_;
73 return if (!defined $self->{lap} && !defined $lap_nr)
74 || (defined $self->{lap} && defined $lap_nr
75 && $self->{lap} == $lap_nr);
77 $self->{lap} = $lap_nr;
78 $self->gui->set_lap($self->{order}, defined $lap_nr ? $lap_nr : '--');
79 if ($self->track->{race_running} && $self->{lap} > 1) {
80 my $now = gettimeofday;
81 my $avg = ($now - $self->track->{race_running_since})
83 $self->{avg_lap} = $avg;
84 $self->gui->set_avg_lap($self->{order}, $avg);
86 $self->gui->set_avg_lap($self->{order}, '--');
91 my ($self, $lap_time) = @_;
93 if (defined $lap_time) {
94 $lap_time = sprintf("%.2f", $lap_time);
95 if ($lap_time > 1.0 && !$self->{in_pit_lane}
96 && (!defined $self->{best_lap}
97 || $self->{best_lap} > $lap_time
100 $self->{best_lap} = $lap_time;
101 my $global = $self->{track}->check_best_lap($lap_time,
104 $self->gui->set_best_lap($self->{order}, $lap_time,
108 $self->gui->set_best_lap($self->{order}, '--');
109 $self->{best_lap} = undef;
112 return if (!defined $self->{laptime} && !defined $lap_time)
113 || (defined $self->{laptime} && defined $lap_time
114 && $self->{laptime} == $lap_time);
116 $self->{laptime} = $lap_time;
118 $self->gui->set_laptime($self->{order}, defined $lap_time
123 my ($self, $driver_name) = @_;
125 return if (!defined $self->{driver} && !defined $driver_name)
126 || (defined $self->{driver} && defined $driver_name
127 && $self->{driver} == $driver_name);
129 $self->{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}
158 $self->gui->set_car_icon($self->{order}, $self->{car_icon});
159 $self->gui->set_throttle($self->{order}, $self->{throttle});
160 $self->gui->set_lap($self->{order}, defined $self->{lap}
161 ? $self->{lap} : '--');
162 $self->gui->set_laptime($self->{order}, defined $self->{laptime}
163 ? $self->{laptime} : '--');
164 $self->gui->set_best_lap($self->{order}, defined $self->{best_lap}
165 ? $self->{best_lap} : '--');
166 $self->gui->set_avg_lap($self->{order}, defined $self->{avg_lap}
167 ? $self->{avg_lap} : '--');
168 $self->gui->set_fuel($self->{order}, $self->{fuel});