hedgewars/uLandGraphics.pas
changeset 5384 83d3b50d7e24
parent 5364 30752b2e99b3
child 5386 ba85acff9828
equal deleted inserted replaced
5382:d5321b22aed2 5384:83d3b50d7e24
    27                                    Left, Right: LongInt;
    27                                    Left, Right: LongInt;
    28                                    end;
    28                                    end;
    29 
    29 
    30 function  addBgColor(OldColor, NewColor: LongWord): LongWord;
    30 function  addBgColor(OldColor, NewColor: LongWord): LongWord;
    31 function  SweepDirty: boolean;
    31 function  SweepDirty: boolean;
    32 function  Despeckle(X, Y: LongInt): boolean;
    32 function  Despeckle(X, Y: LongInt; gfxOnly: boolean): LongWord;
    33 procedure Smooth(X, Y: LongInt);
    33 procedure Smooth(X, Y: LongInt);
    34 function  CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
    34 function  CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
    35 function  DrawExplosion(X, Y, Radius: LongInt): Longword;
    35 function  DrawExplosion(X, Y, Radius: LongInt): Longword;
    36 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    36 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    37 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
    37 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
   698 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y;
   698 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y;
   699 UpdateLandTexture(x, w, y, h)
   699 UpdateLandTexture(x, w, y, h)
   700 end;
   700 end;
   701 
   701 
   702 // was experimenting with applying as damage occurred.
   702 // was experimenting with applying as damage occurred.
   703 function Despeckle(X, Y: LongInt): boolean;
   703 function Despeckle(X, Y: LongInt; gfxOnly: boolean): LongWord;
   704 var nx, ny, i, j, c, xx, yy: LongInt;
   704 var nx, ny, i, j, c, xx, yy: LongInt;
   705     pixelsweep: boolean;
   705     pixelsweep: boolean;
   706 begin
   706 begin
   707 if (cReducedQuality and rqBlurryLand) = 0 then
   707 if (cReducedQuality and rqBlurryLand) = 0 then
   708    begin
   708    begin
   713    begin
   713    begin
   714    xx:= X div 2;
   714    xx:= X div 2;
   715    yy:= Y div 2;
   715    yy:= Y div 2;
   716    end;
   716    end;
   717 pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
   717 pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
       
   718 if not pixelsweep and gfxOnly then exit(0);
   718 if ((Land[Y, X] > 255) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
   719 if ((Land[Y, X] > 255) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
   719     begin
   720     begin
   720     c:= 0;
   721     c:= 0;
   721     for i:= -1 to 1 do
   722     for i:= -1 to 1 do
   722         for j:= -1 to 1 do
   723         for j:= -1 to 1 do
   745             LandPixels[yy, xx]:= LandBackPixel(X, Y)
   746             LandPixels[yy, xx]:= LandBackPixel(X, Y)
   746         else
   747         else
   747             LandPixels[yy, xx]:= 0;
   748             LandPixels[yy, xx]:= 0;
   748 
   749 
   749         Land[Y, X]:= 0;
   750         Land[Y, X]:= 0;
   750         exit(true);
   751         if not pixelsweep then exit(1)  // cannot exit true on pixel sweep, or risk desyncs due to inconsistent resweeps
       
   752         else exit(2)
   751         end;
   753         end;
   752     end;
   754     end;
   753 Despeckle:= false
   755 Despeckle:= 0
   754 end;
   756 end;
   755 
   757 
   756 procedure Smooth(X, Y: LongInt);
   758 procedure Smooth(X, Y: LongInt);
   757 begin
   759 begin
   758 // a bit of AA for explosions
   760 // a bit of AA for explosions
   795         end
   797         end
   796     end
   798     end
   797 end;
   799 end;
   798 
   800 
   799 function SweepDirty: boolean;
   801 function SweepDirty: boolean;
   800 var x, y, xx, yy, ty, tx: LongInt;
   802 var x, y, xx, yy, ty, tx, d: LongInt;
   801     bRes, updateBlock, resweep, recheck, firstpass: boolean;
   803     bRes, updateBlock, resweepCol, resweepGfx, gfxOnly, recheck, firstpass: boolean;
   802 begin
   804 begin
   803 bRes:= false;
   805 bRes:= false;
   804 reCheck:= true;
   806 reCheck:= true;
   805 
   807 
   806 while recheck do
   808 while recheck do
   811         for x:= 0 to LAND_WIDTH div 32 - 1 do
   813         for x:= 0 to LAND_WIDTH div 32 - 1 do
   812             begin
   814             begin
   813             if LandDirty[y, x] <> 0 then
   815             if LandDirty[y, x] <> 0 then
   814                 begin
   816                 begin
   815                 updateBlock:= false;
   817                 updateBlock:= false;
   816                 resweep:= true;
   818                 resweepCol:= true;
       
   819                 resweepGfx:= true;
   817                 firstpass:= true;
   820                 firstpass:= true;
   818                 ty:= y * 32;
   821                 ty:= y * 32;
   819                 tx:= x * 32;
   822                 tx:= x * 32;
   820                 while(resweep) do
   823                 while(resweepCol or resweepGfx) do
   821                     begin
   824                     begin
   822                     resweep:= false;
   825                     gfxOnly:= resweepGfx and not resweepCol;
       
   826                     resweepCol:= false;
       
   827                     resweepGfx:= false;
   823                     for yy:= ty to ty + 31 do
   828                     for yy:= ty to ty + 31 do
   824                         for xx:= tx to tx + 31 do
   829                         for xx:= tx to tx + 31 do
   825                             begin
   830                             begin
   826                             if Despeckle(xx, yy) then
   831                             d:= Despeckle(xx, yy, gfxOnly);
       
   832                             if d <> 0 then
   827                                 begin
   833                                 begin
   828                                 bRes:= true;
   834                                 bRes:= true;
   829                                 updateBlock:= true;
   835                                 updateBlock:= true;
   830                                 resweep:= true;
   836                                 if d = 1 then resweepCol:= true
   831                                 if (yy = ty) and (y > 0) then
   837                                 else resweepGfx:= true;
   832                                     begin
   838                                 if not resweepGfx then
   833                                     LandDirty[y-1, x]:= 1;
   839                                     if (yy = ty) and (y > 0) then
   834                                     recheck:= true;
   840                                         begin
   835                                     end
   841                                         LandDirty[y-1, x]:= 1;
   836                                 else if (yy = ty+31) and (y < LAND_HEIGHT div 32 - 1) then
   842                                         recheck:= true;
   837                                     begin
   843                                         end
   838                                     LandDirty[y+1, x]:= 1;
   844                                     else if (yy = ty+31) and (y < LAND_HEIGHT div 32 - 1) then
   839                                     recheck:= true;
   845                                         begin
   840                                     end;
   846                                         LandDirty[y+1, x]:= 1;
   841                                 if (xx = tx) and (x > 0) then
   847                                         recheck:= true;
   842                                     begin
   848                                         end;
   843                                     LandDirty[y, x-1]:= 1;
   849                                     if (xx = tx) and (x > 0) then
   844                                     recheck:= true;
   850                                         begin
   845                                     end
   851                                         LandDirty[y, x-1]:= 1;
   846                                 else if (xx = tx+31) and (x < LAND_WIDTH div 32 - 1) then
   852                                         recheck:= true;
   847                                     begin
   853                                         end
   848                                     LandDirty[y, x+1]:= 1;
   854                                     else if (xx = tx+31) and (x < LAND_WIDTH div 32 - 1) then
   849                                     recheck:= true;
   855                                         begin
   850                                     end
   856                                         LandDirty[y, x+1]:= 1;
       
   857                                         recheck:= true;
       
   858                                         end
   851                                 end;
   859                                 end;
   852                             if firstpass then Smooth(xx,yy);
   860                             if firstpass then Smooth(xx,yy);
   853                             end;
   861                             end;
   854                     firstpass:= false
   862                     firstpass:= false
   855                     end;
   863                     end;