#Does calling "GetUnitsByType" every frame is a performance hog?

6 messages · Page 1 of 1 (latest)

sterile kettle
#

Title.
Trying to apply a packet-request rate type of buff to cannons map-wide, so the player doesn't have to wait 2 minutes just to apply the buff efficiently.

vast dragon
#

Getunitsbytype itself is pretty lightweight, but looping through the resulting list will become pretty heavy. So imo best practice would be to do getunitsbytype on one frame and then in the next X frames you work through the list piecemeal.

austere dust
#

Iterator logic. Loop over X number per loop and save where your are each time you want to stop. Then just use the saved index to start there next frame.

vast dragon
#

Like StormWing says basically: a loop does not have to start at 0, nor end at the end of the list. In code:
<-startLoop <-listCount gte if
... create list here and get the listcount ...
<-listCount 30 div asint 1 add ->stepLoop
0 ->startLoop
else
<-startLoop dup <-stepLoop add dup ->startLoop swap do
... apply what you want to the list items ...
loop

sterile kettle
#

Mmm alright. Thanks!