]> www.fi.muni.cz Git - slotcarman.git/blobdiff - SCX/Track.pm
Time formatting moved to SCX::GUI
[slotcarman.git] / SCX / Track.pm
index 32f03f40555bcf95fd8d7586e5c4f7efe7fd54ed..c1f66a3e8890307f2b9316042db1427d7dcdde10 100644 (file)
@@ -5,6 +5,7 @@ package SCX::Track;
 use strict;
 use Carp;
 
+use Time::HiRes qw(gettimeofday);
 use Glib qw(TRUE FALSE);
 use SCX::Car;
 
@@ -19,14 +20,18 @@ sub new {
        $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,
+                       id => $i,
+                       track => $self,
                });
+               $self->car($i)->set_order($i);
        }
 
-       bless $self, $class;
+       return $self;
 }
 
 sub car { return shift->{cars}->[shift]; }
@@ -83,19 +88,49 @@ sub race_setup {
                $self->{gui}->rounds('0');
                $self->{race_rounds} = 0;
        }
-       $self->{race_time} = 0;
        $self->{best_lap} = undef;
 
        $self->{gui}->show_semaphore(undef);
        $self->{race_running} = 0;
        $self->{start_in_progress} = 0;
 
-       $self->{gui}->time('00:00');
-       $self->{gui}->best_lap('0.00');
+       $self->{gui}->time(undef);
+       $self->{gui}->best_lap(undef);
 
        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($time, $who);
+               return 1;
        }
+       return 0;
+}
+
+sub qualification_start {
+       my ($self) = @_;
+
+       return if $self->{qualification_running};
+       for my $car (0..5) {
+               $self->car($car)->set_lap(undef);
+               $self->car($car)->set_laptime(undef);
+       }
+
+       $self->{qualification_running} = 1;
+       $self->{gui}->lap('Qualification');
+       $self->{gui}->time(undef);
+       $self->{gui}->best_lap(undef);
 }
 
 1;