with Ada.Streams; use Ada.Streams;
with Objects; use Objects;
package Maps is
MAX_WIDTH : constant Positive;
MAX_HEIGHT : constant Positive;
type Layer_Data is array(Positive range <>) of Natural;
type Layer(size : Positive) is
record
physical : Boolean := False;
data : Layer_Data(1..size);
end record;
type A_Layer is access all Layer;
type Layer_Array is array (Positive range <>) of A_Layer;
type A_Layer_Array is access all Layer_Array;
function Copy( src : A_Layer_Array ) return A_Layer_Array;
procedure Delete( la : in out A_Layer_Array );
procedure Move( dst, src : in out A_Layer_Array );
pragma Postcondition( src = null );
pragma Postcondition( dst = src'Old );
type Map_Object is abstract new Object with private;
type A_Map is access all Map_Object'Class;
function Create_Map( width, height : Positive ) return A_Map;
pragma Postcondition( Create_Map'Result /= null );
function Get_Height( this : not null access Map_Object'Class ) return Positive;
pragma Postcondition( Get_Height'Result <= MAX_HEIGHT );
function Get_Layers( this : not null access Map_Object'Class ) return Positive;
function Get_Layers_Data( this : not null access Map_Object'Class ) return A_Layer_Array;
pragma Postcondition( Get_Layers_Data'Result /= null );
function Get_Tile_Id( this : not null access Map_Object'Class;
layer : Positive;
x, y : Integer ) return Natural;
function Get_Width( this : not null access Map_Object'Class ) return Positive;
pragma Postcondition( Get_Width'Result <= MAX_WIDTH );
function Object_Input( stream : access Root_Stream_Type'Class ) return Map_Object is abstract;
procedure Resize( this : not null access Map_Object'Class;
width,
height : Positive );
procedure Set_Tile( this : not null access Map_Object'Class;
layer : Positive;
x, y : Integer;
tile : Natural );
function Tile_Width( this : not null access Map_Object'Class ) return Positive;
function Copy( src : A_Map ) return A_Map;
pragma Postcondition( Copy'Result /= src or else src = null );
procedure Delete( this : in out A_Map );
pragma Postcondition( this = null );
private
MAX_WIDTH : constant Positive := 1024;
MAX_HEIGHT : constant Positive := 1024;
type Map_Object is abstract new Object with
record
width,
height : Positive := 1;
layers : A_Layer_Array := null;
end record;
procedure Adjust( this : access Map_Object );
procedure Construct( this : access Map_Object;
width,
height,
layers : Positive );
procedure Delete( this : in out Map_Object );
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Map_Object );
for Map_Object'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Map_Object );
for Map_Object'Write use Object_Write;
function A_Map_Input( stream : access Root_Stream_Type'Class ) return A_Map;
for A_Map'Input use A_Map_Input;
procedure A_Map_Output( stream : access Root_Stream_Type'Class; map : A_Map );
for A_Map'Output use A_Map_Output;
procedure A_Map_Read( stream : access Root_Stream_Type'Class; map : out A_Map );
for A_Map'Read use A_Map_Read;
procedure A_Map_Write( stream : access Root_Stream_Type'Class; map : A_Map );
for A_Map'Write use A_Map_Write;
procedure Delete( lyr : in out A_Layer );
function A_Layer_Input( stream : access Root_Stream_Type'Class ) return A_Layer;
for A_Layer'Input use A_Layer_Input;
procedure A_Layer_Output( stream : access Root_Stream_Type'Class; lyr : A_Layer );
for A_Layer'Output use A_Layer_Output;
function A_Layer_Array_Input( stream : access Root_Stream_Type'Class ) return A_Layer_Array;
for A_Layer_Array'Input use A_Layer_Array_Input;
procedure A_Layer_Array_Output( stream : access Root_Stream_Type'Class; la : A_Layer_Array );
for A_Layer_Array'Output use A_Layer_Array_Output;
type Allocator is access function( width, height : Positive ) return A_Map;
procedure Register_Allocator( allocate : not null Allocator );
end Maps;