iT2D Menu: Performance Improvement
by c4dgames · 08/13/2010 (11:32 pm) · 5 comments
In my humble experience, if you try to create a menu with iTGB, adding let's say 5 buttons, it takes almost a second to load a menu (especially on a iPod). If you have more menu, navigating them with this delay it is not ideal.
I found a simple but effective solution to it.
Edit guiBitmapButtonCtrl.cc and substitute the existing setBitmap function with the following:
By using the code above, the engine will only load the file specified in the GUI editor and it will assign the same file for the other modes: n h d i.
If you still want the "mouse hilight" effect, you have to use the following code instead of the line 16-18 above:
I don't think mTextureDepressed and mTextureInactive will ever be needed on iDevices.
Thanks,
Selvin
I found a simple but effective solution to it.
Edit guiBitmapButtonCtrl.cc and substitute the existing setBitmap function with the following:
void GuiBitmapButtonCtrl::setBitmap(const char *name)
{
mBitmapName = StringTable->insert(name);
if(!isAwake())
return;
if (*mBitmapName)
{
char buffer[1024];
char *p;
dStrcpy(buffer, name);
p = buffer + dStrlen(buffer);
mTextureNormal = TextureHandle(buffer, BitmapTexture, true);
//just use normal for now, let's see if performance improves
mTextureHilight = mTextureNormal;
mTextureDepressed = mTextureHilight;
mTextureInactive = mTextureNormal;
}
else
{
mTextureNormal = NULL;
mTextureHilight = NULL;
mTextureDepressed = NULL;
mTextureInactive = NULL;
}
setUpdate();
}From what I understood, every time the engine load a menu, it will try to load for each button 5 files: the file name that you specify in the GUI editor and the equivalent _n _h _d _i. For instance, in our game, we didn't have any of the other 4 files, therefore the engine was accessing the "disk" 20 times unnecessarily (4 times x 5 buttons).By using the code above, the engine will only load the file specified in the GUI editor and it will assign the same file for the other modes: n h d i.
If you still want the "mouse hilight" effect, you have to use the following code instead of the line 16-18 above:
//mTextureHilight = mTextureNormal; dStrcpy(p, "_h"); mTextureHilight = TextureHandle(buffer, BitmapTexture, true); mTextureDepressed = mTextureHilight; mTextureInactive = mTextureNormal;
I don't think mTextureDepressed and mTextureInactive will ever be needed on iDevices.
Thanks,
Selvin
About the author
Founded in 2009, C4D Games is a young team made of individuals who have a great experience in different professional fields. Their target is to develop innovative products and games with a creative and artistic spirit.
#2
You are right, I can see in SOME cases you need them.
The ideal solution is adding in the General section of the GuiBitmapButtonCtrl (GUI Editor) three checkboxes: Hilight, Depressed, Inactive. Only if ticked the engine will try to load the correspondent file otherwise will just assign the normal mode.
Something like that (in pseudo code):
if(Hilight is true)
dStrcpy(p, "_h");
mTextureHilight = TextureHandle(buffer, BitmapTexture, true);
else
mTextureHilight = mTextureNormal;
I can see it will be quite useful for the owners of iT2D. I almost went for a completely different route in trying to improve our menu, very slow on iPod. I was thinking to create them as level and load them in the sceneWindow2D. But this approach defeats the purpose of having an easy to use GUI Editor so luckily I found this other solution proposed above.
Selvin
08/15/2010 (12:16 pm)
I didn't mention it, will do it. Thanks for the suggestion.You are right, I can see in SOME cases you need them.
The ideal solution is adding in the General section of the GuiBitmapButtonCtrl (GUI Editor) three checkboxes: Hilight, Depressed, Inactive. Only if ticked the engine will try to load the correspondent file otherwise will just assign the normal mode.
Something like that (in pseudo code):
if(Hilight is true)
dStrcpy(p, "_h");
mTextureHilight = TextureHandle(buffer, BitmapTexture, true);
else
mTextureHilight = mTextureNormal;
I can see it will be quite useful for the owners of iT2D. I almost went for a completely different route in trying to improve our menu, very slow on iPod. I was thinking to create them as level and load them in the sceneWindow2D. But this approach defeats the purpose of having an easy to use GUI Editor so luckily I found this other solution proposed above.
Selvin
#3
09/13/2010 (2:46 am)
I've tended to just comment out all states but normal and depressed. :)
#4
09/17/2010 (10:04 pm)
Good Work ;-)
#5
i don't know how to use it :(
10/22/2010 (10:37 am)
hi c4dgames, can you provide some simple GUI tutorials?i don't know how to use it :(

Associate Sven Bergström
Luma Arcade
PS : Games with normal buttons NEED depressed and inactive. "Play Online" button for example, it needs to be able to be inactive if you have no internet right? Especially on mobile ;)