RimWorld-LWM.DeepStorage
RimWorld-LWM.DeepStorage copied to clipboard
Add code for support caching
The curly brace format is updated to my setting when I wrote the code. Let me know if you want to keep it consistent with your repo. 😄
Also, why not attach the cache directly to the comp?
I'm not sure this will catch all changes to the actual contents of the storage building, so I'm a bit worried about getting out of sync.
Patch those two Notify methods should cover the case where pawns delivering to and taking out things from storage including cases things are Despawn() or Destory(). And the patch to ListerMergeables covers the situation in which things decay away, split off or get absorbed. I made sure above cases are covered by tracing the call tree. If you are worried about it gets out of sync, we can set up a periodic check on the items in storage and update the cache.
Also, why not attach the cache directly to the comp?
There can be two explanations to it. One is I am too lazy. After I gave up the idea on writing a derived class of Building_Storage, most code in Deep_Storage_Building is done, so I just add a field to the comp.
The second answer is you can think of a cache as a module of a comp, it can be removed easily and without severe consequences. The cache owner, Deep_Storage_Building, implements the ICollection interface, if directly implement the cache on comp, the comp will have to implement the interface or move the logic of updating cache directly into the comp. And if later on different types of caches are needed to interact with other mods or needing to remove the current cache, it would be a headache.
I write up some tests for food basket to test the new cache code. The results looks good so for. I compressed the dll I compile for test. You can try it out yourself.
The code is here: https://github.com/Mhburg/RimWorld-LWM.DeepStorage/tree/master/LWM.DeepStorage.Test/UnitTest and it is also included in this PR.
You only need to load a new game, and the test will run itself. You can check the result in the debug log.
Heh. For future reference,I think separate PRs for different aspects will be been much easier for me to wrap my head around.
Back from the dead: I merged this PR over to my fork (https://github.com/Owlchemist/RimWorld-LWM.DeepStorage), which contained the latest 1.3 build. Spent a lil' while sorting out the conflicts, and now I'm play testing it.
If you're interested in this fork, I can PR it.
As an aside, I'm also working on some non-code related optimizations. The textures, for example.
For the convenience of prototype testing, I put an unlisted workshop mod of the merge here: https://steamcommunity.com/sharedfiles/filedetails/?id=2586897924
Been using it for a few weeks myself, as have a several other folk. Won't be going public with the fork or anything, just available if you wanna preview the changes to consider for official integration.