Last Minute Performance Improvements (Patreon)
Content
The release of v0.28.0 is nearly here (24 hours away!) and I'm still busy finishing off the last few bits of content, bug fixes, and improvements before it's time to test and ship it. Tonight I was finally in the right state of mind to sit down and finish a feature I had experimented with at the beginning of the month: Multithreading.
First, a quick course in program execution and multithreading. You can imagine a program to be like a list of instructions you give to a friend. This list might tell your friend how to bake a cake, and include steps for gathering the ingredients in one place, mixing them together, heating the oven, and so on. A single person (for computers, a "thread") reading through the instructions is the simplest way to write a program. Everything happens in a predictable order. Unfortunately it's also the hardest to speed up; the only way to make it go faster is to get a faster friend. The obvious thing to do is get several friends and have them all work together. One person mixes the dry ingredients, another the wet ingredients, and a final friend pre-heats the oven. When you split up a program onto multiple CPU cores it is called multithreading.
For the most part Lab Rats 2 operates perfectly fine as a sequential program. The game logic is so simple a modern CPU could likely process dozens of turns a second. Where the game slows down is when it needs to display character images. Clothing images need to be loaded, coloured, layered, and (coming in v0.28.0) constrained, placed on top of a person and scaled. If animations are being used the whole thing needs to be processed as a .png and then run through a shader before being displayed. This is usually done in less than second, but that's a noticeable delay if you are scrolling through a list of people and viewing previews. To avoid this delay I have split the character display code in menus into it's own thread. Now when you hover over a character button the menu remains responsive while their preview is created. I have experimented with a similar approach for all character display calls and have had good results, but it will need more work to mesh smoothly with the animation system.
While looking through the display code I have also made some incidental improvements and bug fixes. I think I have fixed the character scaling issues with Macs (thank you to everyone who filled out a bug report, especially if you had some insight into the cause!) and character animation should be slightly faster now.
There are a few more things for me to finish off, so I'm going to get back to work! Lab Rats 2 v0.28.0 will be out this time tomorrow to $5 patrons for bug testing!