Skip to content

Commit e14dde7

Browse files
committed
fix: MainScreen.NormalizeDistance
1 parent b09f100 commit e14dde7

File tree

3 files changed

+98
-18
lines changed

3 files changed

+98
-18
lines changed

osrs/colorfinder.simba

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
(*
2+
# ColorFinder
3+
Methods to interact with the mainscreen.
4+
*)
5+
6+
{$DEFINE SRLT_COLORFINDER_INCLUDED}
7+
{$INCLUDE_ONCE SRLT/osrs.simba}
8+
9+
type
10+
TColorFinder = record
11+
Colors: array of TColorTolerance;
12+
Distance, Erode, Grow: Integer;
13+
LongSide, ShortSide: record Min, Max: Integer; end;
14+
end;
15+
16+
function TColorFinder.Find(area: TBox; atpa: T2DPointArray): Boolean;
17+
var
18+
tpa: TPointArray;
19+
i, l, s: Integer;
20+
finder: TColorFinder;
21+
tmp: T2DPointArray;
22+
begin
23+
// Translate distances
24+
finder.Distance := MainScreen.NormalizeDistance(Self.Distance);
25+
finder.Erode := MainScreen.NormalizeDistance(Self.Erode);
26+
finder.Grow := MainScreen.NormalizeDistance(Self.Grow);
27+
28+
finder.LongSide.Min := MainScreen.NormalizeDistance(Self.LongSide.Min);
29+
finder.ShortSide.Min := MainScreen.NormalizeDistance(Self.ShortSide.Min);
30+
31+
if Self.LongSide.Max = 0 then
32+
finder.LongSide.Max := $FFFFFF
33+
else
34+
finder.LongSide.Max := MainScreen.NormalizeDistance(Self.LongSide.Max);
35+
36+
if Self.ShortSide.Max = 0 then
37+
finder.ShortSide.Max := $FFFFFF
38+
else
39+
finder.ShortSide.Max := MainScreen.NormalizeDistance(Self.ShortSide.Max);
40+
41+
// Find colors
42+
for i := 0 to High(Self.Colors) do
43+
tpa += Target.FindColor(Self.Colors[i], area);
44+
45+
// Process TPA
46+
if tpa <> [] then Exit;
47+
48+
if finder.Grow > 0 then
49+
tpa := tpa.Grow(finder.Grow);
50+
if finder.Erode > 0 then
51+
tpa := tpa.Erode(finder.Erode);
52+
53+
if tpa = [] then Exit;
54+
55+
Result := True;
56+
tmp := tpa.Cluster(finder.Distance);
57+
58+
if (finder.ShortSide.Min > 0) or (finder.ShortSide.Max > 0) or
59+
(finder.LongSide.Min > 0) or (finder.LongSide.Max > 0) then
60+
begin
61+
for i := 0 to High(tmp) do
62+
begin
63+
with tmp[i].Edges().MinAreaRect() do
64+
begin
65+
l := LongSideLen;
66+
s := ShortSideLen;
67+
end;
68+
69+
if ((finder.ShortSide.Min > 0) or (finder.ShortSide.Max > 0)) and (not InRange(s, finder.ShortSide.Min, finder.ShortSide.Max)) then
70+
Continue;
71+
if ((finder.LongSide.Min > 0) or (finder.LongSide.Max > 0)) and (not InRange(l, finder.LongSide.Min, finder.LongSide.Max)) then
72+
Continue;
73+
74+
atpa += tmp[I];
75+
end;
76+
end else
77+
atpa := tmp;
78+
79+
atpa := atpa.SortBySize(True);
80+
end;
81+

osrs/interfaces/mm2ms.simba

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@ Main record responsible for minimap to mainscreen (mm2ms) conversion.
2222
ZoomQuads: array [0..100] of TQuad;
2323
PlayerBoxes: array [0..100] of TBox;
2424
Projector: TMM2MSProjector;
25-
Normalization: record
26-
Projector: TMM2MSProjector;
27-
Base: TPoint;
28-
end;
25+
Normalizer: TMM2MSProjector;
2926
end;
3027

