Page 1 of 1

CEGUI Manager Class

Posted: Mon Jul 12, 2010 12:42
by CrimsonGT
So I was working on a game to kind of learn Ogre more in depth for quite a while. I recently started rewriting it from scratch to clean it up better, and along with this I decided to switch from Canvas to CEGUI. I managed to get some buttons and what not working, and it was quite a bit easier than I assumed. (Feature filled packages usually have quite a learning curve)

Anyways, I am trying to keep everything wrapped up nice and organized this go around, and I wanted to create a GUI Manager class to kind of handle everything. I am still fairly new, so these might be really stupid questions but here goes...

1) I obviously have state management in my application (login screen state, game state, etc). Im wondering if CEGUI has a feature to destroy all existing GUI elements, or if I should just destroy the CEGUI instance when changing states? The first seems much more efficient (keeping the singleton ptr for CEGUI persistent through the life of the application rather than destroying/recreating it to clean up between state switches. What would the recommendation be for this?

2) Canvas didn't really support loading layouts/schemes/etc from XML/LUA so this is a bit new to me. Is the general approach to just hardcode in the GUI elements that won't be changing, such as the main game screen, and use lua script for the others to make quick modifications? Or when using LUA, do most people just use it for everything instead of breaking it up?

3) This is more of a generic question, but as I mentioned wanting to have a little wrapper for CEGUI just for personal organization and what not, what else besides the basics (init/destroy functions, etc) would possibly be suggested as going in there? I still have some reading to do, especially since everything GUI related is revolving around the Canvas approach.

Re: CEGUI Manager Class

Posted: Mon Jul 12, 2010 21:37
by macpl
1) CEGUI::WindowManager::destroyAllWindows() works well enough for me.

As for the others, probably simply a matter of preference and/or needs. Maybe somebody else will have more to write. ;)

Re: CEGUI Manager Class

Posted: Tue Jul 13, 2010 16:31
by Jamarr
CrimsonGT wrote:1) I obviously have state management in my application (login screen state, game state, etc). Im wondering if CEGUI has a feature to destroy all existing GUI elements, or if I should just destroy the CEGUI instance when changing states? The first seems much more efficient (keeping the singleton ptr for CEGUI persistent through the life of the application rather than destroying/recreating it to clean up between state switches. What would the recommendation be for this?


I would not recommend destroying/re-initializing CEGUI; this is the least efficient and most error prone. As mentioned you can use WindowManager::destroyAllWindows() and then re-load/create the windows as needed, but is also inefficient and could be very slow for complex layouts. I would only recommend this if your memory constraints are tight. I believe one of the better methods would be to use multiple GUI sheets. You can attach all layouts associated with each screen to a different gui-sheet, and use an empty gui-sheet for times when you do not need the gui. Then just use CEGUI::WindowManager::setGUISheet to switch between them. This will sacrifice memory for performance, as is nearly always the case.

2) Canvas didn't really support loading layouts/schemes/etc from XML/LUA so this is a bit new to me. Is the general approach to just hardcode in the GUI elements that won't be changing, such as the main game screen, and use lua script for the others to make quick modifications? Or when using LUA, do most people just use it for everything instead of breaking it up?


This is almost too subjective to even comment on. If you want the ability to quickly change your screen/window layouts, I would recommend using the layout xml files as opposed to defining layouts in code; if you prefer reducing load-times, then you may want to define layouts in code. If you want the ability to quickly change/tweak your GUI functionality without having to recompile, then I would go with Lua; if you want easier debugging and less management-overhead exposing functionality to Lua, etc. then code the GUI functionality into your application. Or, mix and match as needed. It really just depends on what you want to do with your GUI.

3) This is more of a generic question, but as I mentioned wanting to have a little wrapper for CEGUI just for personal organization and what not, what else besides the basics (init/destroy functions, etc) would possibly be suggested as going in there? I still have some reading to do, especially since everything GUI related is revolving around the Canvas approach.


Most wrappers probably consists of at least initialization, destruction, and input-injection. Anything else would probably be abstraction.

Re: CEGUI Manager Class

Posted: Wed Jul 14, 2010 15:47
by CrimsonGT
Thank you so much, this was a huge help. I have never used LUA before, does it increase the memory usage substantially?