tophat2d / tophat

:tophat: a 2d game library for Umka
https://tophat2d.dev
BSD 3-Clause "New" or "Revised" License
72 stars 5 forks source link

`th.delta` may sometimes be zero #67

Closed vtereshkov closed 2 years ago

vtereshkov commented 2 years ago

Problem occurs on Windows, but not on Linux.

image

vtereshkov commented 2 years ago

A possible cause of this issue is a different behavior of th.delta: On Linux:

2 
2 
4 
2 
2 
1 
2 
2 
2 
4 
1 
2 
1 
1 
1 
1 

On Windows:

1
0
0
0
0
0
8
0
0
0
5
0
4
2
0
0
0

It seems that the th.deltas are the same on average, but not instantly, due to the implementation of the system timer.

Having th.delta == 0 is not very good for many reasons (for example, one may want a numeric derivative like vel = (pos - prevPos) / th.delta).

Can we limit the frame rate in a tophat-based game? It could solve this issue (and also reduce the CPU load if rendering is done in a separate thread).

vtereshkov commented 2 years ago

My "quick and dirty" solution is twofold:

UPD: Not sure step 2 really has any effect.

marekmaskarinec commented 2 years ago

I could try detecting when player is stuck, but that is not the issue here.

I will try adding vsync to tophat and enable it by default.

vtereshkov commented 2 years ago

After some experimenting, I got this working on Windows. Not sure it's the best solution.

player.um.txt

(+ a delay for non-zero th.delta)

marekmaskarinec commented 2 years ago

@vtereshkov does this still happen to you with the frame limiter?

vtereshkov commented 2 years ago

I didn't see zero th.delta anymore. However, the player may still get stuck in the blocks (though quite rarely).