PDA

View Full Version : findLoading() and waitForLoading();



HKbotz
12-30-2014, 01:33 PM
These two functions involve finding the little "loading - please wait." screen that pops up in the corner when you load a new area. My connection isn't the best and my VM starts to lag a noticeable amount when I have 3+ clients open, so I made these to add to my scripts to help ignore the varying lag I have.

Hope someone else finds it useful as well.

(*
findLoading()
by: HKbotz

Waits to find the small loading screen in the corner when entering new
areas. Returns true if it finds the loading screen, otherwise returns false.

-waitTime: time(in ms) to wait to find loading screen
-tol: the tolerance to use when searching for loading screen bitmap

usage:
findLoading(5000);
if (findLoading(5000, 15)) then
writeLn('Found the loading screen in corner.');
*)
function findLoading(waitTime: integer; tol: integer = 10): boolean;
var
loadingBMP: integer;
p: TPoint;
timer: TTimeMarker;
begin
result := false;
loadingBMP := BitmapFromString(29, 10, 'meJyTFROSpQ1ia7sgqWlEFaOA5g' +
'BNg7BZ+u9T0VigaXiMFfQrZJr5nmHRfyAJZCPrAgoCEV/iBLhiIBs' +
'iCHQqHmNFrQPhfoGEElAEbjKEAbROWl4J4gCu4g0QQSADj7Ec tQfg' +
'5kBsgWsEGgKUhbgNogtZMZCBx1igIcKuiXAukA0xlj+8EcgQN 3JEj' +
'mjijUWWhSiAaASaALEOqB7uWlyBALQX4ikIQosyIIK7HOhOiA hQL1' +
'AW7higaRBxoL3IkUJ1BAAtAqT9');
timer.start();
repeat
if (findBitmapToleranceIn(loadingBMP, p.x, p.y, mainscreen.getBounds(), tol)) then
begin
print('Found loading screen.');
freeBitmap(loadingBMP);
exit(true);
end;
until (timer.getTime() >= waitTime);
print('Couldn''t find loading screen.');
freeBitmap(loadingBMP);
end;


(*
waitForLoading()
by: HKbotz

Finds loading screen, then waits for it to disappear. Returns true if it
was able to find the loading screen and wait for it to disappear again,
otherwise returns false.

-findWait: time(in ms) to wait to find loading screen
-waitTime: time(in ms) to wait for loading screen to go away
-tol: the tolerance to use when searching for loading screen bitmap

usage:
waitForLoading(5000, 5000);

if (waitForLoading(5000, 5000)) then
writeLn('Loaded new aread.');
*)
function waitForLoading(findWait, waitTime: integer; tol: integer = 10): boolean;
var
timer: TTimeMarker;
begin
result := false;
if (findLoading(findWait, tol)) then
begin
timer.start();
repeat
print('Waiting for loading screen to go away...');
if (not findLoading(0, tol)) then
begin
print('Can''t find load screen anymore, must have loaded.');
print('Time it took: ' + intToStr(timer.getTime()));
exit(true);
end;
until (timer.getTime() >= waitTime);
end;
print('Never found loading screen.');
end;

bonsai
12-30-2014, 03:31 PM
Good stuff, thanks for sharing!

KeepBotting
12-30-2014, 03:34 PM
Wow, now that is really clever. I've never even though of this.

Y'know when you see an ad on TV for something you didn't know existed, but desperately need? Yeah, that's this.

Thanks for the share! :)