hedgewars/uLandGraphics.pas
changeset 3602 99c93fa258d6
parent 3601 8a74c9ceaf71
child 3603 b6b1989744ef
equal deleted inserted replaced
3601:8a74c9ceaf71 3602:99c93fa258d6
   139      end;
   139      end;
   140   if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet)
   140   if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet)
   141 end;
   141 end;
   142 
   142 
   143 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
   143 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
   144 var i: LongInt;
   144 var i, t: LongInt;
   145 begin
   145 begin
   146 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   146 t:= y + dy;
       
   147 if (t and LAND_HEIGHT_MASK) = 0 then
   147     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   148     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   148         if (not isMap and ((Land[y + dy, i] and lfIndestructible) = 0)) or ((Land[y + dy, i] and lfBasic) <> 0) then
   149         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
   149             if (cReducedQuality and rqBlurryLand) = 0 then
   150             if (cReducedQuality and rqBlurryLand) = 0 then
   150                 LandPixels[y + dy, i]:= 0
   151                 LandPixels[t, i]:= 0
   151             else
   152             else
   152                 LandPixels[(y + dy) div 2, i div 2]:= 0;
   153                 LandPixels[t div 2, i div 2]:= 0;
   153 
   154 
   154 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   155 t:= y - dy;
       
   156 if (t and LAND_HEIGHT_MASK) = 0 then
   155     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   157     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   156         if (not isMap and ((Land[y - dy, i] and lfIndestructible) = 0)) or ((Land[y - dy, i] and lfBasic) <> 0) then
   158         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
   157             if (cReducedQuality and rqBlurryLand) = 0 then
   159             if (cReducedQuality and rqBlurryLand) = 0 then
   158                 LandPixels[y - dy, i]:= 0
   160                 LandPixels[t, i]:= 0
   159             else
   161             else
   160                 LandPixels[(y - dy) div 2, i div 2]:= 0;
   162                 LandPixels[t div 2, i div 2]:= 0;
   161 
   163 
   162 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   164 t:= y + dx;
       
   165 if (t and LAND_HEIGHT_MASK) = 0 then
   163     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   166     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   164         if (not isMap and ((Land[y + dx, i] and lfIndestructible) = 0)) or ((Land[y + dx, i] and lfBasic) <> 0) then
   167         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
   165             if (cReducedQuality and rqBlurryLand) = 0 then
   168             if (cReducedQuality and rqBlurryLand) = 0 then
   166                 LandPixels[y + dx, i]:= 0
   169                 LandPixels[t, i]:= 0
   167             else
   170             else
   168                 LandPixels[(y + dx) div 2, i div 2]:= 0;
   171                 LandPixels[t div 2, i div 2]:= 0;
   169 
   172 
   170 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   173 t:= y - dx;
       
   174 if (t and LAND_HEIGHT_MASK) = 0 then
   171     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   175     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   172         if (not isMap and ((Land[y - dx, i] and lfIndestructible) = 0)) or ((Land[y - dx, i] and lfBasic) <> 0) then
   176         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
   173             if (cReducedQuality and rqBlurryLand) = 0 then
   177             if (cReducedQuality and rqBlurryLand) = 0 then
   174                 LandPixels[y - dx, i]:= 0
   178                 LandPixels[t, i]:= 0
   175             else
   179             else
   176                 LandPixels[(y - dx) div 2, i div 2]:= 0;
   180                 LandPixels[t div 2, i div 2]:= 0;
   177 
   181 
   178 end;
   182 end;
   179 
   183 
   180 procedure FillLandCircleLinesBG(x, y, dx, dy: LongInt);
   184 procedure FillLandCircleLinesBG(x, y, dx, dy: LongInt);
   181 var i: LongInt;
   185 var i, t: LongInt;
   182 begin
   186 begin
   183 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   187 t:= y + dy;
       
   188 if (t and LAND_HEIGHT_MASK) = 0 then
   184    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   189    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   185        if ((Land[y + dy, i] and lfBasic) <> 0) then
   190        if ((Land[t, i] and lfBasic) <> 0) then
   186            if (cReducedQuality and rqBlurryLand) = 0 then
   191            if (cReducedQuality and rqBlurryLand) = 0 then
   187                LandPixels[y + dy, i]:= LandBackPixel(i, y + dy)
   192                LandPixels[t, i]:= LandBackPixel(i, t)
   188            else
   193            else
   189                LandPixels[(y + dy) div 2, i div 2]:= LandBackPixel(i, y + dy)
   194                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
   190        else
   195        else
   191            if ((Land[y + dy, i] and lfObject) <> 0) then
   196            if ((Land[t, i] and lfObject) <> 0) then
   192                if (cReducedQuality and rqBlurryLand) = 0 then
   197                if (cReducedQuality and rqBlurryLand) = 0 then
   193                    LandPixels[y + dy, i]:= 0
   198                    LandPixels[t, i]:= 0
   194                else
   199                else
   195                    LandPixels[(y + dy) div 2, i div 2]:= 0;
   200                    LandPixels[t div 2, i div 2]:= 0;
   196 
   201 
   197 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   202 t:= y - dy;
       
   203 if (t and LAND_HEIGHT_MASK) = 0 then
   198    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   204    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   199        if ((Land[y - dy, i] and lfBasic) <> 0) then
   205        if ((Land[t, i] and lfBasic) <> 0) then
   200            if (cReducedQuality and rqBlurryLand) = 0 then
   206            if (cReducedQuality and rqBlurryLand) = 0 then
   201                LandPixels[y - dy, i]:= LandBackPixel(i, y - dy)
   207                LandPixels[t, i]:= LandBackPixel(i, t)
   202            else
   208            else
   203                LandPixels[(y - dy) div 2, i div 2]:= LandBackPixel(i, y - dy)
   209                LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
   204        else
   210        else
   205            if ((Land[y - dy, i] and lfObject) <> 0) then
   211            if ((Land[t, i] and lfObject) <> 0) then
   206                if (cReducedQuality and rqBlurryLand) = 0 then
   212                if (cReducedQuality and rqBlurryLand) = 0 then
   207                    LandPixels[y - dy, i]:= 0
   213                    LandPixels[t, i]:= 0
   208                else
   214                else
   209                    LandPixels[(y - dy) div 2, i div 2]:= 0;
   215                    LandPixels[t div 2, i div 2]:= 0;
   210 
   216 
   211 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   217 t:= y + dx;
       
   218 if (t and LAND_HEIGHT_MASK) = 0 then
   212    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   219    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   213        if ((Land[y + dx, i] and lfBasic) <> 0) then
   220        if ((Land[t, i] and lfBasic) <> 0) then
   214            if (cReducedQuality and rqBlurryLand) = 0 then
   221            if (cReducedQuality and rqBlurryLand) = 0 then
   215            LandPixels[y + dx, i]:= LandBackPixel(i, y + dx)
   222            LandPixels[t, i]:= LandBackPixel(i, t)
   216             else 
   223             else 
   217            LandPixels[(y + dx) div 2, i div 2]:= LandBackPixel(i, y + dx)
   224            LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
   218        else
   225        else
   219             if ((Land[y + dx, i] and lfObject) <> 0) then
   226             if ((Land[t, i] and lfObject) <> 0) then
   220             if (cReducedQuality and rqBlurryLand) = 0 then
   227             if (cReducedQuality and rqBlurryLand) = 0 then
   221           LandPixels[y + dx, i]:= 0
   228           LandPixels[t, i]:= 0
   222             else
   229             else
   223            LandPixels[(y + dx) div 2, i div 2]:= 0;
   230            LandPixels[t div 2, i div 2]:= 0;
   224 
   231 
   225 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   232 t:= y - dx;
       
   233 if (t and LAND_HEIGHT_MASK) = 0 then
   226    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   234    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   227        if ((Land[y - dx, i] and lfBasic) <> 0) then
   235        if ((Land[t, i] and lfBasic) <> 0) then
   228             if (cReducedQuality and rqBlurryLand) = 0 then
   236             if (cReducedQuality and rqBlurryLand) = 0 then
   229           LandPixels[y - dx, i]:= LandBackPixel(i, y - dx)
   237           LandPixels[t, i]:= LandBackPixel(i, t)
   230         else 
   238         else 
   231          LandPixels[(y - dx) div 2, i div 2]:= LandBackPixel(i, y - dx)
   239          LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
   232 
   240 
   233        else
   241        else
   234           if ((Land[y - dx, i] and lfObject) <> 0) then
   242           if ((Land[t, i] and lfObject) <> 0) then
   235               if (cReducedQuality and rqBlurryLand) = 0 then
   243               if (cReducedQuality and rqBlurryLand) = 0 then
   236                 LandPixels[y - dx, i]:= 0
   244                 LandPixels[t, i]:= 0
   237               else
   245               else
   238                 LandPixels[(y - dx) div 2, i div 2]:= 0;
   246                 LandPixels[t div 2, i div 2]:= 0;
   239 
   247 
   240 end;
   248 end;
   241 
   249 
   242 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   250 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   243 var i: LongInt;
   251 var i, t: LongInt;
   244 begin
   252 begin
   245 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   253 t:= y + dy;
       
   254 if (t and LAND_HEIGHT_MASK) = 0 then
   246    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   255    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   247        if ((Land[y + dy, i] and lfBasic) <> 0) or ((Land[y + dy, i] and lfObject) <> 0) then
   256        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
   248           begin
   257           begin
   249            if (cReducedQuality and rqBlurryLand) = 0 then
   258            if (cReducedQuality and rqBlurryLand) = 0 then
   250             LandPixels[y + dy, i]:= cExplosionBorderColor
   259             LandPixels[t, i]:= cExplosionBorderColor
   251           else
   260           else
   252             LandPixels[(y + dy) div 2, i div 2]:= cExplosionBorderColor;
   261             LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
   253 
   262 
   254           Land[y + dy, i]:= Land[y + dy, i] or lfDamaged;
   263           Land[t, i]:= Land[t, i] or lfDamaged;
   255           LandDirty[(y + dy) div 32, i div 32]:= 1;
   264           //Despeckle(i, t);
       
   265           LandDirty[t div 32, i div 32]:= 1;
   256           end;
   266           end;
   257 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   267 
       
   268 t:= y - dy;
       
   269 if (t and LAND_HEIGHT_MASK) = 0 then
   258    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   270    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   259        if ((Land[y - dy, i] and lfBasic) <> 0) or ((Land[y - dy, i] and lfObject) <> 0) then
   271        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
   260           begin
   272           begin
   261            if (cReducedQuality and rqBlurryLand) = 0 then
   273            if (cReducedQuality and rqBlurryLand) = 0 then
   262               LandPixels[y - dy, i]:= cExplosionBorderColor 
   274               LandPixels[t, i]:= cExplosionBorderColor 
   263             else
   275             else
   264               LandPixels[(y - dy) div 2, i div 2]:= cExplosionBorderColor;
   276               LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
   265           Land[y - dy, i]:= Land[y - dy, i] or lfDamaged;
   277           Land[t, i]:= Land[t, i] or lfDamaged;
   266           LandDirty[(y - dy) div 32, i div 32]:= 1;
   278           //Despeckle(i, t);
       
   279           LandDirty[t div 32, i div 32]:= 1;
   267           end;
   280           end;
   268 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   281 
       
   282 t:= y + dx;
       
   283 if (t and LAND_HEIGHT_MASK) = 0 then
   269    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   284    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   270        if ((Land[y + dx, i] and lfBasic) <> 0) or ((Land[y + dx, i] and lfObject) <> 0) then
   285        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
   271            begin
   286            begin
   272            if (cReducedQuality and rqBlurryLand) = 0 then
   287            if (cReducedQuality and rqBlurryLand) = 0 then
   273            LandPixels[y + dx, i]:= cExplosionBorderColor
   288            LandPixels[t, i]:= cExplosionBorderColor
   274             else
   289             else
   275            LandPixels[(y + dx) div 2, i div 2]:= cExplosionBorderColor;
   290            LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
   276 
   291 
   277            Land[y + dx, i]:= Land[y + dx, i] or lfDamaged;
   292            Land[t, i]:= Land[t, i] or lfDamaged;
   278            LandDirty[(y + dx) div 32, i div 32]:= 1;
   293            //Despeckle(i, t);
       
   294            LandDirty[t div 32, i div 32]:= 1;
   279            end;
   295            end;
   280 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   296 
       
   297 t:= y - dx;
       
   298 if (t and LAND_HEIGHT_MASK) = 0 then
   281    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   299    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   282        if ((Land[y - dx, i] and lfBasic) <> 0) or ((Land[y - dx, i] and lfObject) <> 0) then
   300        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
   283           begin
   301           begin
   284            if (cReducedQuality and rqBlurryLand) = 0 then
   302            if (cReducedQuality and rqBlurryLand) = 0 then
   285           LandPixels[y - dx, i]:= cExplosionBorderColor 
   303           LandPixels[t, i]:= cExplosionBorderColor 
   286             else
   304             else
   287           LandPixels[(y - dx) div 2, i div 2]:= cExplosionBorderColor;
   305           LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
   288 
   306 
   289           Land[y - dx, i]:= Land[y - dx, i] or lfDamaged;
   307           Land[t, i]:= Land[t, i] or lfDamaged;
   290           LandDirty[(y - dx) div 32, i div 32]:= 1;
   308           //Despeckle(i, y - dy);
       
   309           LandDirty[t div 32, i div 32]:= 1;
   291           end;
   310           end;
   292 end;
   311 end;
   293 
   312 
   294 procedure DrawExplosion(X, Y, Radius: LongInt);
   313 procedure DrawExplosion(X, Y, Radius: LongInt);
   295 var dx, dy, ty, tx, d: LongInt;
   314 var dx, dy, ty, tx, d: LongInt;
   630 y:= max(cpY, topY);
   649 y:= max(cpY, topY);
   631 h:= min(cpY + Image^.h, LAND_HEIGHT) - y;
   650 h:= min(cpY + Image^.h, LAND_HEIGHT) - y;
   632 UpdateLandTexture(x, w, y, h)
   651 UpdateLandTexture(x, w, y, h)
   633 end;
   652 end;
   634 
   653 
       
   654 // was experimenting with applying as damage occurred.
   635 function Despeckle(X, Y: LongInt): boolean;
   655 function Despeckle(X, Y: LongInt): boolean;
   636 var nx, ny, i, j, c: LongInt;
   656 var nx, ny, i, j, c: LongInt;
   637 begin
   657 begin
   638 if ((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0) then // check neighbours
   658 if ((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0) then // check neighbours
   639     begin
   659     begin
   668     end;
   688     end;
   669 Despeckle:= false
   689 Despeckle:= false
   670 end;
   690 end;
   671 
   691 
   672 function SweepDirty: boolean;
   692 function SweepDirty: boolean;
   673 var x, y, xx, yy: LongInt;
   693 var x, y, xx, yy, ty, tx: LongInt;
   674     bRes, updateBlock, resweep, recheck: boolean;
   694     bRes, updateBlock, resweep, recheck: boolean;
   675 begin
   695 begin
   676 bRes:= false;
   696 bRes:= false;
   677 reCheck:= true;
   697 reCheck:= true;
   678 
   698 
   685             begin
   705             begin
   686             if LandDirty[y, x] <> 0 then
   706             if LandDirty[y, x] <> 0 then
   687                 begin
   707                 begin
   688                 updateBlock:= false;
   708                 updateBlock:= false;
   689                 resweep:= true;
   709                 resweep:= true;
       
   710                 ty:= y * 32;
       
   711                 tx:= x * 32;
   690                 while(resweep) do
   712                 while(resweep) do
   691                     begin
   713                     begin
   692                     resweep:= false;
   714                     resweep:= false;
   693                     for yy:= y * 32 to y * 32 + 31 do
   715                     for yy:= ty to ty + 31 do
   694                         for xx:= x * 32 to x * 32 + 31 do
   716                         for xx:= tx to tx + 31 do
   695                             if Despeckle(xx, yy) then
   717                             if Despeckle(xx, yy) then
   696                                 begin
   718                                 begin
   697                                 bRes:= true;
   719                                 bRes:= true;
   698                                 updateBlock:= true;
   720                                 updateBlock:= true;
   699                                 resweep:= true;
   721                                 resweep:= true;
   700                                 if (yy = y*32) and (y > 0) then
   722                                 if (yy = ty) and (y > 0) then
   701                                     begin
   723                                     begin
   702                                     LandDirty[y-1, x]:= 1;
   724                                     LandDirty[y-1, x]:= 1;
   703                                     recheck:= true;
   725                                     recheck:= true;
   704                                     end
   726                                     end
   705                                 else if (yy = y*32+31) and (y < LAND_HEIGHT div 32 - 1) then
   727                                 else if (yy = ty+31) and (y < LAND_HEIGHT div 32 - 1) then
   706                                     begin
   728                                     begin
   707                                     LandDirty[y+1, x]:= 1;
   729                                     LandDirty[y+1, x]:= 1;
   708                                     recheck:= true;
   730                                     recheck:= true;
   709                                     end;
   731                                     end;
   710                                 if (xx = x*32) and (x > 0) then
   732                                 if (xx = tx) and (x > 0) then
   711                                     begin
   733                                     begin
   712                                     LandDirty[y, x-1]:= 1;
   734                                     LandDirty[y, x-1]:= 1;
   713                                     recheck:= true;
   735                                     recheck:= true;
   714                                     end
   736                                     end
   715                                 else if (xx = x*32+31) and (x < LAND_WIDTH div 32 - 1) then
   737                                 else if (xx = tx+31) and (x < LAND_WIDTH div 32 - 1) then
   716                                     begin
   738                                     begin
   717                                     LandDirty[y, x+1]:= 1;
   739                                     LandDirty[y, x+1]:= 1;
   718                                     recheck:= true;
   740                                     recheck:= true;
   719                                     end
   741                                     end
   720                                 end;
   742                                 end;
   721                     end;
   743                     end;
   722                 if updateBlock then UpdateLandTexture(x * 32, 32, y * 32, 32);
   744                 if updateBlock then UpdateLandTexture(tx, 32, ty, 32);
   723                 LandDirty[y, x]:= 0;
   745                 LandDirty[y, x]:= 0;
   724                 end;
   746                 end;
   725             end;
   747             end;
   726         end;
   748         end;
   727      end;
   749      end;