Codechange: replace _realtime_tick with std::chrono #8747
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
_realtime_tick
is a global variable that counts time, driven by the video-drivers mainloop. In many cases there is no longer a need to do it this way, as we can just usestd::chrono
to get the time any moment we want in our code.Additionally, because we have
std::chrono::seconds
etc, there is less bla about what unit aconst
has, making the code slightly more readable.Description
For the first commit
Pretty straight-forward. I did rework some functions slightly to make them simpler. Mostly, wrapping no longer happens (well, every 250+ years (REAL LIFE YEARS @ldpl , not game years!), so .. yeah .. never), so that code can be removed.
Most noticeable change would be the advertisement; instead of keeping 2 variables for "next", just keep one "last" and check if the duration elapsed.
I tested all timeouts except one.
nc
connect and don't do anything. Works.iptables
drop the TCP traffic after connect. client gets dialog counting up to 15 seconds.netstat -n
that the connection is gone.All works as expected.
For the second commit
Two cases were straight-forward. Double click and hover. Nothing special about it. Tested, works as expected.
The third case was a bit more odd, as it was abusing
_realtime_tick
to now if any draw-ticks happened. This is because every mouse interaction can cause a call toHandleMouseEvents
. Luckily, we already have a counter to check if any call to that function has been done during the draw-tick, so instead of using_realtime_tick
like that, use the variable that was intended for it.To have it slightly more readable, this did mean the function had to be moved up a bit.
For the third commit
Yes,
_realtime_tick
was indebug.h
... seems it was originally meant for debugging :D Super weird ..Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.