en:toolworks:docs:apparatus:iterating

This is an old revision of the document!


Iterating

In order to implement your actual Mechanic logic you have to be able to process all of the Filter-matching Subjects (and Subjectives, which are in turn - Subjects). For the purpose of effectiveness and consistency this is not done directly but via Chains. You iterate those Chains iterating all the Subjects and Subjectives inside them.

Chains are iterated with the help of Cursors. Those are very much like container iterators. Multiple Cursors are available but this is more of a multi-threading future-proofing. For now, you should really use a single default Cursor only.

Your basic loop is quite simple. It’s just a while statement with a single condition:

while (Chain.BeginOrAdvance())
{
  ...
}

Inside this loop you can implement some actual logic. Using the Subject's direct or Chain's utility methods:

while (Chain.BeginOrAdvance())
{
  FSubjectHandle Subject = Chain.GetSubject();
  UMyDetail* MyPosition = Chain.GetDetail<UMyDetail>();
  FMyTrait   MyVelocity;
  Chain.GetTrait(MyVelocity);
  MyPosition->X += MyVelocity.VelocityX * DeltaTime;
  MyPosition->Y += MyVelocity.VelocityY * DeltaTime;
  ...
}

  • en/toolworks/docs/apparatus/iterating.1623947373.txt.gz
  • Last modified: 2021/06/17 19:29
  • by vladius