More stuff using tickcount

4

Features on these Courses

Stats

1,470 visits, 1,890 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Aug, 2019.

We've used tickcount%n = 0 to save n times the performance, but what happens if we use tickcount%n = 1?

Divide your work

Each frame can process as much things as the CPU allows. Using the tickcount%n = 0 has its limits. If you put all of your heavy stuff every n frames, then you'll just have a lag spike every n frames.

Instead, divide your work. The number you put after the equal sign is actually the offset from the nth frame. So if you do some work on tickcount%2 = 0 and some on tickcount%2 = 1 then you'll alternate between doing one work then the other over a 2 frames period.

That's not all, if you need to loop through a lot of objects (say AIs), you can instead decide on what frame offset to update them and divide which AIs get updated at any given frame.

A simple way to do this would be to give a new variable to your AI objects and set that value between 0 and n-1. Try to make it so the objects are evenly distributed. Then, right before your for each loop, pick every AI Object that has its update value set to tickcount%n. That way it will only pick the objects that were tagged to be updated on this frame and loop over them.

That way, you still save n times the CPU usilisation overall, but you ALSO avoid random lag spikes !

  • 0 Comments

Want to leave a comment? Login or Register an account!