Results 1 to 7 of 7

Thread: Efficiency of waitUntil, parallel or serial?

  1. #1

    Efficiency of waitUntil, parallel or serial?

    Hi

    I'm wondering what is considered best practice wrt waitUntil efficiency when waiting for several scriptDone statements.
    Code:
    waitUntil {scriptDone _scripthandle1 && scriptDone _scripthandle2 && scriptDone _scripthandle3};
    
    //or something like this
    
    waitUntil {scriptDone _scripthandle1}; //more likely to finish first.
    waitUntil {scriptDone _scripthandle2}; //more likely to finish second.
    waitUntil {scriptDone _scripthandle3}; //more likely to finish third.
    
    //or the reverse order
    
    waitUntil {scriptDone _scripthandle3}; //more likely to finish third.
    waitUntil {scriptDone _scripthandle2}; //more likely to finish second.
    waitUntil {scriptDone _scripthandle1}; //more likely to finish first.
    Should I also combine waitUntil with sleeps? What is best advice?
    Regards
    Carl Gustaffa - left this game due becoming Steam Exclusive

  2. #2
    If you can afford to sleep:
    PHP Code:
    _handles = [_scriptHandle1_scriptHandle2_scriptHandle3];
    waitUntil {sleep 0.5; {not (scriptDone _x)} count _handles == 0}; 
    Of if you think that it would be better checking in serial you could do this:
    PHP Code:
    //Assumes that 1 was started before 2 and all takes about equal time
    _handles = [_scriptHandle1_scriptHandle2_scriptHandle3];
    {
       
    waitUntil {sleep 0.1scriptDone _x};
    } forEach 
    _handles;

    //All scripts done now... 
    Don't really think there is much to say on efficiency on the matter. Time is probably better spent optimizing the actual spawned scripts - or if possible make it just one larger script instead.
    Last edited by Muzzleflash; Aug 3 2012 at 00:38.

  3. #3
    Thanks. Good suggestions.

  4. #4
    If applicable you could use
    Code:
      call compile preProcessFileLineNumbers "script1.sqf";
      call compile preProcessFileLineNumbers "script2.sqf";
      call compile preProcessFileLineNumbers "script3.sqf";
    since that would halt the current script until the other scripts has finished running

    "execVM" is basically short for

    Code:
    [] spawn { call compile preprocessFileLineNumbers "script1.sqf"; };
    from my understanding.
    Last edited by cuel; Aug 3 2012 at 22:36.

  5. #5
    Hi,

    Well my suggestion will be a bit different, what about not using any of the waituntils? Are they needed?
    Imho, this type of procedure should be avoided.

    So, my suggestion would be, remove that extra scripting thread with the waitUntils and modify your scripts to do this by themselves.

    Example (Not tested):

    PHP Code:
    TAG_fnc_scriptDone compile preprocessFileLineNumbers "fn_scriptDone.sqf"
    //fn_scriptDone.sqf
    PHP Code:
    //Function to flag increments

    _wanted 3//How many scripts to wait for?

    if (isnil "TAG_doneScripts"then
    {
    TAG_doneScripts 1;
    }
    else
    {
    TAG_doneScripts TAG_doneScripts 1;
    };

    if (
    TAG_doneScripts == _wantedthen
    {
    //All wanted scripts are done
    //Do something when that happens
    }; 
    //Each of your scripts
    PHP Code:
    //Random script

    //...code...

    //End of script, lets flag this event
    [] call TAG_fnc_scriptDone
    Note this is just a very simple/odd example showing one (of many) way to not having to create another parallel thread.
    Proud community admin/member of The Tour of Teamrespawn

  6. #6
    What scripts are we talking about here?
    If it's initialization and there are no interrupts within you should just use call compile preprocessFile instead of execVM. That way the scripts will be initialized in a guaranteed order - one by one as they were called.

  7. #7
    It's just a "looping" weather script, spawning 3 different processes:
    1) Serial - controlling overcast and fog in serial since they can't be run in parallel. Freq = moderate.
    2) Rain - adjusts, varies, and keep rain level overriding whatever the engine wants to do. Freq = very high.
    3) Wind - basically brings winds up to next level in small steps to avoid the wind sound bug. Freq = low.
    When these three are complete, the cycle starts over with a call from the controlling script with next set of parameters to adjust towards. Even if it deals also with temperatures, latitudes, snow etc, I don't want it to become too intense wrt cycles, as there are other things going on as well. Rain will produce steady rain or showers depending on circumstances, using some kind of clipped curves, and the idea is to have these sync up in MP resetting the curve offsets at given intervals with smooth transitions in between.

Similar Threads

  1. How to Insert Serial on Registry. Bad Serial.
    By skyarcus in forum ARMA 2 & OA - TROUBLESHOOTING
    Replies: 4
    Last Post: Feb 14 2013, 16:37
  2. Script efficiency
    By Double Doppler in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 36
    Last Post: Feb 20 2012, 19:48
  3. ArmA2 efficiency - 2 PC setup?
    By DMarkwick in forum ARMA 2 & OA - GENERAL
    Replies: 9
    Last Post: Feb 26 2010, 02:48
  4. Efficiency question: sleep vs waitUntil
    By galzohar in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 33
    Last Post: Aug 13 2009, 21:26
  5. Sowjet army efficiency
    By Infidel in forum OFFTOPIC
    Replies: 7
    Last Post: Jul 29 2002, 01:54

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •