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 / Tier 2 end program?

Author
Message
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 1st Jan 2016 18:09
Hello, my first post here.

I know that in Tier 1 (AKA BASIC language) I can call program to end prematurely with END command. However, BASIC limits my abilities (And I am used to C++ anyway, so I tend to write "incorrect" BASIC programming and have to go and change them away from C++ style syntax...) and I have been working on Tier 2 program.

However, here is the question. I seem to be unable to find a way to make the program end without closing the window. I tried to look over documentation, but I found no Tier 2 equivalent of END. Reason why I want this, is because I want my program to check during initialization that everything checks out (for example, that the map file is valid/exists) and quit if something goes wrong. Preferably also show an error message to the user, but for now just being able to close down the file would be good. I can always have it write into error log file.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 1st Jan 2016 18:49
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jan 2016 18:52
Here are extracts from how I handle that (and other stuff). This is a project for demonstrating ways to lots of things. Not yet tested with the latest V2 16, but it worked with V2 14. Obviously, there are lots of other files included, but the main template files show how I found out how to shut down an app in Tier 2.

The header file:


The main code file:


I keep meaning to finish the full tutorial and post it, but just keep not having time.
Cheers,
Ancient Lady
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jan 2016 18:54
Funny! george++ referenced my earlier post of similar information.
Cheers,
Ancient Lady
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 1st Jan 2016 20:04
Thanks, will look over them.
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 1st Jan 2016 20:25
Hmm, I thought about this. Do you think this might work?

I changed this:



To


With current loop function looking like this:

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jan 2016 21:12
No, that won't work. You are not supposed to call App.Loop() directly and you cannot change the return value to boolean.

The basic engine controls calling the Loop() method.

Putting a While loop in agk::Loop() is also a bad idea.

The way Tier 2 works is somewhat different from Tier 1.

In Tier 1, you can call Sync() anywhere you want and it will update all user and device inputs and display and physics and such.

In Tier 2, the agk::Sync() call updates display stuff and physics (I think). But it the user and device inputs are updated once each agk::Loop() call.

That is why you end up using a state machine to handle stuff (as my example does).
Cheers,
Ancient Lady
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 1st Jan 2016 21:24
Forgot to mention that the part I said I changed was in core.cpp, so while is already there.

So this is in core.cpp


And changed to what I posted, with template.h looking like this:


And the Loop looking like this in template.cpp


Main reason for this change was that in core.cpp call for App.Loop() happens alone as long as !agk::IsCapturingImage() is true. So adding simple return value to change is to keep the while loop going in core.cpp seemed to be logical.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Jan 2016 22:41
I wouldn't recommend editing Core.cpp.

Especially because you would have to remember to keep making the same changes for every update the happens.

You're better off handling exiting in template.cpp something along the way I showed.

Having said that, your proposed code will probably work.
Cheers,
Ancient Lady
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 2nd Jan 2016 10:56
Hmm, alright, I try to take a look at your code. It looks little bit too big/messy for my own tastes, but that might be more because I don't understand AppGameKit enough. Still, thanks.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jan 2016 18:56
Messy? Too big?

It is set up to deal with multiple compiler environments. The code is designed to be used on all platforms without having to edit the files for each. That is what the '#ifdef' bits are for. (FYI, I've been doing C++ coding for more than 20 years. I believe in heavy commenting. You never know when you have to go back to something you haven't looked at in years. Or have someone in the future have to deal with your code.)

This was an example of how to use state machines to deal with the the Tier 2 handling of the Synch() command. In Tier 2, when you call 'agk::Sync()', it updates displays and physics but not user and device inputs. Those are updated once per app::Loop() execution by the AppGameKit engine.

In Tier 1, you can do something like this and actually get to the print statement:


In Tier 2, this leaves your app completely hung, you will never get to the Print statement:



The important bit for closing the app on demand is this method:


Add this to your template.h file:


Then, you call 'closeThisApp()' somewhere in your app::Loop() when you are ready to close the application.

The Windows 'PostQuitMessage(0)' version is the event that is captured in Core.cpp when it does this check '(msg.message == WM_QUIT)'.

In Windows, when you close an application by clicking on the 'X' in the upper right of the window, that is the message being intercepted in Core.cpp.

My code example shows how to generate that message to be caught by the AppGameKit engine. This then lets the engine do whatever it needs to clean up and close the application.

If you think that you are only ever going to code your app for the Windows program, skip adding the stuff I showed and just call 'PostQuitMessage(0)' when you want it to end. My example (and this is how I do it in my apps) is set up for dealing with compiling the same code files in the multiple environments supported by AGK.
Cheers,
Ancient Lady
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 2nd Jan 2016 19:39
At the moment I am entirely focusing on creating a program for windows. Thanks for the snippets, they cleared up the correct parts a lot.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jan 2016 20:32
Glad to help. Happy Programming!
Cheers,
Ancient Lady
Mandemon
8
Years of Service
User Offline
Joined: 1st Jan 2016
Location: Finland
Posted: 4th Jan 2016 08:42
Right, some reporting.

After messing with the code and getting the main menu up, I noticed that the shutdown failed. After some more messing, I found that it's the #ifdef parts. Don't know why they are messing the code, but I managed to fix it by simply removing them and ONLY using PostQuitMessage(0) in the closeThisApp(). Correct me if I am wrong, but this is only for Windows builds, correct?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 31st Jan 2016 22:44
My files are set up to compile in all of the environements. That is what the '#ifdef' bits are for.

It looks like the newer versions of AppGameKit don't automagically define 'AGKWINDOWS' anymore.

You can add that (and any other defines that you want to catch) in the 'Configuration Properties -> C/C++ -> Preprocessor' page reached by right clicking on the project in MS VS and selecting 'Properties' from the options.

Once I get all my other environments up to date, I'll check to see if the other defines are present or missing.
Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-04-19 21:06:08
Your offset time is: 2024-04-19 21:06:08