Is there a way to find all objects of a specific object type?
by Ron Barbosa · in Torque X 2D · 04/09/2010 (9:06 pm) · 2 replies
I'm working on item drop right now, and I wanted to see if there was a way for me to leverage the TorqueObjectType field associated with each scene object.
Basically I want an array (or List...it doesn't matter) of all objects that have the object type "droppable" in their type list.
I know that I can test object types, but in the case of item drop, I don't have the item. I want to create the item from a list of eligible candidates (the droppables).
Is there a way to query the object database for all objects of a specific type?
Thanks
--RB
Basically I want an array (or List...it doesn't matter) of all objects that have the object type "droppable" in their type list.
I know that I can test object types, but in the case of item drop, I don't have the item. I want to create the item from a list of eligible candidates (the droppables).
Is there a way to query the object database for all objects of a specific type?
Thanks
--RB
#2
Thanks, Henry...I was hoping the engine had some collection of objects by type that I could quickly query.
I'm not a huge fan of looping over objects in the database.
One thing I had considered after I posted the message was writing an OnRegister delegate that does a similar bit mask matching and organizes objects into a collection by group (either a hash or a dictionary).
That would allow me to query for a list of objects that match any type whenever I need to (without having to iterate). It's a bit cumbersome in that I have to remember to add this custom registration delegate to each scene object, but it might help performance.
I only need this for one type so far (and only a few scene templates use that type). Maybe I'll start by only applying the custom delegate to those objects that I want to organize for later processing.
I'll post what I find/implement here.
Thanks again for the answer, Henry!
--RB
04/09/2010 (10:25 pm)
Got it!Thanks, Henry...I was hoping the engine had some collection of objects by type that I could quickly query.
I'm not a huge fan of looping over objects in the database.
One thing I had considered after I posted the message was writing an OnRegister delegate that does a similar bit mask matching and organizes objects into a collection by group (either a hash or a dictionary).
That would allow me to query for a list of objects that match any type whenever I need to (without having to iterate). It's a bit cumbersome in that I have to remember to add this custom registration delegate to each scene object, but it might help performance.
I only need this for one type so far (and only a few scene templates use that type). Maybe I'll start by only applying the custom delegate to those objects that I want to organize for later processing.
I'll post what I find/implement here.
Thanks again for the answer, Henry!
--RB
Torque 3D Owner Henry Shilling
Smokin Skull
ulong bitmask = 0; List<T2DSceneObject> _items = TorqueObjectDatabase.Instance.FindRegisteredObjects<T2DSceneObject>(); TorqueObjectType bonus = TorqueObjectDatabase.Instance.GetObjectType("nme"); bitmask = bonus.Bits; bonus = TorqueObjectDatabase.Instance.GetObjectType("BonusPickup"); bitmask |= bonus.Bits; bonus = TorqueObjectDatabase.Instance.GetObjectType("nme_bullet"); bitmask |= bonus.Bits; for (int i = 0; i < _items.Count; i++) { if ((_items[i].ObjectType.Bits & bitmask) != 0) _items[i].MarkForDelete = true; }So I wanted to get all the objects of a type I made. The FindRegisteredObjects only finds types like T2DSceneObject T2DAnimation etc. So I grab all the objects, and using the Bits bitmask I can sort out the ones I want. This is also why you can only have 32(64?) different types, they are all stored as bit flags.
So I get all the bitmasks for all my types, or them together into my bitmask then kill all the ones that match.