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

chore: Extract window_wrapper and the update loop to their own modules #1939

Merged

Conversation

fredizzimo
Copy link
Member

What kind of change does this PR introduce?

  • Refactor

This splits the window/mod.rs into update_loop and window_wrapper. The opengl window creation has also been split into two functions, the actual window creation and the context creation.

This will make it easier to review the render loop changes in #1870, and to allow some platforms to run in a thread while other platforms don't.

Did this PR introduce a breaking change?

  • No, functionally there are no changes.

window.outer_position().ok(),
);

std::process::exit(RUNNING_TRACKER.exit_code());
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's best to handle the exit directly here. Possibly it could be worth bubbling it up instead, returning ControlFlow::ExitWithCode instead.

Suggested change
std::process::exit(RUNNING_TRACKER.exit_code());
return ControlFlow::ExitWithCode(RUNNING_TRACKER.exit_code());

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably yes, but this code is copied from the original code, and I'm not going to change any logic during this refactoring.

Comment on lines 101 to 104
let expected_frame_length_seconds = 0.0 / refresh_rate;
let frame_duration = Duration::from_secs_f32(expected_frame_length_seconds);

if frame_start - self.previous_frame_start > frame_duration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the division of 0 intended? Because then frame_duration is empty, causing the if clause to be always entered. Possibly you meant 1.0 instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's supposed to be 1.0. I don't know how 0.0 has ended up here, since I think I copied the code from mod.rs, and it's supposed to be exactly the same. I must somehow have typed something by mistake.

I will fix that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

if let FocusedState::UnfocusedNotDrawn = self.focused {
self.focused = FocusedState::Unfocused;
}
self.previous_frame_start = frame_start;
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is entered as soon as the frame is over, then I suppose it's (from the relative perspective of the next frame) more or less when the previous frame ended/the current frame started. Which would also make more sense for the deadline logic, if it was to look at the start of the last frame in order to get the deadline of the current frame, it'd need to add the expected frame duration twice (but it only does it once).

It's a clash between semantics and naming, I believe.

Copy link
Member Author

Choose a reason for hiding this comment

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

The naming is copied from the original code. current_frame_start would perhaps make more sense, but then there's the variable frame_start, which does not make much sense at all, since the loop can be run multiple times until a frame is finally drawn. But I guess that previous_frame_start was chosen to differentiate from that.

But generally, the calculations here are flawed, and that's one of the reasons the smooth rendering branch improves things.

@fredizzimo fredizzimo force-pushed the fsundvik/split-window-wrapper branch from a077e4b to b17fa15 Compare July 24, 2023 11:54
@MultisampledNight MultisampledNight merged commit 39af18d into neovide:main Jul 24, 2023
2 checks passed
@MultisampledNight
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants