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 Limited_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. If this procedure raises an exception, the view will be left 
  54.     -- left without a window and the given 'window' will remain unchanged. 
  55.     procedure Set_Window( this : access Game_View; window : in out A_Window ); 
  56.     pragma Postcondition( window = null ); 
  57.  
  58.     -- Starts the game view, attaching it to the framework. This will attach 
  59.     -- event listeners, processes, start the view's subsystems (audio, etc) 
  60.     -- and begin running the view's process manager. 
  61.     procedure Start( this : access Game_View ); 
  62.  
  63.     -- Stops the game view, detaching it from the framework. This must be called 
  64.     -- after Start and before deleting the object. 
  65.     procedure Stop( this : access Game_View ); 
  66.  
  67.     -- Removes a widget from the view's registry. If the widget was not 
  68.     -- previously registered, nothing happens. 
  69.     procedure Unregister( this : access Game_View; id : String ); 
  70.     pragma Precondition( id'Length > 0 ); 
  71.  
  72.     procedure Delete( this : in out A_Game_View ); 
  73.     pragma Postcondition( this = null ); 
  74.  
  75.     DUPLICATE_ID, 
  76.     ID_NOT_FOUND : exception; 
  77.  
  78. private 
  79.  
  80.     use Ada.Real_Time; 
  81.     use Audio_Players; 
  82.     use Events; 
  83.     use Input_Handlers; 
  84.     use Processes.Managers; 
  85.     use Renderers; 
  86.  
  87.     package Widget_Registry is new Ada.Containers.Indefinite_Hashed_Maps( 
  88.         String, A_Widget, Ada.Strings.Hash_Case_Insensitive, "=", "=" ); 
  89.     use Widget_Registry; 
  90.  
  91.     ----------------------------------------------------------------------------- 
  92.  
  93.     type Game_View is abstract new Limited_Object and Event_Listener and Process with 
  94.         record 
  95.             started, 
  96.             stopped     : Boolean := False; 
  97.             paused      : Boolean := False; 
  98.             win         : A_Window := null; 
  99.             renderer    : A_Renderer := null; 
  100.             audioPlayer : A_Audio_Player := null; 
  101.             inhandler   : A_Input_Handler := null; 
  102.             pman        : A_Process_Manager := null; 
  103.             corral      : A_Corral := null; 
  104.             widgets     : Widget_Registry.Map; 
  105.         end record; 
  106.  
  107.     procedure Construct( this : access Game_View ); 
  108.  
  109.     procedure Delete( this : in out Game_View ); 
  110.  
  111.     function Get_Process_Name( this : access Game_View ) return String; 
  112.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  113.  
  114.     -- Called when the window is requested to close by the OS. The default 
  115.     -- implementation is to simply queue a Queue_Close_Window message which will 
  116.     -- exit the application. If a confirmation dialog or some other activity 
  117.     -- needs to happen first, then this procedure should be overridden. 
  118.     procedure Handle_Close_Request( this : access Game_View ); 
  119.  
  120.     procedure Handle_Event( this : access Game_View; 
  121.                             evt  : in out A_Event; 
  122.                             resp : out Response_Type ); 
  123.     pragma Precondition( evt /= null ); 
  124.  
  125.     -- Called when resource loading is beginning and ending, so a loading 
  126.     -- message can be displayed. 
  127.     procedure Handle_Loading( this : access Game_View; loading : Boolean ); 
  128.  
  129.     -- Called when the game logic is paused or resumed. The base implementation 
  130.     -- does nothing. Override this procedure to perform actions when the game 
  131.     -- pause state changes. 
  132.     procedure Handle_Paused( this : access Game_View; paused : Boolean ); 
  133.  
  134.     procedure Tick( this : access Game_View; upTime, dt : Time_Span ); 
  135.  
  136.     ---------------------------------------------------------------------------- 
  137.  
  138.     type Allocator is 
  139.         access function( xres, yres : Positive; 
  140.                          scale      : Positive ) return A_Game_View; 
  141.  
  142.     procedure Register_Allocator( allocate : not null Allocator ); 
  143.  
  144. end Game_Views;