en:toolworks:docs:apparatus:deferred

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:toolworks:docs:apparatus:deferred [2022/05/29 18:26] – [Removing Traits] vladiusen:toolworks:docs:apparatus:deferred [2022/06/01 20:05] vladius
Line 18: Line 18:
 ====== Removing Traits ====== ====== Removing Traits ======
  
-Removing Traits can also be deferred in a quite similar fashion. Here's an example which removes a "buffed" status from the units, when expiring:<code cpp>+Removing Traits can also be deferred in a quite similar fashion. Here's an [[appi>struct_t_subject_handle.html#a56e0ae342a44051765f2a784718c188d|API]] usage example which removes a "buffed" status from the units, when it'expiring:<code cpp>
 SolidChain->OperateConcurrently([DeltaSeconds](FSolidSubjectHandle Unit, FBuffed& Buffed) // Process the selected units in a parallel fashion. SolidChain->OperateConcurrently([DeltaSeconds](FSolidSubjectHandle Unit, FBuffed& Buffed) // Process the selected units in a parallel fashion.
 { {
Line 29: Line 29:
 </code> </code>
  
 +There is also a possibility to remove all the traits altogether. In a deferred fashion of course. This is just a matter of calling the corresponding [[appi>struct_t_subject_handle.html#a71c1b5b8374a70ed9371d102241533a2|method]] as in here:<code cpp>
 +Unit.RemoveAllTraitsDeferred();
 +</code>
 +
 +====== Spawning Subjects ======
 +
 +Not only traits can be added or removed in a deferred fashion but the whole Subjects can be spawned and despawned this way. So, if you have multiple units spawning a projectile when they're charged, you could do it like so:<code cpp>
 +SolidChain->OperateConcurrently([Mechanism, DeltaSeconds](FSolidSubjectHandle Unit, FCharging& Charging, FDamageDealer& DamageDealer)
 +{
 + Charging.Timeout -= DeltaSeconds;
 + if (Charging.Timeout <= 0.0f)
 + {
 + Mechanism->SpawnDeferred(FProjectile{DamageDealer.Power}); // Spawn a new subject with an FProjectile trait.
 + }
 +});
 +</code>
 +
 +====== Despawning Subjects ======
 +
 +The process of destroying a Subject is quite analogous. Kill all units once their health is zero or below. Just do something like:<code cpp>
 +SolidChain->OperateConcurrently([](FSolidSubjectHandle Unit, FHealth& Health)
 +{
 + if (Health.Level <= 0.0f)
 + {
 + Unit.DespawnDeferred();
 + }
 +});
 +</code>
  
  • en/toolworks/docs/apparatus/deferred.txt
  • Last modified: 2022/06/08 22:06
  • by jispar