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

Automatically close game when Window close signal is sent #420

Merged
merged 2 commits into from Oct 18, 2017

Conversation

@Xaeroxe
Member

Xaeroxe commented Oct 17, 2017

Slight ergonomics improvement, helps the engine behave in a more obvious manner.

@jojolepro
  1. You could remove the "leave on Escape"
    but
  2. You would lose the only examples where you use a key event from a state.

So its fine like that for me.

@torkleyy

I'm not sure if it's a good thing. Sometimes more explicitness and less magic is better.

src/app.rs
@@ -174,6 +174,9 @@ impl<'a, 'b> Application<'a, 'b> {
};
for event in events {
+ if let &Event::WindowEvent { event: WindowEvent::Closed, .. } = &event {

This comment has been minimized.

@torkleyy

torkleyy Oct 17, 2017

Member

So how could the state handle a window close event now?

@torkleyy

torkleyy Oct 17, 2017

Member

So how could the state handle a window close event now?

This comment has been minimized.

@Xaeroxe

Xaeroxe Oct 17, 2017

Member

I could rearrange this so that the state receives this. It just seems odd for our game window to by default not respond to a close event. It confused me for a second when it happened so I'm sure it'd confuse someone not familiar with the engine.

Also it's worth noting that if you want this to be handled properly at all times you have to duplicate the close code for every state your game goes through. Most of our examples have just one state so this isn't as apparent.

@Xaeroxe

Xaeroxe Oct 17, 2017

Member

I could rearrange this so that the state receives this. It just seems odd for our game window to by default not respond to a close event. It confused me for a second when it happened so I'm sure it'd confuse someone not familiar with the engine.

Also it's worth noting that if you want this to be handled properly at all times you have to duplicate the close code for every state your game goes through. Most of our examples have just one state so this isn't as apparent.

This comment has been minimized.

@torkleyy

torkleyy Oct 17, 2017

Member

I see it makes sense, but at least giving the game a notification would be great. Maybe also just call a method which is always when states are stopped? Not sure if we have that already.

@torkleyy

torkleyy Oct 17, 2017

Member

I see it makes sense, but at least giving the game a notification would be great. Maybe also just call a method which is always when states are stopped? Not sure if we have that already.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
Member

Xaeroxe commented Oct 17, 2017

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

This removes the ability to have multiple windows. Might not be used a lot but it is possible to do.

Member

Rhuagh commented Oct 17, 2017

This removes the ability to have multiple windows. Might not be used a lot but it is possible to do.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

Huh, does our renderer even support that? An overwhelming volume of the code I've been writing assumes single window. How would we even go about telling just one window to close?

Member

Xaeroxe commented Oct 17, 2017

Huh, does our renderer even support that? An overwhelming volume of the code I've been writing assumes single window. How would we even go about telling just one window to close?

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

I realize we don't have full support for that yet, but the renderer support it

Member

Rhuagh commented Oct 17, 2017

I realize we don't have full support for that yet, but the renderer support it

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

Can we keep the simple solution for now then and address that shortcoming in a larger "multi-window" PR then? As it stands I'm not even sure how I'm supposed to close just one window

Member

Xaeroxe commented Oct 17, 2017

Can we keep the simple solution for now then and address that shortcoming in a larger "multi-window" PR then? As it stands I'm not even sure how I'm supposed to close just one window

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

There's WindowId in winit but yeah, we can do that in a future PR.

Member

Rhuagh commented Oct 17, 2017

There's WindowId in winit but yeah, we can do that in a future PR.

@Rhuagh

Rhuagh approved these changes Oct 17, 2017

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

I just thought of a second issue, what if the user wants to perform some action on exit? Save data to disc or whatnot?

Member

Rhuagh commented Oct 17, 2017

I just thought of a second issue, what if the user wants to perform some action on exit? Save data to disc or whatnot?

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

@Rhuagh Then they can use the Window::Closed event they receive just before shutdown.

Member

Xaeroxe commented Oct 17, 2017

@Rhuagh Then they can use the Window::Closed event they receive just before shutdown.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

Ah, it still pushes it to the state. Ok then.

Member

Rhuagh commented Oct 17, 2017

Ah, it still pushes it to the state. Ok then.

@omni-viral

Then they can use the Window::Closed event

But this event is Window::Closed and not Engine::Shutdown.
Explicit is better then implicit.
I'm for keeping manual shutdown.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

@omni-viral From an earlier conversation with @torkleyy

I could rearrange this so that the state receives this. It just seems odd for our game window to by default not respond to a close event. It confused me for a second when it happened so I'm sure it'd confuse someone not familiar with the engine.
Also it's worth noting that if you want this to be handled properly at all times you have to duplicate the close code for every state your game goes through. Most of our examples have just one state so this isn't as apparent.

In addition to this all of the states' on_stop function will be called.

If it absolutely must be called Engine::Shutdown I can do that but it would require a whole new event hierarchy to go along with it.

Member

Xaeroxe commented Oct 17, 2017

@omni-viral From an earlier conversation with @torkleyy

I could rearrange this so that the state receives this. It just seems odd for our game window to by default not respond to a close event. It confused me for a second when it happened so I'm sure it'd confuse someone not familiar with the engine.
Also it's worth noting that if you want this to be handled properly at all times you have to duplicate the close code for every state your game goes through. Most of our examples have just one state so this isn't as apparent.

In addition to this all of the states' on_stop function will be called.

If it absolutely must be called Engine::Shutdown I can do that but it would require a whole new event hierarchy to go along with it.

@omni-viral

This comment has been minimized.

Show comment
Hide comment
@omni-viral

omni-viral Oct 17, 2017

Member

@Xaeroxe I just don't like implicit stuff. Also it limits user to do something after window closes (including continue working with other windows left and nontrivial saving that will require more then few milliseconds)

Member

omni-viral commented Oct 17, 2017

@Xaeroxe I just don't like implicit stuff. Also it limits user to do something after window closes (including continue working with other windows left and nontrivial saving that will require more then few milliseconds)

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 17, 2017

Collaborator

On application creation, just have a setting "QuitOnWindowClosed=bool"
At the same place where you specify resolution and window name.

Collaborator

jojolepro commented Oct 17, 2017

On application creation, just have a setting "QuitOnWindowClosed=bool"
At the same place where you specify resolution and window name.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

Not closing when asked is verging on malware-like behavior. I don't feel making this implicit isn't that unreasonable. The game won't close until all states are finished shutting down anyways.

Member

Xaeroxe commented Oct 17, 2017

Not closing when asked is verging on malware-like behavior. I don't feel making this implicit isn't that unreasonable. The game won't close until all states are finished shutting down anyways.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

I'd also like bring emphasis to this part once again: you have to duplicate the close code for every state your game goes through under our current setup.

Member

Xaeroxe commented Oct 17, 2017

I'd also like bring emphasis to this part once again: you have to duplicate the close code for every state your game goes through under our current setup.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

On application creation, just have a setting "QuitOnWindowClosed=bool"
At the same place where you specify resolution and window name.

I like this idea, so I'll implement it.

Member

Xaeroxe commented Oct 17, 2017

On application creation, just have a setting "QuitOnWindowClosed=bool"
At the same place where you specify resolution and window name.

I like this idea, so I'll implement it.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 17, 2017

Member

🎉

Member

Rhuagh commented Oct 17, 2017

🎉

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
Member

Xaeroxe commented Oct 17, 2017

@jojolepro

Could that be in the configs instead?

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 17, 2017

Collaborator

https://github.com/amethyst/amethyst/blob/develop/examples/04_pong/resources/display.ron
Since its related to the rendering/windowing system, it would make more sense if it was an optional value in there.

Collaborator

jojolepro commented Oct 17, 2017

https://github.com/amethyst/amethyst/blob/develop/examples/04_pong/resources/display.ron
Since its related to the rendering/windowing system, it would make more sense if it was an optional value in there.

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

@jojolepro Having that in configs exposed to the user doesn't quite seem right either. This should be set by the developer.

Member

Xaeroxe commented Oct 17, 2017

@jojolepro Having that in configs exposed to the user doesn't quite seem right either. This should be set by the developer.

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 17, 2017

Collaborator

optionally?
I think its possible to have default values with serde in a struct that gets deserialized?

Collaborator

jojolepro commented Oct 17, 2017

optionally?
I think its possible to have default values with serde in a struct that gets deserialized?

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Oct 17, 2017

Member

When you save a new config it will still write the default value.

Member

Xaeroxe commented Oct 17, 2017

When you save a new config it will still write the default value.

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 17, 2017

Collaborator

Ah true, you win! 🎉

Collaborator

jojolepro commented Oct 17, 2017

Ah true, you win! 🎉

@Rhuagh

Rhuagh approved these changes Oct 17, 2017

@Xaeroxe Xaeroxe requested a review from omni-viral Oct 17, 2017

@omni-viral

This comment has been minimized.

Show comment
Hide comment
@omni-viral

omni-viral Oct 18, 2017

Member

@Xaeroxe you can make field to be skipped during serialization if it's equal to default.
There is a ton of programs that don't even close window when X pressed. Most of them ask about saving modifications. Others just hide.
But amethyst is primarily for games and they usually quit when window is closed. Therefore I approve this as you've made it optional

Member

omni-viral commented Oct 18, 2017

@Xaeroxe you can make field to be skipped during serialization if it's equal to default.
There is a ton of programs that don't even close window when X pressed. Most of them ask about saving modifications. Others just hide.
But amethyst is primarily for games and they usually quit when window is closed. Therefore I approve this as you've made it optional

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 18, 2017

Member

bors r+

Member

Rhuagh commented Oct 18, 2017

bors r+

bors bot added a commit that referenced this pull request Oct 18, 2017

Merge #420
420: Automatically close game when Window close signal is sent r=Rhuagh a=Xaeroxe

Slight ergonomics improvement, helps the engine behave in a more obvious manner.
@bors

This comment has been minimized.

Show comment
Hide comment

@bors bors bot merged commit dbba4df into amethyst:develop Oct 18, 2017

3 checks passed

bors Build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Xaeroxe Xaeroxe deleted the Xaeroxe:auto-close branch Oct 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment