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