#1 Crossbones+ - Reputation: 924
Posted 02 September 2012 - 05:58 AM
This is just a quick question but it has been bugging me a while. I have a GameEngine class (probably should be renamed to something less Grande). I have it set so that, before it does all the standard stuff like deleting pointers, destroying bitmaps, it saves the current game. Snippet below:
[source lang="cpp"]GameEngine::~GameEngine(void){ _SaveData("GameData.txt", a_PlayerOne->f_GetScore(), a_PlayerTwo->f_GetScore()); // For every new/BITMAP*, there must be a matching delete/destroy. delete a_Grid; delete a_PlayerOne; delete a_PlayerTwo; destroy_bitmap(a_PlayerO); destroy_bitmap(a_PlayerX); // TODO: (Shape that appears underneath cursor /*if(shapeCursor != NULL){ destroy_bitmap(shapeCursor); }*/ destroy_bitmap(temp); // TODO: destroy_bitmap(a_Buffer);}[/source]
Is this the correct thing I should be doing, or should I make an explicit call to it in the code, before the destructor is run? Are there any dangers of leaving it until the class destructs?
Regards,
Stitchs.
#2 Members - Reputation: 5802
Posted 02 September 2012 - 06:45 AM
Another problem is the hard-coded filename. If you wanted to make it more flexible so you could save the game somewhere else, you would need to pass the filename as an argument, but the destructor doesn't take arguments. This is another indication that saving should be done in a method, not the destructor.
#3 Moderators - Reputation: 6636
Posted 02 September 2012 - 07:05 AM
On another note, identifiers beginning with an underscore followed by a capital letter are reserved for the implementation. Using such identifiers in your own code can cause problems on different platforms.
#4 Crossbones+ - Reputation: 924
Posted 02 September 2012 - 01:15 PM
I'll move into implementing some sort of close-down function that is called independently of the destructor.
Regards,
Stitchs
#5 Members - Reputation: 336
Posted 02 September 2012 - 04:02 PM
Edited by theark, 02 September 2012 - 05:23 PM.
My qualifcations are not here to showcase, but for those I answer and ask, to get a better idea on my knowledge.
BCS Level 2 Certificate for IT Users (ECDL Part 2)
OCR Level 2 National Award in Business
Level 2 First Diploma in Media
Level 3 Diploma in Games Design and Development Extended
BSc Hons in Computer Games Programming (Current - 1st Year)
#6 Marketplace Seller - Reputation: 8937
Posted 02 September 2012 - 04:21 PM
(Corrected, to avoid potential confusion from the missing word)As its already been pointed out, if I was to use your class, I would not expect when it went out of scope/or I deleted it, that it would save a game file.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#7 Members - Reputation: 336
Posted 02 September 2012 - 05:22 PM
(Corrected, to avoid potential confusion from the missing word)
As its already been pointed out, if I was to use your class, I would not expect when it went out of scope/or I deleted it, that it would save a game file.
Thanks, must have missed that when reading it back.
My qualifcations are not here to showcase, but for those I answer and ask, to get a better idea on my knowledge.
BCS Level 2 Certificate for IT Users (ECDL Part 2)
OCR Level 2 National Award in Business
Level 2 First Diploma in Media
Level 3 Diploma in Games Design and Development Extended
BSc Hons in Computer Games Programming (Current - 1st Year)






