From fcb0ae3348ddefd9c795efca0e28529b58a0d4fc Mon Sep 17 00:00:00 2001 From: Tobia Zorzan Date: Mon, 26 Oct 2009 19:19:28 +0100 Subject: [PATCH] Aggiunta gestione bestlap e lastlap sul monitor. --- src/simulator-monitor-gui.adb | 53 +++++++++++++++++++++++++++++++++++-------- src/simulator-monitor-gui.ads | 4 ++-- src/simulator-monitor.ads | 2 +- src/simulator-race.adb | 2 +- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/simulator-monitor-gui.adb b/src/simulator-monitor-gui.adb index 616db24..bbeb98b 100644 --- a/src/simulator-monitor-gui.adb +++ b/src/simulator-monitor-gui.adb @@ -77,9 +77,11 @@ package body Simulator.Monitor.Gui is Gtk_New (Monitor.Model1, (0 => GType_Int, -- Pos 1 => GType_Int, -- Id - 2 => GType_Int, -- Lap + 2 => GType_Int, -- Lap 3 => GType_Int, -- Intermediate - 4 => GType_String -- Colore + 4 => GType_String, -- Colore + 5 => GType_String, -- Best Lap + 6 => GType_String -- Last Lap )); Gtk_New_With_Model (Monitor.Model1_Sort, Monitor.Model1); @@ -115,6 +117,20 @@ package body Simulator.Monitor.Gui is Pack_Start (Monitor.Col, Monitor.Text_R, True); Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 3); + Gtk_New(Monitor.Col); + Gtk_New(Monitor.Text_R); + Set_Title (Monitor.Col, "Best Lap"); + Num := Append_Column (Monitor.Treeview1, Monitor.Col); + Pack_Start (Monitor.Col, Monitor.Text_R, True); + Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 5); + + Gtk_New(Monitor.Col); + Gtk_New(Monitor.Text_R); + Set_Title (Monitor.Col, "Last Lap"); + Num := Append_Column (Monitor.Treeview1, Monitor.Col); + Pack_Start (Monitor.Col, Monitor.Text_R, True); + Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 6); + Set_Headers_Visible (Monitor.Treeview1, True); Set_Rules_Hint (Monitor.Treeview1, True); Set_Reorderable (Monitor.Treeview1, False); @@ -161,7 +177,7 @@ package body Simulator.Monitor.Gui is )); Gtk_New (Monitor.Treeview2, Monitor.Model2); - + Set_Size_Request (Monitor.Treeview2, 250, 250); Gtk_New(Monitor.Col); Gtk_New(Monitor.Text_R); Set_Title (Monitor.Col, "Pos"); @@ -257,7 +273,7 @@ package body Simulator.Monitor.Gui is Pack_Start (Monitor.Hbox1, Monitor.Frame2, - Expand => True, + Expand => False, Fill => True, Padding => 5); @@ -319,7 +335,7 @@ package body Simulator.Monitor.Gui is Padding => 5); Add (Monitor, Monitor.Vbox2); - Set_Size_Request (Monitor, 500, 350); + Set_Size_Request (Monitor, 600, 350); end Initialize; procedure Update_Model (Pos: Positive; @@ -335,6 +351,9 @@ package body Simulator.Monitor.Gui is OldPos : Positive; StrTime : String := "tttttttttt"; StrVel : String := "vvvvvvvv"; + m : Integer; + s : Integer; + c : Integer; begin Gdk.Threads.Enter; -- disabilito ordinamento automatico @@ -354,6 +373,23 @@ package body Simulator.Monitor.Gui is Set (Ref.Model1, Iter, 1, GInt(CarId)); Set (Ref.Model1, Iter, 2, GInt(Lap)); Set (Ref.Model1, Iter, 3, GInt(Intermediate)); + if (BestLap /= Duration'Last) then + m := Integer(Float'Truncation(Float(BestLap)/60.0)); + s := Integer(Float'Truncation(Float(BestLap))) - m*60; + c := Integer(Float'Truncation(Float(BestLap * 1000))) - m*60000 -s *1000; + Set (Ref.Model1, Iter, 5, m'Img & ":" & s'Img & ":" & c'Img); + else + Set (Ref.Model1, Iter, 5, "--"); + end if; + if (LastLap /= Duration'Last) then + m := Integer(Float'Truncation(Float(LastLap)/60.0)); + s := Integer(Float'Truncation(Float(LastLap))) - m*60; + c := Integer(Float'Truncation(Float(LastLap * 1000))) - m*60000 -s *1000; + Set (Ref.Model1, Iter, 6, m'Img & ":" & s'Img & ":" & c'Img); + else + Set (Ref.Model1, Iter, 6, "--"); + end if; + if( Pos - OldPos = 0) then ChangePosition(CarId) := 0; else @@ -390,8 +426,6 @@ package body Simulator.Monitor.Gui is end if; Next(Ref.Model1, Iter); end loop; - - else -- appendo in fondo alla lista Put_Line("Aggiungo a monitor Id: " & CarId'Img & ", Pos: " & Pos'Img & "."); @@ -401,6 +435,8 @@ package body Simulator.Monitor.Gui is Set (Ref.Model1, Iter, 2, GInt(Lap)); Set (Ref.Model1, Iter, 3, GInt(Intermediate)); Set (Ref.Model1, Iter, 4, "white"); + Set (Ref.Model1, Iter, 5, "--"); + Set (Ref.Model1, Iter, 6, "--"); end if; -- aggiorno i valori massimi @@ -414,9 +450,6 @@ package body Simulator.Monitor.Gui is Clear(Ref.Model2); end if; - - - -- se giro e settore giusto aggiungo a statistics if ((Lap = Ref.LastLap) and (Intermediate = Ref.LastInt)) then -- Put_Line("Aggiungo a monitor di destra Id: " & CarId'Img & ", Pos: " & Pos'Img & "."); diff --git a/src/simulator-monitor-gui.ads b/src/simulator-monitor-gui.ads index 4ca9fca..3d81482 100644 --- a/src/simulator-monitor-gui.ads +++ b/src/simulator-monitor-gui.ads @@ -76,8 +76,8 @@ package Simulator.Monitor.Gui is Intermediate: Natural; WakeupTime: Duration; Vel: Float; - LastLap : Duration; - BestLap: Duration); + LastLap : Duration; + BestLap: Duration); procedure Update_BestLap(Id : CarId_T; Lap : Positive; Time : Duration); procedure Update_MaxSpeed(Id : CarId_T; Val : Float); procedure ToggleLock (Widget : access Gtk_Widget_Record'Class); diff --git a/src/simulator-monitor.ads b/src/simulator-monitor.ads index 38c7f52..d1f33a6 100644 --- a/src/simulator-monitor.ads +++ b/src/simulator-monitor.ads @@ -14,7 +14,7 @@ package Simulator.Monitor is Intermediate: Natural; WakeupTime: Duration; Vel: Float; - LastLap : Duration; + LastLap : Duration; BestLap: Duration); procedure Update_BestLap(This : access Monitor_Type; Id : CarId_T; Lap : Positive; Time : Duration); procedure Update_MaxSpeed(This : access Monitor_Type; Id : CarId_T; Val : Float); diff --git a/src/simulator-race.adb b/src/simulator-race.adb index 430bee5..b24a4be 100644 --- a/src/simulator-race.adb +++ b/src/simulator-race.adb @@ -106,7 +106,7 @@ package body Simulator.Race is Ranking.GetLap(Id,OldLap); if (Lap > OldLap and then Lap <= LapsNumber + 1 and then OldLap /= 0) then LastLaps(Id) := LapDuration(Id); - if (BestLaps(Id) < LastLaps(Id)) then + if (BestLaps(Id) > LastLaps(Id)) then BestLaps(Id) := LastLaps(Id); end if; Put_Line("Ultimo giro dell'auto "&Id'Img&" durato "&LastLaps(Id)'Img); -- 2.11.4.GIT