1. with Ada.Real_Time;                     use Ada.Real_Time; 
  2. with Ada.Streams;                       use Ada.Streams; 
  3.  
  4. package Support.Real_Time is 
  5.  
  6.     type Timer_Type is limited private; 
  7.  
  8.     -- Return the elapsed time counted by the timer. 
  9.     function Elapsed( t : Timer_Type ) return Time_Span; 
  10.  
  11.     -- Returns True if the timer has been started and isn't paused. 
  12.     function Is_Running( t : Timer_Type ) return Boolean; 
  13.  
  14.     -- Pauses the timer. Elapsed time will not accumulate until the timer 
  15.     -- is started again. 
  16.     procedure Pause( t : in out Timer_Type ); 
  17.  
  18.     -- Clears elapsed time and starts the timer again. 
  19.     procedure Restart( t : in out Timer_Type ); 
  20.  
  21.     -- Starts or resumes the timer. This will have no effect if the timer is 
  22.     -- already running. 
  23.     procedure Start( t : in out Timer_Type ); 
  24.  
  25.     ---------------------------------------------------------------------------- 
  26.  
  27.     type Frame_Timer is limited private; 
  28.  
  29.     -- Returns true if the rate has been updated since the last check. Note that 
  30.     -- this doesn't mean the rate has changed in value, it means it has been 
  31.     -- recalculated. 
  32.     function Is_Updated( t : Frame_Timer ) return Boolean; 
  33.  
  34.     -- Returns the current frame rate. The value returned is FPS. 
  35.     function Rate( t : access Frame_Timer ) return Natural; 
  36.  
  37.     -- Returns the current frame rate. 
  38.     procedure Rate( t : in out Frame_Timer; fps : out Natural ); 
  39.  
  40.     -- Sets the minimum time to collect ticks before updating the current rate 
  41.     procedure Set_Update_Delay( t : in out Frame_Timer; ts : Time_Span ); 
  42.  
  43.     -- Notifies the timer of a complete frame. 
  44.     procedure Tick( t : in out Frame_Timer ); 
  45.  
  46.     ---------------------------------------------------------------------------- 
  47.  
  48.     function Format( ts : Time_Span ) return String; 
  49.     pragma Postcondition( Format'Result'Length > 0 ); 
  50.  
  51.     function To_Float( ts : Time_Span ) return Long_Float; 
  52.  
  53.     function To_Microseconds( ts : Time_Span ) return Natural; 
  54.  
  55.     function To_Milliseconds( ts : Time_Span ) return Natural; 
  56.  
  57.     function To_Minutes( ts : Time_Span ) return Natural; 
  58.  
  59.     function To_Seconds( ts : Time_Span ) return Natural; 
  60.  
  61.     function To_String( t : Time ) return String; 
  62.  
  63.     function To_String( ts : Time_Span; precision : Natural := 3 ) return String; 
  64.     pragma Postcondition( To_String'Result'Length > 0 ); 
  65.  
  66.     ---------------------------------------------------------------------------- 
  67.  
  68.     function Time_Input( stream : access Root_Stream_Type'Class ) return Time; 
  69.  
  70.     procedure Time_Output( stream : access Root_Stream_Type'Class; t : Time ); 
  71.  
  72. private 
  73.  
  74.     type Timer_Type is limited 
  75.         record 
  76.             started : Time := Time_First;   -- start time, changes when unpaused 
  77.             paused  : Time := Time_First;   -- time of pause (if paused) 
  78.             running : Boolean := False;     -- time is running 
  79.         end record; 
  80.  
  81.     type Frame_Timer is limited 
  82.         record 
  83.             ticks       : Natural := 0;               -- ticks since last update 
  84.             updateDelay : Time_Span := Seconds( 1 );  -- minimum time between updates 
  85.             lastUpdate  : Time := Clock;              -- time of last update 
  86.             updated     : Boolean := True;            -- updated since last check 
  87.             fps         : Natural := 0;               -- calculated fps 
  88.         end record; 
  89.  
  90. end Support.Real_Time;