1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Events.Corrals;                    use Events.Corrals; 
  10. with Events.Listeners;                  use Events.Listeners; 
  11. with Objects;                           use Objects; 
  12. with Processes;                         use Processes; 
  13.  
  14. private with Events; 
  15. private with Physics.Managers; 
  16. private with Processes.Managers; 
  17.  
  18. limited private with Games.Sessions; 
  19.  
  20. package Games is 
  21.  
  22.     -- The Game class is parent object in the Game Logic system, which is 
  23.     -- responsible for managing the game session and all the interactions 
  24.     -- between entities during gameplay. 
  25.     -- 
  26.     -- The Game provides a Process_Manager to run the game logic, a Corral to 
  27.     -- receive events sent to listeners in the game logic, an association of 
  28.     -- modifyable game session variables, and game session persistence. The Game 
  29.     -- object itself is a Process and Event_Listener that is attached to its own 
  30.     -- Process_Manager and Corral facilities. The Game class also provides a 
  31.     -- limited interface, Game_State, which allow objects to reference it and 
  32.     -- access game state information and game session variables without a full 
  33.     -- view of the Game class, which in some cases would cause circular 
  34.     -- dependencies or allow unnecessary exposing of information. 
  35.     type Game is abstract new Limited_Object and Event_Listener with private; 
  36.     type A_Game is access all Game'Class; 
  37.  
  38.     -- Creates a new Game object using the registered allocator. If no 
  39.     -- allocator has been registered, an exception will be raised. 
  40.     function Create_Game return A_Game; 
  41.     pragma Postcondition( Create_Game'Result /= null ); 
  42.  
  43.     -- Finalizes the game logic and detaches it from the framework. This must be 
  44.     -- called before deleting the object, if it has been initialized. 
  45.     procedure Finalize( this : not null access Game'Class ); 
  46.  
  47.     -- Returns the Game's event Corral. It is created during Game construction. 
  48.     function Get_Corral( this : not null access Game'Class ) return A_Corral; 
  49.     pragma Postcondition( Get_Corral'Result /= null ); 
  50.  
  51.     -- Initializes the game logic object and attaches it to the framework. Be 
  52.     -- sure to call Finalize() before deleting the object. 
  53.     procedure Initialize( this : not null access Game'Class ); 
  54.  
  55.     -- Deletes the Game object. Finalize() must be called first, if the Game 
  56.     -- object has been initialized. 
  57.     procedure Delete( this : in out A_Game ); 
  58.     pragma Postcondition( this = null ); 
  59.  
  60. private 
  61.  
  62.     use Events; 
  63.     use Physics.Managers; 
  64.     use Processes.Managers; 
  65.  
  66.     type Game is new Limited_Object and Event_Listener with 
  67.         record 
  68.             initialized, 
  69.             finalized   : Boolean := False; 
  70.             corral      : A_Corral := null; 
  71.             physics     : A_Physics := null; 
  72.             pman        : A_Process_Manager := null; 
  73.             session     : access Games.Sessions.Game_Session'Class := null; 
  74.         end record; 
  75.  
  76.     procedure Construct( this : access Game ); 
  77.  
  78.     procedure Delete( this : in out Game ); 
  79.  
  80.     -- Handles the events that the Game is registered to receive from its Corral. 
  81.     procedure Handle_Event( this : access Game; 
  82.                             evt  : in out A_Event; 
  83.                             resp : out Response_Type ); 
  84.     pragma Precondition( evt /= null ); 
  85.  
  86. end Games;