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

Fixes to the Glium example #117

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

dcz-self
Copy link

@dcz-self dcz-self commented Oct 9, 2024

The example had several problems: freezing, wrong window size, and old glium version.

This fixes the problems.

Copy link
Collaborator

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Really happy to see the new glutin and winit being used via a glium update! There are a few design choices we might want to address though, and I don't think the CI will succeed on this yet.

Comment on lines 195 to 227
print!(
"\rms: {}\t (buffer) + {}\t (UI)",
println!(
"ms: {}\t (buffer) + {}\t (UI)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think \r without ln was here to continuously overwrite the same line.

Copy link
Author

Choose a reason for hiding this comment

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

Oops, I forgot about this. I found it a lot more useful for debugging to print every frame on its own line, though.

event_loop
.run(move |event, elwt| {
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) {
(self.user_event)(event)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason to not inline the original run code directly here?

Copy link
Author

Choose a reason for hiding this comment

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

The closure captures the environment. The struct would have to turn every captured variable into a field, so I just took the easiest path.
Should I turn it into a struct?

Comment on lines +159 to 161
let _ = event_loop_proxy.send_event(UserEvent::WakeUp);
tx.send(data).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we send data though the proxy instead of needing a separate channel?

Copy link
Author

Choose a reason for hiding this comment

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

Kinda, but I think that would make control flow even more complicated. Not every buffer will result in a rendered frame, some buffers will be dropped. Waking up on every buffer from a stream where we can't skip events means that every buffer will have to render, even if there's another one enqueued.
(I'll add the frame skipping next.)


event_loop
.run(move |event, elwt| {
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that if you know a value can only have one variant, you can pattern-match on it in the function signature:

Suggested change
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) {
fn user_event(&mut self, event_loop: &ActiveEventLoop, UserEvent::WakeUp: UserEvent) {

This even works to unpack a tuple or struct field if you pass data as part of UserEvent. Then, since there's only one event, you can also change enum to struct.

Copy link
Author

Choose a reason for hiding this comment

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

I think using the signature as the trait defines it is more readable.
About keeping this as an enum, I think most real-world applications are going to have some form of an enum, so this should make it easier to integrate.

I'm willing to change both if it's required for merging, though.

}

event_loop.run_app(&mut LoopHandler {
user_event: move |_event| {
let t0 = Instant::now();
let data = rx.recv().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Glad to see that this blocking code now only runs on fn user_event(), rather than on every event that used to be delivered in the past!

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Oct 9, 2024

wrong window size

Fwiw I'd argue that this won't fly on tiling window managers, where the size of the window cannot be dictated by the input source (unless the window is made floating). Here the easiest to expect is scaling/stretching?

@dcz-self
Copy link
Author

dcz-self commented Oct 9, 2024

wrong window size
Fwiw I'd argue that this won't fly on tiling window managers, where the size of the window cannot be dictated by the input source (unless the window is made floating). Here the easiest to expect is scaling/stretching?

If a window manager wants to use a different size, then setting the size hint isn't going to stop it. Meanwhile, window managers respecting the size will have the right size.

The right solution for wrong size would be letterboxing, but I'm not ready to tackle that in this moment.

@dcz-self
Copy link
Author

dcz-self commented Oct 9, 2024

I added frame skipping here. Tested by adding an artificial delay in the rendering code and observing that frame latencies don't keep growing forever.

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.

2 participants