hedgewars/uLandGraphics.pas
changeset 8598 9d21bab30893
parent 8596 def92c20cd49
child 8601 7668f92734b8
equal deleted inserted replaced
8597:00adaf34d2a3 8598:9d21bab30893
   245                 LandPixels[t div 2, i div 2]:= 0;
   245                 LandPixels[t div 2, i div 2]:= 0;
   246 
   246 
   247 end;
   247 end;
   248 
   248 
   249 
   249 
   250 function isLandscapeEdge(weight:Longint):boolean;
   250 function isLandscapeEdge(weight:Longint):boolean; inline;
   251 begin
   251 begin
   252     result := (weight < 8) and (weight >= 2);
   252     result := (weight < 8) and (weight >= 2);
   253 end;
       
   254 
       
   255 function isLandscape(weight:Longint):boolean;
       
   256 begin
       
   257     result := weight < 2;
       
   258 end;
       
   259 
       
   260 function isEmptySpace(weight:Longint):boolean;
       
   261 begin
       
   262     result := not isLandscape(weight) and not isLandscapeEdge(weight);
       
   263 end;
   253 end;
   264 
   254 
   265 function getPixelWeight(x, y:Longint): Longint;
   255 function getPixelWeight(x, y:Longint): Longint;
   266 var
   256 var
   267     i, j:Longint;
   257     i, j:Longint;
   287     icePixels: PLongwordArray;
   277     icePixels: PLongwordArray;
   288     pictureX, pictureY: LongInt;
   278     pictureX, pictureY: LongInt;
   289     w, c: LongWord;
   279     w, c: LongWord;
   290     weight: Longint;
   280     weight: Longint;
   291 begin
   281 begin
   292     weight := getPixelWeight(x, y);
   282     // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   293     if isLandscape(weight) then
   283     iceSurface:= SpritesData[sprIceTexture].Surface;
   294         begin
   284     icePixels := iceSurface^.pixels;
   295         // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   285     w:= LandPixels[y, x];
   296         iceSurface:= SpritesData[sprIceTexture].Surface;
   286     w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   297         pictureX := x mod iceSurface^.w;
   287           (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   298         pictureY := y mod iceSurface^.h;
   288           (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   299         icePixels := iceSurface^.pixels;
   289     if w < 128 then w:= w+128;
   300         w:= LandPixels[y, x];
   290     if w > 255 then w:= 255;
   301         w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   291     w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   302               (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   292     //LandPixels[y, x]:= w;
   303               (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   293     LandPixels[y, x]:= addBgColor(w, IceColor);
   304         if w < 128 then w:= w+128;
   294     LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   305         if w > 255 then w:= 255;
   295 end;
   306         w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   296 
   307         //LandPixels[y, x]:= w;
   297 function getIncrementInquarter(dx, dy, quarter: Longint): Longint; inline;
   308         LandPixels[y, x]:= addBgColor(w, IceColor);
       
   309         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
       
   310         Land[y, x] := land[y, x] or lfIce;
       
   311         end
       
   312     else if (isLandscapeEdge(weight)) then
       
   313         begin
       
   314         LandPixels[y, x] := IceEdgeColor;
       
   315         if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce and not lfDamaged;
       
   316         end;
       
   317 
       
   318 end;
       
   319 
       
   320 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
       
   321 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   298 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   322 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   299 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   323 begin
   300 begin
   324     getIncrementInquarter := directionX[quarter] * dx + directionY[quarter] * dy;
   301     getIncrementInquarter := directionX[quarter] * dx + directionY[quarter] * dy;
   325 end;
   302 end;
   326 
   303 
   327 function getIncrementInquarter2(dx, dy, quarter: Longint): Longint;
   304 function getIncrementInquarter2(dx, dy, quarter: Longint): Longint; inline;
   328 const directionY : array [0..3] of Longint = (0, 0, 1, 1);
   305 const directionY : array [0..3] of Longint = (0, 0, 1, 1);
   329 const directionX : array [0..3] of Longint = (1, 1, 0, 0);
   306 const directionX : array [0..3] of Longint = (1, 1, 0, 0);
   330 begin
   307 begin
   331     getIncrementInquarter2 := directionX[quarter] * dx + directionY[quarter] * dy;
   308     getIncrementInquarter2 := directionX[quarter] * dx + directionY[quarter] * dy;
   332 end;
   309 end;
   333 
   310 
   334 procedure FillLandCircleLinesIce(x, y, dx, dy: LongInt);
   311 procedure FillLandCircleLinesIce(x, y, dx, dy: LongInt);
   335 var q, i, t: LongInt;
   312 var q, i, t, px, py: LongInt;
   336 begin
   313 begin
   337 for q := 0 to 3 do
   314 for q := 0 to 3 do
   338     begin
   315     begin
   339         t:= y + getIncrementInquarter(dx, dy, q);
   316     t:= y + getIncrementInquarter(dx, dy, q);
   340         if (t and LAND_HEIGHT_MASK) = 0 then
   317     if (t and LAND_HEIGHT_MASK) = 0 then
   341             for i:= Max(x - getIncrementInquarter2(dx, dy, q), 0) to Min(x + getIncrementInquarter2(dx, dy, q), LAND_WIDTH - 1) do
   318         for i:= Max(x - getIncrementInquarter2(dx, dy, q), 0) to Min(x + getIncrementInquarter2(dx, dy, q), LAND_WIDTH - 1) do
   342                 if (Land[t, i] and (lfIndestructible or lfIce) = 0) and (not disableLandBack or (Land[t, i] > 255))  then
   319             if Land[t, i] and lfIce = 0 then
   343                     if (cReducedQuality and rqBlurryLand) = 0 then
   320                 begin
   344                        drawIcePixel(t, i)
   321                 if (cReducedQuality and rqBlurryLand) = 0 then
   345                     else
   322                     begin
   346                        drawIcePixel(t div 2, i div 2) ;
   323                     px:= i; py:= t
   347     end;
   324                     end
       
   325                 else
       
   326                     begin
       
   327                     px:= i div 2; py:= t div 2
       
   328                     end;
       
   329                 if isLandscapeEdge(getPixelWeight(i, t)) then
       
   330                     begin
       
   331                     if Land[t, i] > 255 then Land[t, i] := Land[t, i] or lfIce and not lfDamaged;
       
   332                     if (LandPixels[py, px] and AMask < 255) and (LandPixels[py, px] and AMask > 0) then
       
   333                         LandPixels[py, px] := (IceEdgeColor and not AMask) or (LandPixels[py, px] and AMask)
       
   334                     else if (LandPixels[py, px] and AMask < 255) or (Land[t, i] > 255) then
       
   335                         LandPixels[py, px] := IceEdgeColor
       
   336                     end
       
   337                 else if Land[t, i] > 255 then
       
   338                     begin
       
   339                     Land[t, i] := Land[t, i] or lfIce and not lfDamaged;
       
   340                     drawIcePixel(py, px)
       
   341                     end
       
   342                 end
       
   343     end
   348 end;
   344 end;
   349 
   345 
   350 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   346 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   351 var dx, dy, d: LongInt;
   347 var dx, dy, d: LongInt;
   352 begin
   348 begin
  1017         Land[y, x]:= lfObject
  1013         Land[y, x]:= lfObject
  1018         else Land[y,x]:= lfBasic
  1014         else Land[y,x]:= lfBasic
  1019         end
  1015         end
  1020     end
  1016     end
  1021 else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255)
  1017 else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255)
  1022 and ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic))
  1018 and (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)
  1023 and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
  1019 and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
  1024     begin
  1020     begin
  1025     if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0))
  1021     if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0))
  1026     or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
  1022     or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
  1027         begin
  1023         begin