- Rework FillLand
- Optimize fade() function a bit, don't call min() function
- Only leave parts of land which touch bottom border in perlin mapgen
--- a/hedgewars/uLand.pas Sun Mar 09 20:53:11 2014 -0400
+++ b/hedgewars/uLand.pas Mon Mar 10 22:47:29 2014 +0400
@@ -322,7 +322,7 @@
with Template do
for i:= 0 to pred(FillPointsCount) do
with fps[i] do
- FillLand(x, y);
+ FillLand(x, y, 0, 0);
DrawEdge(pa, lfBasic);
--- a/hedgewars/uLandGenMaze.pas Sun Mar 09 20:53:11 2014 -0400
+++ b/hedgewars/uLandGenMaze.pas Mon Mar 10 22:47:29 2014 +0400
@@ -481,7 +481,7 @@
DrawEdge(pa, 0);
if maze_inverted then
- FillLand(1, 1+off_y)
+ FillLand(1, 1+off_y, 0, 0)
else
begin
x := 0;
@@ -489,7 +489,7 @@
x := x + 1;
while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
x := x + 1;
- FillLand(x+1, cellsize div 2 + cellsize + off_y);
+ FillLand(x+1, cellsize div 2 + cellsize + off_y, 0, 0);
end;
MaxHedgehogs:= 32;
--- a/hedgewars/uLandGenPerlin.pas Sun Mar 09 20:53:11 2014 -0400
+++ b/hedgewars/uLandGenPerlin.pas Mon Mar 10 22:47:29 2014 +0400
@@ -6,7 +6,11 @@
procedure GenPerlin;
implementation
-uses uVariables, uConsts, uRandom, math; // for min()
+uses uVariables
+ , uConsts
+ , uRandom
+ , uLandOutline // FillLand
+ ;
var p: array[0..511] of LongInt;
@@ -38,7 +42,11 @@
var t0, t1: LongInt;
begin
t0:= fadear[t shr 8];
- t1:= fadear[min(255, t shr 8 + 1)];
+
+ if t0 = fadear[255] then
+ t1:= t0
+ else
+ t1:= fadear[t shr 8 + 1];
fade:= t0 + ((t and 255) * (t1 - t0) shr 8)
end;
@@ -151,11 +159,16 @@
if x + bottomPlateMargin + bottomPlateHeight > width then
r:= r - (x - width + bottomPlateMargin + bottomPlateHeight) * plateFactor;
end;
- if r < 0 then Land[y, x]:= 0 else Land[y, x]:= lfBasic;
+ if r < 0 then Land[y, x]:= 0 else Land[y, x]:= lfObjMask;
end;
end;
+ for x:= 0 to width do
+ if Land[height - 1, x] = lfObjMask then FillLand(x, height - 1, 0, lfBasic);
+ FillLand(0, 0, lfBasic, lfObjMask);
+ FillLand(0, 0, lfBasic, 0);
+
leftX:= 0;
rightX:= 4095;
topY:= 0;
--- a/hedgewars/uLandOutline.pas Sun Mar 09 20:53:11 2014 -0400
+++ b/hedgewars/uLandOutline.pas Mon Mar 10 22:47:29 2014 +0400
@@ -9,8 +9,8 @@
ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
end;
-procedure DrawEdge(var pa: TPixAr; Color: Longword);
-procedure FillLand(x, y: LongInt);
+procedure DrawEdge(var pa: TPixAr; value: Word);
+procedure FillLand(x, y: LongInt; border, value: Word);
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat);
procedure RandomizePoints(var pa: TPixAr);
@@ -56,7 +56,7 @@
end
end;
-procedure FillLand(x, y: LongInt);
+procedure FillLand(x, y: LongInt; border, value: Word);
var xl, xr, dir: LongInt;
begin
Stack.Count:= 0;
@@ -68,18 +68,18 @@
while Stack.Count > 0 do
begin
Pop(xl, xr, y, dir);
- while (xl > 0) and (Land[y, xl] <> 0) do
+ while (xl > 0) and (Land[y, xl] <> border) and (Land[y, xl] <> value) do
dec(xl);
- while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do
+ while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> border) and (Land[y, xr] <> value) do
inc(xr);
while (xl < xr) do
begin
- while (xl <= xr) and (Land[y, xl] = 0) do
+ while (xl <= xr) and ((Land[y, xl] = border) or (Land[y, xl] = value)) do
inc(xl);
x:= xl;
- while (xl <= xr) and (Land[y, xl] <> 0) do
+ while (xl <= xr) and (Land[y, xl] <> border) and (Land[y, xl] <> value) do
begin
- Land[y, xl]:= 0;
+ Land[y, xl]:= value;
inc(xl)
end;
if x < xl then
@@ -91,7 +91,7 @@
end;
end;
-procedure DrawEdge(var pa: TPixAr; Color: Longword);
+procedure DrawEdge(var pa: TPixAr; value: Word);
var i: LongInt;
begin
i:= 0;
@@ -101,7 +101,7 @@
inc(i, 2)
else
begin
- DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, Color);
+ DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, value);
inc(i)
end
end;