This site is being deprecated.

Please see the official X‑Plane Support page for help.

0 votes
asked by (12 points)

Hello! So I have built a plugin in C++ in Ubuntu 19.04, which changes weather after a user-defined delay of some seconds. Problem is when the delay part of the code executes, the XPlane freezes and once the delay is over, XPlane resumes back to normal. I want to change the weather while I am in the air and this would be an inconvenience. So below these are the delay methods I have used and I have not gotten any luck so far:

void sleep(int duration){
    clock_t start_time = clock();
    time_t before = time(0);
    while (difftime(time(0), before) < duration);
}

void sleep(int duration){
    std::this_thread::sleep_for(std::chrono::seconds(duration));
}
Thanks for the help!

1 Answer

0 votes
answered by (5.3k points)

Hi K.C.Manson,

I am not from Laminar Research just a flight simmer from down under unable to answer your problem.

However, I interpret your issue as a development problem rather than a user problem.  I suggest you raise your problem with the LR development team starting with the general email address at [email protected]  I am sure the receiver of your issue will forward to the development team.

Good luck

Glenn  

commented by (12 points)
Hey Glenn! Thank you so much for the answer. I feel that whatever environment provided to the plugin should be in a separate thread, but it seems it's in the same thread which is running the UI and that's why this problem occurs. I solved it using an unusual approach. The XPlane detects key shortcuts, and the plugin can be designed to detect key shortcuts. I made a simple python server which sends keystrokes to the XPlane, whenever the delay I want is completed. The plugin sends an int to python server over local socket and python waits for the delay to complete and then it sends the key shortcut after the delay is finished. In that way, the python code is acting as a callback to XPlane but in a weird way. But that works. I hope someone finds it useful. If someone has a better way, please let me know. Thank you.
commented by (5.3k points)
Glad to know you are up and flying.

Glenn
...