Sleep() to refresh the screen - please help test changes

Following on my own use of version 3.7’s BeanShell Sleep() feature (discussed in this thread), I’ve made (I hope) a couple of improvements. They test out satisfactorily on my MacBook and iMac but could do with testing from users on other platforms.

The changes I’ve made are:-

  1. Handling the delay parameter: when less than 1, Vassal will bypass the Java sleep() method. Currently, the sleep() method is always called and a value below zero is set to an arbitrary 500 ms.
    The primary purpose of this change is to ensure that a zero sleep doesn’t itself impose a delay (as discussed on this stackoverflow thread). This change will also affect the delay variants of Alert() and Audit().

  2. @Brent_Easton’s method to allow Sleep() to force a screen refresh involves creating a dummy dialog window at a large offset, intended to be off-screen. However, implementation of the offset is OS-dependant and, sure enough, the window is visible on MacOS, top left of the logical screen area. As such, a small window, as shown, can be seen whilst the sleep is in operation and its appearance can be distracting:
    image
    I’ve found another method setUndecorated(true) that makes the window effectively invisible whilst still forcing a screen refresh, unlike the setVisible method which does affect screen refresh. With this change in place, the window location becomes irrelevant, at least in my testing on Mac.

I would like some help to test the changes especially on Windows and Linux. I can re-introduce the offset method if it turns out to be needed on these other platforms. I am also interested in whether designers perceive any change to the performance of Sleep(0) in the test build compared with Vassal 3.7.15 and any other feedback.

Technical review of the PR on Github is also welcome, especially as I am a Java / Vassal internals novice.

To test, install your machine’s test build from here (SNAPSHOT-6fb758e) and run your module’s use of Sleep() through its paces.

Caution: Do not use a Vassal 3.8 build to edit your module, as you will not be able to open it in the current version afterwards.

Pleased to report that the build of this PR mentioned above has tested successfully in a full game making extensive use of Sleep(0), MacOS vs Windows.

Further trial and feedback encouraged by anyone else who uses Sleep() or delay versions of Audit() or Alert().

I tried out your build in my The Burning Blue module with the functions that takes the longest time. It was difficult to time because much depends on random die rolls, but subjectively, your build takes the same time as the official version.
I also tried a function that has no random die rolls, but on the other hand not so much use of sleep(0). It took 7.5 seconds in both builds, timed with a stopwatch.

I am pleased to note that there is no problem in this build for my module :slight_smile:

1 Like