Level of Detail

04/02/2011 - Jackson Fields

When procedurally generating the slums in Haste, we quickly found it was prohibitively expensive to attempt to render everything at once. Frame rates plummeted just trying to load everything and then even more when trying to move around the city.

To solve this problem, we realized that slums on the opposite side of the city certainly do not need to be drawn, and slums outside the player's immediate surrounding do not need to be drawn either. So, we partitioned the city into a grid and rendered the slums in full resolution when the player is in the immediate area, and a lower resolution or not at all when the player is further away. To test for this range, we check the player's distance from each region at a much lower interval than the update loop. The call is made frequently enough to load new regions when necessary without having the player run into an unrendered area, while not generating a constant influx of redundant function calls.

When the city is initially loaded, all the buildings are generated with random positions, displacements, and rotations as discussed in our post on Procedural Generation, and stored in a list inside the parent region of the slum. When drawing nearby regions, the buildings are taken from these lists, so the layout of the city is maintained.