Fiddi 68 Posted February 21, 2017 Hello, Would like to get some optimization tips for this loop I have. It gives the enemy sides the possibility of reporting all enemy activity to their friends. It has already intensified my mission greatly, and I was wondering if there's something I can improve upon, as I would guess it's a bit of a performance hog. Anyway, here's the code: while {true} do { _allGroups = allGroups select {!(leader _x getVariable ["excludeZeus", false])}; { _group = _x; _allUnits = allUnits select {(side _group) != (side _x) AND (side _group) knowsAbout _x > 1}; { _group reveal [_x, 1.6]; Sleep 1; true } count _allUnits; true } count _allGroups; Sleep random [2, 4, 8]; }; Share this post Link to post Share on other sites
killzone_kid 1331 Posted February 21, 2017 So basically you force 1.6 value for knowsabout for already detected unit? Sounds like a waste of CPU for just a nudge Share this post Link to post Share on other sites
Fiddi 68 Posted February 21, 2017 45 minutes ago, killzone_kid said: So basically you force 1.6 value for knowsabout for already detected unit? Sounds like a waste of CPU for just a nudge Yeah, well it works in tandem with another function that creates waypoints for groups based on the nearest targets. It makes the mission much more unpredictable. Share this post Link to post Share on other sites
genesis92x 810 Posted February 23, 2017 On 2/21/2017 at 3:53 PM, killzone_kid said: So basically you force 1.6 value for knowsabout for already detected unit? Sounds like a waste of CPU for just a nudge So helpful :D! On 2/21/2017 at 2:04 PM, Fiddi said: Hello, Would like to get some optimization tips for this loop I have. It gives the enemy sides the possibility of reporting all enemy activity to their friends. It has already intensified my mission greatly, and I was wondering if there's something I can improve upon, as I would guess it's a bit of a performance hog. Anyway, here's the code: while {true} do { _allGroups = allGroups select {!(leader _x getVariable ["excludeZeus", false])}; { _group = _x; _allUnits = allUnits select {(side _group) != (side _x) AND (side _group) knowsAbout _x > 1}; { _group reveal [_x, 1.6]; Sleep 1; true } count _allUnits; true } count _allGroups; Sleep random [2, 4, 8]; }; You are actually doing a great job with optimization already. I am just now learning a lot about it now - but I put a few things below...your mileage will vary however. 1) For _allUnits = allUnits select {(side _group) != (side _x) AND (side _group) knowsAbout _x > 1}; Could you use some lazy evaluation here? So something like... _allUnits = allUnits select {(side _group) != (side _x) && {(side _group) knowsAbout _x > 1}}; You will have to test it and see if it helps at all. If the first condition is false, there is no reason to check the second condition at all. 2) It's a small thing...but the shorter the code the better. This means even shortening variable names. The gains this gives would be tiny...but when you are constantly doing a loop every fraction of a second can help. 3) It might be a good idea to private some of these variables. private _allgroups = allGroups select {!(leader _x getVariable ["excludeZeus", false])}; 4) In my own testing I learned that the "getvariable" command can actually be pretty hefty when iterating through many groups/units. Since you are doing groups and not units, it is not bad at all. A part of me wonders if tinkering with finding a way to put the groups into an array and pulling them from there instead of using getvariable. Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted February 24, 2017 you probably don't need to be building your _allGroups array with the same frequency, maybe only update the groups every ~30 seconds. Share this post Link to post Share on other sites