Optimise unit wound storage
The way we currently store wounds on units (in QEGVAR(medical,openWounds)) means we have to loop through the whole array at many points in the code to filter out the ones we aren't interested in.
There's already a comment to remove one element from the wounds array (the ID which is seemingly never used), but beyond that I believe we could be storing these in a much more efficient way if we were using some form sorting or key/value system to speed up retrieval.
This is fairly low priority and would be a nice refactor to do once functionality is all in place.
probably just using a CBA hash is enough? And then seperate by wound type or place?
Yeah was my first thought too. If I was doing it in python I'd have a series of dicts first separating by bodypart and then by wound type:
all_wounds = {
'head': {
'abrasion': {},
...
},
'body': {},
'arm_l': {},
'arm_r': {},
'leg_l': {},
'leg_r': {}
}
I do not think this should be part of the medical rewrite, but instead a follow up once that is done. I'd therefor opt to put this on a different milestone instead.
Agree. Optimization in general can be done after. Rather get this out quickly and then optimize together with minor bugfixing.
I also agree on both suggestions: delay until the rewrite is finished and on the use of CBA hashes.
Should we get a seperate milestone for post-rewrite changes?
With wounding system rework merged I decided to finally have a look at this refactor, before doing anything I thought I'd first inspect everywhere we read the open wounds array in the codebase and count where it makes more sense to have constant time lookup by body part versus a flat structure to iterate:
- Iteration: 2
- Body part lookup: 9
- Irrelevant: 4
With this in mind, I'd probably just use one level of hashmap to be able to quickly lookup the wounds on a given body part, then have the values be flat collections. I don't think we perform searches for specific wound types enough to warrant a second level of hashmaps.
It's a shame SQF has no heap structure since then we could prioritise max wound bleeding for the bandaging logic without having to iterate.