Triggers misbehaving
by Patrick Shaw · in Torque Game Builder · 12/02/2007 (6:33 am) · 4 replies
Hi all,
I am experiencing some strange trigger (mis)behaviors. I have a large level scene with a lot of objects. To improve performance, I am setting up "culling triggers" - when the player is in the trigger, objects are enabled. When the player is not in the trigger, objects are not enabled. It mostly works and my framerate has gone from 25 to 50fps. However, I am getting some weird crashes and object flickering.
Here is the logic I'm using:
1) Objects have two flags "cullee" (can be culled) or "culler" (i.e. the player)
2) On enter, "cullee" objects are added to a simset for that trigger
3) On enter, the "culler" object enables all objects in the simset.
4) On exit, the "culler" object disables all cullees within the simset.
This works 80% of the time, but I have two strange problems:
1.) Creating the simset in the "onlevelLoaded" callback crashes the game. I've done this in other behaviors without any problem.
2.) At certain spots within the trigger relative the cullee object, the player starts firing both the "onLeave" and "onEnter" callbacks. This causes the culled objects to flash on and off.
I am most concerned about #2. Anyone have any suggestions?
Here is the behavior that I'm setting on the trigger:
I am experiencing some strange trigger (mis)behaviors. I have a large level scene with a lot of objects. To improve performance, I am setting up "culling triggers" - when the player is in the trigger, objects are enabled. When the player is not in the trigger, objects are not enabled. It mostly works and my framerate has gone from 25 to 50fps. However, I am getting some weird crashes and object flickering.
Here is the logic I'm using:
1) Objects have two flags "cullee" (can be culled) or "culler" (i.e. the player)
2) On enter, "cullee" objects are added to a simset for that trigger
3) On enter, the "culler" object enables all objects in the simset.
4) On exit, the "culler" object disables all cullees within the simset.
This works 80% of the time, but I have two strange problems:
1.) Creating the simset in the "onlevelLoaded" callback crashes the game. I've done this in other behaviors without any problem.
2.) At certain spots within the trigger relative the cullee object, the player starts firing both the "onLeave" and "onEnter" callbacks. This causes the culled objects to flash on and off.
I am most concerned about #2. Anyone have any suggestions?
Here is the behavior that I'm setting on the trigger:
if (!isObject(cullBehavior))
{
%template = new BehaviorTemplate(cullBehavior);
%template.friendlyName = "Cull objects";
%template.behaviorType = "Trigger";
%template.description = "Cull objects within the trigger's area";
}
function cullBehavior::onBehaviorAdd(%this)
{
%this.owner.EnterCallback = true;
%this.owner.StayCallback = false;
%this.owner.LeaveCallback = true;
%this.occupied = false;
}
//function cullBehavior::onLevelLoaded(%this, %scenegraph)
//{
//%this.objectSet = new SimSet();
//}
function cullBehavior::onEnter(%this, %obj)
{
echo(%obj SPC %obj.config SPC "ENTERED" );
if(!isObject(%this.objectSet))
%this.objectSet = new SimSet();
if(%obj.cullee)
{
%member = %this.objectSet.isMember(%obj);
if (!%member)
{
%this.objectSet.add(%obj);
}
%obj.enabled = %this.occupied;
}
else if (%obj.culler)
{
%this.setEnableAll(true);
%this.occupied = true;
}
}
function cullBehavior::onLeave(%this, %obj)
{
echo(%obj SPC %obj.config SPC "EXITED" );
if(!isObject(%this.objectSet))
%this.objectSet = new SimSet();
if(%obj.culler)
{
%this.setEnableAll(false);
%this.occupied = false;
}
}
function cullBehavior::setEnableAll(%this, %bool)
{
%count = %this.objectSet.getCount();
for (%i = 0; %i < %count; %i++)
{
%obj = %this.objectSet.getObject(%i);
%obj.setEnabled(%bool);
}
}About the author
#2
mattl (at) garagegames (dot) com
I would be happy to take a look at it :)
12/05/2007 (2:38 pm)
If you zip up your project and send it to me at:mattl (at) garagegames (dot) com
I would be happy to take a look at it :)
#3
12/05/2007 (7:20 pm)
Hey how big is your world exactally?
#4
Thanks! I'll shoot my project over to you.
Steven,
The world is currently 3200x1600 game units (16K x 8K pixels) in size. It was originally larger - I trimmed it down to see if I could get a performance boost. However, turns out that the world size wasn't the problem. After playing around for awhile, I found that object count was my limiting factor. I had about 300 game objects running around, about 33% of which were enemy ai related (somewhat expensive scripting-wise). Because the enemies tended to be clustered into "rooms", simple culling is very attractive. The culling triggers helped reducing the overall active object count (especially the enemy units) to around 75-100 and my frame rate jumped to about 45fps.
12/06/2007 (5:59 am)
Matt, Thanks! I'll shoot my project over to you.
Steven,
The world is currently 3200x1600 game units (16K x 8K pixels) in size. It was originally larger - I trimmed it down to see if I could get a performance boost. However, turns out that the world size wasn't the problem. After playing around for awhile, I found that object count was my limiting factor. I had about 300 game objects running around, about 33% of which were enemy ai related (somewhat expensive scripting-wise). Because the enemies tended to be clustered into "rooms", simple culling is very attractive. The culling triggers helped reducing the overall active object count (especially the enemy units) to around 75-100 and my frame rate jumped to about 45fps.
Torque Owner Kevin James
1.) TGB is unreliable sometimes. It may not be a script issue, it may be an engine issue.
2.) Have you tried using pickRect? Look it up in the TGB reference. A trigger would be ideal, but if they are unreliable, perhaps this function would be better.
3.) Some screenshots and captions might jog people's thoughts a little better. You aren't getting any feedback because no one knows what the heck is going on.
Cheers!