Performance Gains, and Large Ships

Hey Folks! Hope everyone had a good weekend. I tried not to stress out too much about the dev issues over the weekend, so as to come back refreshed. I couldn't help it though, and some dev thinking snuck in :)

The good news is that I was able to get some performance gains this morning. It turns out that the bottleneck wasn't the item state updates or line of sight checks. It was actually the sprite rendering.

And weirdly, the framerate drop was apparent with as little as 300-500 sprites on the screen. I knew for a fact that HaxeFlixel could throw more sprites around than that, so I dug into things a little. There's a HaxeFlixel demo called BunnyMark which is used to demonstrate this very thing. And typically, native targets such as Windows should be able to achieve 10s of thousands of sprites on-screen at once.

So I tried building that demo and running it, and sure enough, I was able to lob almost 2000 sprites at the screen before I saw framerate dip to 40 like in my prototype. I looked at the demo's code, and noticed that it didn't do anything too tricky. Basically, it added sprites to a FlxTypedGroup<FlxSprite> instead of a generic FlxGroup.

In my own code, I was adding arbitrary things to my draw groups. Sometimes sprites, sometimes whole groups of sprites. And I think this ruined HaxeFlixel's rendering optimizations. After refactoring the render code to use type groups and just the necessary sprites, I got a pretty big improvement.

Also, I hadn't really considered debug vs. release performance, as in the past, that didn't get much of a gain in Flash. However, HaxeFlixel release blows debug performance away. And where 2000 sprites would start to slow down in debug, I saw no dip in framerate at all when in release. Score!

I may still need to revisit the way I store and render things in the future. But for now, we can proceed with the prefab layouts!

And proceed I did. I started adding tools to insert padding to the layout on the left/right/top/bottom so I can scale-up the size to fit any ship layout. And then, I decided to try tackling a ship of the size I'm hoping for:

IMAGE( The Aeon Hawk!

Yeah, it's ugly as sin. And unfinished. But the size is what I'm aiming for in this prototype: a Millenium Falcon or Firefly sized ship with 2-10 crew. And it runs at 30fps in debug, 60fps in release, without much more than cursory optimizations. That's promising enough for me to feel confident moving forward with this.

I'm still seeing some line-of-sight leakage through corners and diagonals. However, I think this will go away as I fill-in the backsides of the walls, since many of the leaks happen with one-sided wall corners.

Also, those hacky wall sections aren't going to cut it when it comes to sloped and curved walls. I may need to experiment with larger prefabs of curves and slopes. And probably floor tiles to match them, so the lighting doesn't stick out behind walls via the floors.

And, I should really get a few more items on-board, and see if I can hook this layout up to the solar-system flight and planet landing modules, to create a seamless play experience. I'm still sort of banking on finding the fun once these are all connected, so it'll be useful to know if that's true.

So much to do! But the good news is that I think I'm back into fun coding and design territory again for a while. Some juicy tasks ahead!