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

Review usage of reactor.seconds() #585

Open
NotAFile opened this issue Apr 14, 2020 · 8 comments
Open

Review usage of reactor.seconds() #585

NotAFile opened this issue Apr 14, 2020 · 8 comments
Labels
refactoring This issue is related to piqueserver's code refactoring

Comments

@NotAFile
Copy link
Member

There's many places in the code where Twisted's reactor.seconds() is used. However, the timestamps returned by that call are only guaranteed to be valid relative to other calls to reactor.seconds().

The following should be done:

  • world_time used for game logic
  • time.monotonic used for durations, such as "280 seconds"
  • time.time used for absolute time, such as a "Tuesday 12pm"
  • reactor.seconds used for times relative to the event loop, such as call_at(time)
@NotAFile NotAFile added the refactoring This issue is related to piqueserver's code refactoring label Apr 14, 2020
@tayloh
Copy link

tayloh commented Feb 24, 2023

Hi,
We're a group from KTH (a university in Sweden) looking to work with an issue in an open source project, and we decided on working with this issue! :) If we manage to do a good job we might submit a PR, otherwise it's just for learning.

Just want to notify you guys,
Thanks

@NotAFile
Copy link
Member Author

Neat, it's been a few years, was wondering if we were still on the list :)

@aoengin
Copy link

aoengin commented Feb 25, 2023

Hi,
I tried to contact @NotAFile via e-mail and matrix but I could not get a response. Is there anyone who can explain why I should use time.time() in place of reactor.seconds()? I examined the doc of twisted and made several tests but I could not find any differences between these two methods therefore I'm not sure if a refactoring for that situation is necessary and where I should use each method.
Thanks in advance.

@NotAFile
Copy link
Member Author

Hi, @aoengin. Sorry, it's the weekend. I am busy with other stuff. I'll get back to you on this on Monday.

@NotAFile
Copy link
Member Author

@aoengin This issue was originally created in regards to another bug, where a change between reactors caused a lot of issues because one used time.time(), while another used time.monotonic()

time.time() represents some amount of seconds since 1970 UTC, while time.monotonic() is guaranteed to increase by one for every second that the computer has been running. This is important, for example, when your computer goes into sleep, your clock changes, or a leap second happens.

World time represents the amount of time the game world has been alive. This is important for example in the instance of lag, as less time might pass in the game world than in the real world.

These numbers should never be mixed. The initial issue showed that these numbers were being mixed in some cases. Hence the goal of this issue was to try to determine if there were any other of these cases.

@tayloh
Copy link

tayloh commented Mar 2, 2023

We would like to create tests in relation to this issue, is that possible? Would you suggest any specific way to go about it?

@NotAFile
Copy link
Member Author

NotAFile commented Mar 2, 2023

There's not really any way to test this, I'm afraid? This is a wide ranging architectural issue, you can't really write tests for that.

@tayloh
Copy link

tayloh commented Mar 2, 2023

I figured that was the case, thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring This issue is related to piqueserver's code refactoring
Projects
None yet
Development

No branches or pull requests

3 participants