wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.03k stars 607 forks source link

[wpilib, commands] Cache controller BooleanEvents/Triggers and directly construct Triggers #6738

Open Gold856 opened 3 weeks ago

Gold856 commented 3 weeks ago

Fixes #5903, resolves #6445 by updating it to work with the HID templates. (Updating those is great by the way, you just have to change a few lines and regenerate!)

github-actions[bot] commented 3 weeks ago

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

Gold856 commented 3 weeks ago

I don't think I need to do anything for Python? Python Commands already directly constructs Triggers, and since objects are ref-counted, I don't think there's much of a GC concern either.

Gold856 commented 3 weeks ago

Yeah, I'm not sure how to handle axis caches because they're done in a unique way. I suppose I could nest the Map even further (Map<EventLoop, Map<Integer, Map<Double, Trigger>>>), but I feel like that's starting to just be extra overhead for a feature that people might not use.

Alextopher commented 2 weeks ago

I try to lean towards keeping maps as flat a possible. How about Map<EventLoop, Map<Pair<Integer, Double>, Trigger>. Then there is no chance a custom key function can be wrong.