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

Make UiThreadRenderTimer to calculate the next tick time based on expected FPS #17121

Merged
merged 2 commits into from
Sep 29, 2024

Conversation

kekekeks
Copy link
Member

DispatcherTimer.Interval indicates the interval between the previous tick completion and the next one. Render timer, on the other hand, needs to have its interval to indicate time between tick starts.

@kekekeks kekekeks force-pushed the feature/self-adjusting-ui-render-timer branch from 98e46a5 to dcaceb1 Compare September 25, 2024 15:42
return !cancelled;
}, TimeSpan.FromSeconds(1.0 / FramesPerSecond), DispatcherPriority.UiThreadRender);
return Disposable.Create(() => cancelled = true);
_tick?.Invoke(tickedAt);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: _tick is never null, ? can be removed.

}

private static readonly TimeSpan s_minInterval = TimeSpan.FromMilliseconds(1);
private TimeSpan Interval => TimeSpan.FromSeconds(1.0 / _parent.FramesPerSecond);
Copy link
Member

Choose a reason for hiding this comment

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

Since FramesPerSecond can't change, the frame interval can probably be computed only once in the constructor.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0052138-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@kekekeks kekekeks added enhancement backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Sep 25, 2024
@robloo
Copy link
Contributor

robloo commented Sep 26, 2024

UiThreadRenderTimer doesn't follow .NET or Avalonia naming conventions and should be fixed -- probably in 12.0.

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:
IOStream

https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions#capitalization-rules-for-identifiers

Dispatcher.UIThread is the existing Avalonia convention as well.

@maxkatz6
Copy link
Member

UiThreadRenderTimer is a private api, which can't be used directly without enablding private api access.
We can rename it at any point.

@robloo
Copy link
Contributor

robloo commented Sep 27, 2024

@maxkatz6 OK, I did notice the PrivateApi attribute was removed here as well.

@maxkatz6
Copy link
Member

@robloo oh, you are right, it was. Still not a breaking change, but it was likely unintentional, cc @kekekeks.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0052217-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Sep 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 29, 2024
@MrJul MrJul added this pull request to the merge queue Sep 29, 2024
Merged via the queue into master with commit 8742dbd Sep 29, 2024
11 checks passed
@MrJul MrJul deleted the feature/self-adjusting-ui-render-timer branch September 29, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants