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 / Destory/Generating objects - optimization

Author
Message
Daqs
8
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 30th May 2015 05:55
My question is pertaining to destroying/generating objects from the screen and as to what is the most optimized way of doing so? This question is related to Tier 2 C++.

Before I begin the question, I'd like to mention that unlike Unity3D there is only 1 set of Loop(), Begin() & End() functions in AGK. In Unity3D, all scripts have a set of those functions provided they are extended from MonoBehavior.

Question: I am creating different gamestates/scenes, one of which is the main menu which consists of buttons, background, etc. Once the gamestate changes I need to destroy the objects from the main menu and generate the new objects for the next gamestate. As I mentioned above since there is only 1 set of Loop() Begin() & End() in the entire project, I would have to change the states in Loop() which also means I will have to destory and generate objects when changing states in the Loop() function itself.

Now, that means I would have to call agk:estory() for destorying objects which will get updates every frame. Is this optimizaed way of doing stuff in AppGameKit? What about garbage collection? frame drop if there are too many objects getting deleted which gets updated every frame? also most importantly won't this result in a NULL exception since the object won't exist anymore to get destroyed since the said objects in the next frame are already destroyed in the previous frame?

Any help is appreciated. Thanks!
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 30th May 2015 07:44
for destroy objects AppGameKit have some command:

for destroy Sprite : DeleteSprite()
for destroy Image : DeleteImage()
for destroy text : DeleteText()
Daqs
8
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 30th May 2015 07:46
I know that, it doesn't answer my question. Once again, here's the question:

Once the gamestate changes I need to destroy the objects from the main menu and generate the new objects for the next gamestate. As I mentioned above since there is only 1 set of Loop() Begin() & End() in the entire project, I would have to change the states in Loop() which also means I will have to destory and generate objects when changing states in the Loop() function itself.

Now, that means I would have to call agk:: Destory() for destroying objects which will get updates every frame. Is this optimized way of doing stuff in AppGameKit? What about garbage collection? frame drop if there are too many objects getting deleted which gets updated every frame? also most importantly won't this result in a NULL exception since the object won't exist anymore to get destroyed since the said objects in the next frame are already destroyed in the previous frame?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 30th May 2015 09:30
What you should do is make use of constructors and destructors and also maybe write your own Start and Destroy functions.

You should have classes which would be the equivalent of scenes in Unity.

You'd put in the constructor whatever you need to be allocated for that scene and destroy whatever you use in that scene in the destuctor. Try to keep logic to a minimal in constructors

Note that C++ doesn't have garbage collection - the AppGameKit delete commands free up the space that AppGameKit uses for sprites, images etc but you're responsible for whatever you allocate (whatever you use new with you need to have a corresponding delete).
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 30th May 2015 17:53
this is an example code for delete objects:

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 1st Jun 2015 18:12
You would not destroy all old objects in your new gamestate over and over again.

What you want is a transition function or class which gets called only once when moving between scenes. Breaking this down further, the transition code would delete all objects from the previous scene and then load all objects needed for next scene.

Login to post a reply

Server time is: 2024-03-29 12:16:52
Your offset time is: 2024-03-29 12:16:52