Console fix, name suggestion

Kali

10-04-2008 20:53:46

QuickGUIWidget.cpp:76

- TextBox* newTextBox = dynamic_cast<TextBox*>(_createChild(mInstanceName+".ChildTextBox" + Ogre::StringConverter::toString(mItems.size()),TYP$
+ TextBox* newTextBox = dynamic_cast<TextBox*>(_createChild(generateName(TYPE_TEXTBOX), TYPE_TEXTBOX));

The problem with the original code is that mItems.size() does not guarantee a unique name.

Supose you have a max of 30 lines, when you fill up the console (add line31) nr1 is dropped, the size is decreased a second nr30 is generated which results in a trap.

And I was thinking, generateName is quite inneficiënt since it will always try to guess the same name first. This function could definitely benefit from a random generated name or better yet no name at all, that would make the name Lookup for the widgets you do provide a name for faster aswell. I'd say put the widget with a name in the front of the childwidgets array and those without a name at the back and stop a name lookup when you find a widget without a name.

Do you want this ?

kungfoomasta

10-04-2008 22:18:30

Oops. Usually I create a counter and just increment it and use it to create a name, I guess I forgot about that method when writing that code.

I don't think name lookups will occur very frequently, and even if they were, it isn't any worse than searching for a scene node by name, right?

The idea behind generation of names comes from the Visual Studio winforms editor. On the UI you drag a label onto the window and a label it automatically created with default values, and the name "Label1". The next will be "Label2", and so on. If you deleted "Label1" and created a new Label, it will have the name "Label1". Removing names is doable, but it doesn't feel right having widgets without names. All objects should have some kind of lookup ID, and thats what the names main purpose is.

Kali

11-04-2008 00:34:19

Well the reason I brought the inefficiency up here is that when you add line 100 to the console, the first 99 names that are generated will be rejected and this every time you add a line, it seemed like kind of a waste certainly if you were to create consoles with thousands of lines. But a counter would do just fine.