From 4e86fa8065ab8b52b6a03e7feac1d244ebe5b558 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=B2=20Navarin?= Date: Tue, 22 Sep 2009 18:15:21 +0200 Subject: [PATCH] Fixed time duration in call to updatestatistics --- src/simulator-race.adb | 2 +- src/simulator-statistics.ads | 4 ++-- src/simulator-track.adb | 56 ++++++++++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/simulator-race.adb b/src/simulator-race.adb index 4790cf8..5c7197f 100644 --- a/src/simulator-race.adb +++ b/src/simulator-race.adb @@ -66,7 +66,7 @@ package body Simulator.Race is end Kill; or accept UpdateStatistics(Id : CarId_T; Lap : Integer; Sector : Integer; WakeupTime : Duration; Speed : Float; Intermediate: Integer) do - -- Print(" Aggiorno statistiche Lap:"&Lap'Img&" Sector:"&Sector'Img); + --Print(" Aggiorno statistiche Lap:"&Lap'Img&" Sector:"&Sector'Img); if (Lap <= LapsNumber) then Ranking.Insert(item => (Id,Lap,Sector,WakeupTime), pos => pos); diff --git a/src/simulator-statistics.ads b/src/simulator-statistics.ads index 780d7da..9667c78 100644 --- a/src/simulator-statistics.ads +++ b/src/simulator-statistics.ads @@ -3,8 +3,8 @@ package Simulator.Statistics is type RankingLine_T is record Id : CarId_T; - Lap : Positive; - Sector : Positive; + Lap : Natural; + Sector : Natural; WakeupTime : Duration; -- tempo dell'ultimo risveglio end record; type RankingArray_T is array (Integer range 1 .. MaxId) of RankingLine_T; diff --git a/src/simulator-track.adb b/src/simulator-track.adb index e8f1ded..1df429e 100644 --- a/src/simulator-track.adb +++ b/src/simulator-track.adb @@ -155,7 +155,8 @@ package body Simulator.Track is -- Put_Line("Calcolo Tempo di risveglio previsto "& Seconds(finish)'Img); end CalculateDriveTime; - --TODO driveLane aggiorna i carproperties in base al lane percorso + + protected type Semaphore is entry Wait; -- P @@ -236,7 +237,31 @@ package body Simulator.Track is open : Boolean := False; end Sector; type Sector_Array_T is array (Positive range <>) of access Sector; - Sectors : access Sector_Array_T; + Sectors : access Sector_Array_T; + + procedure CheckSurpass(Sector_Id : Natural; CarId : CarId_T) is + begin + Print("Controllo i sorpassi nel settore"& Sector_Id'Img); + if (Sector_Id /= 1) then + if ( (not ExitOrder(Sector_Id - 1).Is_Empty) ) then + if (ExitOrder(Sector_Id - 1).First_Element /= CarId) then + Print("Errore : L'auto ha superato tra l'uscita di un settore e l'entrata nel settore "& Sector_Id'Img); + end if; + -- cancello il primo elemento + ExitOrder(Sector_Id - 1).Delete_First; + end if; + else + if ( (not ExitOrder(Sectors'Length).Is_Empty)) then + if( ExitOrder(Sectors'Length ).First_Element /= CarId) then + Print("Errore : L'auto ha superato tra l'uscita di un settore e l'entrata nel settore "& Sector_Id'Img); + end if; + -- cancello il primo elemento + ExitOrder(Sectors'Length).Delete_First; + end if; + end if; + end CheckSurpass; + + protected body Sector is entry BookExit(my_properties: CarProperties_T; my_time : Time) when True is --Temp : ExitRecord; @@ -302,24 +327,7 @@ type Sector_Array_T is array (Positive range <>) of access Sector; Free := Free - 1; CarLane(my_properties.CarId) := n_lane; - Print("Controllo i sorpassi nel settore"& Sector_Id'Img); - if (Sector_Id /= 1) then - if ( (not ExitOrder(Sector_Id - 1).Is_Empty) ) then - if (ExitOrder(Sector_Id - 1).First_Element /= my_properties.CarId) then - Print("Errore : L'auto ha superato tra l'uscita di un settore e l'entrata nel settore "& Sector_Id'Img); - end if; - -- cancello il primo elemento - ExitOrder(Sector_Id - 1).Delete_First; - end if; - else - if ( (not ExitOrder(Sectors'Length).Is_Empty)) then - if( ExitOrder(Sectors'Length ).First_Element /= my_properties.CarId) then - Print("Errore : L'auto ha superato tra l'uscita di un settore e l'entrata nel settore "& Sector_Id'Img); - end if; - -- cancello il primo elemento - ExitOrder(Sectors'Length).Delete_First; - end if; - end if; + pragma Debug (CheckSurpass(Sector_Id, my_properties.CarId)); Print("Auto "&my_properties.CarId'Img&" percorre Settore: "&Sector_Id'Img&", Tratto:"&n_lane'Img&"."); requeue Corsie(Sector_Id)(n_lane).Demand with abort; @@ -388,6 +396,8 @@ type Sector_Array_T is array (Positive range <>) of access Sector; end Sector; + + protected body Lane_T is entry Demand(my_properties: CarProperties_T; my_time : out Time; my_duration : out Duration; my_fuel: out Float; my_consumption : out Float; my_speed : in out Float) when True is start : Time; @@ -445,6 +455,7 @@ type Sector_Array_T is array (Positive range <>) of access Sector; --Auto si mette nelle linee di partenza. Quando tornerĂ  da questa ciamata, la corsa per l'auto sarĂ  iniziata PitLane(CarProperties.CarId).Wait; + Simulator.Controller.GetRace.UpdateStatistics(CarProperties.CarId, 0,0, (Clock - Time_Of(2009,9,21)), 0.0, 0); --inizio la corsa iterando tra i vari Sector while (RetireRequest(CarProperties.CarId) = False) loop lap := lap + 1; @@ -502,8 +513,7 @@ type Sector_Array_T is array (Positive range <>) of access Sector; inter := 0; end if; - Simulator.Controller.GetRace.UpdateStatistics(CarProperties.CarId, lap,Index, my_duration, Speed, inter); - --Print("BOX: Effettuata la chiamata UPDATESTATISTICS"); + Simulator.Controller.GetRace.UpdateStatistics(CarProperties.CarId, lap,Index,(my_time - Time_Of(2009,9,21)), Speed, inter); delay until my_time; BoxSector.Release(CarProperties); Put_Line("Auto "&CarProperties.CarId'Img&" uscita dalla corsia dei Box"); @@ -549,7 +559,7 @@ type Sector_Array_T is array (Positive range <>) of access Sector; inter := 0; end if; - Simulator.Controller.GetRace.UpdateStatistics(CarProperties.CarId, lap,Index, my_duration, Speed, inter); + Simulator.Controller.GetRace.UpdateStatistics(CarProperties.CarId, lap,Index, (my_time - Time_Of(2009,9,21)), Speed, inter); -- Print("Track: ritornato dalla chiamata a updateStatistics"); delay until my_time; -- 2.11.4.GIT