Search the Community
Showing results for tags 'performace'.
Found 1 result
-
Code optimization, multiple threads of waituntil and spawn
Vandeanson posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hiho Gentlemen, for the past weeks I have been looking into improving the FPS impact my Vandeanson's Apocalypse mod has on missions. What does the mod do? (all the below happens server side only, fyi) 1. []spawn "Position finder function": find well suiting locations to spawn sites of interest (small sized composition of structures, things and AI, e.g. a banditcamp) based on a random players location 2. []spawn "Site spawner function":mark that location (as set in #1.) and starts "waituntil {code to check for condition}" with condition that ANY player gets close to the site 3. create the site, enable dynamic simulation, start despawn timer 4.a [] "spawn hideobjectglobal function" that will hide the objects of a site once no player is near that site, but the despawn timer (item. 5 below) has not run out yet 4.b [] "spawn un-hideobjectglobal function" that will UNhide the objects of a site if a player is near again 5. wait for despawn timer to run out (minimum up-time of a site) 6. start "waituntil {code to check for condition}" with condition that no player is near the site 7. delete the site/AI 8. start at #1. I hope its somehow recognizable, that this should allow for a dynamic environement, with least possible performance impact due to the "waituntil" gating. Sites are only up if really needed e.g. a player is nearby to actually see the site. If the sites and AI are spawned, dynamic simulation is enabled. The performance gains compared to previous versions (where assets where spawned in and FPS was only saved by dyn. simulation) are already quite considerable. The performance saving actions happen through distance checks, waituntil, dynamic simulation, hideobjectglobal and despawn of sites that are no longer needed (e.g. noone within 4k meters proxy) However, the question that is bugging me currently is about the performance impact of having multiple (possibly 100+) waituntil and spawn threads up sametime. waituntil: the mod spawns about 10 type of sites, each sites may be spawned up to 10 times. Each creates an own "waituntil" thread. I seem to understand that these waituntils are continuisly eating up performance until the "condition" is met. Until then, the condition is checked every frame. In my case, these are way to many "check" iterations than needed. A check every 5 seconds is fine as well. Hence I changed the waituntil to waituntil {sleep 5; ...code..}; Question: am I correct that this shold have a "considerable" positive impact on performance of waituntil usage? I got this from forum posts so it should atleast have some hand and feets. [] spawns: most functions need to be spawned in a separate thread, I can not use "call" as the calling script can not be halted until the function returns true and since suspension (waituntil) is not allowed for called functions. Where i can use "call", i do that. Hence, in additiona to a lot of waituntils, I also have multiple spawn threads run more or less complex code sametime. I believe that if i put in sleep timers between each bulk of complex code that should help with performance (e.g. first all bandit camps are spawned, then the next site may start to spawn in). Question: this, if the sleep timers are set right, should put additional ease on cpu. Correct? Also, if I place small sleep timers throughtout spawned code, I should ease possible stutters/lags when spawning stuff. I could also add condition checks (uff, more waituntils) between major functions spawns, that only return true once the previous site/code bulk is done. I hope it is somehow understandable what I am trying to do and what the challenges are that I am worried about. A playable test version of the mod can be found here FYI: (it does not include ALL of the performance saving actions yet, but it should give you a fair picture). Why this post? I would like to understand if: - my thought process is correct - if the issues I am looking into are actual issues worth looking into - if more experienced people would take a similar approach or if I am missing knowledge and the issue could be taken on in better ways. The changes I made already show positive results, but I am sure that there are things that I dont know yet. The above conclusions are based on the last 2 years of coding various projects and reading up various topics online (KK's blog, forum posts, code optimisation guides...) I have no professional coding background, hence I might lack basic knowledge. End of wall of text. I appreciate any feedback, input, source of information and so on that I can get;) Thanks! Cheers VD