Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Application termination (Tier2)

Author
Message
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 7th Jan 2015 19:43 Edited at: 7th Jan 2015 19:43
Do you have any idea of how I can exit an application when the user presses a virtual button?
ie:
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 7th Jan 2015 19:53
In the bottom of your code create a label called QuitGame: or similar. Then in your button press, do a GoTo QuitGame.

That should work. And you can under your label to cleanup if you need to.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 7th Jan 2015 22:13 Edited at: 7th Jan 2015 23:25
Thanks Fluorescent for your advice but I cannot imagine how this can be implemented in C++
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 8th Jan 2015 09:04
Oops! Sorry didn't see that you where using C++.
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 8th Jan 2015 09:12
The quick and hacky way of doing this is simply to call std::exit(0), which will terminate execution immediately. However it wont necessarily do any cleanup, and so is not good practice.

Personally in my own projects (and I will admit this is AppGameKit V1 - so I don't know if it still applies the same to AppGameKit V2), I prefer to change the definition of the app class so that Loop() returns a bool. You can then modify each template to use the return value of Loop to decide whether to exit or not. This has to be done slightly differently for each platform, but on Windows, it would simply mean assigning the result of Loop to bExitLoop in Core.cpp. I hope that helps.

george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 8th Jan 2015 18:16
Quote: "You can then modify each template"

I suppose you suggest me to modify the Core.cpp file from this:


to this:


Oh I missed this point. Surely it helps! Thanks a lot
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 8th Jan 2015 19:11
Great, looks like you've got the Windows one sorted out. Just bear in mind that the code will be different for the other platforms, if you're planning on porting to Android etc.

Anyhow glad it helped . Let me know if you run into problems on any of the other platforms.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Jan 2015 00:54 Edited at: 11th Jan 2015 00:56
This is the code I use to exit my Tier 2 WIP:


You just work out something that checks somewhere in app::Loop for your exit button and then call the above function (which is defined in template.h like this):


The code above also shows how you can use the same header/code files for all AppGameKit supported platforms.

Cheers,
Ancient Lady
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 11th Jan 2015 07:14
Excellent solution Ancient Lady! thanks
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 11th Jan 2015 09:07
That's a nice solution AL. Out of interest, is app::End() called if you do that? Also you can remove the ifdefs from the constructor and destructor as Paul has confirmed that the memset is no longer needed.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Jan 2015 20:47
Lucas, I did see Paul's confirmation of that. I just haven't made the changes in my code, yet. The code I posted was pretty much what I used in V1.

I based the 'closeThisApp' code on what happens when app::End is called. At least that is what I remember doing with this over a year ago.

I will have to revisit this and see if there are any changes in V2 that I need to take into account.

Cheers,
Ancient Lady
unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 12th Jan 2015 16:48
Hey guys, I am under the impression that a "quit function" is not recommended (or maybe allowed) on all platforms? Certainly for the desktop platforms, but not mobile?
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 12th Jan 2015 16:58
Actually you don't need a "quit" function due to the design of the new OS.
Just press the 'home' button on your phone and the application will be removed from your memory resources when the OS will decide for this (Win 8.xx series) or when the user will remove the application from the task list (Android and Apple?)
unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 12th Jan 2015 17:00
Oh okay, wasn't aware Windows did this as well. Have never coded for Metro.

And yes, that's my point for mobile. I believe Apple *might* even reject an app with a "quit" function.

Using AppGameKit v2 T1 + T2!
Systems: Primary: Mac OS X 10.10
Secondary: Windows 7
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 12th Jan 2015 18:17
That is ONLY true for Memtro apps, which can't produce with AppGameKit anyway.

Onwards and sometimes upwards
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Jan 2015 03:48
Yes, both iOS and Android deprecate a 'Close' button.

I have my code set up so that I can enable/disable this button in a config file.

Personally, and because I don't want assume that things are cleaned up as in latest iOS, I like a way to explicitly close an application.

If Google or Apple don't like the button, easy to fix and resubmit.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-05-06 04:16:25
Your offset time is: 2024-05-06 04:16:25