Namespace: object

.evtTools. object

Tools related to objects, for events generated code.


staticgdjs.evtTools.object.pickObjectsIf(predicate, objectsLists, negatePredicate, extraArg){boolean}

Filter objects to keep only the one that fullfil the predicate

Objects that do not fullfil the predicate are removed from objects lists.

Name Type Description
predicate function

The function applied to each object: must return true if the object fulfill the predicate.

objectsLists Hashtable

The lists of objects to trim

negatePredicate boolean

If set to true, the result of the predicate is negated.

extraArg *

Argument passed to the predicate (along with the object). Useful for avoiding relying on temporary closures.

Type Description
boolean true if at least one object fulfill the predicate.

staticgdjs.evtTools.object.pickOnly(objectsLists, runtimeObject)

Keep only the specified object in the lists of picked objects.

Name Type Description
objectsLists Hashtable

The lists of objects to trim

runtimeObject gdjs.RuntimeObject

The object to keep in the lists

staticgdjs.evtTools.object.twoListsTest(predicate, objectsLists1, objectsLists2, inverted, extraArg)

Do a test on two tables of objects so as to pick only the pair of objects for which the test is true.

Note that the predicate method is not called stricly for each pair: When considering a pair of objects, if these objects have already been marked as picked, the predicate method won't be called again.

Cost (Worst case, predicate being always false): Cost(Setting property 'picked' of NbObjList1+NbObjList2 objects to false)

  • Cost(predicate)NbObjList1NbObjList2
  • Cost(Testing NbObjList1+NbObjList2 booleans)
  • Cost(Removing NbObjList1+NbObjList2 objects from all the lists)

Cost (Best case, predicate being always true): Cost(Setting property 'picked' of NbObjList1+NbObjList2 objects to false)

  • Cost(predicate)*(NbObjList1+NbObjList2)
  • Cost(Testing NbObjList1+NbObjList2 booleans)
Name Type Description
predicate gdjsTwoListsTestPredicate

The predicate function is called with the two objects to compare, and an optional argument extraArg

objectsLists1 Hashtable

e.g. Hashtable.newFrom({ A: objects1 });

objectsLists2 Hashtable

e.g. Hashtable.newFrom({ B: objects2 });

inverted boolean

If inverted == true, only the objects of the first table are filtered.

extraArg *

(optional) This argument should be used to avoid declaring the predicate as a closure that would be created and destroyed at each call to twoListsTest (potentially multiple time per frame).