Skip to content

Implement set_time_left in Timer node #107920

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeronimo-schreyer
Copy link
Contributor

If new time_left is bigger than wait_time, sets wait_time value

Updates
scene\main\timer.cpp
scene\main\timer.h

@jeronimo-schreyer jeronimo-schreyer requested a review from a team as a code owner June 24, 2025 02:56
@fire fire requested a review from a team June 24, 2025 04:29
@fire fire moved this to Work in progress in Animation Team Issue Triage Jun 24, 2025
@lyuma
Copy link
Contributor

lyuma commented Jun 24, 2025

It does seem like an oversight, since this functionality is already supported in the newer SceneTreeTimer class.

I would suggest to keep the property setter simple, just like SceneTreeTimer. Always set time_left to what is passed in. There can be reasons to override it. Why disallow this?

Until this is merged, users can use SceneTreeTimer which you can make with get_tree().create_timer(), which does support the property setter

@lodetrick
Copy link
Contributor

How different would this be to just calling $Timer.start(time_left)? It seems like they are filling very similar roles. Also, why does it only change the value if the new value is larger instead of just different than the current time_left?

@fire
Copy link
Member

fire commented Jun 24, 2025

My preference is to approve this pull request because in general properties (time_left) should be read and write. I can approve it officially or wait till all github actions tests pass.

@akien-mga akien-mga changed the title Implemented set_time_left in Timer node Implement set_time_left in Timer node Jun 24, 2025
@AThousandShips AThousandShips added this to the 4.x milestone Jun 24, 2025
@KoBeWi
Copy link
Member

KoBeWi commented Jun 24, 2025

Documentation needs update.

@jeronimo-schreyer
Copy link
Contributor Author

jeronimo-schreyer commented Jun 24, 2025

Also, why does it only change the value if the new value is larger instead of just different than the current time_left?

This change aims to keep the node state as clean and consistent as possible. Setting a time_left larger than wait_time will make the current cycle longer than the rest. I think this also works consistently with a timer functionality, where, if you reduce the wait_time, eventually, you'll expect to hit 0 faster than another regular timer, and trigger the timeout signal. And if you make time_left grow eventually you'll hit wait_time, limiting it.
In the case you want to have one cycle bigger than the rest, then you would need to make it explicit, changing wait_time and then back. I think this corner case makes little sense and somewhat confusing

@jeronimo-schreyer
Copy link
Contributor Author

I was wondering this is going to need to change if we can change time_left on a stopped timer as well

bool Timer::is_stopped() const {
	return get_time_left() <= 0;
}

Should we use ?

bool Timer::is_stopped() const {
	return !processing;
}

@jeronimo-schreyer jeronimo-schreyer requested a review from a team as a code owner June 24, 2025 17:07
Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly want to see it perform the same as SceneTreeTimer, but the implementation of is_stopped() is a bit unexpectedly different. I wouldn't mind seeing it changed to return processing if it has mostly the same effect, since it would be easier to reason about.

For example, think about a case where I set a repeating timer to repeat every 0.1 seconds, but I am at less than 10 FPS. In this case, the timer will become negative and stay negative, and is_stopped() will be false, and get_time_left() will lie and say 0 even though the value is negative, yet a timeout event will be fired every frame. It's unclear what should happen but the current feels a bit wrong to me.

Anyway I'm not saying we should fix everything about the timer class at once, just that we should try our best to make its behavior consistent.

@jeronimo-schreyer
Copy link
Contributor Author

I think the last check is telling me to deprecate time_left property and create a new one. Is this correct?

We could change it to seconds_left

@jeronimo-schreyer jeronimo-schreyer force-pushed the timer_set_time_left branch 2 times, most recently from 033180f to ec9e8f8 Compare July 3, 2025 15:46
@jeronimo-schreyer jeronimo-schreyer requested a review from KoBeWi July 3, 2025 16:52
@jeronimo-schreyer jeronimo-schreyer force-pushed the timer_set_time_left branch 3 times, most recently from 20653f2 to c917550 Compare July 4, 2025 02:36
@KoBeWi KoBeWi modified the milestones: 4.x, 4.6 Jul 7, 2025
@jeronimo-schreyer jeronimo-schreyer force-pushed the timer_set_time_left branch 2 times, most recently from 73577dd to 96d8848 Compare July 7, 2025 21:50
@jeronimo-schreyer jeronimo-schreyer force-pushed the timer_set_time_left branch 2 times, most recently from 97deb7f to 7cc0c26 Compare July 8, 2025 13:25
@jeronimo-schreyer
Copy link
Contributor Author

sorry about the PR mess

@jeronimo-schreyer jeronimo-schreyer force-pushed the timer_set_time_left branch 2 times, most recently from 52e7178 to 3562c99 Compare July 9, 2025 08:59
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more accurate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the property while stopped does nothing and prints an error.

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

Successfully merging this pull request may close these issues.

Add time_left property setter in Timer node
7 participants