Repository: godot
Issue: Relying on `get_process_delta_time()` in `_input` is error prone
Labels: discussion,topic:input

### Godot version

v3.4.stable.official [206ba70f4]

### System information

Ubuntu 18.04

### Issue description

The [documentation recommends](https://docs.godotengine.org/en/stable/getting_started/workflow/best_practices/godot_notifications.html#process-vs-physics-process-vs-input) to avoid handling inputs in `_process` and rather `_input`, and for time-dependent input one should obtain the delta time via [`get_process_delta_time()`](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-process-delta-time).

I've noticed two bugs related to that approach though:
1. The value returned by `get_process_delta_time()` can be uninitialized in the first frame, leading to "big jumps" because it is initialized to 1 sec [here](https://github.com/godotengine/godot/blob/31ded7e126b9d71ed8dddab9ffc1ce813f1a8ec2/scene/main/scene_tree.h#L94). This problem can manifest itself if a user presses e.g. a key slightly before the node becomes ready. The input event will then already be in its input queue, and `_input` will be called without `physics_process_time` having a meaningful value. This will then lead to big/unexpected jumps in the time-dependent input.
2. When frames are dropped it is possible to get multiple calls to `_input` in a single frame, but the delta value obtained from `get_process_delta_time()` doesn't reflect that. Since each call to `_input` will process the event and apply the same delta, we have effectively applied the delta twice in a single frame. This issue depends on the ratio of key repeat rate and frame rate. For instance, under Ubuntu the default key repeat rate is 30 ms. When rendering at solid 60 fps (16.6 ms) the issue shouldn't show up. However if there is a frame drop, the frame delta becomes 33.3 ms, which allows multiple events to be processed in a single frame. Obviously the issue becomes much more pronounced for users that use very low repeat rates. With values below 16.6 ms the issue would be very pronounced.

### Steps to reproduce

I've attached a small demo project that shows the issue. The idea is to rotate a small square with a fixed angular velocity while `<space>` is pressed:

Without frame drops it would look like:

![Peek 2021-12-09 13-21](https://user-images.githubusercontent.com/3620703/145396121-1ad98e53-3d5c-4808-abfb-9c7bf2e8e6c6.gif)

With forced frame drops the behavior turns into:

![Peek 2021-12-09 13-22](https://user-images.githubusercontent.com/3620703/145396226-09cca68e-e6bf-4af4-9f03-ad5f04448232.gif)

<details>

<summary>Code Example</summary>

```gdscript
extends Control

var num_frames := 0
var time := 0.0

func _ready():
    simulate_load(1000)

func _input(event):
    var delta = get_process_delta_time()
    print("_input   @ frame = %d, delta = %s event: %s" % [num_frames, delta, event.as_text()])

    if event.is_pressed() and event.scancode == KEY_SPACE:
        time += delta

func _process(delta):
    print("_process @ frame = %d, delta = %s" % [num_frames, delta])

    # dummy load to simulate frame dropping below 60 fps.
    simulate_load(1000)

    num_frames += 1
    update()

func _draw():
    var x = 100 + 100 * cos(time)
    var y = 100 + 100 * sin(time)
    draw_rect(Rect2(x, y, 10, 10), Color(1, 0, 0))


func simulate_load(n):
    var sum := 0.0
    for _i in n:
        for _j in n:
            sum += 0.1
```

</details>

Issue (1) can be demonstrated by pressing `<space>` while the projects starts. In the output is is visible that the input events registered during loading get processed before any processing happens and with the arbitrary time delta of 1.0 due to its initial value:

```
_input   @ frame = 0, delta = 1 event: Space
_input   @ frame = 0, delta = 1 event: Space
_process @ frame = 0, delta = 0.133334
_process @ frame = 1, delta = 0.133333
_process @ frame = 2, delta = 0.051003
```

### Minimal reproduction project

[InputDeltaIssues.zip](https://github.com/godotengine/godot/files/7684905/InputDeltaIssues.zip)

[Code on GitHub](https://github.com/bluenote10/GodotDebugProjects/tree/master/InputDeltaIssues)