- Joined
- Mar 31, 2015
- Messages
- 28
I have a question about code efficiency.
If I have some function that does something to unit, and I need to call it repeatedly.
For example, it changes unit's vertex color so that unit turns red, but gradually, so I'd want to call the function 255 times over some time, say two seconds, to change color from (255,255,255) to (255,0,0)).
And suppose I want to do that on many units, possibly at once.
What is better approach here:
(A) to make one global timer which calls the function for every unit in group (when I want the unit to turn red, I add it to the unit group and keep a counter for each unit, timer picks all units, call function, and increase each counter, and whenever unit's counter reach some number (255) I reset it and remove unit from group)
or
(B) make as many timers as there are units to be turned red, and each timer calls function just once (per tick), so there are no unit groups.
Hope the question/example is clear enough.
What is more efficient in terms of performance/memory usage?
If I have some function that does something to unit, and I need to call it repeatedly.
For example, it changes unit's vertex color so that unit turns red, but gradually, so I'd want to call the function 255 times over some time, say two seconds, to change color from (255,255,255) to (255,0,0)).
And suppose I want to do that on many units, possibly at once.
What is better approach here:
(A) to make one global timer which calls the function for every unit in group (when I want the unit to turn red, I add it to the unit group and keep a counter for each unit, timer picks all units, call function, and increase each counter, and whenever unit's counter reach some number (255) I reset it and remove unit from group)
or
(B) make as many timers as there are units to be turned red, and each timer calls function just once (per tick), so there are no unit groups.
Hope the question/example is clear enough.
What is more efficient in terms of performance/memory usage?