Add a warning for Timer nodes with very low wait times

Very low wait times behave in unpredictable ways depending on the
rendered frame rate. This is because the timeout signal is only emitted
once per rendered frame (or physics frame, depending on the timer's
process mode).
This commit is contained in:
Hugo Locurcio 2021-10-09 08:57:48 +02:00
parent 6f72d9d19f
commit 42d13e29e2
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
3 changed files with 15 additions and 1 deletions

View file

@ -82,6 +82,7 @@ void Timer::_notification(int p_what) {
void Timer::set_wait_time(double p_time) {
ERR_FAIL_COND_MSG(p_time <= 0, "Time should be greater than zero.");
wait_time = p_time;
update_configuration_warnings();
}
double Timer::get_wait_time() const {
@ -179,6 +180,16 @@ void Timer::_set_process(bool p_process, bool p_force) {
processing = p_process;
}
TypedArray<String> Timer::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();
if (wait_time < 0.05 - CMP_EPSILON) {
warnings.push_back(TTR("Very low timer wait times (< 0.05 seconds) may behave in significantly different ways depending on the rendered or physics frame rate.\nConsider using a script's process loop instead of relying on a Timer for very low wait times."));
}
return warnings;
}
void Timer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_wait_time", "time_sec"), &Timer::set_wait_time);
ClassDB::bind_method(D_METHOD("get_wait_time"), &Timer::get_wait_time);