1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Allegro.Displays;                  use Allegro.Displays; 
  10. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  11. with Objects;                           use Objects; 
  12. with Processes;                         use Processes; 
  13. with Widgets.Containers.Windows;        use Widgets.Containers.Windows; 
  14.  
  15. private with Ada.Real_Time; 
  16.  
  17. package Renderers is 
  18.  
  19.     -- A Renderer is a member of the Game View system and is responsible for 
  20.     -- drawing a Window widget to the screen. Only one renderer exists per 
  21.     -- application. It implements the Process interface to draw on a tick when 
  22.     -- the specified framerate allows. The renderer uses double-buffering for 
  23.     -- updating frames. 
  24.     type Renderer is new Limited_Object and Process with private; 
  25.     type A_Renderer is access all Renderer'Class; 
  26.  
  27.     -- Create a Renderer object that draws 'win' to 'display' at a maximum 
  28.     -- frequency of 'fps'. For best performance, do not attach the Renderer to 
  29.     -- a Process_Manager running at a frequency less than 'fps'; it's best if 
  30.     -- the Process is ticked at the same frequency, or a multiple of it. 
  31.     function Create_Renderer( display : A_Allegro_Display; 
  32.                               win     : not null A_Window; 
  33.                               fps     : Positive ) return A_Renderer; 
  34.     pragma Postcondition( Create_Renderer'Result /= null ); 
  35.  
  36.     -- Deletes the Renderer. 
  37.     procedure Delete( this : in out A_Renderer ); 
  38.     pragma Postcondition( this = null ); 
  39.  
  40. private 
  41.  
  42.     use Ada.Real_Time; 
  43.  
  44.     -- an array of video bitmaps for double/triple-buffering 
  45.     type Page_Array is array(Natural range <>) of A_Allegro_Bitmap; 
  46.     type A_Page_Array is access all Page_Array; 
  47.  
  48.     ---------------------------------------------------------------------------- 
  49.  
  50.     type Renderer is new Limited_Object and Process with 
  51.         record 
  52.             display    : A_Allegro_Display := null; 
  53.             buffer     : A_Allegro_Bitmap := null; 
  54.             win        : A_Window := null; 
  55.             frameDelta : Time_Span := Time_Span_Zero; 
  56.             lastFrame  : Time := Time_First; 
  57.         end record; 
  58.  
  59.     procedure Construct( this    : access Renderer; 
  60.                          display : A_Allegro_Display; 
  61.                          win     : not null A_Window; 
  62.                          fps     : Positive ); 
  63.  
  64.     procedure Delete( this : in out Renderer ); 
  65.  
  66.     function Get_Process_Name( this : access Renderer ) return String; 
  67.  
  68.     -- Updates the screen. 
  69.     procedure Tick( this : access Renderer; time : Tick_Time ); 
  70.  
  71. end Renderers;