Difference between revisions of "Measuring Time to Display Menus"

Added lower bound; minor script clean-up
imported>Khalim19
(→‎Notes: clarification)
imported>Khalim19
(Added lower bound; minor script clean-up)
Line 16: Line 16:
*The time measured is displayed in seconds with precision up to three decimal places. The number of decimal places is restricted by the [[GetUserTime]] function - the "Millisecond" array element returned by the function can only be an integer ranging from 0 to 999.
*The time measured is displayed in seconds with precision up to three decimal places. The number of decimal places is restricted by the [[GetUserTime]] function - the "Millisecond" array element returned by the function can only be an integer ranging from 0 to 999.
*The script runs every frame in order to get the most precise results.
*The script runs every frame in order to get the most precise results.
*The script does not display time below a specified threshold (in seconds). By default the threshold is 0.2 seconds.


==The Script==
==The Script==
Line 39: Line 40:


float timePassed
float timePassed
float timePassedLowerBound  ; time below this threshold will not be displayed


int previousMenuMode
int previousMenuMode
int currentMenuMode
int currentMenuMode
short isNewMenu
short isNewMenu
short isMenuMode ; 0 = GameMode, 1 = MenuMode
short isMenuMode             ; 0 = GameMode, 1 = MenuMode


short runOpenMenuOnce
short runOpenMenuOnce
short initPreviousUserTimeOnce
short initOnce


Begin GameMode
Begin GameMode
set fQuestDelayTime to 0.01
set fQuestDelayTime to 0.01
let previousUserTime := GetUserTime
if (initPreviousUserTimeOnce == 0)
if (initOnce == 0)
; The previousUserTime array is initialized and assigned values below.
set initOnce to 1
set initPreviousUserTimeOnce to 1
set timePassedLowerBound to 0.2
endif
endif
 
if isMenuMode
if isMenuMode
set isMenuMode to 0
set isMenuMode to 0
endif
endif
if runOpenMenuOnce
let previousUserTime := GetUserTime
if (runOpenMenuOnce == 1)
set runOpenMenuOnce to 0
set runOpenMenuOnce to 0
endif
endif
Line 95: Line 97:
set runOpenMenuOnce to 1
set runOpenMenuOnce to 1
; Initialize the previousUserTime array in case the GameMode portion of the
if (initOnce == 0)
; script hasn't kicked in yet (where this array is initialized and assigned values).
set initOnce to 1
if (initPreviousUserTimeOnce == 0)
; Initialize the previousUserTime array in case the GameMode portion of the
set initPreviousUserTimeOnce to 1
; script hasn't kicked in yet (where this array is initialized and assigned values).
let previousUserTime := GetUserTime
let previousUserTime := GetUserTime
set timePassedLowerBound to 0.2
endif
endif
Line 128: Line 131:
let timePassed := currentTime - previousTime + ((currentMilliseconds - previousMilliseconds) / 1000)
let timePassed := currentTime - previousTime + ((currentMilliseconds - previousMilliseconds) / 1000)
 
printc "Menu %g", currentMenuMode
if timePassed >= timePassedLowerBound
printc "Time passed: %.3f", timePassed
printc "Menu %g", currentMenuMode
End
printc "Time passed: %.3f", timePassed
</pre>
endif
End</pre>


==Issues==
==Issues==
Line 142: Line 146:
Ignoring the HUD main menu is not a solution, because if player opens the inventory menu and the mouse cursor points outside the inventory menu, the HUD main menu will be active first. The entire time the mouse is positioned over the HUD main menu would add to the time measured, causing it to be incorrect.
Ignoring the HUD main menu is not a solution, because if player opens the inventory menu and the mouse cursor points outside the inventory menu, the HUD main menu will be active first. The entire time the mouse is positioned over the HUD main menu would add to the time measured, causing it to be incorrect.


If you didn't understand from the description what the issue is, it should be clearer once you use the script in game and watch the console output. You may want to toggle debug text on by typing "tdt" in the console so that the output is displayed even if the console is not active.
If you didn't understand from the description what the issue is, it should be clearer once you change the timePassedLowerBound variable to 0, use the script in game and watch the console output. You may want to toggle debug text on by typing "tdt" in the console so that the output is displayed even if the console is not active.


This issue occurs in any menu.
This issue occurs in any menu. Thankfully, the 0.2 second threshold filters most of the "bogus" time measures.


[[Category: Useful Code]]
[[Category: Useful Code]]
Anonymous user