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

Understanding Sys::Milliseconds #2991

Open
illwieckz opened this issue May 10, 2024 · 5 comments
Open

Understanding Sys::Milliseconds #2991

illwieckz opened this issue May 10, 2024 · 5 comments
Labels
T-Question for questions on how things works on on how to proceed on an issue

Comments

@illwieckz
Copy link
Member

In src/shared/CommonProxies.cpp we have:

static Sys::SteadyClock::time_point baseTime;
int trap_Milliseconds()
{
	return std::chrono::duration_cast<std::chrono::milliseconds>(Sys::SteadyClock::now() - baseTime).count();
}

In src/common/System.cpp we have:

int Milliseconds() {
#ifdef BUILD_VM
	return trap_Milliseconds();
#else
	static Sys::SteadyClock::time_point baseTime = Sys::SteadyClock::now();
	return std::chrono::duration_cast<std::chrono::milliseconds>(Sys::SteadyClock::now() - baseTime).count();
#endif
}

What is the difference between what is done in engine and what is done in VM?

@illwieckz
Copy link
Member Author

Also: is one of them faster?

@illwieckz illwieckz added the T-Question for questions on how things works on on how to proceed on an issue label May 10, 2024
@illwieckz
Copy link
Member Author

We also have this in src/shared/CommonProxies.cpp:

namespace VM {

    void InitializeProxies(int milliseconds) {
        baseTime = Sys::SteadyClock::now() - std::chrono::milliseconds(milliseconds);
        Cmd::InitializeProxy();
        Cvar::InitializeProxy();
    }

Why is the VM one doing the first Sys::SteadyClock::now() in InitializeProxies?

@illwieckz
Copy link
Member Author

For the engine one I forgot the first Sys::SteadyClock::now() is done when setting a static variable so maybe it's also only done once.

@illwieckz
Copy link
Member Author

As an extra question, why is Milliseconds() so slow?

@slipher
Copy link
Contributor

slipher commented May 11, 2024

What is the difference between what is done in engine and what is done in VM?

The VM clock is initialized to the engine's current time, rather than 0. This is just for fun though, you can't count on them being synchronized.

As an extra question, why is Milliseconds() so slow?

On which platform?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Question for questions on how things works on on how to proceed on an issue
Projects
None yet
Development

No branches or pull requests

2 participants