Open JanWielgus opened 3 years ago
TODO in the IVirtualPilot.h file (interface)
Probably issue that make this idea unable to implement is that base flight mode of certain flight mode could be of the same type but this will be a different instance of this flight mode (for example AltHold can have instance of Stabilize as base flight mode but AltHold2 can have different instance, and that instance won't be reset on change between AltHold and AltHold2)
Besides, setting a flight mode by FlightModeType is much easier and less bug prone then by passing a pointer or reference to the concrete instance.
I HAVE AN IDEA!
Maybe rebuild FlightMode base class that it requires to pass VirtualPilot instance and automatically adds itself to it (addFlightMode() method won't be public then). Another solution is to use global reference to it (not pass it in ctor). Or the even the best: use global reference and add flight mode to the virtual pilot when flight mode is initialized (this may require remake that concrete flight modes override a private virtual initialization method, and FlightMode class has public, non virtual initialize() method that adds itself to the VirtualPilot and then calls this private virtual init method).
If several instances of one flight mode will be created (and therefore several will try to add itself to VirtualPilot) the second and all next just will be ignored and won't used or program can be terminated signaling an error.
Consider realizing that comment - checking only flight mode type, not pointer. This will enable to remove adding list of all flight modes at the program startup.
Screenshot from FlightMode.cpp file: