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 Drawing_Contexts; 
  10. private with Games; 
  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. This will cause the thread that called Run to 
  21.     -- return. The value of 'errorCode' determines the value of 'returnCode' 
  22.     -- that will be returned from Run. 
  23.     procedure Stop( this      : not null access Game_Application'Class; 
  24.                     errorCode : Integer := NO_ERROR ); 
  25.  
  26.     ---------------------------------------------------------------------------- 
  27.  
  28.     -- Forces the application to shut down, displaying the given error message. 
  29.     -- If no Application has been created, then the system level shutdown 
  30.     -- procedure will be called. This is only to be used in the case of a fatal 
  31.     -- error. Execution will return from this procedure, so plan accordingly. 
  32.     procedure Terminate_Application( error : String ); 
  33.  
  34. private 
  35.  
  36.     use Drawing_Contexts; 
  37.     use Processes; 
  38.     use Processes.Managers; 
  39.     use Standard.Games; 
  40.  
  41.     type Game_Application is abstract new Gui_Application with 
  42.         record 
  43.             -- the following fields are protected by .lock 
  44.             errorCode : Integer := NO_ERROR;         -- return code for the OS 
  45.             game      : A_Game := null;              -- game logic implementation 
  46.             pman      : A_Process_Manager := null;   -- for application-level processes 
  47.         end record; 
  48.  
  49.     -- Closes the application and releases all resources. Do not call this if 
  50.     -- the application didn't successfully initialize. This should be called 
  51.     -- last by an overriding implementation. 
  52.     procedure Close( this : access Game_Application ); 
  53.  
  54.     -- Override to draw the loading screen displayed while the game is 
  55.     -- initializing. This is the only place where drawing can be done before the 
  56.     -- renderer is created by the game view. If this procedure is left null, the 
  57.     -- window will be solid black until the gui is started. 
  58.     procedure Draw_Loading_Screen( this : access Game_Application; 
  59.                                    dc   : Drawing_Context ) is null; 
  60.  
  61.     -- Initializes the application and game subsystems. The application will 
  62.     -- will open in 640x400 windowed mode by default. This setting can be 
  63.     -- overridden by the application's configuration. To specify the default 
  64.     -- window parameters, call Init(4) instead. Returns True on success. If 
  65.     -- initialization fails, Close will be called automatically to clean up. No 
  66.     -- exceptions will be raised. This should be called first by an overriding 
  67.     -- implementation. 
  68.     function Init( this : access Game_Application ) return Boolean; 
  69.  
  70.     -- Initializes the application and game subsystems. Returns True on success. 
  71.     -- If initialization fails, Close will be called automatically to clean up. 
  72.     -- No exceptions will be raised. This should be called first by an 
  73.     -- overriding implementation. 
  74.     function Init( this         : access Game_Application; 
  75.                    app_xres, 
  76.                    app_yres     : Natural; 
  77.                    app_scale    : Positive; 
  78.                    app_windowed : Boolean ) return Boolean; 
  79.  
  80.     function Run( this : access Game_Application ) return Integer; 
  81.  
  82. end Applications.Gui.Games;