Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision | ||
en:toolworks:docs:apparatus:deferred [2022/05/29 18:26] – [Removing Traits] vladius | en:toolworks:docs:apparatus:deferred [2022/06/05 21:40] – 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 " | + | Removing Traits can also be deferred in a quite similar fashion. Here's an [[appi> |
SolidChain-> | SolidChain-> | ||
{ | { | ||
Line 29: | Line 29: | ||
</ | </ | ||
+ | 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> | ||
+ | Unit.RemoveAllTraitsDeferred(); | ||
+ | </ | ||
+ | |||
+ | ====== 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' | ||
+ | SolidChain-> | ||
+ | { | ||
+ | Charging.Timeout -= DeltaSeconds; | ||
+ | if (Charging.Timeout <= 0.0f) | ||
+ | { | ||
+ | Mechanism-> | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ====== 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:< | ||
+ | SolidChain-> | ||
+ | { | ||
+ | if (Health.Level <= 0.0f) | ||
+ | { | ||
+ | Unit.DespawnDeferred(); | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ====== Applying ===== | ||
+ | |||
+ | Until when? This is quite a logical question when dealing with something that is deferred by design. And the default answer is "when the time is right" | ||
+ | |||
+ | The default automatic behavior minimizes the effort and guarantees that the Deferreds get applied accordingly, | ||
+ | |||
+ | Deferreds Applicators are created explicitly, by calling the [[appi> | ||
+ | { // Start of the explicit scope. | ||
+ | auto Applicator = Mechanism-> | ||
+ | Mechanism-> | ||
+ | // Your first mechanic producing deferred operations. | ||
+ | }); | ||
+ | // The Deferreds won't be applied at this point. | ||
+ | Mechanism-> | ||
+ | // Your second mechanic producing deferred operations. | ||
+ | }); | ||
+ | // Now the Deferreds get actually applied. | ||
+ | } // End of the explicit scope. | ||
+ | </ | ||
+ | Note that the Applicator is actually introduced within its own explicit scope (the curly brace' |