hedgewars/uLand.pas
changeset 2699 249adefa9c1c
parent 2692 ce9992075118
child 2705 2b5625c4ec16
equal deleted inserted replaced
2698:90585aba87ad 2699:249adefa9c1c
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uLand;
    21 unit uLand;
    22 interface
    22 interface
    23 uses SDLh, uLandTemplates, uFloat,
    23 uses SDLh, uLandTemplates, uFloat, uConsts,
    24 {$IFDEF GLES11}
    24 {$IFDEF GLES11}
    25 	gles11,
    25 	gles11;
    26 {$ELSE}
    26 {$ELSE}
    27 	GL,
    27 	GL;
    28 {$ENDIF}
    28 {$ENDIF}
    29 	uConsts;
    29 
    30 type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord;
    30 type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord;
    31 	TCollisionArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of Word;
    31 	TCollisionArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of Word;
    32 	TPreview  = packed array[0..127, 0..31] of byte;
    32 	TPreview  = packed array[0..127, 0..31] of byte;
    33 	TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    33 	TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    34 
    34 
    35 var  Land: TCollisionArray;
    35 var Land: TCollisionArray;
    36      LandPixels: TLandArray;
    36     LandPixels: TLandArray;
    37      LandDirty: TDirtyTag;
    37     LandDirty: TDirtyTag;
    38      hasBorder: boolean; 
    38     hasBorder: boolean; 
    39      hasGirders: boolean;  
    39     hasGirders: boolean;  
    40      playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.
    40     playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.
    41 	 LandBackSurface: PSDL_Surface = nil;
    41     LandBackSurface: PSDL_Surface;
    42 
    42 
       
    43 procedure init_uLand;
       
    44 procedure free_uLand;
    43 procedure GenMap;
    45 procedure GenMap;
    44 function  GenPreview: TPreview;
    46 function  GenPreview: TPreview;
    45 procedure CheckLandDigest(s: shortstring);
    47 procedure CheckLandDigest(s: shortstring);
    46 function  LandBackPixel(x, y: LongInt): LongWord;
    48 function  LandBackPixel(x, y: LongInt): LongWord;
    47 
    49 
   313 var p: PLongWordArray;
   315 var p: PLongWordArray;
   314 begin
   316 begin
   315 	if LandBackSurface = nil then
   317 	if LandBackSurface = nil then
   316 		LandBackPixel:= 0
   318 		LandBackPixel:= 0
   317 	else
   319 	else
   318 		begin
   320 	begin
   319 		p:= LandBackSurface^.pixels;
   321 		p:= LandBackSurface^.pixels;
   320 		LandBackPixel:= p^[LandBackSurface^.w * (y mod LandBackSurface^.h) + (x mod LandBackSurface^.w)];// or $FF000000;
   322 		LandBackPixel:= p^[LandBackSurface^.w * (y mod LandBackSurface^.h) + (x mod LandBackSurface^.w)];// or $FF000000;
   321 		end
   323 	end
   322 end;
   324 end;
   323 
   325 
   324 procedure ColorizeLand(Surface: PSDL_Surface);
   326 procedure ColorizeLand(Surface: PSDL_Surface);
   325 var tmpsurf: PSDL_Surface;
   327 var tmpsurf: PSDL_Surface;
   326     r, rr: TSDL_Rect;
   328     r, rr: TSDL_Rect;
   847             end
   849             end
   848         end;
   850         end;
   849 GenPreview:= Preview
   851 GenPreview:= Preview
   850 end;
   852 end;
   851 
   853 
   852 initialization
   854 procedure init_uLand;
   853 
   855 begin
   854 finalization
   856 	LandBackSurface:= nil;
   855 if LandBackSurface <> nil then
   857 end;
   856 	SDL_FreeSurface(LandBackSurface);
   858 
       
   859 procedure free_uLand;
       
   860 begin
       
   861 	if LandBackSurface <> nil then
       
   862 		SDL_FreeSurface(LandBackSurface);
       
   863 end;
       
   864 
   857 end.
   865 end.