I’m addressing this question directly to @MobiFlight. I choose not to post it in the MobiFlight forum, because it is rather a generic WASM/SimConnect question.
As a learning experience, I am analyzing the source code of the MobiFlight WASM module, to understand its internal workings. Not sure if I’m dealing with the latest version, but I found it here.
I see that in “module_init” the WASM module registers for EVENT_FRAME.
hr = SimConnect_SubscribeToSystemEvent(g_hSimConnect, EVENT_FRAME, "Frame");
In the MyDispatchProc, this event is captured to call “ReadSimVars()”. As far as I understand, this is happening every frame.
case SIMCONNECT_RECV_ID_EVENT_FRAME: {
SIMCONNECT_RECV_EVENT* evt = (SIMCONNECT_RECV_EVENT*)pData;
int eventID = evt->uEventID;
ReadSimVars();
break;
}
“ReadSimVars()” is then itterating through each SimVar and reads its value using “execute_calculator_code”.
// Read a single SimVar and send the current value to SimConnect Clients
void ReadSimVar(SimVar &simVar) {
FLOAT64 val = 0;
execute_calculator_code(std::string(simVar.Name).c_str(), &val, NULL, NULL);
if (simVar.Value == val) return;
simVar.Value = val;
WriteSimVar(simVar);
#if _DEBUG
fprintf(stderr, "MobiFlight: SimVar %s with ID %u has value %f", simVar.Name.c_str(), simVar.ID, simVar.Value);
#endif
}
// Read all dynamically registered SimVars
void ReadSimVars() {
for (auto& value : SimVars) {
ReadSimVar(value);
}
}
Now my question: Isn’t that very inefficient, reading all LVars every frame? Isn’t there a way to use a call similar to RequestDataOnSimObject using a flag SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, and then trigger the client that something changed? Or is that the only way to deal with these LVars?