SRL Archive - SRL Suggestions

CountItemsBlackLine() update


Bobzilla69

2011-05-02 06:07:00

I found that it wont actually count correctly, i used DebugATPA to see what was happening and it appeared not to be large enough to count each item box correctly or to large and not count an item completely.

below is the original and my alteration.

Thought?


changed this

function CountItemsBlackLine(Count, Tol: Integer): Integer;
var
TPA: TPointArray;
I, H: Integer;
TPAA: T2DPointArray;
begin
GameTab(tab_Inv);
result := 0;
FindColors(TPA, SRL_OUTLINE_BLACK, MIX1, MIY1, MIX2, MIY2);
TPAA := TPAToATPAEx(TPA, 42, 36);
H := High(TPAA);
for I := 0 to H do
if InRange(GetArrayLength(TPAA[i]), Count - Tol, Count + Tol) then
Inc(Result);
end;

to this


function CountItemsBlackLine(Count, Tol: Integer): Integer;
var
I, B: Integer;
Search:TBox;
begin
GameTab(tab_Inv);
result := 0;
for i:=1 to 28 do
begin
Search:= InvBox(i);
B:= CountColor(SRL_OUTLINE_BLACK, Search.X1, Search.Y1, Search.X2, Search.Y2 );
if InRange(B, Count - Tol, Count + Tol) then
Inc(Result);
end;
end;

Flight

2011-05-02 07:44:24

Adding parameters… Why wasn't this here before? Nice change Bobzilla, have you tried this with confirmation of it working more accurately?

NCDS

2011-05-02 08:36:54

Just change the width and height here:

TPAA := TPAToATPAEx(TPA, 42, 36);
to adjust it.

Your version calls count color 28 times pretty much back to back which is undoubtedly slower but could also cause lag on some computers, whereas the original version simply calls FindColors once, then splits into an ATPA.


Code-wise the original is much more efficient, so I would suggest trying to work with that.

Bobzilla69

2011-05-02 08:55:59

From: NCDS
Just change the width and height here:

TPAA := TPAToATPAEx(TPA, 42, 36);
to adjust it.

Your version calls count color 28 times pretty much back to back which is undoubtedly slower but could also cause lag on some computers, whereas the original version simply calls FindColors once, then splits into an ATPA.


Code-wise the original is much more efficient, so I would suggest trying to work with that.


i have played with

TPAA := TPAToATPAEx(TPA, 42, 36);

and i cant get it to work

also flight i have tested it and it work brilliantly

Edit:

tried to test it speed wise and i cant tell the difference, granted i did it by simply calling marktime and timefrommark to see difference it was not slower, both where around 15-17 and both went to 32~ at times

i am sure you guys know of a better way to test speed

also tried playing with the TPAA := TPAToATPAEx(TPA, 42, 36); and its still hit an miss, i can get it working for the first 4 items after that it goes tits up for me

Coh3n

2011-05-04 10:14:53

Committed. The difference in speed isn't noticeable. I would rather have something that's a few ms slower and works than something that's faster, but doesn't work.

NCDS

2011-05-04 16:56:44

From: Coh3n
Committed. The difference in speed isn't noticeable. I would rather have something that's a few ms slower and works than something that's faster, but doesn't work.


Yeah your right. I don't see why the original method doesn't work though. :confused: