RimWorld

RimWorld

Animal Gear
Owlchemist 23 Aug, 2021 @ 2:31pm
XML Optimizations
As I was looking into that apparel layers issue, I got horribly sidetracked while snooping through the XML.

I ended up rewriting one of the files and reduced the operation overhead from 26 operations to 10. I couldn't find a git for Animal Gear so I just setup my own real quick post the results, if you're interested in the one example I did: https://raw.githubusercontent.com/Owlchemist/AnimalGear/master/1.3/Patches/Bodies_Animal_Bird.xml

Furthermore, I believe I could significantly reduce the overhead even more by consolidating all the body types into one superpatch instead (at least for the non-modded animals). If that's something you'd like, I could do the rest.
Last edited by Owlchemist; 23 Aug, 2021 @ 2:48pm
< >
Showing 1-13 of 13 comments
Dylan  [developer] 23 Aug, 2021 @ 3:25pm 
Sure, my guess is that it would optimize load times aswell (?) (Like RegEx I never really got deeper into the XML operations than needed to solve a problem ^^)

Is there an easy way to compare the state of the patches XML ingame, if we switch them out? (to minimize testing)

The layer issue (wearing two armor pieces) is it with a modded animal or vanilla? (maybe I can find out more aswell)

(I only work in a local/offline version-control, so I don't have a Git-account - that install may even be older then Github ^^)
Owlchemist 23 Aug, 2021 @ 3:32pm 
It's just to reduce the number of calls into the defs database during game load, mainly. If you've got a fast PC and/or your database isn't that large (not a heavily modded game), these optimizations won't do much. Reducing the frequency of // deep searches will certainly do some favors.

For me, running only this mod by itself, Startup Impact weighs it in at around 120ms for just the patch operations (plus another 30ms for loading them) which is a bit on the heavy side.

Originally posted by Dylan:
Is there an easy way to compare the state of the patches XML ingame, if we switch them out? (to minimize testing)

If you mean like an in-game way to see if the groups are *actually* applied, idk. I'll look into it.

Originally posted by Dylan:
The layer issue (wearing two armor pieces) is it with a modded animal or vanilla? (maybe I can find out more aswell)

Vanila. I was testing with the Thrumbo.
Last edited by Owlchemist; 23 Aug, 2021 @ 3:41pm
Dylan  [developer] 23 Aug, 2021 @ 3:47pm 
@XML overhaul - It would likely also be easier to understand for others, if things are condensed down to less operations - looking forward to it ^^

@AppliedXMLCheck - Worst case I will write some debug tool to go through them all and put out a summary (may make sense anyway to find animals - especially modded - that may need patches)

@Thrumbo - That is actually worring, maybe I missed some changes with 1.3 - I will check it out aswell
Owlchemist 23 Aug, 2021 @ 3:56pm 
Originally posted by Dylan:
@Thrumbo - That is actually worring, maybe I missed some changes with 1.3 - I will check it out aswell

Heck, hold on I take that back. I was testing with those alpha animal spiders I added armor for in the last Equipment update. Got my memory wires crossed 'cause I was doing some thrumbo stuff on the side at the same time. I just tested it now, it's fine. So I guess the spider's body groups could use some attention.
Last edited by Owlchemist; 23 Aug, 2021 @ 3:59pm
Dylan  [developer] 23 Aug, 2021 @ 4:06pm 
ah ok, I was worried there was another new 1.3 issue ^^ because this was only strictly related to misssing/partial body-groups in the past (if the basics you see in the patches are not there (head, neck, torso etc.), the base-game does not perform a lot of crucial checks that can result in those issues)

edit: the 'force wear' AnimalGear debug tool in the dev-options also shows a missing body group text next to the item if it is not found (at least it should ^^)

edit2: In general you can usually expect a modded animal with a custom body to not have them, as the vanilla ones don't and they are only needed for apparel on pawns as far as I know.
Last edited by Dylan; 23 Aug, 2021 @ 4:14pm
Owlchemist 23 Aug, 2021 @ 7:15pm 
Here it is: https://raw.githubusercontent.com/Owlchemist/AnimalGear/master/1.3/Patches/Bodies_Vanilla_Animals.xml

Reduced the patching time so much that Startup Impact doesn't even register it anymore. From 181 operations to 16.

Aside from a reduced size, this format has a few "safe" wild cards which may end up including a few modded animals that would have otherwise gone missed.

I didn't do the dinosaur and dragon xml files yet. Maybe a project for another day or if you wanna do those yourself the template is pretty easy to follow I think.

Also, OutfitThingCategories.xml is broken (but because success=Always is set, it hides this error). I was looking at this patch for a looonnng time scratching my head trying to understand ultimately what it is even trying to accomplish. Not sure. Considering it's hasn't been working in the first place for who knows how long, is it even needed anymore?
Last edited by Owlchemist; 23 Aug, 2021 @ 7:19pm
Dylan  [developer] 24 Aug, 2021 @ 3:15am 
Nice! That is quite the reduction in file-size and operations ^^ I will test it out.


OutfitThingCategories.xml does still work, it adds all apparel(from all mods) that has the 'Animal'-tag, into the category '[Animal Apparel]' in the outfit menu list
(you can see the difference in the outfit menu, if you add/remove the file - without it all animal apparel resides on the root level and with it, all of it is under [Animal Apparel])

The 'ThingCategory' comes from here:
AnimalGear\1.3\Defs\ThingCategoryDefs\ThingCategories_Outfit.xml

I am not certain what exatly the issue with the base-game was back then (this is from around 2018 ^^), but I am relaitvely sure it is weird in some ways because it was the only way to get it to work (something about the order of things that is required to show up in those categories without issue)
Last edited by Dylan; 24 Aug, 2021 @ 3:15am
Owlchemist 25 Aug, 2021 @ 4:02pm 
Originally posted by Dylan:
OutfitThingCategories.xml does still work, it adds all apparel(from all mods) that has the 'Animal'-tag, into the category '[Animal Apparel]' in the outfit menu list
(you can see the difference in the outfit menu, if you add/remove the file - without it all animal apparel resides on the root level and with it, all of it is under [Animal Apparel])

Hmm I'm not so sure about this...
My mod is already just placing them directly into Animal_Apparel category, so no patch is needed.

However, just to test, I temporarily changed the ThingCategory to just Apparel to see if the patch would do its thing and switch it back. It didn't. I'm just seeing it in the root in-game. And just looking at the patch, I can't see how it would theoretically work. The xpath is wrong in a number of ways and like nothing I've never seen before. I would be throwing errors if not suppressed by <success>Always</success>
Last edited by Owlchemist; 25 Aug, 2021 @ 4:03pm
Dylan  [developer] 26 Aug, 2021 @ 11:24am 
I tested it with my 'AnimalGear: Basic' mod, it is still working ok (on/off either adds them to it or leaves them in root) I did have a look at 'Animal Equipment' aswell, you have the thingCategory in AnimalPlateBase if you remove it there and put it in Apparel_SmallAnimalPlateArmor and all the others it does still work (and this is how it was before - it is quite weird why it would not combine the base class and the real def before the patch check - if you have the category in both it adds it two times and leads to a def error when loading the game ^^)
Owlchemist 26 Aug, 2021 @ 2:11pm 
Huh... well okay then! As the saying goes: every day is a school day xD
I've never seen an xpath that works the way that before (like the final bit being the content *within* the node instead of the node itself).
Dylan  [developer] 26 Aug, 2021 @ 2:17pm 
^^ well I likely found it somewhere so no idea :D
I only remember that it was weird for some actual reason(that I don't remember ^^) and it took some time to come to this weird solution, maybe it is not needed anymore, but there are a handfull of other mods out there using the framework, so if it still does its thing and does not throw errors I would rather leave it be.

I will try to test your improvements on the weekend.
Last edited by Dylan; 26 Aug, 2021 @ 2:20pm
Dylan  [developer] 10 Sep, 2021 @ 12:49pm 
well, I will let you know, but I have not yet gotten to it sadly ..
Dylan  [developer] 27 Oct, 2021 @ 11:56am 
hey, I have just fixed the bracket issues and was also looking into the XML-overhaul you created for the same update, I have found this mod which does more or less what I wanted to do, to check if everything is still the same:

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2363322287

(just starting it with and without those changes and comparing the Unified.xml it creates in the mod folder)

There are some differences. Most are probably harmless, but it also adds this:
<li>HeadAttackTool<groups /></li> (and similar)
which seems a bit weird, I am taking a look at it right now, if I can figure out what is going on there
(It likely would need to check if it is already within a group tag in the hierarchy or something)

Edit: Ok, got that one fixed with a "[not(ancestor::groups)]" - I am now only looking at some minor things
Last edited by Dylan; 27 Oct, 2021 @ 12:21pm
< >
Showing 1-13 of 13 comments
Per page: 1530 50