Game Development Community

Tip: don't exec() GuiEditorGui.gui until you need to

by Orion Elenzil · in Torque Game Engine · 12/06/2007 (11:36 am) · 10 replies

In stock TGE 1.3 & 1.4, I've long noticed that during startup, the engine seems to instanciate and then delete one instance of every SimObject class. I'd assumed this was part of IMPLEMENT_CONOBJECT() and just a fact of life, but Tim McClarren commented this morning that it's happening as part of initializing some in-game editor.

Sure enough,
it's due to the instanciation of a GuiControlListPopup in GuiEditorGui.gui,
which initializes its list of all GuiControls by instanciating each SimObject class, then testing the object to see if it's a GuiControl, then deleting it.

i recommend something like the following:

1. delete this line from GuiEditorGui.gui:
GlobalActionMap.bind(keyboard, "f10", GuiEdit);

2. add this to the bottom of default.bind.cs:
$gGuiEditorGuiExeced = false;
function OpenGuiEditor(%val)
{
   if (!$gGuiEditorGuiExeced)
   {
      exec("common/ui/GuiEditorGui.gui");
      $gGuiEditorGuiExeced = true;
   }
   
   GuiEdit(%val);
}

GlobalActionMap.bind   (keyboard, "alt F10", OpenGuiEditor);

this just seems like a cleaner practice, can't hurt startup times, and certainly clarifies the picture if you're trying to do something like count the number of times a class is instanciated.

#1
12/06/2007 (4:51 pm)
Thank you Orion. I killed the GUI Editor along time ago but it's good to know exactly where the performance hit was coming. Tag for laters.
#2
12/06/2007 (6:29 pm)
Thanks for the snippet mate. worked like a charm, and i did notice the slight speed increase. simple but effective.
#3
12/06/2007 (6:53 pm)
Glad to hear it worked !
#4
12/07/2007 (11:23 am)
I believe that for Stock TGE 1.5.2 the exec line should be:
exec("creator/ui/GuiEditorGui.gui");

(GuiEditorGui.gui is generally in the creator folder rather than common?)

I also commented out the similar exec line in creator/main.cs.
#5
12/07/2007 (11:34 am)
Thank Matthew.
#6
12/07/2007 (11:44 am)
Thanks for posting about this!

I also assumed that this behavior was part of IMPLEMENT_CONOBJECT() and moved on.

It is good it isn't...
#7
12/07/2007 (12:59 pm)
There is one pass of the create/delete always (?), but this change seems to delay the other two passes that are associated with the GuiEditorGui.

Thanks for posting about this. It's always been confusing to have so many odd instantiations during development. This makes the process more understandable and less random seeming.
#8
12/07/2007 (1:37 pm)
> There is one pass of the create/delete always
hm, with this change,
if i put a breakpoint in some unused SimObject constructors (in my case, say fxFoliageReplicator or TerrainBlock), they don't trigger until i actually open the GuiEditor.
#9
12/07/2007 (4:30 pm)
A loop of object construction/destruction seems to be called from SimChunk::initChunkMappings() in ChunkFile.cc, called by initGame. (TGE 1.5.2, I used WheeledVehicle, same with fxFoliageReplicator)
#10
12/07/2007 (4:35 pm)
Ah.

the sound you may want to good-naturedly imagine hearing right about now is that of someone with a TGE 1.3 codebase quietly snickering..

;)