Game Development Community

Is RegisterObject slow ?

by Stephane Savioz · in Torque Game Engine · 10/13/2005 (4:33 am) · 4 replies

I have a bunch of 20 missiles that I want to launch from a turret.

I want those missiles to show up on screen simultaneously. (like in picture B below)
For some reason that I ignore, they appear one after one (see picture A below)


www.savioz.ch/garagegames/ml.jpeg


Here is the code :


for(int i=0; i<mMissileNB; i++)
	{
		mMissile[i] = new Projectile();				
		mMissile[i]->onNewDataBlock( mDataBlock->ProjectileData );

		if(mMissile[i]->registerObject() == false)
		{
			Con::warnf(ConsoleLogEntry::General, "Could not register projectile data for projectile of class: %s", mMissile[i]->getDataBlock()->getName());
			delete mMissile[i];
			mMissile[i] = NULL;
		}
	}

Maybe the registerObject() takes time ?
What can I do to have my missiles showing up simultaneously ?

#1
10/13/2005 (8:19 am)
I would do something more like this
// Create your missiles and load the objects
for(int i=0; i<mMissileNB; i++)   
{      
   mMissile[i] = new Projectile();                  
   mMissile[i]->onNewDataBlock( mDataBlock->ProjectileData );      
}

// now rip thought them and register
for(int i=0; i<mMissileNB; i++)   
{      
   if(mMissile[i]->registerObject() == false)      
   {         
      Con::warnf(ConsoleLogEntry::General, 
               "Could not register projectile data for projectile of class: %s", 
               mMissile[i]->getDataBlock()->getName());         
      delete mMissile[i];         
      mMissile[i] = NULL;      
   }   
}


The reason is the onNewDatablocks will load your objects, that is what realy takes the time. So first you create and load your objects. Then you register them all, instead of doing each one individualy.

Edit: Friggin Formating.
#2
10/13/2005 (8:36 am)
Out of curiosity, why aren't you doing this in script? It takes care of all the work for you, and 20-ish objects isn't going to be a big issue at all performance wise.

The call there for "onNewDataBlock()" really accompishes nothing, not sure why you are using it. Instead you should be assigning the datablock directly (since you've elected to do this in code--it's better done in script). onNewDataBlock() is a callback for when a datablock has been assigned, not for assigning datablocks.
#3
10/13/2005 (10:47 am)
The reason you see stuff coming in, incidentally, is because it takes a little time for the networking to catch up. It can only fit so many new items in a single packet.
#4
10/13/2005 (11:32 am)
Why am I doing that in C++ ? It is because I want to learn C++ also.

So far I've done a lot with this awesome engine and a demo of my game will come soon.

thanks for the answers...