Script defined "types" to speed up searching...
by Clint S. Brewer · in Torque Game Engine · 03/28/2005 (1:13 pm) · 0 replies
I'm working on some ai code and find myself doing a good deal of scanning through objects like so:
this works fine, but I feel like it must be scanning too many objects.
is there some better way to do this?
one thing I was thinking would be if script allowed you to set a dynamic script defined type for some objects
then I could define in script a $TypeMask::FoodType, and set that flag on anything that might be food.
then the engine could check agains that when deciding if the item is a candidate in the search.
seems like it would speed things up.
I realize that I can do this in code, add a new type do a rebuild etc....not hard, but if it could be done in script it would be a quicker turn around while coding.
thanks for any pointers.
%interestMask = $TypeMasks::ItemObjectType | $TypeMasks::PlayerObjectType;
initContainerRadiusSearch( %obj.position, %obj.ai_seeRange, %interestMask);
while( (%possibleInterest=containerSearchNext()) != 0)
{
if(isAwareOfObject(%obj, %possibleInterest, %obj.ai_seeFOVcos, %obj.ai_seeRange, %obj.ai_hearRange))
{
switch$( %possibleInterest.getclassname() )
{
case "AIPlayer":
//echo("saw an AIPlayer");
switch$(%possibleInterest.getDataBlock().getname() )
{
case "SheepBody":
//echo("saw another sheep");
case "ShadowBody":
//echo("saw a monster!");
}
blah blah blah etc etc so on and so forth..this works fine, but I feel like it must be scanning too many objects.
is there some better way to do this?
one thing I was thinking would be if script allowed you to set a dynamic script defined type for some objects
then I could define in script a $TypeMask::FoodType, and set that flag on anything that might be food.
then the engine could check agains that when deciding if the item is a candidate in the search.
seems like it would speed things up.
I realize that I can do this in code, add a new type do a rebuild etc....not hard, but if it could be done in script it would be a quicker turn around while coding.
thanks for any pointers.
About the author