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