Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAutomatically close game when Window close signal is sent #420
Conversation
Xaeroxe
added
project: main crate
status: ready
type: improvement
labels
Oct 17, 2017
jojolepro
approved these changes
Oct 17, 2017
- You could remove the "leave on Escape"
but - You would lose the only examples where you use a key event from a state.
So its fine like that for me.
torkleyy
reviewed
Oct 17, 2017
I'm not sure if it's a good thing. Sometimes more explicitness and less magic is better.
| @@ -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.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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
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.
Show comment
Hide comment
This comment has been minimized.
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
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.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@torkleyy r? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
This removes the ability to have multiple windows. Might not be used a lot but it is possible to do. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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?
|
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? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Rhuagh
Oct 17, 2017
Member
I realize we don't have full support for that yet, but the renderer support it
|
I realize we don't have full support for that yet, but the renderer support it |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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
|
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
There's WindowId in winit but yeah, we can do that in a future PR. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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?
|
I just thought of a second issue, what if the user wants to perform some action on exit? Save data to disc or whatnot? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Xaeroxe
Oct 17, 2017
Member
@Rhuagh Then they can use the Window::Closed event they receive just before shutdown.
|
@Rhuagh Then they can use the Window::Closed event they receive just before shutdown. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Ah, it still pushes it to the state. Ok then. |
omni-viral
requested changes
Oct 17, 2017
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.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@omni-viral From an earlier conversation with @torkleyy
In addition to this all of the states' If it absolutely must be called |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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)
|
@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) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
On application creation, just have a setting "QuitOnWindowClosed=bool" |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
I like this idea, so I'll implement it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@omni-viral r? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
https://github.com/amethyst/amethyst/blob/develop/examples/04_pong/resources/display.ron |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@jojolepro Having that in configs exposed to the user doesn't quite seem right either. This should be set by the developer. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jojolepro
Oct 17, 2017
Collaborator
optionally?
I think its possible to have default values with serde in a struct that gets deserialized?
|
optionally? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
When you save a new config it will still write the default value. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Ah true, you win! |
Xaeroxe
assigned
omni-viral
Oct 17, 2017
Xaeroxe
requested a review
from
omni-viral
Oct 17, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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
|
@Xaeroxe you can make field to be skipped during serialization if it's equal to default. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
bors r+ |
Xaeroxe commentedOct 17, 2017
Slight ergonomics improvement, helps the engine behave in a more obvious manner.