VisualServer signals question

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GameSpy

Short version: When I try to retrieve the millisecond before a frame is drawn and the msec after it, I get the same result.

According to: https://docs.godotengine.org/en/stable/classes/class_visualserver.html, the frame_pre_draw signal is emitted before a frame is drawn and frame_post_draw is emitted after. I use this code to get the time in milliseconds when the signals are emitted and they both show the same time.

extends Node

var after
var before


func _ready():
	var ret = VisualServer.connect("frame_pre_draw", self, "_pre_draw")
	ret = VisualServer.connect("frame_post_draw", self, "_post_draw")
	
    return ret


func _post_draw():
	after = OS.get_ticks_msec()
	print("after:" + str(after))


func _pre_draw():
	before = OS.get_ticks_msec()
	print("before: " + str(before))

This returns:
before: 2543
after: 2543

Help ? bug ? gone wrong ? To be continued ?
Amerika exbrain

:bust_in_silhouette: Reply From: tuon

To me this doesn’t seem like a bug. If very little is happening between pre and post draw methods, they could very easily happen within the same millisecond. Use the microseconds method instead (get_ticks_usec()) and see what happens.

Impossible. The 3D scene is running at 90 frames per second (on my integrated Intel HD). For this to be correct it would mean that the scene is running at 1000+ frames per second.

While I was experimenting with the engine I also found out that the _process runs before a scene is rendered except if you lock the texture of the viewport for reading. If you use the lock() on the texture.get_data() of the viewport the results are correct (it does show msec after the scene is rendered and drawn) but the frame rate is halved and turns every 60 fps scene into a slide show.

I went back to check your theory and this time I also included the time my _process begins. It is still broken while the lock() method works. My results from the signals method:

_process: 2373
before: 2373
after:2373

GameSpy | 2020-08-11 19:33