hedgewars/uLandUtils.pas
branchtransitional_engine
changeset 15904 33798b649d9c
parent 15901 f39f0f614dbf
child 15905 022ec6b916b7
equal deleted inserted replaced
15903:230dc46487ea 15904:33798b649d9c
     1 unit uLandUtils;
     1 unit uLandUtils;
     2 interface
     2 interface
     3 uses SDLh;
     3 uses SDLh;
     4 
     4 
       
     5 procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
     5 procedure ResizeLand(width, height: LongWord);
     6 procedure ResizeLand(width, height: LongWord);
     6 procedure DisposeLand();
     7 procedure DisposeLand();
     7 procedure InitWorldEdges();
     8 procedure InitWorldEdges();
     8 
     9 
     9 function  LandGet(y, x: LongInt): Word;
    10 function  LandGet(y, x: LongInt): Word;
    18 
    19 
    19 implementation
    20 implementation
    20 uses uUtils, uConsts, uVariables, uTypes;
    21 uses uUtils, uConsts, uVariables, uTypes;
    21 
    22 
    22 const LibFutureName = 'hwengine_future';
    23 const LibFutureName = 'hwengine_future';
    23 function  create_game_field(width, height: Longword): pointer; cdecl; external LibFutureName;
    24 
       
    25 function  create_empty_game_field(width, height: Longword): pointer; cdecl; external LibFutureName;
       
    26 procedure get_game_field_parameters(game_field: pointer; var width: LongInt; var height: LongInt); cdecl; external LibFutureName;
    24 procedure dispose_game_field(game_field: pointer); cdecl; external LibFutureName;
    27 procedure dispose_game_field(game_field: pointer); cdecl; external LibFutureName;
       
    28 
    25 function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external LibFutureName;
    29 function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external LibFutureName;
    26 procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external LibFutureName;
    30 procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external LibFutureName;
    27 function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external LibFutureName;
    31 function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external LibFutureName;
    28 procedure land_fill(game_field: pointer; x, y: LongInt; border, fill: Word); cdecl; external LibFutureName;
    32 procedure land_fill(game_field: pointer; x, y: LongInt; border, fill: Word); cdecl; external LibFutureName;
    29 
    33 
    30 function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external LibFutureName;
    34 function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external LibFutureName;
    31 procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external LibFutureName;
    35 procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external LibFutureName;
    32 function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external LibFutureName;
    36 function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external LibFutureName;
       
    37 
       
    38 function  generate_templated_game_field(feature_size: Longword; seed, data_path, theme_name: PChar): pointer; cdecl; external LibFutureName;
    33 
    39 
    34 var gameField: pointer;
    40 var gameField: pointer;
    35 
    41 
    36 function  LandGet(y, x: LongInt): Word;
    42 function  LandGet(y, x: LongInt): Word;
    37 begin
    43 begin
    66 function  LandPixelRow(row: LongInt): PLongwordArray;
    72 function  LandPixelRow(row: LongInt): PLongwordArray;
    67 begin
    73 begin
    68     LandPixelRow:= land_pixel_row(gameField, row)
    74     LandPixelRow:= land_pixel_row(gameField, row)
    69 end;
    75 end;
    70 
    76 
       
    77 procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
       
    78 begin
       
    79     seed[byte(seed[0]) + 1]:= #0;
       
    80     theme[byte(theme[0]) + 1]:= #0;
       
    81 
       
    82     gameField:= generate_templated_game_field(featureSize, @seed[1], Str2PChar(dataPath), @theme[1]);
       
    83     get_game_field_parameters(gameField, LAND_WIDTH, LAND_HEIGHT);
       
    84 
       
    85     // let's assume those are powers of two
       
    86     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
       
    87     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
       
    88 
       
    89     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
       
    90 
       
    91     initScreenSpaceVars();
       
    92 end;
       
    93 
    71 procedure ResizeLand(width, height: LongWord);
    94 procedure ResizeLand(width, height: LongWord);
    72 var potW, potH: LongInt;
    95 var potW, potH: LongInt;
    73 begin
    96 begin
    74 potW:= toPowerOf2(width);
    97 potW:= toPowerOf2(width);
    75 potH:= toPowerOf2(height);
    98 potH:= toPowerOf2(height);
    79     LAND_HEIGHT:= potH;
   102     LAND_HEIGHT:= potH;
    80     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
   103     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
    81     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
   104     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
    82     cWaterLine:= LAND_HEIGHT;
   105     cWaterLine:= LAND_HEIGHT;
    83 
   106 
    84     gameField:= create_game_field(LAND_WIDTH, LAND_HEIGHT);
   107     gameField:= create_empty_game_field(LAND_WIDTH, LAND_HEIGHT);
    85     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
   108     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
    86     // 0.5 is already approaching on unplayable
   109     // 0.5 is already approaching on unplayable
    87     if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= cMaxZoomLevel/2;
   110     if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= cMaxZoomLevel/2;
    88     cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
   111     cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
    89     end;
   112     end;