[C++] GUI element destruction

Started by
0 comments, last by Bearhugger 13 years, 7 months ago
Game   Session      In_Game_Menu_GUI          load_button


In my game I have a Game class which handles high level stuff relevant to the game (including manipulating the Session object) and a Session class which represents a session of gameplay. Session holds all game data that should be re-read from file if a new game is started. There is an in-game menu (In_Game_Menu_GUI) that has options like resume, load game, save game, exit. The load game button pushes an event notification to the Screen Event Manager which notifies anyone who has registered for BUTTON_UP. My problem is that before the notification function called by the button is finished, the session has already re-read all its data, which includes the button itself.

I'm looking for an elegant solution to this problem. I've thought of some things:

- Set a bool e.g. load_game to true when notified of the load game button's MOUSE_UP event, instead of re-reading the session data straight away. This is the nicest solution to me but still seems a bit hacky for some reason...

- Move the In_Game_Menu_GUI to the Game class so that it is only read once and hence never has to be destroyed when loading games. My problem with this is that the Session data handles all session-related data and the Game class only needs to have access to Session's functions like Load(), Save(), New(), Delete(), Pause(), etc. There are two other GUI classes in Session that I'd want to move if I moved In_Game_Menu_GUI as well... but I don't like the idea of having classes in Game that logically belong in Session.

Any advice would be appreciated. :)

Cheers.

Advertisement
Have your heard of the document-view paradigm? Many popular GUI tookits encourage it. (MFC and Cocoa enforces it, and WPF does it to some extent by design.)

The "view" displays and modifies the document, and the document is just data and should just be mostly a bunch of get/set accessors. Both entities are independent. From my understanding of your case, (tell me if I'm off) the session would correspond to the document because it seems to handle and store the data you load and save, and the GUI is obviously the view.

Why I'm bringing this up is because, according to the paradigm, the document and the view are separated entities, and one does not belong to the other. So, I don't think your GUI logically belongs to the session. Your second solution seems to be the way to go.

I'm really not the kind to blindly follow conventions and coding standards if I don't see the point, but the document-view design has served me well in game design so I suggest following it.

Of course, like I said, I haven't seen your code so it might be more complicated then that in your case.

This topic is closed to new replies.

Advertisement