hedgewars/uLandGraphics.pas
changeset 5480 37bafa5a7016
parent 5386 ba85acff9828
child 5687 fac606654317
equal deleted inserted replaced
5478:8005a5ab7117 5480:37bafa5a7016
   208                 LandPixels[t div 2, i div 2]:= 0;
   208                 LandPixels[t div 2, i div 2]:= 0;
   209 
   209 
   210 end;
   210 end;
   211 
   211 
   212 function FillLandCircleLinesBG(x, y, dx, dy: LongInt): Longword;
   212 function FillLandCircleLinesBG(x, y, dx, dy: LongInt): Longword;
   213 var i, t: LongInt;
   213 var i, t, by, bx: LongInt;
   214     cnt: Longword;
   214     cnt: Longword;
   215 begin
   215 begin
   216 cnt:= 0;
   216 cnt:= 0;
   217 t:= y + dy;
   217 t:= y + dy;
   218 if (t and LAND_HEIGHT_MASK) = 0 then
   218 if (t and LAND_HEIGHT_MASK) = 0 then
   219    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
   219    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
   220        if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
   220        begin
   221            begin
   221        if (cReducedQuality and rqBlurryLand) = 0 then
   222            inc(cnt);
   222            begin
   223            if (cReducedQuality and rqBlurryLand) = 0 then
   223            by:= t; bx:= i;
   224                LandPixels[t, i]:= LandBackPixel(i, t)
       
   225            else
       
   226                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
       
   227            end
   224            end
   228        else
   225        else
   229            if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
   226            begin
   230                if (cReducedQuality and rqBlurryLand) = 0 then
   227            by:= t div 2; bx:= i div 2;
   231                    LandPixels[t, i]:= 0
   228            end;
   232                else
   229        if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
   233                    LandPixels[t div 2, i div 2]:= 0;
       
   234 
       
   235 t:= y - dy;
       
   236 if (t and LAND_HEIGHT_MASK) = 0 then
       
   237    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
       
   238        if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
       
   239            begin
   230            begin
   240            inc(cnt);
   231            inc(cnt);
   241            if (cReducedQuality and rqBlurryLand) = 0 then
   232            LandPixels[by, bx]:= LandBackPixel(i, t)
   242                LandPixels[t, i]:= LandBackPixel(i, t)
       
   243            else
       
   244                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
       
   245            end
   233            end
   246        else
   234        else
   247            if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
   235            if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
   248                if (cReducedQuality and rqBlurryLand) = 0 then
   236               LandPixels[by, bx]:= 0
   249                    LandPixels[t, i]:= 0
   237        end;
   250                else
   238 
   251                    LandPixels[t div 2, i div 2]:= 0;
   239 t:= y - dy;
   252 
   240 if (t and LAND_HEIGHT_MASK) = 0 then
   253 t:= y + dx;
   241    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
   254 if (t and LAND_HEIGHT_MASK) = 0 then
   242        begin
   255    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
   243        if (cReducedQuality and rqBlurryLand) = 0 then
   256        if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
   244            begin
   257            begin
   245            by:= t; bx:= i;
   258            inc(cnt);
       
   259            if (cReducedQuality and rqBlurryLand) = 0 then
       
   260                LandPixels[t, i]:= LandBackPixel(i, t)
       
   261            else
       
   262                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
       
   263            end
   246            end
   264        else
   247        else
   265            if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
   248            begin
   266                if (cReducedQuality and rqBlurryLand) = 0 then
   249            by:= t div 2; bx:= i div 2;
   267                    LandPixels[t, i]:= 0
   250            end;
   268                else
   251        if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
   269                    LandPixels[t div 2, i div 2]:= 0;
   252            begin
   270 
   253            inc(cnt);
   271 t:= y - dx;
   254            LandPixels[by, bx]:= LandBackPixel(i, t)
       
   255            end
       
   256        else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
       
   257               LandPixels[by, bx]:= 0
       
   258        end;
       
   259 
       
   260 t:= y + dx;
   272 if (t and LAND_HEIGHT_MASK) = 0 then
   261 if (t and LAND_HEIGHT_MASK) = 0 then
   273    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
   262    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
   274        if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
   263        begin
   275            begin
   264        if (cReducedQuality and rqBlurryLand) = 0 then
   276            inc(cnt);
   265            begin
   277            if (cReducedQuality and rqBlurryLand) = 0 then
   266            by:= t; bx:= i;
   278                LandPixels[t, i]:= LandBackPixel(i, t)
       
   279            else
       
   280                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
       
   281            end
   267            end
   282        else
   268        else
   283            if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
   269            begin
   284               if (cReducedQuality and rqBlurryLand) = 0 then
   270            by:= t div 2; bx:= i div 2;
   285                   LandPixels[t, i]:= 0
   271            end;
   286               else
   272        if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
   287                   LandPixels[t div 2, i div 2]:= 0;
   273            begin
       
   274            inc(cnt);
       
   275            LandPixels[by, bx]:= LandBackPixel(i, t)
       
   276            end
       
   277        else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
       
   278            LandPixels[by, bx]:= 0
       
   279        end;
       
   280 t:= y - dx;
       
   281 if (t and LAND_HEIGHT_MASK) = 0 then
       
   282    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
       
   283        begin
       
   284        if (cReducedQuality and rqBlurryLand) = 0 then
       
   285            begin
       
   286            by:= t; bx:= i;
       
   287            end
       
   288        else
       
   289            begin
       
   290            by:= t div 2; bx:= i div 2;
       
   291            end;
       
   292        if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
       
   293            begin
       
   294            inc(cnt);
       
   295            LandPixels[by, bx]:= LandBackPixel(i, t)
       
   296            end
       
   297        else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
       
   298            LandPixels[by, bx]:= 0
       
   299        end;
   288 FillLandCircleLinesBG:= cnt;
   300 FillLandCircleLinesBG:= cnt;
   289 end;
   301 end;
   290 
   302 
   291 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   303 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   292 var i, t: LongInt;
   304 var i, t: LongInt;
   428 UpdateLandTexture(tx, dx, ty, dy);
   440 UpdateLandTexture(tx, dx, ty, dy);
   429 DrawExplosion:= cnt
   441 DrawExplosion:= cnt
   430 end;
   442 end;
   431 
   443 
   432 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
   444 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
   433 var tx, ty, i: LongInt;
   445 var tx, ty, by, bx,  i: LongInt;
   434 begin
   446 begin
   435 for i:= 0 to Pred(Count) do
   447 for i:= 0 to Pred(Count) do
   436     begin
   448     begin
   437     for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do
   449     for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do
   438         for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
   450         for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
   439             if ((Land[ty, tx] and lfBasic) <> 0) and not disableLandBack then
   451             begin
   440                 if (cReducedQuality and rqBlurryLand) = 0 then
   452             if (cReducedQuality and rqBlurryLand) = 0 then
   441                     LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   453                 begin
   442                 else
   454                 by:= ty; bx:= tx;
   443                     LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
   455                 end
   444             else
   456             else
   445                 if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) then
   457                 begin
   446                     if (cReducedQuality and rqBlurryLand) = 0 then
   458                 by:= ty div 2; bx:= tx div 2;
   447                         LandPixels[ty, tx]:= 0
   459                 end;
   448                     else
   460             if ((Land[ty, tx] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then 
   449                         LandPixels[ty div 2, tx div 2]:= 0;
   461                 LandPixels[by, bx]:= LandBackPixel(tx, ty)
       
   462             else if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then 
       
   463                 LandPixels[by, bx]:= 0
       
   464             end;
   450     inc(y, dY)
   465     inc(y, dY)
   451     end;
   466     end;
   452 
   467 
   453 inc(Radius, 4);
   468 inc(Radius, 4);
   454 dec(y, Count * dY);
   469 dec(y, Count * dY);
   477 //
   492 //
   478 //  - (dX, dY) - direction, vector of length = 0.5
   493 //  - (dX, dY) - direction, vector of length = 0.5
   479 //
   494 //
   480 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
   495 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
   481 var nx, ny, dX8, dY8: hwFloat;
   496 var nx, ny, dX8, dY8: hwFloat;
   482     i, t, tx, ty, stX, stY, ddy, ddx: Longint;
   497     i, t, tx, ty, by, bx, stX, stY, ddy, ddx: Longint;
   483     despeckle : Boolean;
   498     despeckle : Boolean;
   484 begin  // (-dY, dX) is (dX, dY) rotated by PI/2
   499 begin  // (-dY, dX) is (dX, dY) rotated by PI/2
   485 stY:= hwRound(Y);
   500 stY:= hwRound(Y);
   486 stX:= hwRound(X);
   501 stX:= hwRound(X);
   487 
   502 
   548         Y:= Y + dY;
   563         Y:= Y + dY;
   549         tx:= hwRound(X);
   564         tx:= hwRound(X);
   550         ty:= hwRound(Y);
   565         ty:= hwRound(Y);
   551         if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and ((Land[ty, tx] and lfIndestructible) = 0) then
   566         if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and ((Land[ty, tx] and lfIndestructible) = 0) then
   552             begin
   567             begin
   553             if ((Land[ty, tx] and lfBasic) <> 0) and not disableLandBack then
   568             if (cReducedQuality and rqBlurryLand) = 0 then
   554                 if (cReducedQuality and rqBlurryLand) = 0 then
   569                 begin
   555                     LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   570                 by:= ty; bx:= tx;
   556                 else
   571                 end
   557                     LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
   572             else
   558             else
   573                 begin
   559               if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) then
   574                 by:= ty div 2; bx:= tx div 2;
   560                 if (cReducedQuality and rqBlurryLand) = 0 then
   575                 end;
   561                 LandPixels[ty, tx]:= 0
   576             if ((Land[ty, tx] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
   562                 else
   577                     LandPixels[by, bx]:= LandBackPixel(tx, ty)
   563                 LandPixels[ty div 2, tx div 2]:= 0;
   578             else if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
       
   579                 LandPixels[by, bx]:= 0;
   564 
   580 
   565             Land[ty, tx]:= 0;
   581             Land[ty, tx]:= 0;
   566             end
   582             end
   567         end;
   583         end;
   568     for t:= 0 to 7 do
   584     for t:= 0 to 7 do
   746             LandPixels[yy, xx]:= LandBackPixel(X, Y)
   762             LandPixels[yy, xx]:= LandBackPixel(X, Y)
   747         else
   763         else
   748             LandPixels[yy, xx]:= 0;
   764             LandPixels[yy, xx]:= 0;
   749 
   765 
   750         Land[Y, X]:= 0;
   766         Land[Y, X]:= 0;
   751         if not pixelsweep then exit(1)  // cannot exit true on pixel sweep, or risk desyncs due to inconsistent resweeps
   767         if not pixelsweep then exit(1)
   752         else exit(2)
   768         else exit(2)
   753         end;
   769         end;
   754     end;
   770     end;
   755 Despeckle:= 0
   771 Despeckle:= 0
   756 end;
   772 end;