1. with Objects;                           use Objects; 
  2. with Maps;                              use Maps; 
  3.  
  4. private with Tiles.Libraries; 
  5.  
  6. package Physics.Clip_Maps is 
  7.  
  8.     -- A Clip_Map is analogous to a Map_Object but it stores Clip_Type values 
  9.     -- instead of tile ids. It is constructed from an existing Layer_Array with 
  10.     -- tile ids and its corresponding tile library. Clip_Maps are used by a 
  11.     -- Physica_Manager to clip entities to solid tile types in the world. 
  12.     type Clip_Map is new Object with private; 
  13.     type A_Clip_Map is access all Clip_Map'Class; 
  14.  
  15.     -- Creates a new empty Clip_Map. 'width' and 'height' are the size of the 
  16.     -- map in tiles, and 'tileWidth' is the size of a tile in pixels. An 
  17.     -- exception will be raised on error. 
  18.     function Create_Clip_Map( width, 
  19.                               height, 
  20.                               tileWidth : Positive; 
  21.                               mapLayers : not null A_Layer_Array; 
  22.                               libName   : String ) return A_Clip_Map; 
  23.     pragma Precondition( libName'Length > 0 ); 
  24.     pragma Postcondition( Create_Clip_Map'Result /= null ); 
  25.  
  26.     -- Returns the type of clipping found at a map location in pixels. 
  27.     function Get( this : not null access Clip_Map'Class; 
  28.                   x, y : Float ) return Clip_Type; 
  29.  
  30.     -- Returns the type of clipping found at a map location in tiles. The upper 
  31.     -- left tile in the map is at 0, 0. 
  32.     function Get( this : not null access Clip_Map'Class; 
  33.                   x, y : Integer ) return Clip_Type; 
  34.  
  35.     -- Returns the map's height in pixels. 
  36.     function Get_Height( this : not null access Clip_Map'Class ) return Positive; 
  37.  
  38.     -- Returns the map's width in pixels. 
  39.     function Get_Width( this : not null access Clip_Map'Class ) return Positive; 
  40.  
  41.     -- Sets the id of a tile at a location in the map. The Clip_Map is updated 
  42.     -- appropriately with the new proper type of clipping at that location. 
  43.     procedure Set_Tile( this  : not null access Clip_Map'Class; 
  44.                         id    : Natural; 
  45.                         x, y  : Natural; 
  46.                         layer : Natural ); 
  47.  
  48.     -- Returns the size of a tile in pixels that the Clip_Map is using. 
  49.     function Tile_Width( this : not null access Clip_Map'Class ) return Positive; 
  50.  
  51.     -- Deletes the Clip_Map. 
  52.     procedure Delete( this : in out A_Clip_Map ); 
  53.     pragma Postcondition( this = null ); 
  54.  
  55. private 
  56.  
  57.     use Tiles.Libraries; 
  58.  
  59.     type Clip_Layer is array (Natural range <>) of Clip_Type; 
  60.     type A_Clip_Layer is access all Clip_Layer; 
  61.  
  62.     type Clip_Map is new Object with 
  63.         record 
  64.             mapWidth,                               -- width in pixels 
  65.             mapHeight,                              -- height in pixels 
  66.             mapWidthTiles,                          -- width in tiles 
  67.             mapHeightTiles,                         -- height in tiles 
  68.             tileWidth      : Positive := 1;         -- size of a tile in pixels 
  69.             mapLayers      : A_Layer_Array := null; -- the actual map in tiles 
  70.             clipLayer      : A_Clip_Layer := null; 
  71.             lib            : A_Tile_Library := null; 
  72.         end record; 
  73.  
  74.     procedure Calculate_Clipping( this : not null access Clip_Map'Class; 
  75.                                   x, y : Integer ); 
  76.  
  77.     -- Raises an exception if library 'libName' can't be loaded. 
  78.     procedure Construct( this      : access Clip_Map; 
  79.                          width, 
  80.                          height, 
  81.                          tileWidth : Positive; 
  82.                          mapLayers : not null A_Layer_Array; 
  83.                          libName   : String ); 
  84.  
  85.     procedure Delete( this : in out Clip_Map ); 
  86.  
  87. end Physics.Clip_Maps;