Skip to content

Commit 7849d7e

Browse files
committed
feat: added testing mainscreen dist normalization
- also added TColorFinder based on 1.4 TRSObjectColorFinder
1 parent fe89d37 commit 7849d7e

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

osrs/interfaces/gametabs/worldswitcher.simba

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ var
406406
available: TRSWorldArray;
407407
world: TRSWorld;
408408
begin
409+
if worlds = [] then
410+
raise GetDebugLn('WorldSwitcher', 'worlds is empty.');
409411
if not Self.Cooldown.IsFinished() then Exit;
410412
if not Self.Open() then Exit;
411413

osrs/interfaces/mm2ms.simba

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ 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;
2529
end;
2630

31+
procedure TMM2MS.Setup();
32+
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]);
37+
end;
38+
2739
(*
2840
## MM2MS.Run
2941
```pascal
@@ -437,6 +449,70 @@ begin
437449
Result := Minimap.FacePoint(Self.Point2MM(pt, 0, Minimap.GetCompassAngle(False)).ToPoint(), randomness);
438450
end;
439451

452+
(*
453+
## MainScreen.NormalizeDistance
454+
```pascal
455+
function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05): Integer;
456+
```
457+
Converts a distance acquired from the **fixed client* and **default zoom** to the
458+
current mainscreen.
459+
460+
Example:
461+
```pascal
462+
// 20 pixels on the fixed client and default zoom(50) is currently x pixels at the current zoom & client size.
463+
WriteLn(MainScreen.TranslateDistance(20));
464+
```
465+
*)
466+
function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05): Integer;
467+
function _SearchUp(value: Single; target: Single; inc: Single): Single;
468+
var
469+
pt: TPoint;
470+
begin
471+
while True do
472+
begin
473+
pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
474+
if MM2MS.Normalization.Base.DistanceTo(pt) > target then
475+
Exit(value);
476+
477+
value *= inc;
478+
end;
479+
end;
480+
481+
function _SearchDown(value: Single; target: Single; dec: Single): Single;
482+
var
483+
pt: TPoint;
484+
begin
485+
while True do
486+
begin
487+
pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
488+
if MM2MS.Normalization.Base.DistanceTo(pt) < target then
489+
Exit(value);
490+
491+
value /= dec;
492+
end;
493+
end;
494+
495+
var
496+
lo, hi, mean: Single;
497+
begin
498+
if dist = 0 then Exit;
499+
500+
hi := _SearchUp(0.1, dist, 1.50);
501+
lo := _SearchDown(hi, dist, 1.50);
502+
503+
hi := _SearchUp(lo, dist, accuracy);
504+
lo := _SearchDown(hi, dist, accuracy);
505+
506+
mean := lo + ((hi - lo) / 2);
507+
508+
with Minimap.Center do
509+
Result := Round(
510+
Minimap.Vector2MS([X, Y, 0], 0).DistanceTo(
511+
Minimap.Vector2MS([X + mean, Y, 0], 0)
512+
));
513+
514+
if Result < 1 then Result := 1;
515+
end;
440516

441517

442518
(*

osrs/interfaces/setup.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ begin
1515
Options.SetupInterface();
1616
WorldSwitcher.SetupInterface();
1717
Logout.SetupInterface();
18-
MM2MS.Projector.SetupProjection();
18+
MM2MS.Setup();
1919
Chat.SetupInterface();
2020
InterfaceArea.SetupInterface();
2121
RSInterface.SetupInterface();

0 commit comments

Comments
 (0)