GameMonkey Script

GameMonkey Script Forums
It is currently Tue Jun 18, 2019 2:59 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: endon
PostPosted: Tue May 05, 2009 6:27 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
I got the idea from GSC, the scripting language in Call of Duty 4/5 (which is a LOT like GM's language and syntax). http://wiki.treyarch.com/wiki/Scripting ... nd_Grammar

An endon is a special type of block that doesn't actually block the thread, but rather causes the thread to be killed when a signal of the matching variable is fired on the thread.

I quite like the idea and so implemented it quite quickly in GM. Usage example is below:

Code:
threadfunc = function()
{
  endon("killme");

  while(1)
  {
    print("doing stuff");
    yield();
  }
};

thread(threadfunc);
sleep(5); // wait 5 secs
signal("killme");


The phrase "doing stuff" will print until after 5 seconds in which the thread kills itself.

Is this going to be any use to anyone?


Top
 Profile  
Reply with quote  
 Post subject: Re: endon
PostPosted: Tue May 05, 2009 6:44 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
definately would be useful, I can think of a number of places I would use it in my bot scripting


Top
 Profile  
Reply with quote  
 Post subject: Re: endon
PostPosted: Tue May 05, 2009 10:31 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
Cool. I've attached a patch for 1.25n which (I think) will implement this in a decent way. Let me know how this works out...


Attachments:
gm_1_25n_endon.rar [26.56 KiB]
Downloaded 226 times
gmsrc_1_25n_endon.txt [5.06 KiB]
Downloaded 218 times
Top
 Profile  
Reply with quote  
 Post subject: Re: endon
PostPosted: Wed May 06, 2009 5:08 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
I like it. I've added these changes to my build, enabled with #define in v1.25o.

Edit: It appears that the killed thread is not being killed correctly. gmThread::Sys_SetState() is likely inadequate for a kill. gmMachine::Sys_SwitchState() would normally be required however this will likely interfere with iteration within the blocked/running lists. I will have to investigate further.

Edit2: Investigating a little further it appears it is safe to change Sys_SetState to Sys_SwitchState as there are no conflicts with list iterators, however I have not tested all code paths. There is another issue however, if the thread is blocked and then signaled with both unblocking and ending signals directly after each other, the ending signal is not carried out due to the thread's pending status.

Edit3: I think I've fixed it apart from testing a code path that may never occur. Changes made to gmMachine::Signal(). Uploaded v1.25p.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group