SRL Archive - Discussions and Debates

who says we can't multithread?


footballjds

2013-12-16 01:25:40

title is weird, huh?

But seriously, we can "almost" multithread.

by using global variables and checks at the beginning of every procedure/function the exits if it was called within so many milliseconds;

I'll outline a quick example below, NOTE this will not compile and is pseudocode/example text.
Please note, you can always write a regular procedure that has no check at the top.
I plan to write an entire script incorporating some of this style throughout(evil chicken lair black dragon + fam sup(terror, tort, yak)):

var
ore_TPA: TPointArray;
_findOre, _setLocation, _walkToBank: integer;

procedure setLocation;
const
threadSleep = 350;
begin
{if the last time this function was called plus the sleep time in milliseconds
is greater than the current time it will exit. Forcing this function to sleep
for the period of time in the const}
if (_setLocation + threadSleep) > getSystemTime then exit;
players[currentPlayer].location := externalFindFunction;
_setLocation := getSystemTime;
end;

procedure updateOreTPA:;
const
threadSleep = 750;
begin
{if the last time this function was called plus the sleep time in milliseconds
is greater than the current time it will exit. Forcing this function to sleep
for the period of time in the const. it will also exit if we're not at the mine,
obviously we wouldn't want to search for ore unles we are at the mine.}
if ((_findOre + threadSleep) > getSystemTime) or
(players[currentPlayer].location <> 'mine')then exit;
ore_TPA := FindOrePoints;
_findOre := getSystemTime;
end;

procedure walkToBank;
const
threadSleep = 150;//low number is fine because it will BARELY use resources if it doesn't execute
begin
{unless the procedure hasn't been called in 150 millisceonds, we're not already
at the bank AND the inventory is full we're going to exit out of this}
if ((_walkToBank + threadSleep) > getSystemTime) or (players[currentPlayer].location = 'bank') or (tabBackpack.count < 28) then exit;
if walkPath('bank') then writeln('we walked to the bank');
end;

begin
while true do
begin
walkToBank
updateOreTPA;
setLocation;
wait(10);
end;
end.

footballjds

2013-12-16 01:28:26

close enough

Flight

2013-12-16 02:11:59

This reminds me of Android's Delta Time system. This is pretty clever and simple but I keep thinking there's instances in which this wouldn't be enough. I'll think it over, I know there's examples I just can't think of any right now.

Perhaps someone could post some good examples of how we could use multi-threading to our advantage in our scripts? And let's compare that to what football has pointed out.

bg5

2013-12-16 08:41:07

From: Flight
This reminds me of Android's Delta Time system. This is pretty clever and simple but I keep thinking there's instances in which this wouldn't be enough. I'll think it over, I know there's examples I just can't think of any right now.

Perhaps someone could post some good examples of how we could use multi-threading to our advantage in our scripts? And let's compare that to what football has pointed out.


I made one here about looking for NPC, while SPS walking:
http://villavu.com/forum/showthread.php?t=103201&page=3&p=1274526#post1274526

Kyle

2013-12-16 08:47:15

I think a lot of people are trying to downplay the usefullness of TRUE multi threading. It is quite easy to do this type of psuedo multithreading, but it lacks by far, the power of true multi threading. If we could have it in simba, we could realtime location check our selves so we aren't constantly checking during the script slowing it down. We could also have a realtime progress report system, and anything else that gets called a lot, we could do w/out slowing it down. I know you can call the location checker at the beginnings of loops and all, but with my PC script, that doesn't cut it. I have to call it literally like every part of every loop so it knows instantly when we are out of the game to get in the next boat. I am definitely for the implementation of true Multithreading integrated in simba!

footballjds

2013-12-16 10:17:52

From: Flight
This reminds me of Android's Delta Time system. This is pretty clever and simple but I keep thinking there's instances in which this wouldn't be enough. I'll think it over, I know there's examples I just can't think of any right now.

Perhaps someone could post some good examples of how we could use multi-threading to our advantage in our scripts? And let's compare that to what football has pointed out.


One thing I have no solution for is when the mouse is being moved. It blocks other things from running. I wish we had true multithreading.

Ashaman88

2013-12-16 10:18:58

From: footballjds
One thing I have no solution for is when the mouse is being moved. It blocks other things from running. I wish we had true multithreading.


Yeah that's what I was thinking about too :/ But we can still manage w/o

footballjds

2013-12-16 10:22:24

From: Ashaman88
Yeah that's what I was thinking about too :/ But we can still manage w/o


meh, I want to write a screen scraper bot in JAVA. robot.class isn't there for no reason, afterall.

Kevin

2013-12-16 10:46:27

From: footballjds
meh, I want to write a screen scraper bot in JAVA. robot.class isn't there for no reason, afterall.


I think I have a framework for a basic one that I had started creating before discovering SRL actually…

Kyle

2013-12-16 11:08:12

Yeah I really think that having even a basic way in which to multithread, whether it be w/ a java client or somehow through simba, would be absolutely huge for scripts. Any that rely of location finding would benefit immensely..

Gu3st...

2013-12-16 12:46:32

The problem where the mouse moving blocking all other calculations actually made me so irritated I made a system kind of like OP where the actual mouse moving was a part of the "looping" he posted.
It involved chopping up the path the mouse had to move into very small pieces, making the mouse only move a tiny bit each time it is looped; then my mainloop could i.e check for color changes and whatnot in-between all mouse-movement.
The way I changed where the mouse would end up was by just editing two global variables named mouse_X and mouse_Y. This system was *very* useful for object finding functions as they could update the mouse end-location while the mouse was moving; making sure the cursor hit the target.
You could also call the "normal" mouse moving functions directly, and it was basically up to you to choose when you wanted to use the system and when you didn't want it.

I also feel like we can update SRL so that when we add multi-threading to lape we can extremely easy just enable it in our include and it would work. This wouldn't take too much time, we'd just have to come up with a system that would work before doing any changes to the include.

If anyone is up for making a pseudo-multithreading system that can be used easily (easy to add "threads", easy to pause/unpause, etc), then I personally guarantee that I will work towards getting it into the official include.

Now onto the "What would X benefit from true multithreading?"
SIMBA: Simba would benefit a lot with multithreading. We have to look at the big picture here: Simba is just an IDE of sorts. Simba has it's own "life" outside of this forum, but currently it is not exactly "living the dream" as a program someone would download "for fun". Adding more features enables that to happen, multi-threading is the next step in the process of evolving Simba as such a program.
SRL: SRL could benefit from it becuase then we could add threads that takes care of login checks, object finding, mouse movement, color checks, typing, debugging systems, interface finding, random checks, etc.. This would mean we can do all these things simultaneously and would boost not the include, but all scripts using it as well.
Scripters: Scripters can now add their own object finding procedures to SRL's object finding thread and cange variables used in objects.simba to specify exactly what they want to do. Scripters will develop a new way to think about scripts that will unlock great potential in the field of development. Scripts will become more than just scripts; now we can create programs that can do things outside of SRL as well! We can create a media player or a youtube movie downloader with GUI or whatever.

Someone tell me where my logic fails; until then will I think of multi-threading as 100% positive for Simba and this forum.

footballjds

2013-12-16 13:19:34

wouldn't that make the mouse jumpy if you're finding and sorting through colors for 30 milliseconds?

Kevin

2013-12-16 13:43:34

From: footballjds
wouldn't that make the mouse jumpy if you're finding and sorting through colors for 30 milliseconds?


A 33rd of one second? Some mice barely update that fast.

Although it would definitely be a jumpy mouse, no arguments there. How often is mouse position updated on RS?

Gu3st...

2013-12-16 13:45:45

You guys really think I made it slow? Of course not. The mouse movement wasn't noticeably different.
You don't think I already thought about that when I made the system…? :p

Flight

2013-12-16 20:54:09

From: Zyt3x
You guys really think I made it slow? Of course not. The mouse movement wasn't noticeably different.
You don't think I already thought about that when I made the system…? :p


I've done this already and posted the results, unfortunately they didn't get so much attention:
Scrolling through the bank while searching for a DTM (original version)
Mouse movement fun #2 (Dynamic UpText searching) < This one would work wonderfully with Warpie's OCR engine & plugin. Both of which will absolutely be featured in AeroLib.

Gu3st...

2013-12-17 09:13:11

From: Flight
I've done this already and posted the results, unfortunately they didn't get so much attention:
Scrolling through the bank while searching for a DTM (original version)
Mouse movement fun #2 (Dynamic UpText searching) < This one would work wonderfully with Warpie's OCR engine & plugin. Both of which will absolutely be featured in AeroLib.
Yes! Exactly! :)

This is awesome, Flight. Great work!
This is an excellent example of what great work the current developers are capable of.

Do you have a thread for AeroLib yet? If not then feel free to PM me any work or questions if you want my input. I'd love to hear more about it.

cause

2013-12-17 12:11:34

From: Flight
I've done this already and posted the results, unfortunately they didn't get so much attention:
Scrolling through the bank while searching for a DTM (original version)
Mouse movement fun #2 (Dynamic UpText searching) < This one would work wonderfully with Warpie's OCR engine & plugin. Both of which will absolutely be featured in AeroLib.


Zyt3x summed it up, where is the thread for AeroLib?? Would love to hear more about it