LR2 Image Drawing Optimization (Patreon)
Content
Last update cycle I took some time to look at the way images were displayed and profile what was taking up the bulk of the time. I had expected the bulk of the time to be taken up by the animation system having to convert the displayable into a flat .png, but the answer was more complex than that. The conversion was inefficient, but it was taking up closer to 50% of the time needed to display rather than dominating the process. Additionally, I was noticing a strong correlation between the complexity of a girls outfit and how long it was taking to display, both with and without animation. Now you can say you're giving your girls skimpy uniforms for performance reasons!
I've been thinking about this for a while, but a comment from a patron finally kicked me off in the right direction. All of the images for LR2 are cropped to a specific size based on the position they are for (standing, sitting, doggy, etc). For many images this results in a lot of empty space but it makes layering the images trivial. For a long time I didn't think this would be a problem: the actual image files are tiny. My patron noted that they will only be tiny when they are compressed, when a 500x1080 pixel image is uncompressed by Ren'py to be it's going to take the same amount of space regardless of what it contains. Just as importantly, any operations I perform on that stack of images (like applying an alpha mask to hide or colour sections of it) will involve a lot of calculations for sections of the image that are blank.
The fix for this is simple, at least as a concept. If I crop all of the clothing items images to their bounding box I remove the bulk of the empty space from most images (patterns, jewellery, makeup, and skimpy lingerie especially). To properly align the cropped images I will need to keep track of their new offset and apply that shift when they are put into a compound image. In practice this will require some new script writing for GIMP to find the bounding box for each clothing item and to crop it to that item. The code inside of Lab Rats 2 will require very few alterations and should hopefully run significantly faster.