SRL Archive - Discussions and Debates

Multi-threading in SCAR?


The Claw

2007-09-02 00:56:43

I think thats what its called, is it possible? It would be pretty sweet to be able to run multiple functions/procedures simultaneously

Bam Bam

2007-09-02 01:00:51

Ive chatted with Freddy about the possibility before.

If I remember correctly he said that he might make a function to simply call another function / procedure in its own thread but he said that actually making a TThread class like Delphi has probably won't happen

Edit:

The blunt answer to your question is that it is not possible unless you use TTimers which really suck

ruler

2007-09-02 01:16:52

You can do 2 threads in SCAR. SCAR is 2 threads.

GUI and SCRIPT

just fling things onto the GUI thread

threadsafe call ro seomthing is the function i think

regecks

2007-09-02 05:05:42

I spoke to Kaitnieks a long time ago about /true/ multi-threading, and he told me, while it was possible, there was no in-built functionality in the scripting API he is using to allow such a feature.
However, it is also possible to create another Script object and then custom-code functionality for interaction between the two, but it'd be a handful to make …

R0b0t1

2007-09-02 23:08:34

Well then… Why would thou not be able to make threads in said Del-phi?

Special Ed

2007-09-03 00:02:28

*slap* Lol, naw j/k.

But the only way to "multi - thread* is to use two SCAR Scripts independently talking to each other. You use SendInterScarMessage and ReceiveInterScarMessage to do this. I was working on something like this for a while but I kinda gave up after a while. Maybe I'll start working on it again, who knows?

Santa_Clause

2007-09-03 01:00:22

I think n3ss3s did something like this before. He made a script rotate the camera while it was clicking on things…that is…if I remember correctly.

Bobarkinator

2007-09-03 01:10:51

That wasn't really threading

Wizzup?

2007-09-03 02:16:02

Key Down and Click, thats not multi thread.

Thread Functions:

[php]function SetTimeout(secs: Integer; procname: string): Integer;
Set timed procedure. After secs seconds a procedure with name procname will be called. The procedure should have no parameters and it's only called once (you can SetTimeout again in the procedure).
Example:
SetTimeout(1,'StartPlaying'); will set procedure StartPlaying on timer and it will be called after 1 second.
Declaration:
procedure StartPlaying;
begin
…
end;

function ThreadSafeCall(ProcName: string; var V: TVariantArray): TVariant;
Calls function or procedure in thread-safe way. SCAR scripts operate in separate thread to prevent main form freezing and as a rule threads are not allowed to create, modify or even access forms or controls directly. That means scripts can't create or use forms or controls directly, operate with debug image directly etc. Most of SCAR functions that access forms (Writeln, Status, Readln, LoadDebugImg, ect) are thread-safe already. However if you're operating with debug window canvas directly for an example, you're risking to make SCAR unstable or crash it.
Example:
var
Params: TVariantArray;

procedure ChangeTitle(s: string);
begin
GetSelf.Caption:= s;
end;
….
setarraylength(Params, 1);
Params[0]:= 'Test';
ThreadSafeCall('ChangeTitle', Params);

procedure ClearTimeout(s: string);
Cancels a single timed procedure set with SetTimeout.

procedure ClearTimeouts;
Cancels all timed procedures set with SetTimeout.
[/php]

ruler

2007-09-03 02:40:00

Wizzup? does know the SCAR API.

meh I found it when i was making my scar obfuscator. Scripters back then used it alot. mostly for gui work if i recall.

rotflmfwao

2007-09-04 20:33:15

What about SendMultiScarMessage or sumthin like that? Just a universal inter-scar message?

mastaraymond

2007-09-05 10:04:18

From: rotflmfwao
What about SendMultiScarMessage or sumthin like that? Just a universal inter-scar message?
You can make a very basic multi-threading system in scar… Using SetTimeout; Kind easy:rolleyes:.

ruler

2007-09-05 11:39:07

explain setTimeOut

mastaraymond

2007-09-05 14:14:07

From: ruler
explain setTimeOut
No i was wrong ^^. SetTimeOut calls another procedure\function after the time sou speficy in the SetTimeOut procedure: SetTimeOut(1,'test'); This will call the procedure Test 1 second after you used this procedure.

program New;
var
I , Temp: integer;
Procedure Bla;
begin;
WritelN('JEEE!');
Wait(500);
SetTimeout(1,'bla');
end;
begin
SetTimeout(1,'bla');
Wait(200);
For I:= 0 to 999999999999999999 do
begin;
Temp := GetSystemTime;
Wait(1000);
Writeln(inttostr(Getsystemtime-temp));
end;
end.
But it doesn't operate in a seperate thread, it just pauses the action your doing..

mastaraymond

2007-09-05 14:28:15

From: c0de
That would create an endless loop and SCAR would choke after some time ;-) Trust me I have experience lol.

I tried to say, it doesn't work as it is suppose to x)

rotflmfwao

2007-09-10 20:30:01

sooooo….. Am I right???

Btw, you could also use SaveSetting. That works really well for me :/

elementalelf

2007-09-11 02:32:36

in short, there is no way short of completely deconstructing scar, to make it work with hyperthreaded/multicore processors.

moreover why would you want to? there is no concievable benefit that could not be gotten by using an only slightly laggier repeat/wait/until(this) script.
the best way to utilize hyperthreaded/dual core processors is by running VMware.

edit: perhaps i should qualify the first statement
multithreading can only occur on a processor which either supports hyperthreading(alot of the later P4's do this) or is multicored(almost any new processor is multicored)
however there is alot more to multithreading then just telling the processor "do this while its doing this"
you have to specify which core gets which instruction etc etc.

mastaraymond

2007-09-11 10:00:16

From: elementalelf
in short, there is no way short of completely deconstructing scar, to make it work with hyperthreaded/multicore processors.

moreover why would you want to? there is no concievable benefit that could not be gotten by using an only slightly laggier repeat/wait/until(this) script.
the best way to utilize hyperthreaded/dual core processors is by running VMware.

edit: perhaps i should qualify the first statement
multithreading can only occur on a processor which either supports hyperthreading(alot of the later P4's do this) or is multicored(almost any new processor is multicored)
however there is alot more to multithreading then just telling the processor "do this while its doing this"
you have to specify which core gets which instruction etc etc.

The benefits of multi-threading are, you can do multiple things at the SAME time. Thats what I need especially when your working on forms :s.

Freddy1990

2007-09-11 10:12:45

From: regecks
I spoke to Kaitnieks a long time ago about /true/ multi-threading, and he told me, while it was possible, there was no in-built functionality in the scripting API he is using to allow such a feature.
However, it is also possible to create another Script object and then custom-code functionality for interaction between the two, but it'd be a handful to make …


That's exactly why I haven't added it yet

warship45

2007-09-11 13:36:29

the only thing in scar i can think of that would need to be threaded is the randoms because they need to bw run oftern. The dlls for scar can be multi-threaded, so if you could get commands from scar into a dll plugin then they can be multi-threaded.

this would take to much work to get the commands and functions from srl into a dll becaue of all of the code rewrite that would be needed but it would work and give you multi-threading in scar tho i say this but scar will just run the dll until it is done so you could have to script the whole code in the dll or it will not work at all.