3128
procedure TMM2MS.Setup();
3229
begin
33-
Self.Projector.SetupProjection();
34-
Self.Normalization.Projector.SetupProjection();
35-
Self.Normalization.Projector.UpdateZoom(0);
36-
Self.Normalization.Base := Self.Normalization.Projector.Run([0, 0, 0], [0, 0, 0]);
30+
Self.Projector.SetupProjection(RSClient.Mode);
31+
Self.Normalizer.SetupProjection(ERSMode.FIXED);
32+
Self.Normalizer.UpdateZoom(50);
3733
end;
3834

3935
(*
@@ -464,14 +460,17 @@ WriteLn(MainScreen.TranslateDistance(20));
464460
```
465461
*)
466462
function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05): Integer;
463+
const
464+
BASE: TPoint = [260,181];
465+
467466
function _SearchUp(value: Single; target: Single; inc: Single): Single;
468467
var
469468
pt: TPoint;
470469
begin
471470
while True do
472471
begin
473-
pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
474-
if MM2MS.Normalization.Base.DistanceTo(pt) > target then
472+
pt := MM2MS.Normalizer.Run([value, 0, 0], [0, 0, 0]);
473+
if BASE.DistanceTo(pt) > target then
475474
Exit(value);
476475

477476
value *= inc;
@@ -484,8 +483,8 @@ function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05)
484483
begin
485484
while True do
486485
begin
487-
pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
488-
if MM2MS.Normalization.Base.DistanceTo(pt) < target then
486+
pt := MM2MS.Normalizer.Run([value, 0, 0], [0, 0, 0]);
487+
if BASE.DistanceTo(pt) < target then
489488
Exit(value);
490489

491490
value /= dec;
@@ -494,6 +493,7 @@ function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05)
494493

495494
var
496495
lo, hi, mean: Single;
496+
arr: TPointArray;
497497
begin
498498
if dist = 0 then Exit;
499499

@@ -506,10 +506,9 @@ begin
506506
mean := lo + ((hi - lo) / 2);
507507

508508
with Minimap.Center do
509-
Result := Round(
510-
Minimap.Vector2MS([X, Y, 0], 0).DistanceTo(
511-
Minimap.Vector2MS([X + mean, Y, 0], 0)
512-
));
509+
arr := MM2MS.Run([[X,Y], [X+mean,Y]], 0);
510+
511+
Result := Round(arr[0].DistanceTo(arr[1]));
513512

514513
if Result < 1 then Result := 1;
515514
end;

osrs/interfaces/mm2ms_projector.simba

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type
1717
const
1818
ZOOM2RSZOOM: TSingleArray = [0.0000, 0.0025, 0.0065, 0.0100, 0.0130, 0.0165, 0.0205, 0.0235, 0.0280, 0.0310, 0.0350, 0.0390, 0.0430, 0.0430, 0.0465, 0.0515, 0.0555, 0.0605, 0.0645, 0.0690, 0.0740, 0.0785, 0.0835, 0.0885, 0.0935, 0.0990, 0.1045, 0.1095, 0.1150, 0.1205, 0.1260, 0.1325, 0.1385, 0.1455, 0.1505, 0.1585, 0.1635, 0.1635, 0.1705, 0.1775, 0.1845, 0.1925, 0.1995, 0.2055, 0.2145, 0.2215, 0.2305, 0.2365, 0.2465, 0.2545, 0.2635, 0.2725, 0.2825, 0.2905, 0.3005, 0.3105, 0.3195, 0.3285, 0.3405, 0.3555, 0.3615, 0.3705, 0.3825, 0.3825, 0.3945, 0.4065, 0.4185, 0.4305, 0.4425, 0.4575, 0.4695, 0.4815, 0.4965, 0.5115, 0.5265, 0.5385, 0.5535, 0.5685, 0.5835, 0.5985, 0.6165, 0.6315, 0.6495, 0.6645, 0.6825, 0.7035, 0.7215, 0.7215, 0.7395, 0.7575, 0.7815, 0.7995, 0.8175, 0.8355, 0.8595, 0.8835, 0.9015, 0.9255, 0.9495, 0.9735, 1.000];
1919

20-
procedure TMM2MSProjector.SetupProjection();
20+
procedure TMM2MSProjector.SetupProjection(mode: ERSMode);
2121
begin
22-
case RSClient.Mode of
22+
case mode of
2323
ERSMode.FIXED:
2424
begin
2525
Self.ScaleMin := 0.83 * MainScreen.Bounds.Height / 503; // fixed client height

0 commit comments

Comments
 (0)