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. private with Games; 
  10. private with Game_Views; 
  11. private with Processes; 
  12. private with Processes.Managers; 
  13.  
  14. package Applications.Gui.Games is 
  15.  
  16.     -- An abstract application class that runs an event-based game. 
  17.     type Game_Application is abstract new Gui_Application with private; 
  18.     type A_Game_Application is access all Game_Application'Class; 
  19.  
  20.     -- Stops the running game application. This will cause the thread that 
  21.     -- called Run to return. 'errorCode' is the application's return code that 
  22.     -- will eventually be returned to the operating system. Use NO_ERROR during 
  23.     -- a normal shutdown. 
  24.     procedure Stop( this      : not null access Game_Application'Class; 
  25.                     errorCode : Integer := NO_ERROR ); 
  26.  
  27.     ---------------------------------------------------------------------------- 
  28.  
  29.     -- Forces the application to shut down, displaying the given error message. 
  30.     -- If no Application has been created, then the system level shutdown 
  31.     -- procedure will be called. This is only to be used in the case of a fatal 
  32.     -- error. Execution will return from this procedure, so plan accordingly. 
  33.     procedure Terminate_Application( error : String ); 
  34.  
  35. private 
  36.  
  37.     use Game_Views; 
  38.     use Processes; 
  39.     use Processes.Managers; 
  40.     use Standard.Games; 
  41.  
  42.     type Game_Application is abstract new Gui_Application with 
  43.         record 
  44.             -- the following fields are protected by .lock 
  45.             errorCode : Integer := NO_ERROR;         -- return code for the OS 
  46.             view      : A_Game_View := null;         -- game view implementation 
  47.             game      : A_Game := null;              -- game logic implementation 
  48.             pman      : A_Process_Manager := null;   -- for application-level processes 
  49.         end record; 
  50.  
  51.     -- Finalizes the application and releases all resources. Do not call this if 
  52.     -- the application didn't successfully initialize. This should be called 
  53.     -- last by an overriding implementation. 
  54.     procedure Finalize( this : access Game_Application ); 
  55.  
  56.     -- Override to draw the loading screen displayed while the game is 
  57.     -- initializing. This is the only place where drawing can be done before the 
  58.     -- renderer is created by the game view. If this procedure is left null, the 
  59.     -- window will be solid black until the gui is started. 
  60.     procedure Draw_Loading_Screen( this : access Game_Application ) is null; 
  61.  
  62.     -- Initializes the application and game subsystems. Returns True on success. 
  63.     -- If initialization fails, Finalize should not be called. No exceptions 
  64.     -- will be raised. This should be called first by an overriding 
  65.     -- implementation. 
  66.     function Initialize( this : access Game_Application ) return Boolean; 
  67.  
  68.     -- Allows an application to preload resources before the game begins. The 
  69.     -- loading screen drawn by Draw_Loading_Screen() will be displayed in the 
  70.     -- window while the resources are loaded. 
  71.     -- 
  72.     -- Sound effects are good resources to pre-load, to avoid the loading delay 
  73.     -- in-game when a sound is played for the first time. 
  74.     procedure Load_Resources( this : access Game_Application ) is null; 
  75.  
  76.     function Run( this : access Game_Application ) return Integer; 
  77.  
  78. end Applications.Gui.Games;