Skip to content

Commit bf44aa7

Browse files
committed
fix: update to latest simba with single cluster
1 parent de6269b commit bf44aa7

File tree

4 files changed

+32
-186
lines changed

4 files changed

+32
-186
lines changed

osrs/finders/items/itemfinder.simba

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,31 @@ begin
263263
end;
264264
end;
265265

266+
267+
procedure TRSItemFinder.Show(item: TRSItem);
268+
var
269+
display, img: TImage;
270+
i, h, w, x: Integer;
271+
begin
272+
try
273+
display := TImage.Create();
274+
275+
for img in Self.GetImages(item) do
276+
begin
277+
if img.Height > h then h:= img.Height;
278+
w := img.Width;
279+
x := display.Width;
280+
display.SetSize(x+w, h);
281+
display.DrawImage(img,[x,0]);
282+
end;
283+
284+
display.Show();
285+
finally
286+
display.Free();
287+
end;
288+
end;
289+
290+
266291
var
267292
ItemFinder: TRSItemFinder;
268293

utils/math/geometry.simba

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ begin
6868
end;
6969

7070

71-
function TPointArray.ClusterEx(dist: Single): T2DPointArray; overload;
72-
begin
73-
if (Length(Self) < 700) then
74-
Exit(NRSplitTPA(Self, dist, dist));
75-
Result := NRClusterTPA(Self, dist);
76-
end;
77-
78-
function TPointArray.ClusterEx(distX, distY: Single): T2DPointArray; overload;
79-
begin
80-
Result := NRSplitTPA(Self, distX, distY);
81-
end;
82-
83-
8471
function TPointArray.AStar(start, goal: TPoint; diagonalTravel: Boolean = True): TPointArray;
8572
begin
8673
Result := AStarTPA(Self, start, goal, diagonalTravel);

utils/webgraph.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ var
325325
i, bestLength, tempLength: Integer;
326326
begin
327327
pArea := TPointArray.CreateFromCircle(p, 20, True).Intersection(Self.WalkableSpace);
328-
pAreaClusters := pArea.ClusterEx(1);
328+
pAreaClusters := pArea.Cluster(1);
329329

330330
if Self.ObjectClusters = [] then Exit(pArea.NearestPoint(p));
331331

utils/webgraphgen.simba

Lines changed: 6 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ var
180180
end;
181181
connectA, connectB: TIntegerArray;
182182
begin
183-
doors := Self.FindDoors(red.ClusterEx(1), map);
183+
doors := Self.FindDoors(red.Cluster(1), map);
184184
SetLength(connectedDoors, Length(doors));
185185
with white.Bounds() do
186186
SetLength(connectionMap, X2, Y2);
187187

188188
minLen := Self.MinimumTiles * RSTranslator.TileArea;
189189

190-
for cluster in white.ClusterEx(1).SortBySize(True) do
190+
for cluster in white.Cluster(1).SortBySize(True) do
191191
begin
192192
if Length(cluster) <= minLen then Continue; //remove very small spaces
193193

@@ -244,7 +244,7 @@ begin
244244

245245
nodes := [];
246246
for tpa in skeleton.Partition(Self.Spacing) do
247-
nodes += tpa.ClusterEx(1.5).Means();
247+
nodes += tpa.Cluster(1.5).Means();
248248

249249
for d in connectA do
250250
begin
@@ -299,172 +299,6 @@ begin
299299
SetLength(Result.Names, Length(Result.Nodes));
300300
end;
301301

