Disaster averted for now

Yesterday I said I was going to scale-test the way I was destroying game tiles, so I built a relatively large map to see how it would perform when I started blowing holes in it:

This is the end result, which has good enough performance to convince me that I can make this scale to a per-room basis, with possible hacky subdivision of surfaces as necessary.

The gristly details

To get this to be performant for this large a room, I needed to do some performance tweaking. The first time I successfully ran the test, each block destroyed off the largest connected surface took over a second. I dug in for some performance testing with the magic of Stopwatch, where I confirmed my worst fear: over 99% of the performance was asking Box2D to create the loop shapes. I was beginning to think that this negative result would force me to drop Box2D altogether, but then I hit upon the idea of eliminating redundant co-linear loop vertices — my naive first implementation just added a new segment to the loop for every tile it processed. This reduces the number of vertices in the chain by a couple orders of magnitude and brings the complexity of the shape down to where Box2D can easily chew it. I’ll be coming up with other tests of Box2D’s fundamental capabilities in the next few days.

Leave a Reply

Your email address will not be published. Required fields are marked *