Devtober Day 3


I opened up my level editor scene and tried to remember the way I wrote adding seasonal assets before. Turns out, they weren’t properly implemented in the first place, so I finished that up, fixed some bugs, and ensured that my outputted atlas had different versions between spring/summer and autumn/winter/wasteland. Also made a quick EditorScript to randomize rotation of all of them. Loaded up the game and there they were in my map!

While moving around the map, however, I noticed some nasty frame drops. Did adding these assets, few as they are, tank performance?

Well, no, because other maps that are still completely empty still had similar lag spikes, so that’s probably not the issue. I know what tool I can use to answer this question.

The performance profiler. Anyway, lag spikes are at a regular interval. That’s when an NPC group is running its behavior tree to decide whether it should issue any new orders (and steeper lag spikes when it does, in fact, change orders). In particular, though, some of those functions in the column were ones I wrote intending that they were only called infrequently (one of them creates some RefCounted objects and returns them). If they are called dozens or hundreds of times in a frame, that is a problem.

After doing some low-hanging-fruit optimizations (changing a user interface to poll certain values more occasionally, caching data that used to be created on-demand). On a “normal” frame, it still looks iffy but under 16.7 ms, and it’s not my scripts that are the problem.

OK, so behavior trees aren’t the only source of occasional lag spikes, it looks like some callbacks from the game event heap are problematic as well (this one is generating a unit. There’s probably a way to move that to a different thread, or at the very least spread out the work over multiple threads.

The rest of the long process time? Probably due to slow 2D rendering that is harder to address. I’m already using RenderingServer, not nodes, for these static background assets. I suspect either overdraw (lots of transparent pixels), or lack of batching is causing problems here. I will try loading this in the 4.4 demo tomorrow to see if it helps. Overdraw might be addressable if I do mesh conversions (so it no longer draws squares for everything), but that would require writing a lot of additional tool code.

I will note that my PC isn’t super new, and its processor is fairly weak compared to the rest of it, so maybe if I had a more modern computer I wouldn’t be getting frame drops at all. Still! That’s no excuse. I would like my game to run well on computers that are older and weaker than mine (I think people would expect as much from a solo-developed indie game in any case). There are more things I can do to address performance, but not all of them are achievable in just one day.

Get War for the Fauna Wilds

Leave a comment

Log in with itch.io to leave a comment.