302-
function TWebGraphGenerator._BuildGraph2(map: TImage; white, red: TPointArray): TWebGraph;
303-
var
304-
a, b, i, j, n, d, len, hi: Integer;
305-
atpa, parts: T2DPointArray;
306-
skeleton, nodes, tpa, doorsInTpa, doorNodes: TPointArray;
307-
bounds: TBox;
308-
p, q: TPoint;
309-
nodesTree, skeletonTree: TSlackTree;
310-
jInRange, nInRange: Boolean;
311-
connectionMap: array of TIntegerMatrix;
312-
doors: TRSDoorArray;
313-
door: TRSDoor;
314-
doorPaths: T2DIntegerArray;
315-
connectedDoors: array of record
316-
After, Before: Boolean;
317-
end;
318-
connectA, connectB: TIntegerArray;
319-
dists: TDoubleArray;
320-
begin
321-
atpa := white.ClusterEx(1).SortBySize(True);
322-
doors := Self.FindDoors(red.ClusterEx(1), map);
323-
SetLength(connectedDoors, Length(doors));
324-
with white.Bounds() do
325-
SetLength(connectionMap, X2, Y2);
326-
327-
for i := 0 to High(atpa) do
328-
begin
329-
if Length(atpa[i]) <= Self.MinimumTiles * RSTranslator.TileArea then
330-
Continue; //remove very small spaces
331-
332-
connectA := [];
333-
connectB := [];
334-
335-
hi := High(connectedDoors);
336-
for d := 0 to hi do
337-
begin
338-
if connectedDoors[d].After and connectedDoors[d].Before then
339-
begin
340-
Result.Doors += doors[d];
341-
Delete(doors, d, 1);
342-
Delete(connectedDoors, d, 1);
343-
hi -= 1;
344-
d -= 1;
345-
Continue;
346-
end;
347-
348-
if not connectedDoors[d].After and atpa[i].Contains(doors[d].After) then
349-
connectA += d;
350-
if not connectedDoors[d].Before and atpa[i].Contains(doors[d].Before) then
351-
connectB += d;
352-
end;
353-
354-
bounds := atpa[i].Bounds();
355-
if Max(bounds.Width, bounds.Height) < Self.NodeRadius then
356-
begin
357-
Result.Nodes += atpa[i].Median(); //mark spaces less than NodeRadius with a single node and continue
358-
359-
for d in connectA do
360-
begin
361-
Result.Nodes += doors[d].After;
362-
connectedDoors[d].After := True;
363-
SetLength(Result.Paths, Length(Result.Nodes));
364-
Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
365-
Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
366-
end;
367-
368-
for d in connectB do
369-
begin
370-
Result.Nodes += doors[d].Before;
371-
connectedDoors[d].Before := True;
372-
SetLength(Result.Paths, Length(Result.Nodes));
373-
Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
374-
Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
375-
end;
376-
377-
Continue;
378-
end;
379-
380-
skeleton := atpa[i].Erode(1).Skeleton(2, 6);
381-
382-
if skeleton = [] then
383-
begin
384-
Result.Nodes += atpa[i].Median();
385-
386-
for d in connectA do
387-
begin
388-
Result.Nodes += doors[d].After;
389-
connectedDoors[d].After := True;
390-
SetLength(Result.Paths, Length(Result.Nodes));
391-
Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
392-
Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
393-
end;
394-
395-
for d in connectB do
396-
begin
397-
Result.Nodes += doors[d].Before;
398-
connectedDoors[d].Before := True;
399-
SetLength(Result.Paths, Length(Result.Nodes));
400-
Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
401-
Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
402-
end;
403-
404-
Continue;
405-
end;
406-
407-
nodes := [];
408-
409-
for tpa in skeleton.Partition(Self.Spacing) do
410-
for tpa in tpa.ClusterEx(1.5) do
411-
nodes += tpa.Mean();
412-
413-
for d in connectA do
414-
begin
415-
nodes += doors[d].After;
416-
connectedDoors[d].After := True;
417-
end;
418-
419-
for d in connectB do
420-
begin
421-
nodes += doors[d].Before;
422-
connectedDoors[d].Before := True;
423-
end;
424-
425-
nodesTree.Init(nodes);
426-
len := Length(Result.Nodes);
427-
SetLength(Result.Nodes, len + Length(nodes));
428-
SetLength(Result.Paths, Length(Result.Nodes));
429-
430-
for j := 0 to High(nodesTree.Data) do
431-
begin
432-
p := nodesTree.Data[j].Split;
433-
tpa := nodesTree.KNearest(p, Self.MaxConnections, True);
434-
435-
for q in tpa do
436-
begin
437-
if Max(Abs(p.X - q.X), Abs(p.Y - q.Y)) > Self.Spacing * 2 then Continue;
438-
439-
if map.ColorsInLine(p, q, [$0, $FF, $333333]) then
440-
if map.ColorsInLineEx(p, q, [$0, $FF, $333333]) then
441-
if atpa[i].ExtractBox(TBox.Create(Min(p.X, q.X), Min(p.Y, q.Y), Max(p.X, q.X), Max(p.Y, q.Y))).AStar(p, q, True) = [] then
442-
Continue;
443-
444-
connectionMap[q.X, q.Y] += j;
445-
end;
446-
end;
447-
448-
for j := 0 to High(nodesTree.Data) do
449-
begin
450-
p := nodesTree.Data[j].Split;
451-
Result.Nodes[j+len] := p;
452-
for n in connectionMap[p.X, p.Y] do
453-
begin
454-
Result.Nodes[n+len] := nodesTree.Data[n].Split;
455-
456-
if not Result.Paths[j+len].Contains(n+len) then
457-
Result.Paths[j+len] += n+len;
458-
if not Result.Paths[n+len].Contains(j+len) then
459-
Result.Paths[n+len] += j+len;
460-
end;
461-
end;
462-
end;
463-
464-
SetLength(Result.Paths, Length(Result.Nodes));
465-
SetLength(Result.Names, Length(Result.Nodes));
466-
end;
467-
468302

469303
function TWebGraphGenerator.BuildGraph(name: String; map: TImage): TWebGraph;
470304
var
@@ -483,16 +317,16 @@ begin
483317

484318
gray := map.FindColor($333333, 0);
485319

486-
whiteClusters := white.ClusterEx(1);
487-
grayClusters := gray.ClusterEx(1);
320+
whiteClusters := white.Cluster(1);
321+
grayClusters := gray.Cluster(1);
488322

489323
for i := 0 to High(whiteClusters) do
490324
begin
491325
if Length(whiteClusters[i]) <= 6 then Continue;
492326

493327
graySubset := gray.ExtractBox(whiteclusters[i].Bounds().Expand(80));
494328
merged := whiteclusters[i] + graySubset;
495-
mergedClusters := merged.ClusterEx(1);
329+
mergedClusters := merged.Cluster(1);
496330

497331
for j := 0 to high(mergedClusters) do
498332
if mergedClusters[j].Contains(whiteClusters[i][0]) then

0 commit comments

Comments
 (0)