X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=SCX%2FTrack.pm;h=90724290bc5252bd2bb7b897486d7ec23d3ef72c;hb=HEAD;hp=c88e6f8540ff024ce9d67c9636b60310084d4096;hpb=113a957a90fa08bd75eb5f2d48b529bcc1eb860c;p=slotcarman.git diff --git a/SCX/Track.pm b/SCX/Track.pm index c88e6f8..9072429 100644 --- a/SCX/Track.pm +++ b/SCX/Track.pm @@ -7,6 +7,7 @@ use Carp; use Glib qw(TRUE FALSE); use SCX::Car; +use SCX::Sound; our $SEMAPHORE_STEP = 1000; @@ -20,6 +21,7 @@ sub new { round => 0, now => 0, qualification_setup => -100, + no_semaphore => $args->{no_semaphore}, }; bless $self, $class; @@ -36,6 +38,8 @@ sub new { $self->{gui}->time(undef); $self->{gui}->best_lap(undef, undef); + $self->{sound} = new SCX::Sound; + return $self; } @@ -49,6 +53,11 @@ sub race_start { if ($time - $self->{qualification_setup} < 1) { $self->{qualification_running} = 1; + } elsif ($self->{no_semaphore}) { + $self->{round} = 0; + $self->{race_running} = 1; + $self->{race_running_since} = $self->{now}; + $self->{start_in_progress} = undef; } else { $self->{round} = 0; $self->{race_running} = 0; @@ -81,6 +90,7 @@ sub semaphore_step { } else { $self->{gui}->show_semaphore(undef); $self->{semaphore} = undef; + $self->{sound}->start(); } return FALSE; } @@ -109,27 +119,13 @@ sub race_setup { $self->{best_lap} = undef; $self->{gui}->show_semaphore(undef); - $self->{race_running} = 0; - $self->{qualification_running} = 0; - $self->{start_in_progress} = 0; - - $self->{gui}->time(undef); - $self->{gui}->best_lap(undef); -} - -sub reset { - my ($self) = @_; - $self->{race_running} = 0; $self->{qualification_running} = 0; $self->{start_in_progress} = 0; $self->{race_finishing} = 0; - $self->{best_lap} = undef; - $self->{round} = 0; - $self->print_rounds; - $self->{gui}->best_lap(undef); $self->{gui}->time(undef); + $self->{gui}->best_lap(undef); for my $car (0..5) { $self->car($car)->reset; @@ -153,8 +149,8 @@ sub print_rounds { $self->{gui}->rounds($msg); } -sub check_best_lap { - my ($self, $time, $who) = @_; +sub notify_best_lap { + my ($self, $id, $time, $who) = @_; return if !defined $time || $time == 0; @@ -165,6 +161,16 @@ sub check_best_lap { || $time < $self->{best_lap}) { $self->{best_lap} = $time; $self->{gui}->best_lap($time, $who); + + for my $car (0..5) { + $self->car($car)->set_global_best($car == $id); + $self->car($car)->print_best_lap; + } + + if (!$self->{race_running} || $self->{round} > 1) { + # skip the first round in the race + $self->{sound}->best_lap($id); + } return 1; } return 0; @@ -229,6 +235,9 @@ sub recalc_order { if ($self->{round} && $self->{race_rounds} && $self->{round} > $self->{race_rounds}) { + if (!$self->{race_finishing}) { + $self->{sound}->winner($new_order[0]); + } $self->{race_finishing} = 1; }