--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Events.Corrals; use Events.Corrals;
with Events.Listeners; use Events.Listeners;
with Objects; use Objects;
with Processes; use Processes;
private with Events;
private with Physics.Managers;
private with Processes.Managers;
limited private with Games.Sessions;
package Games is
-- The Game class is parent object in the Game Logic system, which is
-- responsible for managing the game session and all the interactions
-- between entities during gameplay.
--
-- The Game provides a Process_Manager to run the game logic, a Corral to
-- receive events sent to listeners in the game logic, an association of
-- modifyable game session variables, and game session persistence. The Game
-- object itself is a Process and Event_Listener that is attached to its own
-- Process_Manager and Corral facilities. The Game class also provides a
-- limited interface, Game_State, which allow objects to reference it and
-- access game state information and game session variables without a full
-- view of the Game class, which in some cases would cause circular
-- dependencies or allow unnecessary exposing of information.
type Game is abstract new Limited_Object and Event_Listener with private;
type A_Game is access all Game'Class;
-- Creates a new Game object using the registered allocator. If no
-- allocator has been registered, an exception will be raised.
function Create_Game return A_Game;
pragma Postcondition( Create_Game'Result /= null );
-- Finalizes the game logic and detaches it from the framework. This must be
-- called before deleting the object, if it has been initialized.
procedure Finalize( this : not null access Game'Class );
-- Returns the Game's event Corral. It is created during Game construction.
function Get_Corral( this : not null access Game'Class ) return A_Corral;
pragma Postcondition( Get_Corral'Result /= null );
-- Initializes the game logic object and attaches it to the framework. Be
-- sure to call Finalize() before deleting the object.
procedure Initialize( this : not null access Game'Class );
-- Deletes the Game object. Finalize() must be called first, if the Game
-- object has been initialized.
procedure Delete( this : in out A_Game );
pragma Postcondition( this = null );
private
use Events;
use Physics.Managers;
use Processes.Managers;
type Game is new Limited_Object and Event_Listener with
record
initialized,
finalized : Boolean := False;
corral : A_Corral := null;
physics : A_Physics := null;
pman : A_Process_Manager := null;
session : access Games.Sessions.Game_Session'Class := null;
end record;
procedure Construct( this : access Game );
procedure Delete( this : in out Game );
-- Handles the events that the Game is registered to receive from its Corral.
procedure Handle_Event( this : access Game;
evt : in out A_Event;
resp : out Response_Type );
pragma Precondition( evt /= null );
end Games;