--
-- 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.
--
private with Games;
private with Game_Views;
private with Processes;
private with Processes.Managers;
package Applications.Gui.Games is
-- An abstract application class that runs an event-based game.
type Game_Application is abstract new Gui_Application with private;
type A_Game_Application is access all Game_Application'Class;
-- Stops the running game application. This will cause the thread that
-- called Run to return. 'errorCode' is the application's return code that
-- will eventually be returned to the operating system. Use NO_ERROR during
-- a normal shutdown.
procedure Stop( this : not null access Game_Application'Class;
errorCode : Integer := NO_ERROR );
----------------------------------------------------------------------------
-- Forces the application to shut down, displaying the given error message.
-- If no Application has been created, then the system level shutdown
-- procedure will be called. This is only to be used in the case of a fatal
-- error. Execution will return from this procedure, so plan accordingly.
procedure Terminate_Application( error : String );
private
use Game_Views;
use Processes;
use Processes.Managers;
use Standard.Games;
type Game_Application is abstract new Gui_Application with
record
-- the following fields are protected by .lock
errorCode : Integer := NO_ERROR; -- return code for the OS
view : A_Game_View := null; -- game view implementation
game : A_Game := null; -- game logic implementation
pman : A_Process_Manager := null; -- for application-level processes
end record;
-- Finalizes the application and releases all resources. Do not call this if
-- the application didn't successfully initialize. This should be called
-- last by an overriding implementation.
procedure Finalize( this : access Game_Application );
-- Override to draw the loading screen displayed while the game is
-- initializing. This is the only place where drawing can be done before the
-- renderer is created by the game view. If this procedure is left null, the
-- window will be solid black until the gui is started.
procedure Draw_Loading_Screen( this : access Game_Application ) is null;
-- Initializes the application and game subsystems. Returns True on success.
-- If initialization fails, Finalize should not be called. No exceptions
-- will be raised. This should be called first by an overriding
-- implementation.
function Initialize( this : access Game_Application ) return Boolean;
-- Allows an application to preload resources before the game begins. The
-- loading screen drawn by Draw_Loading_Screen() will be displayed in the
-- window while the resources are loaded.
--
-- Sound effects are good resources to pre-load, to avoid the loading delay
-- in-game when a sound is played for the first time.
procedure Load_Resources( this : access Game_Application ) is null;
function Run( this : access Game_Application ) return Integer;
end Applications.Gui.Games;