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:-
-
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(). -
@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:
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.