Stellarium / stellarium

Stellarium is a free GPL software which renders realistic skies in real time with OpenGL. It is available for Linux/Unix, Windows and macOS. With Stellarium, you really see what you can see with your eyes, binoculars or a small telescope.
https://stellarium.org
GNU General Public License v2.0
7.65k stars 818 forks source link

SCRIPTING: setObserverLocation REQUIRES core.wait #3821

Open roohif opened 2 months ago

roohif commented 2 months ago

I am using Stellarium to extract data in a "batch" fashion, if you know what I mean. So I am changing location, and then grabbinhg some attributes for the Sun/Moon, and then changing location again.

For example:

core.setObserverLocation("Sydney, Australia", 0)
var thisMoonAlt = core.getObjectInfo("Moon")["altitude"]

core.setObserverLocation("Perth, Australia", 0)
var thatMoonAlt = core.getObjectInfo("Moon")["altitude"]

What I'm seeing a lot is thisMoonAlt == thatMoonAlt. It's like Stellarium hasn't yet processed the move of the observer, and is giving me the old value. I've seen a lot of code online that says I need to add core.wait() to give it time to catch up, but I guess I was hoping that there was some way to force it to block until the location has been processed .. ?

gzotti commented 2 months ago

No, that lot of code online and in our own documentation does what we recommend for such cases. Add a core.wait(0.1) or so to give it time to catch up, i.e., allow one frame drawing cycle, else you are updating the location without actually computing anything. If there was an alternative, it would have been documented.

10110111 commented 2 months ago

Would it be possible to emit some kind of signal like frameStarted for the JS code to connect to?

gzotti commented 2 months ago

You mean, adding core.wait(SignalName) instead of just waiting a short time? Maybe. This might be helpful to minimize the waiting delay. Such signal could be emitted after all computations are done and drawing begins. However, some computations are done during drawing, so maybe rather add and connect to a signal 'nextFrameComplete' (hard to foresee intermixed frame counters?) or use a counter initialized with 2 and counting down, to compute&draw 2 frames before returning the numbers. The core.wait(smallDelay) is a solution that at least works now and has worked since 2012 or so. Feel free to optimize! I think some command to be given manually to yield processing to the main loop is unavoidable.

github-actions[bot] commented 1 month ago

Hello @roohif!

Thank you for suggesting this enhancement.