C: C++ timers
Most of you may be familiar with the TICK18 token variable which is incremented at 18Hz. Another option to make use of the 18Hz increment system (like making 0.5 second timers and such) is to call a function from the PANEL_SERVICE_PRE_UPDATE case of your callback function which increments your timing variable which you simply reset to 0 when it is equal to 9 (for a 0.5 second timer).
The following however is an undocumented function in the simulator which returns total time elapsed in seconds with sub-18Hz accuracy.
In your choice of your project's header files, do the following function prototype:
typedef double (__cdecl *fGetSimTime)();
Then in your module_init function:
HMODULE hsimsched = NULL;
fGetSimTime GetSimTime6 = NULL;
void FSAPI module_init(void)
{
GetModuleHandleEx( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, L"simscheduler.dll", &hsimsched);
if(hsimsched)
GetSimTime6 = (fGetSimTime)GetProcAddress(hsimsched, MAKEINTRESOURCEA(6));//Note, for FSX SP2 use 4 instead of 6. Also note that if you wish to distinguish dynamically between sim versions, FSX Acceleration has a offset (function address-hsimsched value) of 0x1530, and SP2 of 0x14D0. FSX SE may vary as builds get released but since FSXA and SP2 aren't likely to change you can check if it is not equal to their offsets and the P3D v2 function isn't located by function name, you can assume FSX SE and use ordinal 6.
}
Now wherever you wish to call this function, include the header where the prototype is contained and add:
extern fGetSimTime GetSimTime6;
To call it and find out how much time has passed:
double time = GetSimTime6();
UPDATE:
The ordinal used by P3D v2.5 is different to that of FSXA. Also, the format is such that the decorated function name is available from the dll. So for P3D v2.5, use the following:
GetSimTime6 = (fGetSimTime)GetProcAddress(hsimsched, "?GetElapsedSimTimeSec@@YGNXZ");