Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a delta value that isn't influenced by Engine.TimeScale #8027

Closed
InkPhoenix opened this issue Oct 8, 2023 · 3 comments
Closed

Add a delta value that isn't influenced by Engine.TimeScale #8027

InkPhoenix opened this issue Oct 8, 2023 · 3 comments

Comments

@InkPhoenix
Copy link

Describe the project you are working on

3D Racing game

Describe the problem or limitation you are having in your project

Currently there only exists the delta value to get frame times, which is influenced by Engine.TimeScale. This is bad for things like framerate counters, which require accurate frametimes no matter the time scale.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Having an additional delta value ("Engine.unscaled_delta" for example) that isn't influenced by Engine.TimeScale would help framerate counters to maintain accuracy while manipulating time scale.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Engine.unscaled_delta could just be calculated as Engine.unscaled_delta = delta / Engine.TimeScale.

e.g:
Engine.TimeScale = 1.0 | delta = 0.061551 | Engine.unscaled_delta = 0.061551 / 1 = 0.061551
Engine.TimeScale = 0.5 | delta = 0.0307755 | Engine.unscaled_delta = 0.0307755 / 0.5 = 0.061551
Engine.TimeScale = 1.5 | delta = 0.0923265 | Engine.unscaled_delta = 0.0923265 / 1.5 = 0.061551

0.061551 in this example, is the frametime (delta) as it would be if timescale was set to 1 (normal speed), and as can be seen in this example the output is always as if timescale was set to nomal speed.

Alternatively, for better performance, Engine.unscaled_delta would ideally be cached before Engine.TimeScale changes delta's value, for better performance, although i'm not very familiar with how delta is calculated so i'm not completely sure how feasible this caching alternative would be to implement.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Like i demonstrated, this unscaled delta value can already be calculated with just delta and Engine.TimeScale. However having a proper value for this ("Engine.unscaled_delta" or example) would make for cleaner code, as well as make it easier for former Unity developers migrating to Godot (as Unity already contains this value in the form of "Time.unscaledDeltaTime").

Is there a reason why this should be core and not an add-on in the asset library?

It's a simple addition that leads to simpler code.

@AThousandShips
Copy link
Member

This is available internally as get_process_step, could easily be exposed

@Calinou
Copy link
Member

Calinou commented Oct 8, 2023

Thanks for the proposal! Consolidating in #7775.

This is bad for things like framerate counters, which require accurate frametimes no matter the time scale.

To create a custom FPS counter, use the difference between OS.get_ticks_usec() between the current frame and previous frame (stored in a member variable) instead.

@InkPhoenix
Copy link
Author

To create a custom FPS counter, use the difference between OS.get_ticks_usec() between the current frame and previous frame (stored in a member variable) instead.

Thanks, i couldn't find that function under OS, but i did find it under Time

https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-ticks-usec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants