Asylum Dev Diary 34 – Breaking the Bottleneck

As I reported yesterday there was a rather nasty bottleneck n the games performance. After using the profiler tools to work out why it was clear that the lighting wasn’t cleaning up as much as it should and the game was trying to deal with dozens of lights on every frame.

So, my idea was to change the way the lights are built so that a placeholder sprite is used instead of each light sprite, when the placeholder enters the screen it is switched out for the relevant light sprite, and subsequently when the light sprite leaves the display it switched back to the placeholder. This way the game only usually needs to handle up to about 12 lights at a time.

Now this can still be too much when there are a lot of things casting shadows, so in addition to the above placeholders I am also dynamically changing only the closest lights to the player to be dynamic (shadows that can move), once the player is outside of the influence area the light is switched back to static.

This has stabilised the framerate and I’m not seeing any freezing in game any more. The doors need a little extra work as they need to be able to switch lights to dynamic state as well so that the shadows they cast animate with the door movements.

As a bonus treat, I have attached an editor level screen shot showing the floor map with the lighting placeholders, just so you can see the complexity of the situation. The yellow outlined boxes are light placeholders, solid squares are trigger points that cause in game actions and interactions. Doesn’t look quite as nice with the lights on full with no shadows and shaders 😉