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 Limited_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.     -- Starts the game logic and attaches it to the framework. 
  39.     procedure Start( this : access Game ); 
  40.  
  41.     -- Stops the game logic and detaches it from the framework. 
  42.     procedure Stop( this : access Game ); 
  43.  
  44.     -- Deletes the Game. 
  45.     procedure Delete( this : in out A_Game ); 
  46.     pragma Postcondition( this = null ); 
  47.  
  48. private 
  49.  
  50.     use Ada.Real_Time; 
  51.     use Associations; 
  52.     use Events; 
  53.     use Physics.Managers; 
  54.     use Processes.Managers; 
  55.     use Worlds; 
  56.  
  57.     package View_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Game_View, "=" ); 
  58.  
  59.     ---------------------------------------------------------------------------- 
  60.  
  61.     type Game is abstract new Limited_Object and Event_Listener and Process with 
  62.         record 
  63.             started, 
  64.             stopped     : Boolean := False; 
  65.             views       : View_Lists.List; 
  66.             corral      : A_Corral := null; 
  67.             physics     : A_Physics := null; 
  68.             pman        : A_Process_Manager := null; 
  69.             sessionVars : A_Association := null; 
  70.             world       : A_World := null; 
  71.             playing     : Boolean := False; 
  72.             paused      : Boolean := False; 
  73.         end record; 
  74.  
  75.     procedure Construct( this : access Game ); 
  76.  
  77.     procedure Delete( this : in out Game ); 
  78.  
  79.     -- Ends the current game session. Game logic is stopped and the Game_State 
  80.     -- event is sent. 
  81.     procedure End_Game( this : access Game ); 
  82.  
  83.     -- Adds 'val' to game session variable 'var'. A Game_Var_Changed event is 
  84.     -- queued. An exception is raised on error. 
  85.     procedure Game_Var_Add( this : access Game; var : String; val : Integer ); 
  86.     pragma Precondition( var'Length > 0 ); 
  87.  
  88.     function Get_Process_Name( this : access Game ) return String; 
  89.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  90.  
  91.     procedure Handle_Event( this : access Game; 
  92.                             evt  : in out A_Event; 
  93.                             resp : out Response_Type ); 
  94.     pragma Precondition( evt /= null ); 
  95.  
  96.     -- Begins a new game session from the start. Override this procedure to 
  97.     -- setup initial game state and load the first game world. Call this 
  98.     -- procedure from the overriding one first. 
  99.     procedure New_Game( this : access Game ); 
  100.  
  101.     -- Pauses the game logic. If overriding this procedure, call it explicitly 
  102.     -- first in the overriding Pause procedure. It will set the paused flag in 
  103.     -- the game object to the value of 'enabled'. 
  104.     procedure Pause( this : access Game; enabled : Boolean ); 
  105.  
  106.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  107.     -- queued. 
  108.     procedure Set_Game_Var( this : access Game; var : String; val : Integer ); 
  109.     pragma Precondition( var'Length > 0 ); 
  110.  
  111.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  112.     -- queued. 
  113.     procedure Set_Game_Var( this : access Game; var : String; val : Boolean ); 
  114.     pragma Precondition( var'Length > 0 ); 
  115.  
  116.     -- Sets the game's current world and attaches the world to the framework. 
  117.     -- The previous world will be detached from the framework and deleted. 
  118.     procedure Set_World( this : not null access Game'Class; world : A_World ); 
  119.  
  120.     procedure Tick( this : access Game; upTime, dt : Time_Span ); 
  121.  
  122.     ---------------------------------------------------------------------------- 
  123.  
  124.     type Allocator is access function return A_Game; 
  125.  
  126.     procedure Register_Allocator( allocate : not null Allocator ); 
  127.  
  128. end Games;