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

[no squash] porting.h maintenance #14095

Merged
merged 2 commits into from Dec 15, 2023
Merged

[no squash] porting.h maintenance #14095

merged 2 commits into from Dec 15, 2023

Conversation

sfan5
Copy link
Member

@sfan5 sfan5 commented Dec 12, 2023

To do

This PR is Ready for Review.

How to test

no need really

@sfan5 sfan5 added Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements Bugfix 🐛 PRs that fix a bug labels Dec 12, 2023
- correctly use value of _POSIX_MONOTONIC_CLOCK
- drop special path for macOS: it supports clock_gettime since macOS 10.12
@srifqi
Copy link
Member

srifqi commented Dec 12, 2023

Using self-compiled MinGW build on Windows 10,

fps_max master This PR
30 FPS 30±1 FPS 30±1 FPS
60 FPS 61±1 FPS 58±1 FPS
120 FPS 122±1 FPS 115±1 FPS
240 FPS 244±2 FPS 220±1 FPS
(trend) (higher) (lower)

In some cases, the Minetest's FPS counter is lower (by around 1 FPS) than the Xbox Game Bar's FPS info using this PR version.

@sfan5
Copy link
Member Author

sfan5 commented Dec 12, 2023

Hm.
I can reproduce that it undershoots the target FPS in wine (if I trust our FPS counter), this would point towards a bug in the timer code.

@sfan5
Copy link
Member Author

sfan5 commented Dec 12, 2023

Some debugging code to add to myusleep:

	auto start = getTimeUs();
	WaitForSingleObject(timer, INFINITE);
	auto end = getTimeUs();

	if (fabs(fabs(end-start) - usecs) > 100) {
		char buf[100];
		snprintf(buf, 100, "wanted to sleep %dus actually %dus", (int)usecs, (int)fabs(end-start));
		actionstream << buf << std::endl;
	}
	CloseHandle(timer);

I sometimes see it sleeping up to double the requested time for small amounts like 1000.
Inserting similar code into the Linux code path it never triggers for me.

It's weird because CreateWaitableTimerExW + CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is supposed to be more accurate way to sleep on win32.

@sfan5
Copy link
Member Author

sfan5 commented Dec 13, 2023

Well I've run out of things to try so I'll convert this PR to only the maintenance changes.

@sfan5 sfan5 removed the Bugfix 🐛 PRs that fix a bug label Dec 13, 2023
@sfan5 sfan5 changed the title [no squash] Fix the FPS limiter on Windows (and other minor stuff) [no squash] porting.h maintenance Dec 13, 2023
@sfan5 sfan5 added the Trivial The change is a trivial bug fix, documentation or maintenance change, as per the Git Guidelines label Dec 13, 2023
Copy link
Member

@srifqi srifqi left a comment

Choose a reason for hiding this comment

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

The code looks good to me. I can not test on other than Windows, though.

@sfan5 sfan5 merged commit bd06466 into minetest:master Dec 15, 2023
13 checks passed
@sfan5 sfan5 deleted the timer branch December 15, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements Trivial The change is a trivial bug fix, documentation or maintenance change, as per the Git Guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants