hedgewars/uLandGenPerlin.pas
branchtransitional_engine
changeset 15900 128ace913837
parent 15155 c0ae9f4f9589
equal deleted inserted replaced
15899:73cdc306888f 15900:128ace913837
     9 uses uVariables
     9 uses uVariables
    10     , uConsts
    10     , uConsts
    11     , uRandom
    11     , uRandom
    12     , uLandOutline // FillLand
    12     , uLandOutline // FillLand
    13     , uUtils
    13     , uUtils
       
    14     , uLandUtils
    14     ;
    15     ;
    15 
    16 
    16 var p: array[0..511] of LongInt;
    17 var p: array[0..511] of LongInt;
    17 
    18 
    18 const fadear: array[byte] of LongInt =
    19 const fadear: array[byte] of LongInt =
    37 3990, 3997, 4004, 4011, 4018, 4024, 4030, 4035, 4041, 4046, 4050,
    38 3990, 3997, 4004, 4011, 4018, 4024, 4030, 4035, 4041, 4046, 4050,
    38 4055, 4059, 4063, 4066, 4070, 4073, 4076, 4078, 4081, 4083, 4085,
    39 4055, 4059, 4063, 4066, 4070, 4073, 4076, 4078, 4081, 4083, 4085,
    39 4086, 4088, 4089, 4091, 4092, 4092, 4093, 4094, 4094, 4095, 4095,
    40 4086, 4088, 4089, 4091, 4092, 4092, 4093, 4094, 4094, 4095, 4095,
    40 4095, 4095, 4095, 4095, 4095);
    41 4095, 4095, 4095, 4095, 4095);
    41 
    42 
    42 function fade(t: LongInt) : LongInt; inline;
    43 function fade(t: LongInt) : LongInt;
    43 var t0, t1: LongInt;
    44 var t0, t1: LongInt;
    44 begin
    45 begin
    45     t0:= fadear[t shr 8];
    46     t0:= fadear[t shr 8];
    46 
    47 
    47     if t0 = fadear[255] then
    48     if t0 = fadear[255] then
    51 
    52 
    52     fade:= t0 + ((t and 255) * (t1 - t0) shr 8)
    53     fade:= t0 + ((t and 255) * (t1 - t0) shr 8)
    53 end;
    54 end;
    54 
    55 
    55 
    56 
    56 function lerp(t, a, b: LongInt) : LongInt; inline;
    57 function lerp(t, a, b: LongInt) : LongInt;
    57 begin
    58 begin
    58     lerp:= a + ((Int64(b) - a) * t shr 12)
    59     lerp:= a + ((Int64(b) - a) * t shr 12)
    59 end;
    60 end;
    60 
    61 
    61 
    62 
    62 function grad(hash, x, y: LongInt) : LongInt; inline;
    63 function grad(hash, x, y: LongInt) : LongInt;
    63 var h, v, u: LongInt;
    64 var h, v, u: LongInt;
    64 begin
    65 begin
    65     h:= hash and 15;
    66     h:= hash and 15;
    66     if h < 8 then u:= x else u:= y;
    67     if h < 8 then u:= x else u:= y;
    67     if h < 4 then v:= y else
    68     if h < 4 then v:= y else
    72 
    73 
    73     grad:= u + v
    74     grad:= u + v
    74 end;
    75 end;
    75 
    76 
    76 
    77 
    77 function inoise(x, y: LongInt) : LongInt; inline;
    78 function inoise(x, y: LongInt) : LongInt;
    78 const N = $10000;
    79 const N = $10000;
    79 var xx, yy, u, v, A, AA, AB, B, BA, BB: LongInt;
    80 var xx, yy, u, v, A, AA, AB, B, BA, BB: LongInt;
    80 begin
    81 begin
    81     xx:= (x shr 16) and 255;
    82     xx:= (x shr 16) and 255;
    82     yy:= (y shr 16) and 255;
    83     yy:= (y shr 16) and 255;
   203                     r:= r - (x - width + bottomPlateMargin + bottomPlateHeight);
   204                     r:= r - (x - width + bottomPlateMargin + bottomPlateHeight);
   204             end;
   205             end;
   205             }
   206             }
   206 
   207 
   207             if r < rCutoff then
   208             if r < rCutoff then
   208                 Land[y, x]:= 0
   209                 LandSet(y, x, 0)
   209             else if param1 = 0 then
   210             else if param1 = 0 then
   210                 Land[y, x]:= lfObjMask
   211                 LandSet(y, x, lfObjMask)
   211             else
   212             else
   212                 Land[y, x]:= lfBasic
   213                 LandSet(y, x, lfBasic)
   213         end;
   214         end;
   214     end;
   215     end;
   215 
   216 
   216     if param1 = 0 then
   217     if param1 = 0 then
   217         begin
   218         begin
   218         for x:= 0 to width do
   219         for x:= 0 to width do
   219             if Land[height - 1, x] = lfObjMask then FillLand(x, height - 1, 0, lfBasic);
   220             if LandGet(height - 1, x) = lfObjMask then FillLand(x, height - 1, 0, lfBasic);
   220 
   221 
   221         // strip all lfObjMask pixels
   222         // strip all lfObjMask pixels
   222         for y:= minY to LAND_HEIGHT - 1 do
   223         for y:= minY to LAND_HEIGHT - 1 do
   223             for x:= 0 to LAND_WIDTH - 1 do
   224             for x:= 0 to LAND_WIDTH - 1 do
   224                 if Land[y, x] = lfObjMask then
   225                 if LandGet(y, x) = lfObjMask then
   225                     Land[y, x]:= 0;
   226                     LandSet(y, x, 0);
   226         end;
   227         end;
   227 
   228 
   228     playWidth:= width;
   229     playWidth:= width;
   229     playHeight:= height;
   230     playHeight:= height;
   230     leftX:= 0;
   231     leftX:= 0;