godot icon indicating copy to clipboard operation
godot copied to clipboard

Timer wait time 0.01 is not enough small

Open Rocket-Buddha opened this issue 9 years ago • 6 comments

Timer wait time 0.01 is not enough small.

Rocket-Buddha avatar Dec 20 '16 01:12 Rocket-Buddha

Pretty sure you can do it less than 0.01s...?

ghost avatar Dec 20 '16 03:12 ghost

What about just doing a call_deferred and/or adding _fixed_process deltas instead?

bojidar-bg avatar Dec 20 '16 07:12 bojidar-bg

I don't understand how call_deferred works.

Rocket-Buddha avatar Dec 20 '16 12:12 Rocket-Buddha

If I understood correctly, 0.01 seconds is less than a frame (aka more than 60 fps), so how do you expect it to work? You can already set the Timer to use _fixed_process but even that would not work because the game doesn't updates fast enough. The only option I see is to set your game's framerate higher, or not using a timer since the timeout will happen before the next frame anyways.

You can do something like this, which is an approximation:

var interval = 0.01
var time = interval

func _fixed_process(delta):
	time -= delta
	# If the interval is smaller than a frame,
	# timeout() can be called more than once per frame (beware of 0 interval though)
	while time < 0:
		time += interval
		timeout()

func timeout():
	# do stuff

Zylann avatar Dec 20 '16 16:12 Zylann

I' am writing a scoreboard discount. As I see it, if I could setup the timer wait time in less than 0.01 I will allowed to update the label text 2 times between frames. I don't care if one this update is never seen. Your code is similar to Timer internal code; I don't want to reinvent the wheel. But your comment let me think, that I need a more efficient solution, thanks.

Rocket-Buddha avatar Dec 22 '16 14:12 Rocket-Buddha

I don't see anything that can be implemented in Godot here, if you need to make operations faster than the game loop, you need to find some tricks which would be game specific (like setting the FPS to 120 and slowing down everything else..). But it mostly sounds like you're trying to implement bad design, if you need to change a label twice per frame, just skip the 1st change and do the 2nd one...

akien-mga avatar Jan 02 '17 12:01 akien-mga