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 Actors; 
  8. private with Ada.Containers.Indefinite_Doubly_Linked_Lists; 
  9. private with Ada.Containers.Ordered_Maps; 
  10. private with Ada.Real_Time; 
  11. private with Associations; 
  12. private with Entities; 
  13. private with Events; 
  14. private with Physics.Managers; 
  15. private with Processes.Managers; 
  16. private with Worlds; 
  17.  
  18. package Games is 
  19.  
  20.     type Game is abstract new Limited_Object and Event_Listener and Process with private; 
  21.     type A_Game is access all Game'Class; 
  22.  
  23.     -- Creates a new Game object, using the registered allocator. 
  24.     function Create_Game return A_Game; 
  25.     pragma Postcondition( Create_Game'Result /= null ); 
  26.  
  27.     -- Adds a view to the game logic. 'view' is consumed and then owned by the 
  28.     -- Game object. 
  29.     procedure Add_View( this : not null access Game'Class; 
  30.                         view : in out A_Game_View ); 
  31.     pragma Precondition( view /= null ); 
  32.     pragma Postcondition( view = null ); 
  33.  
  34.     -- Adds 'val' to game session variable 'var'. A Game_Var_Changed event is 
  35.     -- queued. An exception is raised on error. 
  36.     procedure Game_Var_Add( this : not null access Game'Class; 
  37.                             var  : String; 
  38.                             val  : Integer ); 
  39.     pragma Precondition( var'Length > 0 ); 
  40.  
  41.     -- Returns the Game's event corral. It is created during Game construction. 
  42.     function Get_Corral( this : not null access Game'Class ) return A_Corral; 
  43.     pragma Postcondition( Get_Corral'Result /= null ); 
  44.  
  45.     -- Returns the value of game session var 'var' as an integer. An exception 
  46.     -- will be raised on error. 
  47.     function Get_Game_Var( this : not null access Game'Class; 
  48.                            var  : String ) return Integer; 
  49.  
  50.     -- Unloads the current world and attaches the new world to the game 
  51.     -- framework. If an error occurs, an exception will be raised and the 
  52.     -- current world not change. 
  53.     procedure Load_World( this : not null access Game'Class; name : String ); 
  54.     pragma Postcondition( name'Length > 0 ); 
  55.  
  56.     -- Starts the game logic and attaches it to the framework. 
  57.     procedure Start( this : access Game ); 
  58.  
  59.     -- Stops the game logic and detaches it from the framework. 
  60.     procedure Stop( this : not null access Game'Class ); 
  61.  
  62.     -- Deletes the Game. 
  63.     procedure Delete( this : in out A_Game ); 
  64.     pragma Postcondition( this = null ); 
  65.  
  66. private 
  67.  
  68.     use Actors; 
  69.     use Ada.Real_Time; 
  70.     use Associations; 
  71.     use Entities; 
  72.     use Events; 
  73.     use Physics.Managers; 
  74.     use Processes.Managers; 
  75.     use Worlds; 
  76.  
  77.     package Actor_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Actor, "=" ); 
  78.  
  79.     package Actor_Maps is new Ada.Containers.Ordered_Maps( Entity_Id, A_Actor, "<", "=" ); 
  80.  
  81.     package View_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Game_View, "=" ); 
  82.  
  83.     ---------------------------------------------------------------------------- 
  84.  
  85.     type Game is abstract new Limited_Object and Event_Listener and Process with 
  86.         record 
  87.             started, 
  88.             stopped     : Boolean := False; 
  89.             views       : View_Lists.List; 
  90.             corral      : A_Corral := null; 
  91.             physics     : A_Physics := null; 
  92.             pman        : A_Process_Manager := null; 
  93.             sessionVars : A_Association := null; 
  94.             world       : A_World := null; 
  95.             actors      : Actor_Lists.List; 
  96.             actorIndex  : Actor_Maps.Map; 
  97.             playing     : Boolean := False; 
  98.             paused      : Boolean := False; 
  99.         end record; 
  100.  
  101.     -- Adds the Game object as an event listener for a set of events. Override 
  102.     -- this procedure, calling it first, to listen for additional events. 
  103.     procedure Add_Event_Listeners( this : access Game ); 
  104.  
  105.     procedure Construct( this : access Game ); 
  106.  
  107.     procedure Delete( this : in out Game ); 
  108.  
  109.     -- Ends the current game session. Game logic is stopped and the Game_State 
  110.     -- event is sent. 
  111.     procedure End_Game( this : access Game ); 
  112.  
  113.     -- Gets the Process name of the Game object. 
  114.     function Get_Process_Name( this : access Game ) return String; 
  115.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  116.  
  117.     procedure Handle_Event( this : access Game; 
  118.                             evt  : in out A_Event; 
  119.                             resp : out Response_Type ); 
  120.     pragma Precondition( evt /= null ); 
  121.  
  122.     -- Unloads the current world and attaches the new world to the game 
  123.     -- framework. 'world' will be consumed. 
  124.     procedure Load_World( this  : not null access Game'Class; 
  125.                           world : in out A_World ); 
  126.     pragma Postcondition( world = null ); 
  127.  
  128.     -- Begins a new game session from the start. Override this procedure to 
  129.     -- setup initial game state and load the first game world. Call this 
  130.     -- procedure from the overriding one first. 
  131.     procedure New_Game( this : access Game ); 
  132.  
  133.     -- Pauses the game logic. If overriding this procedure, call it explicitly 
  134.     -- first in the overriding Pause procedure. It will set the paused flag in 
  135.     -- the game object to the value of 'enabled'. 
  136.     procedure Pause( this : access Game; enabled : Boolean ); 
  137.  
  138.     -- Removes the Game object as an event listener for a set of events. If 
  139.     -- Add_Event_Listener is overridden, then this should be overridden to 
  140.     -- remove the additional specific events. Call this last in the overriding 
  141.     -- implementation. 
  142.     procedure Remove_Event_Listeners( this : access Game ); 
  143.  
  144.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  145.     -- queued. 
  146.     procedure Set_Game_Var( this : not null access Game'Class; 
  147.                             var  : String; 
  148.                             val  : Integer ); 
  149.     pragma Precondition( var'Length > 0 ); 
  150.  
  151.     -- Sets game session variable 'var' to 'val'. A Game_Var_Changed event is 
  152.     -- queued. 
  153.     procedure Set_Game_Var( this : not null access Game'Class; 
  154.                             var  : String; 
  155.                             val  : Boolean ); 
  156.     pragma Precondition( var'Length > 0 ); 
  157.  
  158.     procedure Tick( this : access Game; upTime, dt : Time_Span ); 
  159.  
  160.     -- Unloads the currently loaded world, detaching it from the game framework 
  161.     -- and deleting temporal actors. 
  162.     procedure Unload_World( this : not null access Game'Class ); 
  163.  
  164.     ---------------------------------------------------------------------------- 
  165.  
  166.     type Allocator is access function return A_Game; 
  167.  
  168.     procedure Register_Allocator( allocate : not null Allocator ); 
  169.  
  170. end Games;