Better Scene Streaming: The Final Solution
I missed a couple weeks there, but I’m back now. Where I left things last time was that I had implemented a better solution for my scene streaming, but had envisioned a much better solution.
Tonight, after reacclimating to the code, I first added some execution time logging. Before I go making any changes, I want to know the current performance. Using std::chrono I captured the time at the beginning and end of the function and then got the microseconds delta. I then added that to a ring buffer of the last 60 frames, and finally I average all the times in the buffer to get the average run time for the function.
With the current state of my algorithm, the average scene update times were:
When static: 0.55 - 0.65ms
When moving: 0.85 - 1.2ms
I then set out to implement the new algorithm. As described, I wanted to use the min and max visible tile information along with the movement speed and direction to determine the selection of tiles at the edge of the screen that needed to be loaded or unloaded. The logic for this wasn’t too bad, although currently there’s a little bit of code duplication.
Once I have the list of indices to load and unload I then just iterate over them and execute my previous load/unload logic. I was able to remove the visibility checks, since I know for a fact these are off-screen tiles. The last thing I needed to do was handle scene entity loading. Since scene entities are loaded by their tile row (hack for now), I loop over all the rows within view +/- move buffer and run the existing entity load/unload on them.
After all that work, I tested it out and it works as expected. I found an index out of bounds bug, but otherwise it’s all good. And the best part is it was a significant performance improvement!
With the new algorithm, the average scene update times are:
Static: 0.12 - 0.15ms
Active 0.55 - 0.75ms
That’s a feel good moment.
This concludes my Phase 8 rendering R&D. I’ll sit down this week and figure out what phase 9 looks like, but right now UI is a big need, for both debugging and starting to make any kind of gameplay. That is likely what’s next. Fun fun!