Drawn maps: Erase land outside of land bounds
authorWuzzy <Wuzzy2@mail.ru>
Sat, 15 Jun 2019 02:50:51 +0200
changeset 15162 af14c418c92f
parent 15161 53342ce3f0a6
child 15163 d97f0b96e45f
Drawn maps: Erase land outside of land bounds
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uLandPainted.pas
--- a/hedgewars/uLand.pas	Sat Jun 15 01:18:40 2019 +0200
+++ b/hedgewars/uLand.pas	Sat Jun 15 02:50:51 2019 +0200
@@ -298,15 +298,16 @@
 
     if GameType = gmtLandPreview then
         cFeatureSize:= 3;
-    ResizeLand((4096 * max(min(cFeatureSize,24),3)) div 12, (2048 * max(min(cFeatureSize,24),3)) div 12);
-    uLandPainted.Draw;
+    playWidth:= (4096 * max(min(cFeatureSize,24),3)) div 12;
+    playHeight:= (2048 * max(min(cFeatureSize,24),3)) div 12;
+    ResizeLand(playWidth, playHeight);
 
     hasGirders:= true;
-    playHeight:= LAND_HEIGHT;
-    playWidth:= LAND_WIDTH;
     leftX:= ((LAND_WIDTH - playWidth) div 2);
     rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
     topY:= LAND_HEIGHT - playHeight;
+
+    uLandPainted.Draw;
 end;
 
 function SelectTemplate: LongInt;
--- a/hedgewars/uLandGraphics.pas	Sat Jun 15 01:18:40 2019 +0200
+++ b/hedgewars/uLandGraphics.pas	Sat Jun 15 02:50:51 2019 +0200
@@ -51,6 +51,7 @@
 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; LandFlags: Word): boolean; inline;
 function ForcePlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; Tint: LongWord; Behind, flipHoriz, flipVert: boolean): boolean; inline;
 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, outOfMap, force, behind, flipHoriz, flipVert: boolean; LandFlags: Word; Tint: LongWord): boolean;
+procedure EraseLandRectRaw(X, Y, width, height: LongWord);
 procedure EraseLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert: boolean);
 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture;
 
@@ -840,6 +841,17 @@
 
 end;
 
+procedure EraseLandRectRaw(X, Y, width, height: LongWord);
+var tx, ty: LongWord;
+begin
+for ty:= 0 to height - 1 do
+    for tx:= 0 to width - 1 do
+        begin
+        LandPixels[ty, tx]:= 0;
+        Land[Y + ty, X + tx]:= 0;
+        end;
+end;
+
 procedure EraseLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert: boolean);
 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt;
     p: PByteArray;
--- a/hedgewars/uLandPainted.pas	Sat Jun 15 01:18:40 2019 +0200
+++ b/hedgewars/uLandPainted.pas	Sat Jun 15 02:50:51 2019 +0200
@@ -129,6 +129,13 @@
         prevPoint:= pe^.point;
         pe:= pe^.next;
         end;
+
+    if (topY > 0) then
+        EraseLandRectRaw(0, 0, LAND_WIDTH, topY - 1);
+    if (leftX > 0) then
+        EraseLandRectRaw(0, topY, leftX - 1, LAND_HEIGHT - topY);
+    if (rightX < (LAND_WIDTH - 1)) then
+        EraseLandRectRaw(rightX + 1, topY, LAND_WIDTH - (rightX + 1), LAND_HEIGHT - topY);
 end;
 
 procedure initModule;