Pipok 0 Posted January 22, 2004 Does anybody can tell me please, what method is less processor occupying: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> #looplabel ?(Traktor distance gracz)<3:{some actions here} ?(Traktor distance gracz)>=3:{some other actions} ~3 goto "looplabel" or rather: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> #looplabel @(Traktor distance gracz)<3 {some actions here} @(Traktor distance gracz)>=3 {Some other actions} goto "looplabel" Thank You in advance. Share this post Link to post Share on other sites
Taurus 20 Posted January 22, 2004 i think conditions @ is less processor occupying, but I'm not sure. This is an very good question that even I want to have an answer to. Share this post Link to post Share on other sites
Rastavovich 0 Posted January 22, 2004 Afaik the suspend command (~) needs less cpu intensive, since the @ condition checks every cycle, while the suspend simply waits untill it is time to work further. Share this post Link to post Share on other sites
Pipok 0 Posted January 22, 2004 Quote[/b] ]Afaik the suspend command (~) needs less cpu intensive, since the @ condition checks every cycle, while the suspend simply waits untill it is time to work further. The first my thought was the same, but... "~3" condition, is checked with each cycle if actual time is the time of last command+3 seconds... so... this seems to be just like "@" condition. So, in first code sample, there is three conditions to check instead of one condition in second example... Do I am wrong? Share this post Link to post Share on other sites
bn880 5 Posted January 22, 2004 The ~ is actually loaded into game variables/state and is _very_ CPU efficient. It likely is loaded into a table of timed events in a dynamic array, it may even be a sorted array (linked list) thus limiting number of checks per cycle. ~ in your example is at least 10x less CPU intensive. Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 22, 2004 Quote[/b] ]This is an very good question that even I want to have an answer to. Me to, till recently I used the @ quite alot, now I'm not so sure. I did a quick test based on some of the threads here and at OFPEC: Loop.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#Loop ~0.5 LCount=LCount+1 If !(EndLoop) then {goto "Loop"} AT.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> @(Call {ATCount=ATCount+1; EndLoop}) Launched from init.sqs with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> LCount=0 TCount=0 ATCount=0 Hint "Start" EndLoop=False Call {[] Exec "Loop.sqs"; [] Exec "AT.sqs"} ~30 EndLoop=True Hint Format ["LCount %1 TCount %2",LCount,ATCount] LCount came out as expected 58. But ATCount scored a massive 855, works out to be roughly the same as ~0.03. In the example above my frame rate according to @ was 0.03, on the desert island with no units on screen. Does that mean my scripts will never execute any quicker than ~0.03? Or that I should make sure my scripts never try to execute quicker than ~0.03? Perhaps you should only use @ for graphic related checks. Say for making a marker follow the position of your squad. Would using @ mean the marker position will always match the units on screen? Cheers Share this post Link to post Share on other sites
dinger 1 Posted January 22, 2004 Each line of script is parsed in a separate time slice. What happens in between depends on load (both total script load and CPU load). Generally speaking, ~ is more efficient than @. ~ does two things -- it sets a __waittime variable, and it allows the script section of OFP to pass on to another script. So if you do ~.000001, for example, the waittime will be shorter than the slice of time that line of script is allocated, but it will let OFP divert its attention to other scripts. @ has the same "switch" effect, but is equivalent to a loop that runs every frame. Most of the time, we don't need something to run every frame. Even for many graphical applications 5 times second is plenty. Share this post Link to post Share on other sites
Taurus 20 Posted January 22, 2004 hmm, interesting. seems I'm about to do an ctrl+a shift+delete on my scripts then. because all of them are using @  or   depending how you look at it. [ edit] So, does triggers work as @ or? e.g. condition: !(alive unit1) would be the same as @!(alive unit1) in a script? Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 23, 2004 I modified the script, setting the goto loop's wait to ~0.0001. Loop.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#Loop LCount=LCount+1 ~0.0001 If (DoLoop) then {goto "Loop"} AT.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> @!(Call {ATCount=ATCount+1; DoLoop}) Launched from init.sqs with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> LCount=0 TCount=0 ATCount=0 Hint "Start" Call {DoLoop=True; [] Exec "Loop.sqs"; [] Exec "AT.sqs"} ~30 DoLoop=False ~3 Hint Format ["LCount %1 ATCount %2 TCount %3",LCount,ATCount,TCount] It executed at the same frequency as the @ script (~0.03). For me this raises more questions than answers. I also added this to a triggers condition field: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Call {If (DoLoop) Then {TCount=TCount+1; True}} Just to confirm that triggers do operate at ~0.5, which it did. Share this post Link to post Share on other sites
bn880 5 Posted January 23, 2004 You would have to test under heavy loads as well. However, yes, most of the time ~0.00001 is added not to swamp the cpu even more than @ Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 23, 2004 Quote[/b] ]You would have to test under heavy loads as well I will try stressing out the graphics card and processor individualy as well as together. I was wondering how OFP might allocate\determine this time slice for each frame? I always envisaged the @ command adding its user defined condition to a stack? With OFP checking this stack every frame. The ~ would be added to the same stack? But with a condition that checked how much time had elapsed? P.S I do try and read all the post from you guys at CoC, my apologies if I'm covering old ground. Share this post Link to post Share on other sites
Pipok 0 Posted January 23, 2004 Quote[/b] ](...) seems I'm about to do an ctrl+a shift+delete on my scripts then. because all of them are using @ (...) Heh, it seems, that I have to do the same with my scripts. Well, it's OF, and that's why I love him. :-) Thank You all for so deep analysis. That's really helpfull to me. Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 23, 2004 I'm still not 100% convined that: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">@((Time-_LastTime)>5) Is completely different to ~5 when it comes to whats required from the CPU: And that @(True) puts more strain on the CPU than using the ~0.0000001. Unless the ~ in OFP executes specific code relating to processor sharing? Either way, if it does not lag your mission then dont worry about I think I will carry on using @ for checking things like Booleans, I'll just try not to use it for anything more complicated in larger scripts. Share this post Link to post Share on other sites
Taurus 20 Posted January 23, 2004 Now I'm confused. take two examples <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">@!(alive unit) ... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#Loop ~1 ?(alive unit): goto "Loop" ... which one would be most effective? Share this post Link to post Share on other sites
bn880 5 Posted January 24, 2004 I'm still not 100% convined that:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">@((Time-_LastTime)>5) Is completely different to ~5 when it comes to whats required from the CPU: It IS completely different. In several ways. Share this post Link to post Share on other sites
Pipok 0 Posted January 27, 2004 I am impressed... Just two of about five "@" have changed to "~" loops, and... about 8-12 fps more... no stuttering, no delays... That's the way I'll do this from now... Thank You all. Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 27, 2004 @The_Taurus Depends what the command Alive does. When I said Booleans I really ment variables defined as booleans. I figure they will require the least amount of processing from the CPU. If the Alive command just checks a memory address for a boolean value then I think it would be less hassle than counting time in a loop along with testing for dead AI? I will try and test it. @bn880 When you say "completely different" you mean the logic is different and not just that, the compiled code of OFP will always run faster than the runtime scripts? @Pipok Which where the ones that showed the best improvement? Cheers Share this post Link to post Share on other sites
Taurus 20 Posted January 27, 2004 Sgt_Wilson: I've changed it from @ to ~delay now and I'm experiencing and tremendous gain in both fps and general performance. However, I'm confused about the "inconsistency" of this game. How come some commands/scripts work at one time, and not the other? Well that's a completely different discussion. Thanks for all the tips ;) Share this post Link to post Share on other sites
bn880 5 Posted January 28, 2004 @bn880When you say "completely different" you mean the logic is different and not just that, the compiled code of OFP will always run faster than the runtime scripts? Well, what was the example... Quote[/b] ]@((Time-_LastTime)>5) versus ~5 What happens with the first example is more less (afaik)Token @ found(look for expression), token open bracket1 found,token open bracket2 found,T-i-m-e string constant,subtraction token found, _LastTime string constant, close bracket2 found, close bracket, greater than comparator found, float value 5 found, close bracket1 found, end of expression then all this is interpreted by OFP, Time is dereferenced, comparison is made, if true the script continues, otherwise this is queued up for the next frame and the whole process starts again. Notice parsing is done a character at a time.. (of course this is not exactly how a parser/tokenizer will work, but close enough.) In the second example a ~ token is detected and a float value of 5 is found, this is stored as an event in a list of events somewhere in the game space. We are now talking very few operations per frame to check for this condition, especially if we are talking a sorted linked list for events. Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 28, 2004 @The_Taurus Thanks, I've used a few @!(Alive)'s myself. I'll try changing them. @bn880 It probably seems like a strange question, nobody in there right mind should use @ to wait 5 seconds. My point was that OFP still has to do some maths using the ~ command. But how about if you had something like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#Loop ~1 GT=True @(True)....Not sure about the timing of this so possible @(GT) GT=False goto "Loop" Then perhaps 50 scripts running something like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#Loop @(GT) ....Do stuff here..... goto "Loop" Would this even work. If it did would it put less strain on the CPU than having fifty scripts all with there own 1 second delays, posted on the stack? Cheers Share this post Link to post Share on other sites
bn880 5 Posted January 28, 2004 I think I have explained enough about this... I don't have a magical calculator to tell you 1@ vs 50 ~1's and it also varies with CPU load. You will have to try in that case, as you are bringing up cases where benefits of either method are not clear. In your example though the singe @ is definately better than 50 scripts with ~1's and loops Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 29, 2004 Sorry, but your as near to BIS as I can get to ask questions. With the exception of the odd post from Suma There might well be method to my madness, until I understand how OFP tackles some of the basic tasks. I wont know for sure But thanks, I do feel as though I have a better grasp now. Hopefully the more people that read this, the less chance of more vauge\stupid questions. Cheers Share this post Link to post Share on other sites