Skip to content

Commit 4c7a76f

Browse files
committed
fix: graphgen
1 parent dbfae39 commit 4c7a76f

File tree

6 files changed

+191
-116
lines changed

6 files changed

+191
-116
lines changed

osrs/map/mapdebugger.simba

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ begin
2828
Self.ImageBox.SetImage(Self.Images[TLazComboBox(sender).ItemIndex], False);
2929
end;
3030

31-
31+
{$H-}
3232
procedure TMapDebugger.ImgBoxPaint(sender: TImageBox; canvas: TImageBoxCanvas; r: TLazRect);
3333
var
3434
p: TPoint;
@@ -57,15 +57,15 @@ begin
5757
tpa := tpa.Connect().Difference(tpa);
5858
canvas.DrawPoints(tpa, $F7AA4E);
5959
end;
60+
{$H+}
6061

61-
procedure TMapDebugger.ImgBoxMouseMove(sender: TImageBox; shift: ELazShiftStates; x, y: Integer);
62+
procedure TMapDebugger.ImgBoxMouseMove(sender: TImageBox; {$H-}shift: ELazShiftStates;{$H+} x, y: Integer);
6263
var
6364
p: TPoint;
64-
canvas: TImageBoxCanvas;
6565
begin
6666
p := Self.GetGlobal([x,y]);
6767
Self.Coordinate.Caption := 'Coordinate: ' + ToStr(p.X) + ' X ' + ToStr(p.Y) + ' Y';
68-
Sender.Repaint();
68+
sender.Repaint();
6969
end;
7070

7171

osrs/map/maploader.simba

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -447,41 +447,17 @@ end;
447447

448448
function TRSMapLoader.SetupGraph(name: String; idx, plane, padding: Integer; collision: TImage): TWebGraph;
449449
var
450-
gray, white, merged, graySubset: TPointArray;
451-
whiteClusters, grayClusters, mergedClusters: T2DPointArray;
452-
i, j: Integer;
450+
i: Integer;
453451
begin
454452
Result := Self.GetGraph(name, plane, collision);
455453
Result.Nodes := Self.GetGlobal(idx, Result.Nodes, [padding,padding]);
456454

457-
white := collision.FindColor($FFFFFF, 0);
458-
gray := collision.FindColor($333333, 0);
459-
460-
white := Self.GetGlobal(idx, white, [padding,padding]);
461-
gray := Self.GetGlobal(idx, gray, [padding,padding]);
462-
463-
whiteClusters := white.Cluster(1.0);
464-
grayClusters := gray.Cluster(1.0);
465-
466-
for i := 0 to High(whiteClusters) do
467-
begin
468-
if Length(whiteClusters[i]) <= 6 then
469-
Continue;
470-
471-
graySubset := gray.ExtractBox(whiteclusters[i].Bounds().Expand(80));
472-
merged := whiteclusters[i] + graySubset;
473-
mergedClusters := merged.Cluster(1.0);
474-
475-
for j := 0 to high(mergedClusters) do
476-
if mergedClusters[j].Contains(whiteClusters[i][0]) then
477-
begin
478-
Result.WalkableClusters += mergedClusters[j];
479-
Break;
480-
end;
481-
end;
455+
Result.WalkableSpace := Self.GetGlobal(idx, Result.WalkableSpace, [padding,padding]);
456+
for i := 0 to High(Result.WalkableClusters) do
457+
Result.WalkableClusters[i] := Self.GetGlobal(idx, Result.WalkableClusters[i], [padding,padding]);
482458

483-
Result.WalkableSpace := white + gray;
484-
Result.ObjectClusters := grayClusters;
459+
for i := 0 to High(Result.ObjectClusters) do
460+
Result.ObjectClusters[i] := Self.GetGlobal(idx, Result.ObjectClusters[i], [padding,padding]);
485461

486462
for i := 0 to High(Result.Doors) do
487463
begin

utils/math/geometry.simba

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ begin
6868
end;
6969

7070

71-
function TPointArray.Cluster(dist: Single): T2DPointArray; overload;
71+
function TPointArray.ClusterEx(dist: Single): T2DPointArray; overload;
7272
begin
7373
if (Length(Self) < 700) then
7474
Exit(NRSplitTPA(Self, dist, dist));
7575
Result := NRClusterTPA(Self, dist);
7676
end;
7777

78-
function TPointArray.Cluster(distX, distY: Single): T2DPointArray; overload;
78+
function TPointArray.ClusterEx(distX, distY: Single): T2DPointArray; overload;
7979
begin
8080
Result := NRSplitTPA(Self, distX, distY);
8181
end;

utils/misc.simba

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ begin
9191
end;
9292

9393

94-
function TImage.ColorsInLine(start, stop: TPoint; colors: TIntegerArray): Boolean;
94+
function TImage.ColorsInLineEx(start, stop: TPoint; colors: TIntegerArray): Boolean;
9595
var
9696
x, y: Integer;
9797
pXCross, pYCross, qXCross, qYCross: Boolean;
@@ -112,3 +112,64 @@ begin
112112

113113
Result := (pXCross and pYCross) or (qXCross and qYCross);
114114
end;
115+
116+
//credits: Simba1400/Source/MML/simba.tpa.pas#L2440C10-L2440C21
117+
function TImage.ColorsInLine(start, stop: TPoint; colors: TIntegerArray): Boolean;
118+
var
119+
Xinc, YInc: Int32;
120+
TwoDxAccumulatedError, TwoDyAccumulatedError: Integer;
121+
current, d, twoD: TPoint;
122+
begin
123+
d := [(stop.X-start.X), (stop.Y-start.Y)];
124+
twoD := [d.X + d.X, d.Y + d.Y];
125+
current := start;
126+
Xinc := 1;
127+
Yinc := 1;
128+
129+
if (d.X < 0) then
130+
begin
131+
Xinc := -1;
132+
d.X := - d.X;
133+
twoD.X := - twoD.X;
134+
end;
135+
136+
if (d.Y < 0) then
137+
begin
138+
Yinc := -1;
139+
d.Y := -d.Y;
140+
twoD.Y := - twoD.Y;
141+
end;
142+
143+
if ((d.X = 0) and (D.Y = 0)) then
144+
Exit;
145+
146+
if (d.Y <= d.X) then
147+
begin
148+
repeat
149+
Inc(current.X, Xinc);
150+
Inc(TwoDxAccumulatedError, twoD.Y);
151+
if (TwoDxAccumulatedError > d.X) then
152+
begin
153+
Inc(current.Y, Yinc);
154+
Dec(TwoDxAccumulatedError, twoD.X);
155+
end;
156+
157+
if Self.Pixel[current.X, current.Y] in colors then Exit(True);
158+
until (current.X = stop.X);
159+
160+
Exit;
161+
end;
162+
163+
repeat
164+
Inc(current.Y, Yinc);
165+
Inc(TwoDyAccumulatedError, twoD.X);
166+
167+
if (TwoDyAccumulatedError > d.Y) then
168+
begin
169+
Inc(current.X, Xinc);
170+
Dec(TwoDyAccumulatedError, twoD.Y);
171+
end;
172+
173+
if Self.Pixel[current.X, current.Y] in colors then Exit(True);
174+
until (current.Y = stop.Y);
175+
end;

utils/webgraph.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ var
292292
i, bestLength, tempLength: Integer;
293293
begin
294294
pArea := TPointArray.CreateFromCircle(p, 20, True).Intersection(Self.WalkableSpace);
295-
pAreaClusters := pArea.Cluster(1.0);
295+
pAreaClusters := pArea.ClusterEx(1);
296296

297297
if Self.ObjectClusters = [] then Exit(pArea.NearestPoint(p));
298298

0 commit comments

Comments
 (0)