hedgewars/uLandGenPerlin.pas
branchqmlfrontend
changeset 10515 7705784902e1
parent 10510 9329dab04490
child 10702 528d899443ab
equal deleted inserted replaced
10458:f7a199346c3e 10515:7705784902e1
     8 implementation
     8 implementation
     9 uses uVariables
     9 uses uVariables
    10     , uConsts
    10     , uConsts
    11     , uRandom
    11     , uRandom
    12     , uLandOutline // FillLand
    12     , uLandOutline // FillLand
       
    13     , uUtils
    13     ;
    14     ;
    14 
    15 
    15 var p: array[0..511] of LongInt;
    16 var p: array[0..511] of LongInt;
    16 
    17 
    17 const fadear: array[byte] of LongInt = 
    18 const fadear: array[byte] of LongInt =
    18 (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 6, 7, 9, 10, 12,
    19 (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 6, 7, 9, 10, 12,
    19 14, 17, 19, 22, 25, 29, 32, 36, 40, 45, 49, 54, 60, 65, 71,
    20 14, 17, 19, 22, 25, 29, 32, 36, 40, 45, 49, 54, 60, 65, 71,
    20 77, 84, 91, 98, 105, 113, 121, 130, 139, 148, 158, 167, 178,
    21 77, 84, 91, 98, 105, 113, 121, 130, 139, 148, 158, 167, 178,
    21 188, 199, 211, 222, 234, 247, 259, 273, 286, 300, 314, 329, 344,
    22 188, 199, 211, 222, 234, 247, 259, 273, 286, 300, 314, 329, 344,
    22 359, 374, 390, 407, 424, 441, 458, 476, 494, 512, 531, 550,
    23 359, 374, 390, 407, 424, 441, 458, 476, 494, 512, 531, 550,
    41 function fade(t: LongInt) : LongInt; inline;
    42 function fade(t: LongInt) : LongInt; inline;
    42 var t0, t1: LongInt;
    43 var t0, t1: LongInt;
    43 begin
    44 begin
    44     t0:= fadear[t shr 8];
    45     t0:= fadear[t shr 8];
    45 
    46 
    46     if t0 = fadear[255] then 
    47     if t0 = fadear[255] then
    47         t1:= t0
    48         t1:= t0
    48     else
    49     else
    49         t1:= fadear[t shr 8 + 1];
    50         t1:= fadear[t shr 8 + 1];
    50 
    51 
    51     fade:= t0 + ((t and 255) * (t1 - t0) shr 8)
    52     fade:= t0 + ((t and 255) * (t1 - t0) shr 8)
    52 end;
    53 end;
    53 
    54 
    54 
    55 
    55 function lerp(t, a, b: LongInt) : LongInt; inline;
    56 function lerp(t, a, b: LongInt) : LongInt; inline;
    56 begin
    57 begin
    57     lerp:= a + (Int64(b - a) * t shr 12)
    58     lerp:= a + ((Int64(b) - a) * t shr 12)
    58 end;
    59 end;
    59 
    60 
    60 
    61 
    61 function grad(hash, x, y: LongInt) : LongInt; inline;
    62 function grad(hash, x, y: LongInt) : LongInt; inline;
    62 var h, v, u: LongInt;
    63 var h, v, u: LongInt;
   100 begin
   101 begin
   101     f:= t * t * t * (t * (t * 6 - 15) + 10);
   102     f:= t * t * t * (t * (t * 6 - 15) + 10);
   102 end;
   103 end;
   103 
   104 
   104 procedure inoise_setup();
   105 procedure inoise_setup();
   105 var i, ii, t: LongInt;
   106 var i, ii, t: Longword;
   106 begin
   107 begin
   107     for i:= 0 to 254 do
   108     for i:= 0 to 254 do
   108         p[i]:= i + 1;
   109         p[i]:= i + 1;
   109     p[255]:= 0;
   110     p[255]:= 0;
   110 
   111 
   118 
   119 
   119     for i:= 0 to 255 do
   120     for i:= 0 to 255 do
   120         p[256 + i]:= p[i];
   121         p[256 + i]:= p[i];
   121 end;
   122 end;
   122 
   123 
   123 const detail = 150000;
   124 const width = 4096;
   124     width = 4096;
   125       height = 2048;
   125     height = 2048;
   126       minY = 500;
   126     minY = 500;
       
   127 
   127 
   128     //bottomPlateHeight = 90;
   128     //bottomPlateHeight = 90;
   129     //bottomPlateMargin = 1200;
   129     //bottomPlateMargin = 1200;
   130     margin = 200;
   130     margin = 200;
   131 
   131 
   132 procedure GenPerlin;
   132 procedure GenPerlin;
   133 var y, x, {dy, }di, dj, df, r, param1, param2: LongInt;
   133 var y, x, {dy, }di, dj, df, r, param1, param2, rCutoff, detail: LongInt;
   134 begin
   134 begin
   135     param1:= cTemplateFilter div 3;
   135     param1:= cTemplateFilter div 3;
   136     param2:= cTemplateFilter mod 3;
   136     param2:= cTemplateFilter mod 3;
       
   137     rCutoff:= min(max((26-cFeatureSize)*4,15),85);
       
   138     detail:= (26-cFeatureSize)*16000+50000; // feature size is a slider from 1-25 at present. flip it for perlin
   137 
   139 
   138     df:= detail * (6 - param2 * 2);
   140     df:= detail * (6 - param2 * 2);
   139 
   141 
   140     inoise_setup();
   142     inoise_setup();
   141 
   143 
   167                 if x + bottomPlateMargin + bottomPlateHeight > width then
   169                 if x + bottomPlateMargin + bottomPlateHeight > width then
   168                     r:= r - (x - width + bottomPlateMargin + bottomPlateHeight);
   170                     r:= r - (x - width + bottomPlateMargin + bottomPlateHeight);
   169             end;
   171             end;
   170             }
   172             }
   171 
   173 
   172             if r < 50 then Land[y, x]:= 0 else Land[y, x]:= lfObjMask;
   174             if r < rCutoff then
   173 
   175                 Land[y, x]:= 0
       
   176             else if param1 = 0 then
       
   177                 Land[y, x]:= lfObjMask
       
   178             else
       
   179                 Land[y, x]:= lfBasic
   174         end;
   180         end;
   175     end;
   181     end;
   176 
   182 
   177     if param1 = 0 then
   183     if param1 = 0 then
   178         begin
   184         begin