Monday, July 21, 2014

FMod - Code Correctness

Since the Bio Menace modder on the Keen:Modding forums is still experiencing problems using Abiathar on Bio Menace 3, I put up a new beta for him today. It includes the error reporter I wrote yesterday, and some other interesting things.

In Bio Menace and other games, there are some infoplane values I do not understand. They're not links, and not sprites, but some other sort of data attached to the tile. Interpreted as links, they usually point inside the level, which makes Abiathar think they're valid links. Therefore, they get adjusted (to point to the same relative location) by the Row and Column Adjusters when you insert or delete rows. Unfortunately, this messes up values that are not actually links. So, I added a setting to control this behavior. The default is still to update links when they have no icon and point inside the level, but there are two new ones: to not update links and to only update links where the foreground tile has one of a few specific properties. The tileinfo-checking one looks to make sure that the special-effect property of the foreground tile is one amenable to links (e.g. doors, keys, switches). It is not the default because it typically doesn't work on the Keen 5 world map - the doors have different properties at edit time - and because it takes a little longer to check every tile with a possible link. The option can be found in the settings for the adjuster tools.

Then, just for laughs, I ran Code Analysis on all the projects in the Abiathar solution. The default rule set found one issue, right in the loading of the non-Carmackized maps: a double disposal of a stream object. The analyzer claims that it could throw ObjectDisposedException, but I've never seen that happen on my machine. On the other hand, it is entirely possible that this was the bug causing trouble for the Bio Menace modder. After fixing that, I tried analyzing with all the rule sets. That didn't work well - apparently I am horrible at naming variables and designing interface contracts - and so I removed all the rule sets except Performance and something else I can't remember - maybe Usage or Reliability. (I had Maintainability in there for a while, but it was just complaining about things I can't fix now, specifically everything having an unacceptable cyclomatic complexity, class binding count, or maintainability index.) Going through Performance found a boatload of methods that could be made Shared, which I did, and also a generous helping of unused variables and methods, which is not terribly surprising given the number of nontrivial changes the code base has gone through. The other rule set helped me discover a lot of IDisposable things that were not disposed - who knew the browser dialogs could cause memory leaks? Of course, it also raised silly complaints about not disposing things before they went out of scope: they were used out of the local scope. After going through most of the issue logs and suppressing the spurious warnings, Abiathar runs a little faster!

And somewhere along the way, I changed a straggler "* 13" to a "* 18" in the New Project Wizard, making the Tile Partitioning step finally use the MAPTHEAD file correctly to get the number of infoplane icons.

No comments:

Post a Comment