hedgewars/uLandGraphics.pas
changeset 6990 40e5af28d026
parent 6982 8d41d22a291d
child 7035 823caba67738
equal deleted inserted replaced
6989:4c35e9cf6057 6990:40e5af28d026
   670 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; indestructible: boolean): boolean;
   670 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; indestructible: boolean): boolean;
   671 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt;
   671 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt;
   672     p: PByteArray;
   672     p: PByteArray;
   673     Image: PSDL_Surface;
   673     Image: PSDL_Surface;
   674 begin
   674 begin
       
   675 TryPlaceOnLand:= false;
   675 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
   676 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
   676 
   677 
   677 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true);
   678 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true);
   678 Image:= SpritesData[Obj].Surface;
   679 Image:= SpritesData[Obj].Surface;
   679 w:= SpritesData[Obj].Width;
   680 w:= SpritesData[Obj].Width;
   691 case bpp of
   692 case bpp of
   692     4: for y:= 0 to Pred(h) do
   693     4: for y:= 0 to Pred(h) do
   693         begin
   694         begin
   694         for x:= 0 to Pred(w) do
   695         for x:= 0 to Pred(w) do
   695             if (PLongword(@(p^[x * 4]))^) <> 0 then
   696             if (PLongword(@(p^[x * 4]))^) <> 0 then
   696                 if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT)
   697                 if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or
   697                 or ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then
   698                    ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then
   698                     begin
   699                     begin
   699                     if SDL_MustLock(Image) then
   700                         if SDL_MustLock(Image) then
   700                         SDL_UnlockSurface(Image);
   701                             SDL_UnlockSurface(Image);
   701                     exit(false)
   702                         exit;
   702                     end;
   703                     end;
   703         p:= @(p^[Image^.pitch]);
   704         p:= @(p^[Image^.pitch]);
   704         end;
   705         end;
   705     end;
   706     end;
   706 
   707 
   756 
   757 
   757 function Despeckle(X, Y: LongInt): boolean;
   758 function Despeckle(X, Y: LongInt): boolean;
   758 var nx, ny, i, j, c, xx, yy: LongInt;
   759 var nx, ny, i, j, c, xx, yy: LongInt;
   759     pixelsweep: boolean;
   760     pixelsweep: boolean;
   760 begin
   761 begin
   761 if (cReducedQuality and rqBlurryLand) = 0 then
   762     Despeckle:= true;
   762     begin
   763 
   763     xx:= X;
   764     if (cReducedQuality and rqBlurryLand) = 0 then
   764     yy:= Y;
   765     begin
       
   766         xx:= X;
       
   767         yy:= Y;
   765     end
   768     end
   766 else
   769     else
   767     begin
   770     begin
   768     xx:= X div 2;
   771         xx:= X div 2;
   769     yy:= Y div 2;
   772         yy:= Y div 2;
   770     end;
   773     end;
   771 pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
   774 
   772 if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
   775     pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
   773     begin
   776     if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
   774     c:= 0;
   777     begin
   775     for i:= -1 to 1 do
   778         c:= 0;
   776         for j:= -1 to 1 do
   779         for i:= -1 to 1 do
   777             if (i <> 0) or (j <> 0) then
   780             for j:= -1 to 1 do
   778                 begin
   781                 if (i <> 0) or (j <> 0) then
   779                 ny:= Y + i;
   782                 begin
   780                 nx:= X + j;
   783                     ny:= Y + i;
   781                 if ((ny and LAND_HEIGHT_MASK) = 0) and ((nx and LAND_WIDTH_MASK) = 0) then
   784                     nx:= X + j;
       
   785                     if ((ny and LAND_HEIGHT_MASK) = 0) and ((nx and LAND_WIDTH_MASK) = 0) then
   782                     begin
   786                     begin
   783                     if pixelsweep then
   787                         if pixelsweep then
   784                         begin
   788                         begin
   785                         if ((cReducedQuality and rqBlurryLand) <> 0) then
   789                             if ((cReducedQuality and rqBlurryLand) <> 0) then
   786                             begin
   790                             begin
   787                             nx:= nx div 2;
   791                                 nx:= nx div 2;
   788                             ny:= ny div 2
   792                                 ny:= ny div 2
   789                             end;
   793                             end;
   790                         if LandPixels[ny, nx] <> 0 then
   794                             if LandPixels[ny, nx] <> 0 then
   791                             inc(c);
   795                                 inc(c);
   792                         end
   796                         end
   793                     else if Land[ny, nx] > 255 then
   797                     else if Land[ny, nx] > 255 then
   794                         inc(c);
   798                         inc(c);
   795                     end
   799                     end
   796                 end;
   800                 end;
   797 
   801 
   798     if c < 4 then // 0-3 neighbours
   802         if c < 4 then // 0-3 neighbours
   799         begin
   803         begin
   800         if ((Land[Y, X] and lfBasic) <> 0) and (not disableLandBack) then
   804             if ((Land[Y, X] and lfBasic) <> 0) and (not disableLandBack) then
   801             LandPixels[yy, xx]:= LandBackPixel(X, Y)
   805                 LandPixels[yy, xx]:= LandBackPixel(X, Y)
   802         else
   806             else
   803             LandPixels[yy, xx]:= 0;
   807                 LandPixels[yy, xx]:= 0;
   804 
   808 
   805         if not pixelsweep then
   809             if not pixelsweep then
   806             begin
   810             begin
   807             Land[Y, X]:= 0;
   811                 Land[Y, X]:= 0;
   808             exit(true)
   812                 exit
   809             end
   813             end
   810         end;
   814         end;
   811     end;
   815     end;
   812 Despeckle:= false
   816     Despeckle:= false
   813 end;
   817 end;
   814 
   818 
   815 procedure Smooth(X, Y: LongInt);
   819 procedure Smooth(X, Y: LongInt);
   816 begin
   820 begin
   817 // a bit of AA for explosions
   821 // a bit of AA for explosions