1. with Events.Corrals;                    use Events.Corrals; 
  2. with Events.Listeners;                  use Events.Listeners; 
  3. with Objects;                           use Objects; 
  4. with Processes;                         use Processes; 
  5. with Widgets;                           use Widgets; 
  6. with Widgets.Containers.Windows;        use Widgets.Containers.Windows; 
  7.  
  8. private with Ada.Containers.Indefinite_Hashed_Maps; 
  9. private with Ada.Strings.Hash_Case_Insensitive; 
  10. private with Ada.Real_Time; 
  11. private with Audio_Players; 
  12. private with Events; 
  13. private with Input_Handlers; 
  14. private with Processes.Managers; 
  15. private with Renderers; 
  16.  
  17. package Game_Views is 
  18.  
  19.     type Game_View is abstract new Object and Event_Listener and Process with private; 
  20.     type A_Game_View is access all Game_View'Class; 
  21.     pragma No_Strict_Aliasing( A_Game_View ); 
  22.  
  23.     function Create_Game_View( xres, yres : Positive; 
  24.                                scale      : Positive ) return A_Game_View; 
  25.     pragma Postcondition( Create_Game_View'Result /= null ); 
  26.  
  27.     -- Attachs a process to the view's process manager. 
  28.     procedure Attach( this : access Game_View; process : not null A_Process ); 
  29.  
  30.     -- Detaches a process from the view's process manager. 
  31.     procedure Detach( this : access Game_View; process : not null A_Process ); 
  32.  
  33.     -- Returns the view's corral. The view creates its corral at construction so 
  34.     -- this will never return null. 
  35.     function Get_Corral( this : not null access Game_View'Class ) return A_Corral; 
  36.     pragma Postcondition( Get_Corral'Result /= null ); 
  37.  
  38.     -- Returns a widget in the registry by id. Raises exception ID_NOT_FOUND if 
  39.     -- the widget does not exist. 
  40.     function Get_Widget( this : access Game_View; id : String ) return A_Widget; 
  41.     pragma Postcondition( Get_Widget'Result /= null ); 
  42.  
  43.     -- Returns the view's Window widget. This may return null if the window has 
  44.     -- not yet been set. 
  45.     function Get_Window( this : access Game_View ) return A_Window; 
  46.  
  47.     -- Adds a widget to the view's widget registry. Raises exception 
  48.     -- DUPLICATE_ID if a widget with the same id already exists. 
  49.     procedure Register( this : access Game_View; widget : not null A_Widget ); 
  50.  
  51.     -- Sets the view's Window widget. If window is null, the view's window will 
  52.     -- be removed. The view's Renderer is deleted and recreated when the window 
  53.     -- is changed. 
  54.     procedure Set_Window( this : access Game_View; window : in out A_Window ); 
  55.     pragma Postcondition( window = null ); 
  56.  
  57.     -- Starts the game view, attaching it to the framework. This will attach 
  58.     -- event listeners, processes, start the view's subsystems (audio, etc) 
  59.     -- and begin running the view's process manager. 
  60.     procedure Start( this : access Game_View ); 
  61.  
  62.     -- Stops the game view, detaching it from the framework. This must be called 
  63.     -- after Start and before deleting the object. 
  64.     procedure Stop( this : access Game_View ); 
  65.  
  66.     -- Removes a widget from the view's registry. If the widget was not 
  67.     -- previously registered, nothing happens. 
  68.     procedure Unregister( this : access Game_View; id : String ); 
  69.     pragma Precondition( id'Length > 0 ); 
  70.  
  71.     procedure Delete( this : in out A_Game_View ); 
  72.     pragma Postcondition( this = null ); 
  73.  
  74.     DUPLICATE_ID, 
  75.     ID_NOT_FOUND : exception; 
  76.  
  77. private 
  78.  
  79.     use Ada.Real_Time; 
  80.     use Audio_Players; 
  81.     use Events; 
  82.     use Input_Handlers; 
  83.     use Processes.Managers; 
  84.     use Renderers; 
  85.  
  86.     package Widget_Registry is new Ada.Containers.Indefinite_Hashed_Maps( 
  87.         String, A_Widget, Ada.Strings.Hash_Case_Insensitive, "=", "=" ); 
  88.     use Widget_Registry; 
  89.  
  90.     ----------------------------------------------------------------------------- 
  91.  
  92.     type Game_View is abstract new Object and Event_Listener and Process with 
  93.         record 
  94.             started, 
  95.             stopped     : Boolean := False; 
  96.             paused      : Boolean := False; 
  97.             win         : A_Window := null; 
  98.             renderer    : A_Renderer := null; 
  99.             audioPlayer : A_Audio_Player := null; 
  100.             inhandler   : A_Input_Handler := null; 
  101.             pman        : A_Process_Manager := null; 
  102.             corral      : A_Corral := null; 
  103.             widgets     : Widget_Registry.Map; 
  104.         end record; 
  105.  
  106.     -- Raises COPY_NOT_ALLOWED. 
  107.     procedure Adjust( this : access Game_View ); 
  108.  
  109.     procedure Construct( this : access Game_View ); 
  110.  
  111.     procedure Delete( this : in out Game_View ); 
  112.  
  113.     function Get_Process_Name( this : access Game_View ) return String; 
  114.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  115.  
  116.     -- Called when the window is requested to close by the OS. The default 
  117.     -- implementation is to simply queue a Queue_Close_Window message which will 
  118.     -- exit the application. If a confirmation dialog or some other activity 
  119.     -- needs to happen first, then this procedure should be overridden. 
  120.     procedure Handle_Close_Request( this : access Game_View ); 
  121.  
  122.     procedure Handle_Event( this : access Game_View; 
  123.                             evt  : in out A_Event; 
  124.                             resp : out Response_Type ); 
  125.     pragma Precondition( evt /= null ); 
  126.  
  127.     -- Called when resource loading is beginning and ending, so a loading 
  128.     -- message can be displayed. 
  129.     procedure Handle_Loading( this : access Game_View; loading : Boolean ); 
  130.  
  131.     -- Called when the game logic is paused or resumed. The base implementation 
  132.     -- does nothing. Override this procedure to perform actions when the game 
  133.     -- pause state changes. 
  134.     procedure Handle_Paused( this : access Game_View; paused : Boolean ); 
  135.  
  136.     procedure Tick( this : access Game_View; upTime, dt : Time_Span ); 
  137.  
  138.     ---------------------------------------------------------------------------- 
  139.  
  140.     type Allocator is 
  141.         access function( xres, yres : Positive; 
  142.                          scale      : Positive ) return A_Game_View; 
  143.  
  144.     procedure Register_Allocator( allocate : not null Allocator ); 
  145.  
  146. end Game_Views;