Game Development Community

Alpha2 1.1 setLifetime()

by NEOK · in Torque Game Builder · 01/05/2006 (6:28 am) · 2 replies

I wonder if this bug is fixed in Alpha2 because I'm getting the same problem still.

Here's my code.
$WORLD_WIDTH = 76;
$WORLD_HEIGHT = 136;

datablock t2dImageMapDatablock(db_Question)
{
	imageMode = full;
	imageName = "~/client/images/misc/Question";
	filterPad = true;	
};

function testCreateAni(%dbName , %xy,%time)
{
	
	%sampleAni = new t2dStaticSprite() { scenegraph = t2dScene; };
	%sampleAni.setPosition(%xy);
	%sampleAni.setSize( "10 10" );
	%sampleAni.setImageMap( %dbName );
	%sampleAni.setLayer(0);
	%sampleAni.setLifeTime(%time);
}

function test()
{
	for(%i=0; %i<100; %i++)
	{
		%x = getrandom(-($WORLD_WIDTH/2),$WORLD_WIDTH/2);	
		%y = getrandom(-($WORLD_HEIGHT/2),$WORLD_HEIGHT/2);	
		%time = getrandom(1,5);	
		testCreateAni(db_question,%x SPC %y,%time);
	}
}

I've just tested spawning 100 t2dStaticSprite objects across the screen when test() is called. Those sprites should be removed at least 5 sec later. But occasionaly some objects hang on like this.

cfs3.blog.daum.net/upload_control/download.blog?fhandle=MDRLV0lAZnMzLmJsb2cuZGF1bS5uZXQ6L0lNQUdFLzAvMS5qcGcudGh1bWI=&filename=1.jpg
on WindowsXp.

#1
01/05/2006 (8:13 am)
No, it has not been fixed. It's a floating point precission error.

Go to line 4094 in t2dSceneObject.cc and change
// Reduce Lifetime.
setLifetime( getLifetime() - elapsedTime );

to

// Reduce Lifetime.
mLifetime -= elapsedTime;

and it will work.
#2
01/05/2006 (10:04 am)
I posted this on a related thread but here it is again...

Instead of targetting that specific function, I looked at the "setLifetime()" function and the check for lifetimeactive is bad so I changed that function to...
void t2dSceneObject::setLifetime( const F32 lifetime )
{
    // Usage Flag.
    mLifetimeActive = mGreaterThanZero( lifetime );

    // Is life active?
    if ( mLifetimeActive )
    {
        // Yes, so set to incoming lifetime.
        mLifetime = lifetime;
    }
    else
    {
        // No, so reset it to be safe.
        mLifetime = 0.0f;
    }
}
... and all appears well. If you can see any problem with this then please shout as I'm a little tired over here but it does seem correct.

- Melv.