Comet 4c - Plugin Development #5

Replay and Situations

A very busy period for photography in the Spring slowed progress on the Comet. I’m happy to announce that all the plug-ins except the one for astronomical navigation (sextant) have been written. I am now churning through the testing and debugging process, checking each function and variable, making sure it does what it’s supposed to do.


Replay Mode

Not everything has been straight forward. One of the problems when writing plug-ins is compatibility with X-Plane replay mode. X-Plane can only possibly record datarefs it knows about — in other words its own stock datarefs. Any custom datarefs created for custom systems are ignored.

Although it is possible to save data to an external file, all the experiments I’ve made have found it to reduce FPS. In my view it would be totally unsatisfactory to have such a dead weight affecting the Comet in normal flight for the occasional use of replay mode.

Instead, plug-ins recognise when the system is in replay mode and switch the animation of needles, switches and levers from custom datarefs to stock X-Plane datarefs. It’s not perfect: some of the subtlety of the original systems is lost; unique instruments, like the Comet’s ADF3 and ADF4, remain frozen at the last known frequency — but the needles read accurately for that frequency. Key instruments: horizon, ASI, altimeter, compass, RMI, engine and fuel gauges remain accurate.


Situations

For those not familiar with X-Plane situations, it is a standard X-Plane feature for saving the location, attitude and velocity of an aircraft in flight. It will also save radio frequencies and autopilot settings so the aircraft continues doing what it was doing when it was saved — more or less.

As with replay mode, X-Plane only recognises stock datarefs when saving situations. Therefore the Comet plugins are designed to use X-Plane datarefs wherever practicable. For example: the Comet autopilot doesn’t just switch on, there are other switches that have to be on first, but when all that’s done, the final “ON” command is to the stock X-Plane autopilot.

This has the advantage that if the plug-in detects it is in replay mode, it can take logical decisions based on things that happen during the replay. For example: if it finds that the X-Plane autopilot has switched itself on, it follows that all the other switches in the Comet that allow that to happen must have been switched on too, and this is done retrospectively. It might not be in exactly the sequence carried out by the user, but that’s a minor drawback.

With replay, this is largely cosmetic: the plane will follow the path it followed faithfully, regardless of the position of switches, levers and instruments; but when loading situations, it’s critical. If essential Comet systems were not configured for flight it could not continue to fly. If individual fuel tank cocks (which do not exist in X-Plane) remain closed, the engines will be starved of fuel. If the hydraulics are not on-line, the plane will not even be controllable.

The difficulty with situations is that there is no dataref to say a situation is loading. The clue is in the dataref: sim/time/total_flight_time_sec, which resets to zero when an aircraft is loaded (including after a crash), or when a situation is loaded. Therefore if the time is zero and the plugins detect that the engines were already running, it is reasonable to assume that the fuel cocks should be on. If the time is zero and the Comet is some distance off the ground, then it’s reasonable to assume it’s in flight, and the hydraulics will be configured for flight. The plug-in makes these (and similar things) happen.

Again, it’s not perfect: not all situations can be configured as the user intended. If the user attempted to save a situation with a deliberate fault, perhaps with the hydraulic circuit selectors in the wrong position, the plug-in could not possibly cope with that. The hydraulics would always be configured (correctly) for flight.

As with all these things, I hope that my programming skills continue to improve so I can achieve a higher and higher level of realism — or that X-Plane itself broadens the scope of replays and situations to cope with custom datarefs. Until then, this is an effective work-around.


Problems

For some reason, situations have to be loaded twice before the autopilot engages properly. If the aircraft is loaded afresh, sitting on the tarmac, and a situation is loaded, the autopilot refuses to engage at all. If a situation is loaded, then immediately loaded again, the aircraft is stable and behaves normally. I see no logical reason for this yet, but there must be some crucial difference between the aircraft’s state when the situation is loaded the second time. I am investigating …

--
GMM-P (31-07-2014)



blog comments powered by Disqus