--
-- 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.
--
with Objects; use Objects;
with Maps; use Maps;
private with Tiles.Libraries;
package Physics.Clip_Maps is
-- A Clip_Map is analogous to a Map_Object but it stores Clip_Type values
-- instead of tile ids. It is constructed from an existing Layer_Array with
-- tile ids and its corresponding tile library. Clip_Maps are used by a
-- Physica_Manager to clip entities to solid tile types in the world.
type Clip_Map is new Object with private;
type A_Clip_Map is access all Clip_Map'Class;
-- Creates a new empty Clip_Map. 'width' and 'height' are the size of the
-- map in tiles, and 'tileWidth' is the size of a tile in pixels. An
-- exception will be raised on error.
function Create_Clip_Map( width,
height,
tileWidth : Positive;
mapLayers : not null A_Layer_Array;
libName : String ) return A_Clip_Map;
pragma Precondition( libName'Length > 0 );
pragma Postcondition( Create_Clip_Map'Result /= null );
-- Returns the type of clipping found at a map location in pixels.
function Get( this : not null access Clip_Map'Class;
x, y : Float ) return Clip_Type;
-- Returns the type of clipping found at a map location in tiles. The upper
-- left tile in the map is at 0, 0.
function Get( this : not null access Clip_Map'Class;
x, y : Integer ) return Clip_Type;
-- Returns the map's height in pixels.
function Get_Height( this : not null access Clip_Map'Class ) return Positive;
-- Returns the map's width in pixels.
function Get_Width( this : not null access Clip_Map'Class ) return Positive;
-- Sets the id of a tile at a location in the map. The Clip_Map is updated
-- appropriately with the new proper type of clipping at that location.
procedure Set_Tile( this : not null access Clip_Map'Class;
id : Natural;
x, y : Natural;
layer : Natural );
-- Returns the size of a tile in pixels that the Clip_Map is using.
function Tile_Width( this : not null access Clip_Map'Class ) return Positive;
-- Deletes the Clip_Map.
procedure Delete( this : in out A_Clip_Map );
pragma Postcondition( this = null );
private
use Tiles.Libraries;
type Clip_Layer is array (Natural range <>) of Clip_Type;
type A_Clip_Layer is access all Clip_Layer;
type Clip_Map is new Object with
record
mapWidth, -- width in pixels
mapHeight, -- height in pixels
mapWidthTiles, -- width in tiles
mapHeightTiles, -- height in tiles
tileWidth : Positive := 1; -- size of a tile in pixels
mapLayers : A_Layer_Array := null; -- the actual map in tiles
clipLayer : A_Clip_Layer := null;
lib : A_Tile_Library := null;
end record;
-- Raises an exception if library 'libName' can't be loaded.
procedure Construct( this : access Clip_Map;
width,
height,
tileWidth : Positive;
mapLayers : not null A_Layer_Array;
libName : String );
procedure Delete( this : in out Clip_Map );
end Physics.Clip_Maps;