Performance Gains and Code Refactoring
Added 2018-09-09 05:49:20 +0000 UTCGood news to everyone who was running into general slowdowns and unresponsiveness in Lab Rats 2! Yesterday and today I focused on refactoring two major sections of old code and have had great success with it. TL;DR: you will see a 5 fold performance gain and future work with drawing characters will be easier for me. But I like writing about programming, so stick around if you want to know more about the details.
The first rewrite was for the section of code that actually tells Ren'py to show an image to the screen. Previously each image that made up a character - their body, hair, and each clothing object on them - was called and told to draw itself to the screen. By ordering these calls correctly the collection of images would be layered and end up forming the characters sprite. There were a couple of problems with this system. If I wanted to apply a change to the character sprite (say, a simple sprite animation/distortion) I needed to apply it separately to each image and ensure somehow that all of the images remained in synch with each other. Additionally, Ren'py needed to store a bunch of independent small images, which made sprite level operations computationally expensive because they were repeated for a lot of pixels that ended up being obscured by images layered above them.
The new drawing system now passes all displayable up to the Person class layer. When I call the_person.draw_person() all of the images are gathered together and flattened into a single image, then drawn to the screen. This means I only have to worry about manipulating a single image, which is both faster for Ren'py and simpler for me. This change will not have produced any observable effects while playing yet, but it will make changes in the future much simpler and let me use a wider range of sprite transformations.
The next major change was to how images were stored internally. Previously each image for a character's body, clothing, hair, and so on was stored as an instance of the Ren'py class Image. All instances of a type of clothing, hair, etc. pointed towards a single object that stored all of the Image instances which ensured there was not a massive duplication of data. Unfortunately Ren'py has a hard time understanding how to save data structures like this and would duplicate the Image array for every character while it was saving. Image loads and stores the image file so it can be displayed quickly, but it takes up a lot of space which resulted in very slow loading (and rollback, which uses the same fundamental saving system). This saving and rollback lag got more pronounced as the number of characters in a game rose.
Now the filenames for characters are stored instead of actual Image instances, and an Image object is created on demand when something needs to be drawn to the screen. A test with a ridiculous number of characters (1717) in the new system suggests each character takes up about 6.2kb when being saved. In the old system each character averaged 30kb. This suggests a five fold increase in performance wherever saving and loading characters is concerned. In my test game beginning and end of day turns took about four seconds to process and rollback was impractically slow, but the other elements of the game functioned without any lag. I will be looking into how to improve rollback speed in the future.
This about wraps up my look at the lower level code of LR2 for this update. My next goal is to add in new business policies and serum traits.
Comments
While we're in there-- the A-cup boobs look more like B's to me.
Dubsington
2018-09-15 00:40:51 +0000 UTCGreat optimisation work, makes me want to break more rule about not coding in my spare time and load up your code this weekend for a nosey
FooLord
2018-09-14 16:47:27 +0000 UTCSo here's something that seems counter-intuitive. This may be an intentional choice, but I'd argue against it as it's inherently misleading. This is in regards to Breast Size. In the game you have chosen, to say the least, strange Breast Sizing. They are as follows: A, AA, B, C, D, DD, DDD, E, F, and FF. From the first A to the last FF you have the breast size increasing. However, in doing so you have DDD as smaller than E when it is in fact the same size as F. I'll go into an explanation on what cup sizing is below: Breast sizes are usually done in two parts the band size and the cup size. For example the bra size 34C refers to a 34 inch "band", that is the circumference of the chest just below the breast, and a C cup. To determine the letter cup you measure, in inches, the circumferance of the chest at nipple height, or where the breasts are fullest, and round up to the nearest whole number. You then subtract the band size to give yourself a smaller number typically ranging from 1-7. Then the letter refers to the difference. A = 1 inch B = 2 inches C = 3 inches D = 4 inches E = 5 inches F = 6 inches G = 7 inches So what about AA, DD, DDD, FF, etc.? This is where fashion companies like telling girls they are small. Girls don't wear a pant size of 32, they wear a pant size "0" and "2". So instead of telling a girl they have an E cup they'll say, "Oh no, it's actually a DD", and instead of an F cup they are just a DDD. What this means is that with your current sizes we have some overlap where AA and B are the same size. DD and E are the same size and DDD and F are the same size. There is also a technicality where becasue of the predominance of DD they usually will list F cups as FF and G cups as GG. You won't usually see a cupsize for just F or G. Here's a calculator I found online that can help: <a href="https://foreveryourslingerie.ca/bra-school-bra-calculator" rel="nofollow noopener" target="_blank">https://foreveryourslingerie.ca/bra-school-bra-calculator</a>
TheMGA
2018-09-11 21:57:43 +0000 UTCSerious!! I added some ideas on how stamina could be increased through the goal system in the post below this one. Is love a way to fairly increase stamina instead of just changing it in the console.
Tim R Mercado
2018-09-11 18:17:38 +0000 UTCCool, keep up! :3
Offshore - Adult Games Developer
2018-09-10 10:24:34 +0000 UTCVren, can you have the stamina reset when you go to bed, instead of when you wake up? If you use all your stamina points each day, then you can't take advantage of the late-night booty calls, which is a real shame. On a related note-- if there is a way to increase stamina I can't find it. It really should be a trainable attribute, maybe like focus/intelligence/charisma.
Dubsington
2018-09-09 20:09:23 +0000 UTCAgreed! It seems that the Patreon amount has slowly been evaporating. I think some "eye-candy" additions would likely spur higher $$$
2018-09-09 13:41:28 +0000 UTCoh and can a lily type character look be added ?
2018-09-09 07:53:34 +0000 UTCwhat about when you have lotsa employees and you cant see all their names or at night in main and theres 50 peeps and only see maybe 15 names
2018-09-09 07:42:58 +0000 UTCEpic. Slow-down wasn't quite game killing, but did mean that I kept my personel list well-trimmed. 20-25 people max if I could manage it. If things speed up, I can let that bloat out a bit hopefully, which will be extra useful if/when further changes occur to job balancing.
Scott Snelling
2018-09-09 06:55:06 +0000 UTC