1. with Events.Corrals;                    use Events.Corrals; 
  2. with Events.Listeners;                  use Events.Listeners; 
  3. with Game_Views;                        use Game_Views; 
  4. with Objects;                           use Objects; 
  5. with Processes;                         use Processes; 
  6.  
  7. private with Ada.Containers.Indefinite_Doubly_Linked_Lists; 
  8. private with Ada.Real_Time; 
  9. private with Associations; 
  10. private with Events; 
  11. private with Physics.Managers; 
  12. private with Processes.Managers; 
  13. private with Worlds; 
  14.  
  15. package Games is 
  16.  
  17.     type Game is abstract new Object and Event_Listener and Process with private; 
  18.     type A_Game is access all Game'Class; 
  19.  
  20.     -- Creates a new Game object, using the registered allocator. 
  21.     function Create_Game return A_Game; 
  22.     pragma Postcondition( Create_Game'Result /= null ); 
  23.  
  24.     -- Adds a view to the game logic. 'view' is consumed and then owned by the 
  25.     -- Game object. 
  26.     procedure Add_View( this : access Game; view : in out A_Game_View ); 
  27.     pragma Precondition( view /= null ); 
  28.     pragma Postcondition( view = null ); 
  29.  
  30.     -- Returns the Game's event corral. It is created during Game construction. 
  31.     function Get_Corral( this : access Game ) return A_Corral; 
  32.     pragma Postcondition( Get_Corral'Result /= null ); 
  33.  
  34.     -- Raises exception on error, clearing the current world. 
  35.     procedure Load_World( this : access Game; name : String ); 
  36.     pragma Postcondition( name'Length > 0 ); 
  37.  
  38.     -- Begins a new game session from the start. 
  39.     procedure New_Game( this : access Game ) is abstract; 
  40.  
  41.     -- Starts the game logic and attaches it to the framework. 
  42.     procedure Start( this : access Game ); 
  43.  
  44.     -- Stops the game logic and detaches it from the framework. 
  45.     procedure Stop( this : access Game ); 
  46.  
  47.     -- Deletes the Game. 
  48.     procedure Delete( this : in out A_Game ); 
  49.     pragma Postcondition( this = null ); 
  50.  
  51. private 
  52.  
  53.     use Ada.Real_Time; 
  54.     use Associations; 
  55.     use Events; 
  56.     use Physics.Managers; 
  57.     use Processes.Managers; 
  58.     use Worlds; 
  59.  
  60.     package View_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Game_View, "=" ); 
  61.  
  62.     ---------------------------------------------------------------------------- 
  63.  
  64.     type Game is abstract new Object and Event_Listener and Process with 
  65.         record 
  66.             views       : View_Lists.List; 
  67.             corral      : A_Corral := null; 
  68.             physics     : A_Physics := null; 
  69.             pman        : A_Process_Manager := null; 
  70.             sessionVars : A_Association := null; 
  71.             world       : A_World := null; 
  72.             paused      : Boolean := False; 
  73.         end record; 
  74.  
  75.     -- Raises COPY_NOT_ALLOWED. 
  76.     procedure Adjust( this : access Game ); 
  77.  
  78.     procedure Construct( this : access Game ); 
  79.  
  80.     procedure Delete( this : in out Game ); 
  81.  
  82.     -- Adds 'val' to game session variable 'var'. A Game_Var_Changed event is 
  83.     -- queued. An exception is raised on error. 
  84.     procedure Game_Var_Add( this : access Game; var : String; val : Integer ); 
  85.     pragma Precondition( var'Length > 0 ); 
  86.  
  87.     function Get_Process_Name( this : access Game ) return String; 
  88.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  89.  
  90.     procedure Handle_Event( this : access Game; 
  91.                             evt  : in out A_Event; 
  92.                             resp : out Response_Type ); 
  93.     pragma Precondition( evt /= null ); 
  94.  
  95.     -- Pauses the game logic. If overriding this procedure, call it explicitly 
  96.     -- first in the overriding Pause procedure. It will set the paused flag in 
  97.     -- the game object to the value of 'enabled'. 
  98.     procedure Pause( this : access Game; enabled : Boolean ); 
  99.  
  100.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  101.     -- queued. 
  102.     procedure Set_Game_Var( this : access Game; var : String; val : Integer ); 
  103.     pragma Precondition( var'Length > 0 ); 
  104.  
  105.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  106.     -- queued. 
  107.     procedure Set_Game_Var( this : access Game; var : String; val : Boolean ); 
  108.     pragma Precondition( var'Length > 0 ); 
  109.  
  110.     -- Sets the game's current world and attaches the world to the framework. 
  111.     -- The previous world will be detached from the framework and deleted. 
  112.     procedure Set_World( this : not null access Game'Class; world : A_World ); 
  113.  
  114.     procedure Tick( this : access Game; upTime, dt : Time_Span ); 
  115.  
  116.     ---------------------------------------------------------------------------- 
  117.  
  118.     type Allocator is access function return A_Game; 
  119.  
  120.     procedure Register_Allocator( allocate : not null Allocator ); 
  121.  
  122. end Games;